+ * Value is of type Integer
and is interpreted as follows:
+ *
SourceViewerConfiguration
to configure its
@@ -3044,6 +3070,7 @@
}
public void mouseDown(MouseEvent e) {
+ handleMouseDown(e);
}
public void mouseUp(MouseEvent e) {
@@ -4541,6 +4568,13 @@
return;
}
+ if (PREFERENCE_MOUSE_RIGHT_CLICK_CARET_MODE.equals(property)) {
+ IPreferenceStore store = getPreferenceStore();
+ if(store != null) {
+ rightMouseMode = store.getInt(PREFERENCE_MOUSE_RIGHT_CLICK_CARET_MODE);
+ }
+ }
+
}
/**
@@ -6495,6 +6529,71 @@
}
/**
+ * Handles a mouse event on the editor (currently only right-clicks) as per user
+ * preferences. See {@link #PREFERENCE_MOUSE_RIGHT_CLICK_CARET_MODE}.
+ *
+ * @param e The MouseEvent to be handled.
+ *
+ * @since 3.5
+ */
+ protected void handleMouseDown(MouseEvent e) {
+
+ if(e.button!=3)
+ return;
+
+ // If the mode is -1 it has not yet been set
+ if(rightMouseMode == -1) {
+ IPreferenceStore store = getPreferenceStore();
+ if(store != null) {
+ rightMouseMode = store.getInt(PREFERENCE_MOUSE_RIGHT_CLICK_CARET_MODE);
+ }
+ }
+
+ if(rightMouseMode == 0)
+ return;
+
+ StyledText textWidget = null;
+ ISourceViewer viewer = fSourceViewer;
+ if (viewer != null)
+ textWidget = viewer.getTextWidget();
+
+ if(textWidget == null)
+ return;
+
+ int mouseOffset=-1;
+ try {
+ mouseOffset = textWidget.getOffsetAtLocation(new Point(e.x,e.y));
+ }
+ catch (IllegalArgumentException ex) {
+
+ }
+
+ if(mouseOffset == -1)
+ {
+ int lineIndex=textWidget.getLineIndex(e.y)+1;
+
+ if(lineIndex >= textWidget.getLineCount())
+ mouseOffset = textWidget.getCharCount();
+ else
+ mouseOffset = textWidget.getOffsetAtLine(lineIndex)-1;
+ }
+
+ if(textWidget.getSelectionCount() > 0)
+ {
+ if(rightMouseMode == 1)
+ return;
+
+ Point textSelection = textWidget.getSelection();
+ boolean withinSelection = (mouseOffset >= textSelection.x) && (mouseOffset < textSelection.y);
+
+ if(withinSelection)
+ return;
+ }
+
+ textWidget.setCaretOffset(mouseOffset);
+ }
+
+ /**
* Handles a potential change of the cursor position.
* Subclasses may extend.
*