X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.ui%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fui%2Feditor2%2FSCLModuleEditor2.java;h=0e068d69bd3568387a8ba73fbbe1599d741e15a3;hp=05015bb0b36dfeba8cee5afa2b44d3e11bd8d527;hb=40a091212c4702e861d504e8a1d8e9c2550dfaf6;hpb=6f11a60dee43d620d500c0cf5af34a1d91c80a8b diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2.java index 05015bb0b..0e068d69b 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor2/SCLModuleEditor2.java @@ -10,6 +10,7 @@ import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.link.LinkedModeModel; import org.eclipse.jface.text.link.LinkedPosition; +import org.eclipse.jface.text.source.DefaultCharacterPairMatcher; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ST; @@ -23,6 +24,7 @@ import org.eclipse.ui.contexts.IContextService; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.IUpdate; +import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; import org.eclipse.ui.texteditor.TextNavigationAction; import org.simantics.scl.ui.editor.SCLSourceViewerConfigurationNew; import org.simantics.scl.ui.editor.completion.SCLTextEditorEnvironment; @@ -32,8 +34,17 @@ import org.simantics.scl.ui.editor2.iterator.JavaWordIterator; import com.ibm.icu.text.BreakIterator; public class SCLModuleEditor2 extends TextEditor { + + private static final char[] CHARS = new char[] { '(', ')', '{', '}', '[', ']', '<', '>' }; + + private static final String MATCHING_BRACKETS = "matchingBrackets"; + private static final String MATCHING_BRACKETS_COLOR = "matchingBracketsColor"; + private static final String HIGHLIGHT_BRACKET_AT_CARET_LOCATION = "highlightBracketAtCaretLocation"; + private static final String ENCLOSING_BRACKETS = "enclosingBrackets"; + private boolean disposed = false; protected ResourceManager resourceManager; + private DefaultCharacterPairMatcher matcher; public SCLModuleEditor2() { super(); @@ -52,6 +63,10 @@ public class SCLModuleEditor2 extends TextEditor { public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); + getPreferenceStore().setValue(MATCHING_BRACKETS, true); + getPreferenceStore().setValue(MATCHING_BRACKETS_COLOR, "192,192,192"); + getPreferenceStore().setValue(HIGHLIGHT_BRACKET_AT_CARET_LOCATION, true); + getPreferenceStore().setValue(ENCLOSING_BRACKETS, true); } @Override @@ -92,12 +107,21 @@ public class SCLModuleEditor2 extends TextEditor { protected void updatePartName() { setPartName(getEditorInput().getName()); } + + @Override + protected void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) { + matcher = new DefaultCharacterPairMatcher(CHARS); + support.setCharacterPairMatcher(matcher); + support.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR, HIGHLIGHT_BRACKET_AT_CARET_LOCATION, ENCLOSING_BRACKETS); + super.configureSourceViewerDecorationSupport(support); + } @Override public void dispose() { disposed = true; super.dispose(); resourceManager.dispose(); + matcher.dispose(); } public boolean isDisposed() {