### Eclipse Workspace Patch 1.0 #P org.eclipse.ui.editors Index: src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties,v retrieving revision 1.75 diff -u -r1.75 TextEditorMessages.properties --- src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties 15 May 2008 10:35:17 -0000 1.75 +++ src/org/eclipse/ui/internal/editors/text/TextEditorMessages.properties 1 Apr 2009 03:52:22 -0000 @@ -39,6 +39,12 @@ TextEditorDefaultsPreferencePage_smartHomeEnd= &Smart caret positioning at line start and end TextEditorDefaultsPreferencePage_showWhitespaceCharacters= Sh&ow whitespace characters TextEditorDefaultsPreferencePage_textDragAndDrop= Enable drag and dro&p of text + +TextEditorDefaultsPreferencePage_rightMouseMode= Right-click moves c&aret when: +TextEditorDefaultsPreferencePage_rightMouseMode_never=Never +TextEditorDefaultsPreferencePage_rightMouseMode_noSelection=No Selection +TextEditorDefaultsPreferencePage_rightMouseMode_always=Always + TextEditorPreferencePage_colorsAndFonts_link= More colors can be configured on the Colors and Fonts preference page. TextEditorPreferencePage_colorsAndFonts_link_tooltip= Show the Colors and Fonts preferences Index: src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java,v retrieving revision 1.47 diff -u -r1.47 TextEditorDefaultsPreferencePage.java --- src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java 18 Mar 2009 10:50:30 -0000 1.47 +++ src/org/eclipse/ui/internal/editors/text/TextEditorDefaultsPreferencePage.java 1 Apr 2009 03:52:22 -0000 @@ -449,6 +449,7 @@ overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SMART_HOME_END)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TEXT_DRAG_AND_DROP_ENABLED)); + overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractTextEditor.PREFERENCE_MOUSE_RIGHT_CLICK_CARET_MODE)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SHOW_TEXT_HOVER_AFFORDANCE)); overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.INT, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HOVER_ENRICH_MODE)); @@ -570,6 +571,14 @@ Preference textDragAndDrop= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TEXT_DRAG_AND_DROP_ENABLED, label, null); addCheckBox(appearanceComposite, textDragAndDrop, new BooleanDomain(), 0); + label=TextEditorMessages.TextEditorDefaultsPreferencePage_rightMouseMode; + Preference rightMouse= new Preference(AbstractTextEditor.PREFERENCE_MOUSE_RIGHT_CLICK_CARET_MODE, label, null); + EnumeratedDomain rightMouseDomain= new EnumeratedDomain(); + rightMouseDomain.addValue(new EnumValue(0, TextEditorMessages.TextEditorDefaultsPreferencePage_rightMouseMode_never)); + rightMouseDomain.addValue(new EnumValue(1, TextEditorMessages.TextEditorDefaultsPreferencePage_rightMouseMode_noSelection)); + rightMouseDomain.addValue(new EnumValue(2, TextEditorMessages.TextEditorDefaultsPreferencePage_rightMouseMode_always)); + addCombo(appearanceComposite, rightMouse, rightMouseDomain, 0); + label= TextEditorMessages.TextEditorDefaultsPreferencePage_warn_if_derived; Preference warnIfDerived= new Preference(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED, label, null); addCheckBox(appearanceComposite, warnIfDerived, new BooleanDomain(), 0); Index: src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java,v retrieving revision 1.31 diff -u -r1.31 TextEditorMessages.java --- src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java 15 May 2008 10:35:17 -0000 1.31 +++ src/org/eclipse/ui/internal/editors/text/TextEditorMessages.java 1 Apr 2009 03:52:22 -0000 @@ -131,6 +131,10 @@ public static String TextEditorDefaultsPreferencePage_warn_if_derived; public static String TextEditorDefaultsPreferencePage_showWhitespaceCharacters; public static String TextEditorDefaultsPreferencePage_textDragAndDrop; + public static String TextEditorDefaultsPreferencePage_rightMouseMode; + public static String TextEditorDefaultsPreferencePage_rightMouseMode_never; + public static String TextEditorDefaultsPreferencePage_rightMouseMode_noSelection; + public static String TextEditorDefaultsPreferencePage_rightMouseMode_always; public static String LinkedModeConfigurationBlock_annotationPresentationOptions; public static String LinkedModeConfigurationBlock_SQUIGGLES; public static String LinkedModeConfigurationBlock_UNDERLINE; #P org.eclipse.ui.workbench.texteditor Index: src/org/eclipse/ui/texteditor/AbstractTextEditor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java,v retrieving revision 1.305 diff -u -r1.305 AbstractTextEditor.java --- src/org/eclipse/ui/texteditor/AbstractTextEditor.java 19 Mar 2009 16:31:17 -0000 1.305 +++ src/org/eclipse/ui/texteditor/AbstractTextEditor.java 1 Apr 2009 03:52:25 -0000 @@ -13,6 +13,7 @@ * Benjamin Muskalla - https://bugs.eclipse.org/bugs/show_bug.cgi?id=41573 * Stephan Wahlbrink - Wrong operations mode/feedback for text drag over/drop in text editors - https://bugs.eclipse.org/bugs/show_bug.cgi?id=206043 * Tom Eicher (Avaloq Evolution AG) - block selection mode + * Luke Gumbley - https://bugs.eclipse.org/bugs/show_bug.cgi?id=19825 *******************************************************************************/ package org.eclipse.ui.texteditor; @@ -2196,6 +2197,25 @@ */ public static final String PREFERENCE_HOVER_ENRICH_MODE= "hoverReplaceMode"; //$NON-NLS-1$ + /** + * A named preference that controls the behaviour of the caret when the right mouse button + * is clicked. + *

+ * Value is of type Integer and is interpreted as follows: + *

+ *
    + *
  • 0: "Never" - No effect (default).
  • + *
  • 1: "No Selection" - If there is a selection, no effect. If there is no selection, + * move the caret to the current mouse position.
  • + *
  • 2: "Always" - If there is a selection but it was not clicked, or if there is no + * selection, clear the selection and move the caret to the current mouse position. + * If there is a selection and it was clicked, no effect.
  • + *
+ * + * @since 3.5 + */ + public static final String PREFERENCE_MOUSE_RIGHT_CLICK_CARET_MODE="mouseRightClickCaretMode"; //$NON-NLS-1$ + /** Menu id for the editor context menu. */ public static final String DEFAULT_EDITOR_CONTEXT_MENU_ID= "#EditorContext"; //$NON-NLS-1$ /** Menu id for the ruler context menu. */ @@ -2576,7 +2596,13 @@ */ private KeyBindingSupportForAssistant fKeyBindingSupportForContentAssistant; - + /** + * Current setting of the right mouse button mode. + * + * @since 3.5 + */ + private int rightMouseMode=-1; + /** * Creates a new text editor. If not explicitly set, this editor uses * a 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. *