Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 22577 Details for
Bug 14654
[typing] Single line selection on triple-click
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch to add support for triple-clicking
org.eclipse.jface.text-tripleclick_patch.txt (text/plain), 19.85 KB, created by
Chris Wiebe
on 2005-06-07 19:22:33 EDT
(
hide
)
Description:
patch to add support for triple-clicking
Filename:
MIME Type:
Creator:
Chris Wiebe
Created:
2005-06-07 19:22:33 EDT
Size:
19.85 KB
patch
obsolete
>Index: src/org/eclipse/jface/text/TextViewer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java,v >retrieving revision 1.135 >diff -u -r1.135 TextViewer.java >--- src/org/eclipse/jface/text/TextViewer.java 6 Jun 2005 15:08:37 -0000 1.135 >+++ src/org/eclipse/jface/text/TextViewer.java 7 Jun 2005 23:13:24 -0000 >@@ -39,6 +39,7 @@ > import org.eclipse.swt.events.MouseAdapter; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.events.MouseListener; >+import org.eclipse.swt.events.MouseMoveListener; > import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.events.SelectionListener; > import org.eclipse.swt.events.TraverseEvent; >@@ -95,7 +96,7 @@ > public class TextViewer extends Viewer implements > ITextViewer, ITextViewerExtension, ITextViewerExtension2, ITextViewerExtension4, ITextViewerExtension6, IEditingSupportRegistry, > ITextOperationTarget, ITextOperationTargetExtension, >- IWidgetTokenOwner, IWidgetTokenOwnerExtension, IPostSelectionProvider { >+ IWidgetTokenOwner, IWidgetTokenOwnerExtension, IPostSelectionProvider, ITextViewerMultipleClickExtension { > > /** Internal flag to indicate the debug state. */ > public static final boolean TRACE_ERRORS= false; >@@ -152,36 +153,94 @@ > preservedText= null; > } > } >- >+ > /** >- * Connects a text double click strategy to this viewer's text widget. >- * Calls the double click strategy when the mouse has been double clicked >+ * Connects a text multiple click strategy to this viewer's text widget. >+ * Calls the multiple click strategy when the mouse has been clicked multiple times > * inside the text editor. > */ >- class TextDoubleClickStrategyConnector extends MouseAdapter { >- >- /** Internal flag to remember that a double clicked occurred. */ >- private boolean fDoubleClicked= false; >+ class TextMultiClickStrategyConnector implements MouseListener, MouseMoveListener { > >+ private boolean fTriggerOnMouseDown; >+ private long fClickInterval; >+ private long fLastClickTime; >+ private int fClickCount; >+ > /** > * Creates a new text double click strategy adapter. > */ >- public TextDoubleClickStrategyConnector() { >+ public TextMultiClickStrategyConnector() { >+ reset(); > } > >+ private void reset() { >+ fTriggerOnMouseDown = true; //TODO could this be made into a preference option somewhere? >+ fClickCount = 0; >+ fLastClickTime = 0; >+ fClickInterval = Display.getCurrent().getDoubleClickTime(); >+ } >+ > /* > * @see MouseListener#mouseDoubleClick(MouseEvent) > */ > public void mouseDoubleClick(MouseEvent e) { >- fDoubleClicked= true; >+ // ignore >+ } >+ >+ /* >+ * @see MouseMoveListener#mouseMove(MouseEvent) >+ */ >+ public void mouseMove(MouseEvent e) { >+ reset(); > } > > /* >+ * @see MouseListener#mouseDown(MouseEvent) >+ */ >+ public void mouseDown(MouseEvent e) { >+ resetIfExpired(e); >+ >+ if (e.button != 1) { >+ return; >+ } >+ >+ if (fTriggerOnMouseDown) { >+ handleClick(e); >+ } >+ } >+ >+ /* > * @see MouseListener#mouseUp(MouseEvent) > */ > public void mouseUp(MouseEvent e) { >- if (fDoubleClicked) { >- fDoubleClicked= false; >+ resetIfExpired(e); >+ >+ if (e.button != 1) { >+ return; >+ } >+ >+ if (!fTriggerOnMouseDown) { >+ handleClick(e); >+ } >+ } >+ >+ private void resetIfExpired(MouseEvent e) { >+ long time = (e.time & 0xFFFFFFFFL); >+ if ((time - fLastClickTime) > fClickInterval) { >+ reset(); >+ } >+ } >+ >+ private void handleClick(MouseEvent e) { >+ ++fClickCount; >+ if (fClickCount > 1) { >+ handleMultiClick(fClickCount); >+ } >+ fLastClickTime = (e.time & 0xFFFFFFFFL); >+ } >+ >+ private void handleMultiClick(int clicks) { >+ if (clicks == 2 && fDoubleClickStrategies != null && !fDoubleClickStrategies.isEmpty()) { > ITextDoubleClickStrategy s= (ITextDoubleClickStrategy) selectContentTypePlugin(getSelectedRange().x, fDoubleClickStrategies); > if (s != null) { > StyledText textWidget= getTextWidget(); >@@ -191,10 +250,20 @@ > if (newSelection.y > 0 && !oldSelection.equals(newSelection)) > textWidget.copy(DND.SELECTION_CLIPBOARD); > } >+ } else if (clicks > 2 && fMultiClickStrategies != null && !fMultiClickStrategies.isEmpty()) { >+ ITextMultipleClickStrategy s= (ITextMultipleClickStrategy) selectContentTypePlugin(getSelectedRange().x, fMultiClickStrategies); >+ if (s != null) { >+ StyledText textWidget= getTextWidget(); >+ Point oldSelection= textWidget.getSelection(); >+ s.multipleClicked(TextViewer.this, clicks); >+ Point newSelection= textWidget.getSelection(); >+ if (newSelection.y > 0 && !oldSelection.equals(newSelection)) >+ textWidget.copy(DND.SELECTION_CLIPBOARD); >+ } > } > } > } >- >+ > /** > * Monitors the area of the viewer's document that is visible in the viewer. > * If the area might have changed, it informs the text viewer about this >@@ -1215,8 +1284,8 @@ > private IDocumentAdapter fDocumentAdapter; > /** The slave document manager */ > private ISlaveDocumentManager fSlaveDocumentManager; >- /** The text viewer's double click strategies connector */ >- private TextDoubleClickStrategyConnector fDoubleClickStrategyConnector; >+ /** The text viewer's multiple click strategies connector */ >+ private TextMultiClickStrategyConnector fMultiClickStrategyConnector; > /** The text viewer's view port guard */ > private ViewportGuard fViewportGuard; > /** Caches the graphical coordinate of the first visible line */ >@@ -1322,6 +1391,8 @@ > protected Map fDefaultPrefixChars; > /** The text viewer's text double click strategies */ > protected Map fDoubleClickStrategies; >+ /** The text viewer's text multi-click strategies */ >+ protected Map fMultiClickStrategies; > /** The text viewer's undo manager */ > protected IUndoManager fUndoManager; > /** The text viewer's auto indent strategies */ >@@ -1511,9 +1582,12 @@ > */ > public void activatePlugins() { > >- if (fDoubleClickStrategies != null && !fDoubleClickStrategies.isEmpty() && fDoubleClickStrategyConnector == null) { >- fDoubleClickStrategyConnector= new TextDoubleClickStrategyConnector(); >- fTextWidget.addMouseListener(fDoubleClickStrategyConnector); >+ if (fMultiClickStrategyConnector == null && >+ ((fDoubleClickStrategies != null && !fDoubleClickStrategies.isEmpty()) || >+ (fMultiClickStrategies != null && !fMultiClickStrategies.isEmpty()))) { >+ fMultiClickStrategyConnector= new TextMultiClickStrategyConnector(); >+ fTextWidget.addMouseListener(fMultiClickStrategyConnector); >+ fTextWidget.addMouseMoveListener(fMultiClickStrategyConnector); > } > > ensureHoverControlManagerInstalled(); >@@ -1593,12 +1667,17 @@ > fDoubleClickStrategies= null; > } > >+ if (fMultiClickStrategies != null) { >+ fMultiClickStrategies.clear(); >+ fMultiClickStrategies= null; >+ } >+ > if (fTextHovers != null) { > fTextHovers.clear(); > fTextHovers= null; > } > >- fDoubleClickStrategyConnector= null; >+ fMultiClickStrategyConnector= null; > > if (fTextHoverManager != null) { > fTextHoverManager.dispose(); >@@ -3260,6 +3339,19 @@ > fDoubleClickStrategies.remove(contentType); > } > >+ /* >+ * @see ITextViewerMultipleClickExtension#setTextMultipleClickStrategy(ITextMultiClickStrategy, String) >+ */ >+ public void setTextMultipleClickStrategy(ITextMultipleClickStrategy strategy, String contentType) { >+ >+ if (strategy != null) { >+ if (fMultiClickStrategies == null) >+ fMultiClickStrategies= new HashMap(); >+ fMultiClickStrategies.put(contentType, strategy); >+ } else if (fMultiClickStrategies != null) >+ fMultiClickStrategies.remove(contentType); >+ } >+ > /** > * Selects from the given map the one which is registered under > * the content type of the partition in which the given offset is located. >Index: src/org/eclipse/jface/text/source/SourceViewer.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java,v >retrieving revision 1.51 >diff -u -r1.51 SourceViewer.java >--- src/org/eclipse/jface/text/source/SourceViewer.java 6 Jun 2005 15:08:37 -0000 1.51 >+++ src/org/eclipse/jface/text/source/SourceViewer.java 7 Jun 2005 23:13:24 -0000 >@@ -363,6 +363,7 @@ > > setAutoEditStrategies(configuration.getAutoEditStrategies(this, t), t); > setTextDoubleClickStrategy(configuration.getDoubleClickStrategy(this, t), t); >+ setTextMultipleClickStrategy(configuration.getMultipleClickStrategy(this, t), t); > > int[] stateMasks= configuration.getConfiguredTextHoverStateMasks(this, t); > if (stateMasks != null) { >Index: src/org/eclipse/jface/text/source/SourceViewerConfiguration.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java,v >retrieving revision 1.17 >diff -u -r1.17 SourceViewerConfiguration.java >--- src/org/eclipse/jface/text/source/SourceViewerConfiguration.java 19 Apr 2005 12:41:15 -0000 1.17 >+++ src/org/eclipse/jface/text/source/SourceViewerConfiguration.java 7 Jun 2005 23:13:24 -0000 >@@ -18,6 +18,7 @@ > import org.eclipse.jface.text.DefaultAutoIndentStrategy; > import org.eclipse.jface.text.DefaultInformationControl; > import org.eclipse.jface.text.DefaultTextDoubleClickStrategy; >+import org.eclipse.jface.text.DefaultTextMultipleClickStrategy; > import org.eclipse.jface.text.DefaultUndoManager; > import org.eclipse.jface.text.IAutoEditStrategy; > import org.eclipse.jface.text.IAutoIndentStrategy; >@@ -27,6 +28,7 @@ > import org.eclipse.jface.text.IInformationControlCreator; > import org.eclipse.jface.text.ITextDoubleClickStrategy; > import org.eclipse.jface.text.ITextHover; >+import org.eclipse.jface.text.ITextMultipleClickStrategy; > import org.eclipse.jface.text.IUndoManager; > import org.eclipse.jface.text.contentassist.IContentAssistant; > import org.eclipse.jface.text.formatter.IContentFormatter; >@@ -192,6 +194,19 @@ > } > > /** >+ * Returns the multiple click strategy ready to be used in this viewer when multiple clicking >+ * onto text of the given content type. This implementation always returns a new instance of >+ * <code>DefaultTextMultipleClickStrategy</code>. >+ * >+ * @param sourceViewer the source viewer to be configured by this configuration >+ * @param contentType the content type for which the strategy is applicable >+ * @return a multiple click strategy or <code>null</code> if multiple clicking should not be supported >+ */ >+ public ITextMultipleClickStrategy getMultipleClickStrategy(ISourceViewer sourceViewer, String contentType) { >+ return new DefaultTextMultipleClickStrategy(); >+ } >+ >+ /** > * Returns the prefixes to be used by the line-shift operation. This implementation > * always returns <code>new String[] { "\t", " " }</code>. > * >Index: src/org/eclipse/jface/text/DefaultTextMultipleClickStrategy.java >=================================================================== >RCS file: src/org/eclipse/jface/text/DefaultTextMultipleClickStrategy.java >diff -N src/org/eclipse/jface/text/DefaultTextMultipleClickStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/text/DefaultTextMultipleClickStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,234 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2004 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; >+ >+import java.text.BreakIterator; >+import java.text.CharacterIterator; >+ >+ >+/** >+ * Standard implementation of >+ * {@link org.eclipse.jface.text.ITextMultipleClickStrategy}. >+ * <p> >+ * Selects words using <code>java.text.BreakIterator</code> for the default >+ * locale. >+ * <p> >+ * This class is not intended to be subclassed. >+ * >+ * @see java.text.BreakIterator >+ */ >+public class DefaultTextMultipleClickStrategy implements ITextMultipleClickStrategy { >+ >+ >+ /** >+ * Implements a character iterator that works directly on >+ * instances of <code>IDocument</code>. Used to collaborate with >+ * the break iterator. >+ * >+ * @see IDocument >+ * @since 2.0 >+ */ >+ static class DocumentCharacterIterator implements CharacterIterator { >+ >+ /** Document to iterate over. */ >+ private IDocument fDocument; >+ /** Start offset of iteration. */ >+ private int fOffset= -1; >+ /** End offset of iteration. */ >+ private int fEndOffset= -1; >+ /** Current offset of iteration. */ >+ private int fIndex= -1; >+ >+ /** Creates a new document iterator. */ >+ public DocumentCharacterIterator() { >+ } >+ >+ /** >+ * Configures this document iterator with the document section to be visited. >+ * >+ * @param document the document to be iterated >+ * @param iteratorRange the range in the document to be iterated >+ */ >+ public void setDocument(IDocument document, IRegion iteratorRange) { >+ fDocument= document; >+ fOffset= iteratorRange.getOffset(); >+ fEndOffset= fOffset + iteratorRange.getLength(); >+ } >+ >+ /* >+ * @see CharacterIterator#first() >+ */ >+ public char first() { >+ fIndex= fOffset; >+ return current(); >+ } >+ >+ /* >+ * @see CharacterIterator#last() >+ */ >+ public char last() { >+ fIndex= fOffset < fEndOffset ? fEndOffset -1 : fEndOffset; >+ return current(); >+ } >+ >+ /* >+ * @see CharacterIterator#current() >+ */ >+ public char current() { >+ if (fOffset <= fIndex && fIndex < fEndOffset) { >+ try { >+ return fDocument.getChar(fIndex); >+ } catch (BadLocationException x) { >+ } >+ } >+ return DONE; >+ } >+ >+ /* >+ * @see CharacterIterator#next() >+ */ >+ public char next() { >+ if (fIndex == fEndOffset -1) >+ return DONE; >+ >+ if (fIndex < fEndOffset) >+ ++ fIndex; >+ >+ return current(); >+ } >+ >+ /* >+ * @see CharacterIterator#previous() >+ */ >+ public char previous() { >+ if (fIndex == fOffset) >+ return DONE; >+ >+ if (fIndex > fOffset) >+ -- fIndex; >+ >+ return current(); >+ } >+ >+ /* >+ * @see CharacterIterator#setIndex(int) >+ */ >+ public char setIndex(int index) { >+ fIndex= index; >+ return current(); >+ } >+ >+ /* >+ * @see CharacterIterator#getBeginIndex() >+ */ >+ public int getBeginIndex() { >+ return fOffset; >+ } >+ >+ /* >+ * @see CharacterIterator#getEndIndex() >+ */ >+ public int getEndIndex() { >+ return fEndOffset; >+ } >+ >+ /* >+ * @see CharacterIterator#getIndex() >+ */ >+ public int getIndex() { >+ return fIndex; >+ } >+ >+ /* >+ * @see CharacterIterator#clone() >+ */ >+ public Object clone() { >+ DocumentCharacterIterator i= new DocumentCharacterIterator(); >+ i.fDocument= fDocument; >+ i.fIndex= fIndex; >+ i.fOffset= fOffset; >+ i.fEndOffset= fEndOffset; >+ return i; >+ } >+ } >+ >+ >+ /** >+ * The document character iterator used by this strategy. >+ * @since 2.0 >+ */ >+ private DocumentCharacterIterator fDocIter= new DocumentCharacterIterator(); >+ >+ >+ /** >+ * Creates a new default text triple click strategy. >+ */ >+ public DefaultTextMultipleClickStrategy() { >+ super(); >+ } >+ >+ /* >+ * @see org.eclipse.jface.text.ITextTripleClickStrategy#tripleClicked(org.eclipse.jface.text.ITextViewer) >+ */ >+ public void multipleClicked(ITextViewer text, int clicks) { >+ >+ int position= text.getSelectedRange().x; >+ >+ if (position < 0) >+ return; >+ >+ try { >+ IDocument document= text.getDocument(); >+ IRegion line= document.getLineInformationOfOffset(position); >+ int start= 0; >+ int end= 0; >+ >+ if (clicks == 2) { >+ if (position == line.getOffset() + line.getLength()) >+ return; >+ >+ fDocIter.setDocument(document, line); >+ >+ BreakIterator breakIter= BreakIterator.getWordInstance(); >+ breakIter.setText(fDocIter); >+ >+ start= breakIter.preceding(position); >+ if (start == BreakIterator.DONE) >+ start= line.getOffset(); >+ >+ end= breakIter.following(position); >+ if (end == BreakIterator.DONE) >+ end= line.getOffset() + line.getLength(); >+ >+ if (breakIter.isBoundary(position)) { >+ if (end - position > position- start) >+ start= position; >+ else >+ end= position; >+ } >+ } else { >+ fDocIter.setDocument(document, line); >+ >+ BreakIterator breakIter= BreakIterator.getLineInstance(); >+ breakIter.setText(fDocIter); >+ >+ start= line.getOffset(); >+ end= line.getOffset() + line.getLength(); >+ } >+ >+ if (start != end) >+ text.setSelectedRange(start, end - start); >+ >+ } catch (BadLocationException x) { >+ } >+ } >+} >Index: src/org/eclipse/jface/text/ITextMultipleClickStrategy.java >=================================================================== >RCS file: src/org/eclipse/jface/text/ITextMultipleClickStrategy.java >diff -N src/org/eclipse/jface/text/ITextMultipleClickStrategy.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/text/ITextMultipleClickStrategy.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,34 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2004 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; >+ >+ >+/** >+ * A text multiple click strategy defines the reaction of a text viewer to multiple >+ * mouse click events (3 or more). The strategy must be installed on an >+ * {@link org.eclipse.jface.text.ITextViewer}. >+ * <p> >+ * Clients may implement this interface or use the standard implementation >+ * <code>DefaultTextMultipleClickStrategy</code>. >+ * >+ * @see org.eclipse.jface.text.ITextViewer >+ * @see org.eclipse.jface.text.ITextViewerMultipleClickExtension >+ */ >+public interface ITextMultipleClickStrategy { >+ >+ /** >+ * The mouse has been multiple clicked on the given text viewer. >+ * >+ * @param viewer the viewer into which has been multiple clicked >+ * @param clicks the number of mouse clicks >+ */ >+ void multipleClicked(ITextViewer viewer, int clicks); >+} >Index: src/org/eclipse/jface/text/ITextViewerMultipleClickExtension.java >=================================================================== >RCS file: src/org/eclipse/jface/text/ITextViewerMultipleClickExtension.java >diff -N src/org/eclipse/jface/text/ITextViewerMultipleClickExtension.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/jface/text/ITextViewerMultipleClickExtension.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,30 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2004 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; >+ >+/** >+ * Extension interface for {@link org.eclipse.jface.text.ITextViewer}. >+ * Introduces the concept of a multiple mouse click strategy. >+ * >+ * @see org.eclipse.jface.text.ITextMultipleClickStrategy >+ * @since 3.1 >+ */ >+public interface ITextViewerMultipleClickExtension { >+ >+ /** >+ * Sets this viewer's text multiple click strategy for the given content type. >+ * >+ * @param strategy the new multiple click strategy. <code>null</code> is a valid argument. >+ * @param contentType the type for which the strategy is registered >+ */ >+ void setTextMultipleClickStrategy(ITextMultipleClickStrategy strategy, String contentType); >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 14654
:
14386
|
14387
| 22577