Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 356139
Collapse All | Expand All

(-)src/org/eclipse/edt/ide/ui/internal/contentassist/proposalhandlers/EGLTemplateProposal.java (+40 lines)
Added Link Here
1
package org.eclipse.edt.ide.ui.internal.contentassist.proposalhandlers;
2
3
import org.eclipse.jface.text.BadLocationException;
4
import org.eclipse.jface.text.IRegion;
5
import org.eclipse.jface.text.templates.Template;
6
import org.eclipse.jface.text.templates.TemplateBuffer;
7
import org.eclipse.jface.text.templates.TemplateContext;
8
import org.eclipse.jface.text.templates.TemplateException;
9
import org.eclipse.jface.text.templates.TemplateProposal;
10
import org.eclipse.swt.graphics.Image;
11
12
public class EGLTemplateProposal extends TemplateProposal {
13
14
	private String delimiter;
15
	
16
	public EGLTemplateProposal(Template template, TemplateContext context,
17
			IRegion region, Image image, String adelimiter) {
18
		super(template, context, region, image);
19
		
20
		delimiter = adelimiter;
21
	}
22
	
23
	public String getAdditionalProposalInfo() {
24
	    try {
25
		    getContext().setReadOnly(true);
26
			TemplateBuffer templateBuffer;
27
			try {
28
				templateBuffer= getContext().evaluate(getTemplate());
29
			} catch (TemplateException e) {
30
				return null;
31
			}
32
33
			return templateBuffer.getString().replace(delimiter, "<br>");
34
35
	    } catch (BadLocationException e) {
36
			return null;
37
		}
38
	}
39
40
}
(-)src/org/eclipse/edt/ide/ui/internal/templates/EGLTemplateContext.java (-1 / +1 lines)
Lines 20-26 Link Here
20
import org.eclipse.edt.ide.core.internal.errors.ParseStack;
20
import org.eclipse.edt.ide.core.internal.errors.ParseStack;
21
import org.eclipse.edt.ide.ui.EDTUIPlugin;
21
import org.eclipse.edt.ide.ui.EDTUIPlugin;
22
import org.eclipse.edt.ide.ui.internal.CodeFormatterUtil;
22
import org.eclipse.edt.ide.ui.internal.CodeFormatterUtil;
23
import org.eclipse.jdt.internal.corext.util.Strings;
23
import org.eclipse.edt.ide.ui.internal.Strings;
24
import org.eclipse.jface.text.BadLocationException;
24
import org.eclipse.jface.text.BadLocationException;
25
import org.eclipse.jface.text.IDocument;
25
import org.eclipse.jface.text.IDocument;
26
import org.eclipse.jface.text.IRegion;
26
import org.eclipse.jface.text.IRegion;
(-)src/org/eclipse/edt/ide/ui/internal/templates/TemplateEngine.java (-5 / +12 lines)
Lines 18-29 Link Here
18
import org.eclipse.edt.ide.core.internal.errors.TokenStream;
18
import org.eclipse.edt.ide.core.internal.errors.TokenStream;
19
import org.eclipse.edt.ide.ui.EDTUIPlugin;
19
import org.eclipse.edt.ide.ui.EDTUIPlugin;
20
import org.eclipse.edt.ide.ui.internal.PluginImages;
20
import org.eclipse.edt.ide.ui.internal.PluginImages;
21
import org.eclipse.edt.ide.ui.internal.contentassist.proposalhandlers.EGLTemplateProposal;
22
import org.eclipse.jface.text.BadLocationException;
21
import org.eclipse.jface.text.IDocument;
23
import org.eclipse.jface.text.IDocument;
22
import org.eclipse.jface.text.IRegion;
24
import org.eclipse.jface.text.IRegion;
23
import org.eclipse.jface.text.ITextViewer;
25
import org.eclipse.jface.text.ITextViewer;
24
import org.eclipse.jface.text.Region;
26
import org.eclipse.jface.text.Region;
25
import org.eclipse.jface.text.templates.Template;
27
import org.eclipse.jface.text.templates.Template;
26
import org.eclipse.jface.text.templates.TemplateProposal;
27
import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
28
import org.eclipse.jface.text.templates.persistence.TemplatePersistenceData;
28
import org.eclipse.swt.graphics.Point;
29
import org.eclipse.swt.graphics.Point;
29
30
Lines 52-63 Link Here
52
	/**
53
	/**
53
	 * Returns the array of matching templates.
54
	 * Returns the array of matching templates.
54
	 */
55
	 */
55
	public TemplateProposal[] getResults() {
56
	public EGLTemplateProposal[] getResults() {
56
		return (TemplateProposal[]) fProposals.toArray(new TemplateProposal[fProposals.size()]);
57
		return (EGLTemplateProposal[]) fProposals.toArray(new EGLTemplateProposal[fProposals.size()]);
57
	}
58
	}
58
59
59
	public void complete(TokenStream tokenStream, ITextViewer viewer, int completionPosition, ParseStack parseStack, String prefix) {
60
	public void complete(TokenStream tokenStream, ITextViewer viewer, int completionPosition, ParseStack parseStack, String prefix) {
60
		IDocument document = viewer.getDocument();
61
		IDocument document = viewer.getDocument();
62
		String lineDelimiter = "\n";
63
		try {
64
			lineDelimiter =document.getLineDelimiter(0);
65
		} catch (BadLocationException e) {
66
		}
67
		
61
		Point selection = viewer.getSelectedRange();
68
		Point selection = viewer.getSelectedRange();
62
		EGLTemplateContext context = fContextType.createContext(document, completionPosition - prefix.length(), selection.y + prefix.length(), parseStack, prefix);
69
		EGLTemplateContext context = fContextType.createContext(document, completionPosition - prefix.length(), selection.y + prefix.length(), parseStack, prefix);
63
		int start = context.getStart();
70
		int start = context.getStart();
Lines 68-78 Link Here
68
			// If the template matches the prefix, then set up the necessary info and add to list of completions.
75
			// If the template matches the prefix, then set up the necessary info and add to list of completions.
69
			if (context.canEvaluate(templates[i])) {
76
			if (context.canEvaluate(templates[i])) {
70
				fProposals.add(
77
				fProposals.add(
71
					new TemplateProposal(
78
					new EGLTemplateProposal(
72
						templates[i],
79
						templates[i],
73
						context,
80
						context,
74
						region,
81
						region,
75
						PluginImages.get(PluginImages.IMG_OBJS_TEMPLATE)));
82
						PluginImages.get(PluginImages.IMG_OBJS_TEMPLATE),lineDelimiter));
76
			}
83
			}
77
		}
84
		}
78
	}
85
	}

Return to bug 356139