summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepak Azad2012-02-10 05:27:51 (EST)
committer Dani Megert2012-02-10 05:27:51 (EST)
commitb8d0417ed59519a46d28cac812ad3b7393dd83e9 (patch)
tree163e5f5c761fa497dc6f600ecbfc0d5d9cbb3a39
parentf7e9c6e267deffe8ad723ad4b8c99d360e585a7b (diff)
downloadeclipse.platform.text-b8d0417ed59519a46d28cac812ad3b7393dd83e9.zip
eclipse.platform.text-b8d0417ed59519a46d28cac812ad3b7393dd83e9.tar.gz
eclipse.platform.text-b8d0417ed59519a46d28cac812ad3b7393dd83e9.tar.bz2
Fixed bug 366400: [preferences][syntax highlighting] New preference tov20120210-1027
always show enclosing brackets
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java30
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java20
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java38
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java52
-rw-r--r--org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF2
-rw-r--r--org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java68
6 files changed, 189 insertions, 21 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
index 7b4b9e6..c329c61 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/DefaultCharacterPairMatcher.java
@@ -29,7 +29,7 @@ import org.eclipse.jface.text.TextUtilities;
*
* @since 3.3
*/
-public class DefaultCharacterPairMatcher implements ICharacterPairMatcher {
+public class DefaultCharacterPairMatcher implements ICharacterPairMatcher, ICharacterPairMatcherExtension {
private int fAnchor= -1;
private final CharPairs fPairs;
@@ -107,6 +107,34 @@ public class DefaultCharacterPairMatcher implements ICharacterPairMatcher {
}
}
+ /**
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcherExtension#findEnclosingPeerCharacters(org.eclipse.jface.text.IDocument,
+ * int)
+ * @since 3.8
+ */
+ public IRegion findEnclosingPeerCharacters(IDocument doc, int offset) {
+ if (doc == null || offset < 0 || offset > doc.getLength())
+ return null;
+ try {
+ for (int offset1= offset; offset1 >= 0; offset1--) {
+ char prevChar= doc.getChar(Math.max(offset1 - 1, 0));
+ if (fPairs.contains(prevChar) && fPairs.isStartCharacter(prevChar)) {
+ IRegion match= performMatch(doc, offset1);
+ if (match != null) {
+ int matchOffset= match.getOffset();
+ int matchLength= match.getLength();
+ if ((matchOffset <= offset) && (matchOffset + matchLength > offset)) {
+ return match;
+ }
+ }
+ }
+ }
+ } catch (BadLocationException ble) {
+ return null;
+ }
+ return null;
+ }
+
/*
* Performs the actual work of matching for #match(IDocument, int).
*/
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
index 09ca2a4..b969b8f 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -14,15 +14,15 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
/**
- * A character pair matcher finds to a character at a certain document offset
- * the matching peer character. It is the matchers responsibility to define the
- * concepts of "matching" and "peer". The matching process starts at a given
- * offset. Starting of this offset, the matcher chooses a character close to
- * this offset. The anchor defines whether the chosen character is left or right
- * of the initial offset. The matcher then searches for the matching peer
- * character of the chosen character and if it finds one, delivers the minimal
- * region of the document that contains both characters.
- *
+ * A character pair matcher finds to a character at a certain document offset the matching peer
+ * character. It is the matchers responsibility to define the concepts of "matching" and "peer". The
+ * matching process starts at a given offset. Starting of this offset, the matcher chooses a
+ * character close to this offset. The anchor defines whether the chosen character is left or right
+ * of the initial offset. The matcher then searches for the matching peer character of the chosen
+ * character and if it finds one, delivers the minimal region of the document that contains both
+ * characters.
+ *
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcherExtension
* @since 2.1
*/
public interface ICharacterPairMatcher {
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java
new file mode 100644
index 0000000..f5c114b
--- /dev/null
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcherExtension.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright (c) 2012 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jface.text.source;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+
+/**
+ * Extension interface {@link org.eclipse.jface.text.source.ICharacterPairMatcher}.
+ * <p>
+ * Extends the character pair matcher with the concept of enclosing peer characters at a caret
+ * offset.
+ *
+ * @see org.eclipse.jface.text.source.ICharacterPairMatcher
+ * @since 3.8
+ */
+public interface ICharacterPairMatcherExtension {
+
+ /**
+ * Starting at the given offset, the matcher searches for a pair of enclosing peer characters
+ * and if it finds one, returns the minimal region of the document that contains the pair.
+ *
+ * It returns <code>null</code> if there is no enclosing pair.
+ *
+ * @param iDocument the document to work on
+ * @param i the start offset
+ * @return the minimal region containing the peer characters
+ */
+ IRegion findEnclosingPeerCharacters(IDocument iDocument, int i);
+}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java
index 0306bca..783bd06 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -55,6 +55,12 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
private Position fPairPosition= new Position(0, 0);
/** The anchor indicating whether the character is left or right of the caret */
private int fAnchor;
+ /** Whether to highlight enclosing peer characters or not. */
+ private boolean fHighlightEnclosingPeerCharcters;
+ /** Whether to highlight the character at caret location or not. */
+ private boolean fHighlightCharacterAtCaretLocation;
+ /** Whether a character is present at caret location or not. */
+ private boolean fCharacterPresentAtCaretLocation;
/**
@@ -72,6 +78,27 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
}
/**
+ * Sets whether to highlight the character at caret location or not.
+ *
+ * @param highlightCharacterAtCaretLocation whether to highlight the character at caret location
+ * or not
+ * @since 3.8
+ */
+ public void setHighlightCharacterAtCaretLocation(boolean highlightCharacterAtCaretLocation) {
+ fHighlightCharacterAtCaretLocation= highlightCharacterAtCaretLocation;
+ }
+
+ /**
+ * Sets whether to highlight enclosing peer characters or not.
+ *
+ * @param highlightEnclosingPeerCharcters whether to highlight enclosing peer characters or not
+ * @since 3.8
+ */
+ public void setHighlightEnclosingPeerCharacters(boolean highlightEnclosingPeerCharcters) {
+ fHighlightEnclosingPeerCharcters= highlightEnclosingPeerCharcters;
+ }
+
+ /**
* Sets the color in which to highlight the match character.
*
* @param color the color
@@ -158,10 +185,15 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
offset -= region.getOffset();
}
- if (ICharacterPairMatcher.RIGHT == fAnchor)
+ if (fHighlightCharacterAtCaretLocation || (fHighlightEnclosingPeerCharcters && !fCharacterPresentAtCaretLocation)) {
draw(gc, offset, 1);
- else
- draw(gc, offset + length -1, 1);
+ draw(gc, offset + length - 1, 1);
+ } else {
+ if (ICharacterPairMatcher.RIGHT == fAnchor)
+ draw(gc, offset, 1);
+ else
+ draw(gc, offset + length - 1, 1);
+ }
}
/**
@@ -218,6 +250,12 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
}
IRegion pair= fMatcher.match(document, selection.x);
+ boolean characterPresentAtCaretLocation= (pair != null);
+ if (pair == null && fHighlightEnclosingPeerCharcters && fMatcher instanceof ICharacterPairMatcherExtension) {
+ ICharacterPairMatcherExtension matcher= (ICharacterPairMatcherExtension)fMatcher;
+ pair= matcher.findEnclosingPeerCharacters(document, selection.x);
+ }
+
if (pair == null) {
deactivate(true);
return;
@@ -232,8 +270,8 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
} else if (pair.getOffset() != fPairPosition.getOffset() ||
pair.getLength() != fPairPosition.getLength() ||
- fMatcher.getAnchor() != fAnchor) {
-
+ fMatcher.getAnchor() != fAnchor ||
+ characterPresentAtCaretLocation != fCharacterPresentAtCaretLocation) {
// otherwise only do something if position is different
// remove old highlighting
@@ -243,6 +281,7 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
fPairPosition.offset= pair.getOffset();
fPairPosition.length= pair.getLength();
fAnchor= fMatcher.getAnchor();
+ fCharacterPresentAtCaretLocation= characterPresentAtCaretLocation;
// apply new highlighting
handleDrawRequest(null);
@@ -255,6 +294,7 @@ public final class MatchingCharacterPainter implements IPainter, PaintListener {
fPairPosition.offset= pair.getOffset();
fPairPosition.length= pair.getLength();
fAnchor= fMatcher.getAnchor();
+ fCharacterPresentAtCaretLocation= characterPresentAtCaretLocation;
fTextWidget.addPaintListener(this);
fPaintPositionManager.managePosition(fPairPosition);
diff --git a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
index 6e4bb65..f59ad2c 100644
--- a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
+++ b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.ui.workbench.texteditor; singleton:=true
-Bundle-Version: 3.7.100.qualifier
+Bundle-Version: 3.8.0.qualifier
Bundle-Activator: org.eclipse.ui.internal.texteditor.TextEditorPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java
index d386c05..4aa6a76 100644
--- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java
+++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/SourceViewerDecorationSupport.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 2012 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -34,14 +34,14 @@ import org.eclipse.jface.text.ITextViewerExtension4;
import org.eclipse.jface.text.MarginPainter;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationPainter;
+import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy;
+import org.eclipse.jface.text.source.AnnotationPainter.ITextStyleStrategy;
import org.eclipse.jface.text.source.IAnnotationAccess;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.ISharedTextColors;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.MatchingCharacterPainter;
-import org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy;
-import org.eclipse.jface.text.source.AnnotationPainter.ITextStyleStrategy;
@@ -237,6 +237,10 @@ public class SourceViewerDecorationSupport {
private String fMarginPainterColumnKey;
/** Preference key for the matching character painter */
private String fMatchingCharacterPainterEnableKey;
+ /** Preference key for highlighting character at caret location */
+ private String fMatchingCharacterPainterHighlightCharacterAtCaretLocationKey;
+ /** Preference key for enclosing peer characters */
+ private String fMatchingCharacterPainterEnclosingPeerCharactersKey;
/** Preference key for the matching character painter color */
private String fMatchingCharacterPainterColorKey;
/** The property change listener */
@@ -471,6 +475,24 @@ public class SourceViewerDecorationSupport {
}
/**
+ * Sets the preference keys for the matching character painter.
+ *
+ * @param enableKey the preference key for the matching character painter
+ * @param colorKey the preference key for the color used by the matching character painter
+ * @param highlightCharacterAtCaretLocationKey the preference key for highlighting character at
+ * caret location
+ * @param enclosingPeerCharactersKey the preference key for highlighting enclosing peer
+ * characters
+ *
+ * @since 3.8
+ */
+ public void setMatchingCharacterPainterPreferenceKeys(String enableKey, String colorKey, String highlightCharacterAtCaretLocationKey, String enclosingPeerCharactersKey) {
+ setMatchingCharacterPainterPreferenceKeys(enableKey, colorKey);
+ fMatchingCharacterPainterEnclosingPeerCharactersKey= enclosingPeerCharactersKey;
+ fMatchingCharacterPainterHighlightCharacterAtCaretLocationKey= highlightCharacterAtCaretLocationKey;
+ }
+
+ /**
* Sets the symbolic font name that is used for computing the margin width.
*
* @param symbolicFontName the symbolic font name
@@ -511,6 +533,22 @@ public class SourceViewerDecorationSupport {
return;
}
+ if (fMatchingCharacterPainterHighlightCharacterAtCaretLocationKey != null && fMatchingCharacterPainterHighlightCharacterAtCaretLocationKey.equals(p)) {
+ if (fMatchingCharacterPainter != null) {
+ fMatchingCharacterPainter.setHighlightCharacterAtCaretLocation(isCharacterAtCaretLocationShown());
+ fMatchingCharacterPainter.paint(IPainter.CONFIGURATION);
+ }
+ return;
+ }
+
+ if (fMatchingCharacterPainterEnclosingPeerCharactersKey != null && fMatchingCharacterPainterEnclosingPeerCharactersKey.equals(p)) {
+ if (fMatchingCharacterPainter != null) {
+ fMatchingCharacterPainter.setHighlightEnclosingPeerCharacters(areEnclosingPeerCharactersShown());
+ fMatchingCharacterPainter.paint(IPainter.CONFIGURATION);
+ }
+ return;
+ }
+
if (fMatchingCharacterPainterColorKey != null && fMatchingCharacterPainterColorKey.equals(p)) {
if (fMatchingCharacterPainter != null) {
fMatchingCharacterPainter.setColor(getColor(fMatchingCharacterPainterColorKey));
@@ -653,6 +691,8 @@ public class SourceViewerDecorationSupport {
if (fSourceViewer instanceof ITextViewerExtension2) {
fMatchingCharacterPainter= new MatchingCharacterPainter(fSourceViewer, fCharacterPairMatcher);
fMatchingCharacterPainter.setColor(getColor(fMatchingCharacterPainterColorKey));
+ fMatchingCharacterPainter.setHighlightCharacterAtCaretLocation(isCharacterAtCaretLocationShown());
+ fMatchingCharacterPainter.setHighlightEnclosingPeerCharacters(areEnclosingPeerCharactersShown());
ITextViewerExtension2 extension= (ITextViewerExtension2) fSourceViewer;
extension.addPainter(fMatchingCharacterPainter);
}
@@ -686,6 +726,28 @@ public class SourceViewerDecorationSupport {
}
/**
+ * Tells whether character at caret location is shown.
+ *
+ * @return <code>true</code> if character at caret location is shown
+ */
+ private boolean isCharacterAtCaretLocationShown() {
+ if (fPreferenceStore != null && fMatchingCharacterPainterHighlightCharacterAtCaretLocationKey != null)
+ return fPreferenceStore.getBoolean(fMatchingCharacterPainterHighlightCharacterAtCaretLocationKey);
+ return false;
+ }
+
+ /**
+ * Tells whether enclosing peer characters are shown.
+ *
+ * @return <code>true</code> if the enclosing peer characters are shown
+ */
+ private boolean areEnclosingPeerCharactersShown() {
+ if (fPreferenceStore != null && fMatchingCharacterPainterEnclosingPeerCharactersKey != null)
+ return fPreferenceStore.getBoolean(fMatchingCharacterPainterEnclosingPeerCharactersKey);
+ return false;
+ }
+
+ /**
* Shows the cursor line.
*/
private void showCursorLine() {