diff options
author | Markus Keller | 2009-10-12 12:18:58 +0000 |
---|---|---|
committer | Markus Keller | 2009-10-12 12:18:58 +0000 |
commit | f08972036c457735c1728749302aebe4264e6e04 (patch) | |
tree | c23ba5ddb15d5d3414437708f228599d3f5e884d | |
parent | e1ef40c4c6e7d5a51fca8cff14fa7dad9fad1e8c (diff) | |
download | eclipse.platform.text-f08972036c457735c1728749302aebe4264e6e04.tar.gz eclipse.platform.text-f08972036c457735c1728749302aebe4264e6e04.tar.xz eclipse.platform.text-f08972036c457735c1728749302aebe4264e6e04.zip |
Bug 275890 : Share code of "Show Change Ruler Tooltip" and "Show Tooltip Description"
Bug 276065: [implementation] AbstractTextEditor should better deal with its information presenter
-rw-r--r-- | org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java | 23 | ||||
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF | 2 | ||||
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/FocusedInformationPresenter.java (renamed from org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/FocusedInformationPresenter.java) | 17 | ||||
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java | 146 | ||||
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java | 8 | ||||
-rw-r--r-- | org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java | 8 |
6 files changed, 57 insertions, 147 deletions
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java index 64a2b2dd8c5..83d37edc302 100644 --- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java +++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java @@ -126,6 +126,7 @@ import org.eclipse.ui.internal.editors.text.NLSUtility; import org.eclipse.ui.internal.editors.text.RefreshEditorAction; import org.eclipse.ui.internal.texteditor.AnnotationColumn; import org.eclipse.ui.internal.texteditor.BooleanPreferenceToggleAction; +import org.eclipse.ui.internal.texteditor.FocusedInformationPresenter; import org.eclipse.ui.internal.texteditor.LineNumberColumn; import org.eclipse.ui.internal.texteditor.TextChangeHover; import org.eclipse.ui.keys.IBindingService; @@ -157,24 +158,6 @@ import org.eclipse.ui.editors.text.ITextEditorHelpContextIds; public abstract class AbstractDecoratedTextEditor extends StatusTextEditor { /** - * Command ID of the command to display a sticky ruler hover for the current caret location. - * Value <code>"org.eclipse.ui.edit.text.showChangeRulerInformation"</code>). - * - * @since 3.5 - */ - //TODO: move to ITextEditorActionDefinitionIds and make API - private static final String SHOW_CHANGE_RULER_INFORMATION_ID= "org.eclipse.ui.edit.text.showChangeRulerInformation"; //$NON-NLS-1$ - - /** - * Name of the action displaying a sticky ruler hover for the current caret location. - * - * Value: <code>"ShowChangeRulerInformation"</code> - * @since 3.5 - */ - //TODO: move to ITextEditorActionConstants and make API - private static final String SHOW_CHANGE_RULER_INFORMATION= "ShowChangeRulerInformation"; //$NON-NLS-1$ - - /** * Preference key for showing the line number ruler. */ private final static String LINE_NUMBER_RULER= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER; @@ -1252,8 +1235,8 @@ public abstract class AbstractDecoratedTextEditor extends StatusTextEditor { showChangeRulerInformation(); } }; - action.setActionDefinitionId(SHOW_CHANGE_RULER_INFORMATION_ID); - setAction(SHOW_CHANGE_RULER_INFORMATION, action); + action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_CHANGE_RULER_INFORMATION_ID); + setAction(ITextEditorActionConstants.SHOW_CHANGE_RULER_INFORMATION, action); } /** diff --git a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF index fa848586fe0..cdc49e9a432 100644 --- a/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF +++ b/org.eclipse.ui.workbench.texteditor/META-INF/MANIFEST.MF @@ -9,7 +9,7 @@ Bundle-Vendor: %providerName Bundle-Localization: plugin Export-Package: org.eclipse.ui.contentassist, - org.eclipse.ui.internal.texteditor;x-internal:=true; texteditor="split"; mandatory:="texteditor", + org.eclipse.ui.internal.texteditor; texteditor="split"; mandatory:="texteditor"; x-friends:="org.eclipse.ui.editors", org.eclipse.ui.internal.texteditor.quickdiff;x-internal:=true, org.eclipse.ui.internal.texteditor.quickdiff.compare.equivalence;x-internal:=true, org.eclipse.ui.internal.texteditor.rulers;x-internal:=true, diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/FocusedInformationPresenter.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/FocusedInformationPresenter.java index ed9cd6b268a..83e49b76103 100644 --- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/FocusedInformationPresenter.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/internal/texteditor/FocusedInformationPresenter.java @@ -8,7 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ -package org.eclipse.ui.texteditor; +package org.eclipse.ui.internal.texteditor; import org.eclipse.swt.widgets.Shell; @@ -37,7 +37,7 @@ import org.eclipse.jface.text.source.SourceViewerConfiguration; * * @since 3.5 */ -class FocusedInformationPresenter extends InformationPresenter { +public class FocusedInformationPresenter extends InformationPresenter { /** * Information provider used to present focused information shells. @@ -91,20 +91,15 @@ class FocusedInformationPresenter extends InformationPresenter { } } - /** - * The source viewer. - */ + private final ISourceViewer fSourceViewer; - /** - * The source viewer configuration. - */ private final SourceViewerConfiguration fSourceViewerConfiguration; /** - * Creates a new focused information presenter and installs it on the given source viewer + * Creates a focused information presenter and installs it on the source viewer. * * @param sourceViewer the source viewer - * @param sourceViewerConfiguration the viewer configuration + * @param sourceViewerConfiguration the configuration */ public FocusedInformationPresenter(ISourceViewer sourceViewer, SourceViewerConfiguration sourceViewerConfiguration) { super(new DefaultInformationControlCreator()); @@ -118,7 +113,7 @@ class FocusedInformationPresenter extends InformationPresenter { } /** - * Tries to show a focused ("sticky") annotation hover. + * Tries show a focused ("sticky") annotation hover. * * @param annotationHover the annotation hover to show * @param line the line for which to show the hover diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java index 84ae331fdc4..fa5ddd51526 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java @@ -109,14 +109,12 @@ import org.eclipse.jface.window.IShellProvider; import org.eclipse.jface.text.AbstractInformationControlManager; import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DefaultInformationControl; import org.eclipse.jface.text.DefaultLineTracker; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IFindReplaceTarget; import org.eclipse.jface.text.IFindReplaceTargetExtension; -import org.eclipse.jface.text.IInformationControl; import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IMarkRegionTarget; import org.eclipse.jface.text.IRegion; @@ -146,9 +144,7 @@ import org.eclipse.jface.text.TextUtilities; import org.eclipse.jface.text.ITextViewerExtension8.EnrichMode; import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; import org.eclipse.jface.text.information.IInformationProvider; -import org.eclipse.jface.text.information.IInformationProviderExtension; import org.eclipse.jface.text.information.IInformationProviderExtension2; -import org.eclipse.jface.text.information.InformationPresenter; import org.eclipse.jface.text.link.LinkedModeModel; import org.eclipse.jface.text.link.LinkedPosition; import org.eclipse.jface.text.quickassist.IQuickAssistAssistant; @@ -156,9 +152,7 @@ import org.eclipse.jface.text.revisions.RevisionInformation; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.CompositeRuler; import org.eclipse.jface.text.source.IAnnotationHover; -import org.eclipse.jface.text.source.IAnnotationHoverExtension; import org.eclipse.jface.text.source.IAnnotationModel; -import org.eclipse.jface.text.source.ILineRange; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.ISourceViewerExtension3; import org.eclipse.jface.text.source.ISourceViewerExtension4; @@ -201,6 +195,7 @@ import org.eclipse.ui.actions.ContributedAction; import org.eclipse.ui.dialogs.PropertyDialogAction; import org.eclipse.ui.dnd.IDragAndDropService; import org.eclipse.ui.internal.texteditor.EditPosition; +import org.eclipse.ui.internal.texteditor.FocusedInformationPresenter; import org.eclipse.ui.internal.texteditor.NLSUtility; import org.eclipse.ui.internal.texteditor.TextEditorPlugin; import org.eclipse.ui.internal.texteditor.rulers.StringSetSerializer; @@ -1840,51 +1835,6 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit /** - * Information provider used to present focusable information shells. - * - * @since 3.3 - */ - private static final class InformationProvider implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 { - - private IRegion fHoverRegion; - private Object fHoverInfo; - private IInformationControlCreator fControlCreator; - - InformationProvider(IRegion hoverRegion, Object hoverInfo, IInformationControlCreator controlCreator) { - fHoverRegion= hoverRegion; - fHoverInfo= hoverInfo; - fControlCreator= controlCreator; - } - /* - * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int) - */ - public IRegion getSubject(ITextViewer textViewer, int invocationOffset) { - return fHoverRegion; - } - /** - * {@inheritDoc} - * - * @deprecated As of 2.1, replaced by {@link IInformationProviderExtension#getInformation2(ITextViewer, IRegion)} - */ - public String getInformation(ITextViewer textViewer, IRegion subject) { - return fHoverInfo == null ? null : fHoverInfo.toString(); - } - /* - * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) - * @since 3.2 - */ - public Object getInformation2(ITextViewer textViewer, IRegion subject) { - return fHoverInfo; - } - /* - * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator() - */ - public IInformationControlCreator getInformationPresenterControlCreator() { - return fControlCreator; - } - } - - /** * This action behaves in two different ways: If there is no current text * hover, the javadoc is displayed using information presenter. If there is * a current text hover, it is converted into a information presenter in @@ -1939,7 +1889,7 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit if (sourceViewer instanceof ISourceViewerExtension3) { // does an annotation hover exist? IAnnotationHover annotationHover= ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover(); - if (annotationHover != null && makeAnnotationHoverFocusable(sourceViewer, annotationHover)) + if (annotationHover != null && makeAnnotationHoverFocusable(annotationHover)) return; } @@ -1972,14 +1922,15 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit if (textHover instanceof IInformationProviderExtension2) // this is conceptually wrong, but left here for backwards compatibility controlCreator= ((IInformationProviderExtension2)textHover).getInformationPresenterControlCreator(); - IInformationProvider informationProvider= new InformationProvider(hoverRegion, hoverInfo, controlCreator); + IInformationProvider informationProvider= new FocusedInformationPresenter.InformationProvider(hoverRegion, hoverInfo, controlCreator); - fInformationPresenter.setOffset(offset); - fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM); - fInformationPresenter.setMargins(6, 6); // default values from AbstractInformationControlManager + FocusedInformationPresenter informationPresenter= getInformationPresenter(); + informationPresenter.setOffset(offset); + informationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM); + informationPresenter.setMargins(6, 6); // default values from AbstractInformationControlManager String contentType= TextUtilities.getContentType(sourceViewer.getDocument(), getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer()), offset, true); - fInformationPresenter.setInformationProvider(informationProvider, contentType); - fInformationPresenter.showInformation(); + informationPresenter.setInformationProvider(informationProvider, contentType); + informationPresenter.showInformation(); return true; @@ -1991,56 +1942,30 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit /** * Tries to make an annotation hover focusable (or "sticky"). * - * @param sourceViewer the source viewer to display the hover over * @param annotationHover the hover to make focusable * @return <code>true</code> if successful, <code>false</code> otherwise */ - private boolean makeAnnotationHoverFocusable(ISourceViewer sourceViewer, IAnnotationHover annotationHover) { + private boolean makeAnnotationHoverFocusable(IAnnotationHover annotationHover) { IVerticalRulerInfo info= getVerticalRuler(); int line= info.getLineOfLastMouseButtonActivity(); if (line == -1) return false; - try { - - // compute the hover information - Object hoverInfo; - if (annotationHover instanceof IAnnotationHoverExtension) { - IAnnotationHoverExtension extension= (IAnnotationHoverExtension) annotationHover; - ILineRange hoverLineRange= extension.getHoverLineRange(sourceViewer, line); - if (hoverLineRange == null) - return false; - final int maxVisibleLines= Integer.MAX_VALUE; // allow any number of lines being displayed, as we support scrolling - hoverInfo= extension.getHoverInfo(sourceViewer, hoverLineRange, maxVisibleLines); - } else { - hoverInfo= annotationHover.getHoverInfo(sourceViewer, line); - } - - // hover region: the beginning of the concerned line to place the control right over the line - IDocument document= sourceViewer.getDocument(); - int offset= document.getLineOffset(line); - String contentType= TextUtilities.getContentType(document, getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer()), offset, true); - - IInformationControlCreator controlCreator= null; - if (annotationHover instanceof IInformationProviderExtension2) // this is undocumented, but left here for backwards compatibility - controlCreator= ((IInformationProviderExtension2) annotationHover).getInformationPresenterControlCreator(); - else if (annotationHover instanceof IAnnotationHoverExtension) - controlCreator= ((IAnnotationHoverExtension) annotationHover).getHoverControlCreator(); - - IInformationProvider informationProvider= new InformationProvider(new Region(offset, 0), hoverInfo, controlCreator); - - fInformationPresenter.setOffset(offset); - fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_RIGHT); - fInformationPresenter.setMargins(4, 0); // AnnotationBarHoverManager sets (5,0), minus SourceViewer.GAP_SIZE_1 - fInformationPresenter.setInformationProvider(informationProvider, contentType); - fInformationPresenter.showInformation(); - - return true; - - } catch (BadLocationException e) { - return false; - } + return getInformationPresenter().openFocusedAnnotationHover(annotationHover, line); } + + /** + * Returns the information presenter (creates it if necessary). + * + * @return the information presenter + * @since 3.6 + */ + private FocusedInformationPresenter getInformationPresenter() { + if (fInformationPresenter == null) { + fInformationPresenter= new FocusedInformationPresenter(getSourceViewer(), getSourceViewerConfiguration()); + } + return fInformationPresenter; + } // modified version from TextViewer private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) { @@ -2066,7 +1991,6 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit } catch (IllegalArgumentException e) { return -1; } - } } @@ -2583,10 +2507,10 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit */ private Object fTextDragAndDropToken; /** - * The information presenter. + * The information presenter, may be <code>null</code>. * @since 3.3 */ - private InformationPresenter fInformationPresenter; + private FocusedInformationPresenter fInformationPresenter; /** * Tells whether this editor has been activated at least once. @@ -3472,19 +3396,6 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit IVerticalRuler ruler= getVerticalRuler(); if (ruler instanceof CompositeRuler) updateContributedRulerColumns((CompositeRuler) ruler); - - IInformationControlCreator informationControlCreator= new IInformationControlCreator() { - public IInformationControl createInformationControl(Shell shell) { - return new DefaultInformationControl(shell, true); - } - }; - - fInformationPresenter= new InformationPresenter(informationControlCreator); - // sizes: see org.eclipse.jface.text.TextViewer.TEXT_HOVER_*_CHARS - fInformationPresenter.setSizeConstraints(100, 12, true, true); - fInformationPresenter.install(getSourceViewer()); - fInformationPresenter.setDocumentPartitioning(getSourceViewerConfiguration().getConfiguredDocumentPartitioning(getSourceViewer())); - } /** @@ -4406,6 +4317,11 @@ public abstract class AbstractTextEditor extends EditorPart implements ITextEdit fKeyBindingSupportForQuickAssistant.dispose(); fKeyBindingSupportForQuickAssistant= null; } + + if (fInformationPresenter != null) { + fInformationPresenter.uninstall(); + fInformationPresenter= null; + } super.dispose(); } diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java index 61ddac3c73d..48c73add3e4 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionConstants.java @@ -672,4 +672,12 @@ public interface ITextEditorActionConstants extends IWorkbenchActionConstants { * @since 3.5 */ String BLOCK_SELECTION_MODE= "BlockSelectionMode"; //$NON-NLS-1$ + + /** + * Name of the action displaying a sticky ruler hover for the current caret location. + * + * Value: <code>"ShowChangeRulerInformation"</code> + * @since 3.6 + */ + public static final String SHOW_CHANGE_RULER_INFORMATION= "ShowChangeRulerInformation"; //$NON-NLS-1$ } diff --git a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java index 07ee3bd1e18..b78a84f0bfb 100644 --- a/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java +++ b/org.eclipse.ui.workbench.texteditor/src/org/eclipse/ui/texteditor/ITextEditorActionDefinitionIds.java @@ -577,4 +577,12 @@ public interface ITextEditorActionDefinitionIds extends IWorkbenchActionDefiniti * @since 3.5 */ String BLOCK_SELECTION_MODE= "org.eclipse.ui.edit.text.toggleBlockSelectionMode"; //$NON-NLS-1$ + + /** + * Command ID of the command to display a sticky ruler hover for the current caret location. + * Value <code>"org.eclipse.ui.edit.text.showChangeRulerInformation"</code>. + * + * @since 3.6 + */ + public static final String SHOW_CHANGE_RULER_INFORMATION_ID= "org.eclipse.ui.edit.text.showChangeRulerInformation"; //$NON-NLS-1$ } |