Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorteicher2004-04-08 10:32:23 +0000
committerteicher2004-04-08 10:32:23 +0000
commit502738a455175780443e17b7850ff5053486b83d (patch)
tree0db1ff9c38a2b077384dc48dc3e01c583d37eb58
parentfa6149f6959010ab7d49002a340ab8051f0cdf86 (diff)
downloadeclipse.platform.text-502738a455175780443e17b7850ff5053486b83d.tar.gz
eclipse.platform.text-502738a455175780443e17b7850ff5053486b83d.tar.xz
eclipse.platform.text-502738a455175780443e17b7850ff5053486b83d.zip
allow validation in templateproposals
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java54
1 files changed, 45 insertions, 9 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java
index fb13c3173..b464e5f8b 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java
@@ -112,15 +112,8 @@ public class TemplateProposal implements ICompletionProposal, ICompletionProposa
return;
}
- int start, end;
- if (fContext instanceof DocumentTemplateContext) {
- DocumentTemplateContext docContext = (DocumentTemplateContext)fContext;
- start= docContext.getStart();
- end= docContext.getEnd();
- } else {
- start= fRegion.getOffset();
- end= start + fRegion.getLength();
- }
+ int start= getReplaceOffset();
+ int end= getReplaceEndOffset();
// insert template string
IDocument document= viewer.getDocument();
@@ -224,6 +217,42 @@ public class TemplateProposal implements ICompletionProposal, ICompletionProposa
return buffer.getString().length();
}
+ /**
+ * Returns the offset of the range in the document that will be replaced by
+ * applying this template.
+ *
+ * @return the offset of the range in the document that will be replaced by
+ * applying this template
+ */
+ private int getReplaceOffset() {
+ int start;
+ if (fContext instanceof DocumentTemplateContext) {
+ DocumentTemplateContext docContext = (DocumentTemplateContext)fContext;
+ start= docContext.getStart();
+ } else {
+ start= fRegion.getOffset();
+ }
+ return start;
+ }
+
+ /**
+ * Returns the end offset of the range in the document that will be replaced
+ * by applying this template.
+ *
+ * @return the end offset of the range in the document that will be replaced
+ * by applying this template
+ */
+ private int getReplaceEndOffset() {
+ int end;
+ if (fContext instanceof DocumentTemplateContext) {
+ DocumentTemplateContext docContext = (DocumentTemplateContext)fContext;
+ end= docContext.getEnd();
+ } else {
+ end= fRegion.getOffset() + fRegion.getLength();
+ }
+ return end;
+ }
+
/*
* @see ICompletionProposal#getSelection(IDocument)
*/
@@ -311,6 +340,13 @@ public class TemplateProposal implements ICompletionProposal, ICompletionProposa
* @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
*/
public boolean validate(IDocument document, int offset, DocumentEvent event) {
+ try {
+ int replaceOffset= getReplaceOffset();
+ String content= document.get(replaceOffset, getReplaceEndOffset() - replaceOffset);
+ return fTemplate.getName().startsWith(content);
+ } catch (BadLocationException e) {
+ // concurrent modification - ignore
+ }
return false;
}

Back to the top