|
From: <caw...@us...> - 2007-05-29 13:22:47
|
Revision: 2547
http://svn.sourceforge.net/rubyeclipse/?rev=2547&view=rev
Author: cawilliams
Date: 2007-05-29 06:22:45 -0700 (Tue, 29 May 2007)
Log Message:
-----------
include CommentHoverProvider, and also allow F2 to change focus to RDoc when it is shown. (so you can read the whole thing)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.properties
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyInformationProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyTypeHover.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.properties 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/plugin.properties 2007-05-29 13:22:45 UTC (rev 2547)
@@ -57,6 +57,8 @@
buildPathPageName=Ruby Load Path
+commentHover=Ruby RDoc comment hover
+
PerspectiveRuby.name=Ruby
ViewRubyResources.name=Ruby Resources
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2007-05-29 13:22:45 UTC (rev 2547)
@@ -442,6 +442,11 @@
contextId="org.rubypeople.rdt.ui.rubyEditorScope "
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
</key>
+ <key
+ sequence="F2"
+ contextId="org.rubypeople.rdt.ui.rubyEditorScope"
+ commandId="org.rubypeople.rdt.ui.edit.text.ruby.show.rdoc"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
<!-- alternative for some gtk input modes -->
<key
platform="gtk"
@@ -490,6 +495,12 @@
id="org.rubypeople.rdt.ui.category.project ">
</category>
<command
+ name="%ActionDefinition.showRdoc.name"
+ description="%ActionDefinition.showRdoc.description"
+ categoryId="org.eclipse.ui.category.edit"
+ id="org.rubypeople.rdt.ui.edit.text.ruby.show.rdoc">
+ </command>
+ <command
categoryId="org.rubypeople.rdt.ui.category.source"
description="%ActionDefinition.format.description"
id="org.rubypeople.rdt.ui.edit.text.ruby.format"
@@ -923,6 +934,10 @@
id="org.rubypeople.rdt.ui.ProblemHover">
</hover>
<hover
+ id="com.aptana.rdt.ui.RubyCommentHover"
+ class="org.rubypeople.rdt.internal.ui.text.ruby.hover.CommentHoverProvider"
+ label="%commentHover"/>
+ <hover
id="org.rubypeople.rdt.ui.RiDocHover"
class="org.rubypeople.rdt.internal.ui.text.ruby.hover.RiDocHoverProvider"
label="%rdocHover"/>
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -3,6 +3,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
+import java.util.ResourceBundle;
import java.util.Stack;
import org.eclipse.core.resources.IMarker;
@@ -20,24 +21,36 @@
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.AbstractInformationControlManager;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultInformationControl;
import org.eclipse.jface.text.DocumentCommand;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentExtension;
import org.eclipse.jface.text.IDocumentListener;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.ILineTracker;
import org.eclipse.jface.text.IPositionUpdater;
import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.ITextViewerExtension;
+import org.eclipse.jface.text.ITextViewerExtension2;
+import org.eclipse.jface.text.ITextViewerExtension4;
import org.eclipse.jface.text.ITextViewerExtension5;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.TextUtilities;
+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.ILinkedModeListener;
import org.eclipse.jface.text.link.LinkedModeModel;
import org.eclipse.jface.text.link.LinkedModeUI;
@@ -46,11 +59,16 @@
import org.eclipse.jface.text.link.LinkedModeUI.ExitFlags;
import org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy;
import org.eclipse.jface.text.source.Annotation;
+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.ICharacterPairMatcher;
+import org.eclipse.jface.text.source.ILineRange;
import org.eclipse.jface.text.source.IOverviewRuler;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.ISourceViewerExtension3;
import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.IVerticalRulerInfo;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
@@ -60,11 +78,13 @@
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.search.ui.IContextMenuConstants;
+import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.custom.VerifyKeyListener;
import org.eclipse.swt.events.VerifyEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPartListener2;
@@ -83,6 +103,8 @@
import org.eclipse.ui.texteditor.IEditorStatusLine;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.eclipse.ui.texteditor.MarkerAnnotation;
+import org.eclipse.ui.texteditor.ResourceAction;
+import org.eclipse.ui.texteditor.TextEditorAction;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.texteditor.link.EditorLinkedModeUI;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -96,12 +118,13 @@
import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
-import org.rubypeople.rdt.internal.ui.RubyUIMessages;
import org.rubypeople.rdt.internal.ui.actions.CompositeActionGroup;
import org.rubypeople.rdt.internal.ui.actions.FoldingActionGroup;
+import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
import org.rubypeople.rdt.internal.ui.text.RubyHeuristicScanner;
import org.rubypeople.rdt.internal.ui.text.Symbols;
+import org.rubypeople.rdt.internal.ui.text.ruby.hover.SourceViewerInformationControl;
import org.rubypeople.rdt.ui.IWorkingCopyManager;
import org.rubypeople.rdt.ui.PreferenceConstants;
import org.rubypeople.rdt.ui.actions.FormatAction;
@@ -177,6 +200,8 @@
private CompositeActionGroup fActionGroups;
private CompositeActionGroup fContextMenuGroup;
+ private InformationPresenter fInformationPresenter;
+
public RubyEditor() {
super();
@@ -242,6 +267,12 @@
ISelectionProvider provider= getSite().getSelectionProvider();
ISelection selection= provider.getSelection();
+ ResourceAction resAction= new TextOperationAction(RubyEditorMessages.getBundleForConstructedKeys(), "ShowRDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$
+ resAction= new InformationDispatchAction(RubyEditorMessages.getBundleForConstructedKeys(), "ShowRDoc.", (TextOperationAction) resAction); //$NON-NLS-1$
+ resAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SHOW_RDOC);
+ setAction("ShowRDoc", resAction); //$NON-NLS-1$
+// PlatformUI.getWorkbench().getHelpSystem().setHelp(resAction, IRubyHelpContextIds.SHOW_JAVADOC_ACTION);
+
SurroundWithBeginRescueAction beginRescueAction = new SurroundWithBeginRescueAction(this);
beginRescueAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SURROUND_WITH_BEGIN_RESCUE);
beginRescueAction.update(selection);
@@ -273,6 +304,19 @@
public void createPartControl(Composite parent) {
super.createPartControl(parent);
+ IInformationControlCreator informationControlCreator= new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell shell) {
+ boolean cutDown= false;
+ int style= cutDown ? SWT.NONE : (SWT.V_SCROLL | SWT.H_SCROLL);
+ return new DefaultInformationControl(shell, SWT.RESIZE | SWT.TOOL, style, new HTMLTextPresenter(cutDown));
+ }
+ };
+
+ fInformationPresenter= new InformationPresenter(informationControlCreator);
+ fInformationPresenter.setSizeConstraints(60, 10, true, true);
+ fInformationPresenter.install(getSourceViewer());
+ fInformationPresenter.setDocumentPartitioning(IRubyPartitions.RUBY_PARTITIONING);
+
ProjectionViewer projectionViewer = (ProjectionViewer) getSourceViewer();
fProjectionSupport = new ProjectionSupport(projectionViewer, getAnnotationAccess(),
@@ -1674,4 +1718,248 @@
option= project.getOption(SPACES_FOR_TABS, true);
return RubyCore.SPACE.equals(option);
}
+
+ /**
+ * 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
+ * order to make it sticky.
+ */
+ class InformationDispatchAction extends TextEditorAction {
+
+ /** The wrapped text operation action. */
+ private final TextOperationAction fTextOperationAction;
+
+ /**
+ * Creates a dispatch action.
+ *
+ * @param resourceBundle the resource bundle
+ * @param prefix the prefix
+ * @param textOperationAction the text operation action
+ */
+ public InformationDispatchAction(ResourceBundle resourceBundle, String prefix, final TextOperationAction textOperationAction) {
+ super(resourceBundle, prefix, RubyEditor.this);
+ if (textOperationAction == null)
+ throw new IllegalArgumentException();
+ fTextOperationAction= textOperationAction;
+ }
+
+ /*
+ * @see org.eclipse.jface.action.IAction#run()
+ */
+ public void run() {
+
+ ISourceViewer sourceViewer= getSourceViewer();
+ if (sourceViewer == null) {
+ fTextOperationAction.run();
+ return;
+ }
+
+ if (sourceViewer instanceof ITextViewerExtension4) {
+ ITextViewerExtension4 extension4= (ITextViewerExtension4) sourceViewer;
+ if (extension4.moveFocusToWidgetToken())
+ return;
+ }
+
+ if (sourceViewer instanceof ITextViewerExtension2) {
+ // does a text hover exist?
+ ITextHover textHover= ((ITextViewerExtension2) sourceViewer).getCurrentTextHover();
+ if (textHover != null && makeTextHoverFocusable(sourceViewer, textHover))
+ return;
+ }
+
+ if (sourceViewer instanceof ISourceViewerExtension3) {
+ // does an annotation hover exist?
+ IAnnotationHover annotationHover= ((ISourceViewerExtension3) sourceViewer).getCurrentAnnotationHover();
+ if (annotationHover != null && makeAnnotationHoverFocusable(sourceViewer, annotationHover))
+ return;
+ }
+
+ // otherwise, just run the action
+ fTextOperationAction.run();
+ }
+
+ /**
+ * Tries to make a text hover focusable (or "sticky").
+ *
+ * @param sourceViewer the source viewer to display the hover over
+ * @param textHover the hover to make focusable
+ * @return <code>true</code> if successful, <code>false</code> otherwise
+ * @since 3.2
+ */
+ private boolean makeTextHoverFocusable(ISourceViewer sourceViewer, ITextHover textHover) {
+ Point hoverEventLocation= ((ITextViewerExtension2) sourceViewer).getHoverEventLocation();
+ int offset= computeOffsetAtLocation(sourceViewer, hoverEventLocation.x, hoverEventLocation.y);
+ if (offset == -1)
+ return false;
+
+ try {
+ IRegion hoverRegion= textHover.getHoverRegion(sourceViewer, offset);
+ if (hoverRegion == null)
+ return false;
+
+ String hoverInfo= textHover.getHoverInfo(sourceViewer, hoverRegion);
+
+ IInformationControlCreator controlCreator= null;
+ if (textHover instanceof IInformationProviderExtension2)
+ controlCreator= ((IInformationProviderExtension2)textHover).getInformationPresenterControlCreator();
+
+ IInformationProvider informationProvider= new InformationProvider(hoverRegion, hoverInfo, controlCreator);
+
+ fInformationPresenter.setOffset(offset);
+ fInformationPresenter.setAnchor(AbstractInformationControlManager.ANCHOR_BOTTOM);
+ fInformationPresenter.setMargins(6, 6); // default values from AbstractInformationControlManager
+ String contentType= TextUtilities.getContentType(sourceViewer.getDocument(), IRubyPartitions.RUBY_PARTITIONING, offset, true);
+ fInformationPresenter.setInformationProvider(informationProvider, contentType);
+ fInformationPresenter.showInformation();
+
+ return true;
+
+ } catch (BadLocationException e) {
+ return false;
+ }
+ }
+
+ /**
+ * 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
+ * @since 3.2
+ */
+ private boolean makeAnnotationHoverFocusable(ISourceViewer sourceViewer, 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, IRubyPartitions.RUBY_PARTITIONING, offset, true);
+
+ IInformationControlCreator controlCreator= null;
+
+ /*
+ * XXX: This is a hack to avoid API changes at the end of 3.2,
+ * and should be fixed for 3.3, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=137967
+ */
+ if ("org.eclipse.jface.text.source.projection.ProjectionAnnotationHover".equals(annotationHover.getClass().getName())) { //$NON-NLS-1$
+ controlCreator= new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell shell) {
+ int shellStyle= SWT.RESIZE | SWT.TOOL | getOrientation();
+ int style= SWT.V_SCROLL | SWT.H_SCROLL;
+ return new SourceViewerInformationControl(shell, shellStyle, style);
+ }
+ };
+
+ } else {
+ if (annotationHover instanceof IInformationProviderExtension2)
+ 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;
+ }
+ }
+
+ // modified version from TextViewer
+ private int computeOffsetAtLocation(ITextViewer textViewer, int x, int y) {
+
+ StyledText styledText= textViewer.getTextWidget();
+ IDocument document= textViewer.getDocument();
+
+ if (document == null)
+ return -1;
+
+ try {
+ int widgetOffset= styledText.getOffsetAtLocation(new Point(x, y));
+ Point p= styledText.getLocationAtOffset(widgetOffset);
+ if (p.x > x)
+ widgetOffset--;
+
+ if (textViewer instanceof ITextViewerExtension5) {
+ ITextViewerExtension5 extension= (ITextViewerExtension5) textViewer;
+ return extension.widgetOffset2ModelOffset(widgetOffset);
+ } else {
+ IRegion visibleRegion= textViewer.getVisibleRegion();
+ return widgetOffset + visibleRegion.getOffset();
+ }
+ } catch (IllegalArgumentException e) {
+ return -1;
+ }
+
+ }
+ }
+
+ /**
+ * Information provider used to present focusable information shells.
+ *
+ * @since 3.2
+ */
+ 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;
+ }
+ /*
+ * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion)
+ */
+ public String getInformation(ITextViewer textViewer, IRegion subject) {
+ return 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;
+ }
+ }
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorActionContributor.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -1,5 +1,8 @@
package org.rubypeople.rdt.internal.ui.rubyeditor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.ResourceBundle;
import org.eclipse.jface.action.IAction;
@@ -8,6 +11,8 @@
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.actions.RetargetAction;
import org.eclipse.ui.ide.IDEActionFactory;
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
import org.eclipse.ui.texteditor.ITextEditor;
@@ -17,17 +22,27 @@
import org.rubypeople.rdt.internal.ui.RubyUIMessages;
import org.rubypeople.rdt.internal.ui.actions.FoldingActionGroup;
import org.rubypeople.rdt.ui.actions.IRubyEditorActionDefinitionIds;
+import org.rubypeople.rdt.ui.actions.RdtActionConstants;
import org.rubypeople.rdt.ui.actions.RubyActionIds;
public class RubyEditorActionContributor extends BasicTextEditorActionContributor {
+ private List fPartListeners= new ArrayList();
+
protected RetargetTextEditorAction contentAssistProposal;
private RetargetTextEditorAction fGotoMatchingBracket;
private RetargetTextEditorAction fQuickAssistAction;
+
+ private RetargetAction fRetargetShowRubyDoc;
+ private RetargetTextEditorAction fShowRubyDoc;
public RubyEditorActionContributor() {
super();
ResourceBundle b = RubyEditorMessages.getBundleForConstructedKeys();
+
+ fRetargetShowRubyDoc= new RetargetAction(RdtActionConstants.SHOW_RUBY_DOC, RubyEditorMessages.ShowRDoc_label);
+ fRetargetShowRubyDoc.setActionDefinitionId(IRubyEditorActionDefinitionIds.SHOW_RDOC);
+ markAsPartListener(fRetargetShowRubyDoc);
contentAssistProposal = new RetargetTextEditorAction(RubyUIMessages.getResourceBundle(),
"ContentAssistProposal.");
@@ -38,7 +53,13 @@
fQuickAssistAction= new RetargetTextEditorAction(RubyEditorMessages.getBundleForConstructedKeys(), "CorrectionAssistProposal."); //$NON-NLS-1$
fQuickAssistAction.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICK_ASSIST);
+ fShowRubyDoc= new RetargetTextEditorAction(b, "ShowRDoc."); //$NON-NLS-1$
+ fShowRubyDoc.setActionDefinitionId(IRubyEditorActionDefinitionIds.SHOW_RDOC);
}
+
+ protected final void markAsPartListener(RetargetAction action) {
+ fPartListeners.add(action);
+ }
public void contributeToMenu(IMenuManager menuManager) {
IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
@@ -98,4 +119,37 @@
actionBars.setGlobalActionHandler(IDEActionFactory.ADD_TASK.getId(), getAction(textEditor, IDEActionFactory.ADD_TASK.getId()));
actionBars.setGlobalActionHandler(IDEActionFactory.BOOKMARK.getId(), getAction(textEditor, IDEActionFactory.BOOKMARK.getId()));
}
+
+ @Override
+ public void init(IActionBars bars, IWorkbenchPage page) {
+ Iterator e= fPartListeners.iterator();
+ while (e.hasNext())
+ page.addPartListener((RetargetAction) e.next());
+
+ super.init(bars, page);
+//
+// bars.setGlobalActionHandler(ITextEditorActionDefinitionIds.TOGGLE_SHOW_SELECTED_ELEMENT_ONLY, fTogglePresentation);
+// bars.setGlobalActionHandler(IRubyEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, fToggleMarkOccurrencesAction);
+
+ bars.setGlobalActionHandler(RdtActionConstants.SHOW_RUBY_DOC, fShowRubyDoc);
+ }
+
+ /*
+ * @see IEditorActionBarContributor#dispose()
+ */
+ public void dispose() {
+
+ Iterator e= fPartListeners.iterator();
+ while (e.hasNext())
+ getPage().removePartListener((RetargetAction) e.next());
+ fPartListeners.clear();
+
+ if (fRetargetShowRubyDoc != null) {
+ fRetargetShowRubyDoc.dispose();
+ fRetargetShowRubyDoc= null;
+ }
+
+ setActiveEditor(null);
+ super.dispose();
+ }
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorMessages.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditorMessages.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -42,6 +42,8 @@
private static final String BUNDLE_FOR_CONSTRUCTED_KEYS= "org.rubypeople.rdt.internal.ui.rubyeditor.ConstructedRubyEditorMessages";//$NON-NLS-1$
private static ResourceBundle fgBundleForConstructedKeys= ResourceBundle.getBundle(BUNDLE_FOR_CONSTRUCTED_KEYS);
+ public static String ShowRDoc_label;
+
/**
* Returns the message bundle which contains constructed keys.
*
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyInformationProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyInformationProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyInformationProvider.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -0,0 +1,169 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 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.rubypeople.rdt.internal.ui.text.ruby.hover;
+
+
+import org.eclipse.jface.text.DefaultInformationControl;
+import org.eclipse.jface.text.IInformationControl;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.information.IInformationProvider;
+import org.eclipse.jface.text.information.IInformationProviderExtension2;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IPartListener;
+import org.eclipse.ui.IPerspectiveDescriptor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.rubypeople.rdt.internal.ui.text.HTMLTextPresenter;
+import org.rubypeople.rdt.internal.ui.text.RubyWordFinder;
+import org.rubypeople.rdt.ui.text.ruby.hover.IRubyEditorTextHover;
+
+
+public class RubyInformationProvider implements IInformationProvider, IInformationProviderExtension2 {
+
+ class EditorWatcher implements IPartListener {
+
+ /**
+ * @see IPartListener#partOpened(IWorkbenchPart)
+ */
+ public void partOpened(IWorkbenchPart part) {
+ }
+
+ /**
+ * @see IPartListener#partDeactivated(IWorkbenchPart)
+ */
+ public void partDeactivated(IWorkbenchPart part) {
+ }
+
+ /**
+ * @see IPartListener#partClosed(IWorkbenchPart)
+ */
+ public void partClosed(IWorkbenchPart part) {
+ if (part == fEditor) {
+ fEditor.getSite().getWorkbenchWindow().getPartService().removePartListener(fPartListener);
+ fPartListener= null;
+ }
+ }
+
+ /**
+ * @see IPartListener#partActivated(IWorkbenchPart)
+ */
+ public void partActivated(IWorkbenchPart part) {
+ update();
+ }
+
+ public void partBroughtToTop(IWorkbenchPart part) {
+ update();
+ }
+ }
+
+ protected IEditorPart fEditor;
+ protected IPartListener fPartListener;
+
+ protected String fCurrentPerspective;
+ protected IRubyEditorTextHover fImplementation;
+
+ /**
+ * The presentation control creator.
+ *
+ * @since 3.2
+ */
+ private IInformationControlCreator fPresenterControlCreator;
+
+
+
+ public RubyInformationProvider(IEditorPart editor) {
+
+ fEditor= editor;
+
+ if (fEditor != null) {
+
+ fPartListener= new EditorWatcher();
+ IWorkbenchWindow window= fEditor.getSite().getWorkbenchWindow();
+ window.getPartService().addPartListener(fPartListener);
+
+ update();
+ }
+ }
+
+ protected void update() {
+
+ IWorkbenchWindow window= fEditor.getSite().getWorkbenchWindow();
+ IWorkbenchPage page= window.getActivePage();
+ if (page != null) {
+
+ IPerspectiveDescriptor perspective= page.getPerspective();
+ if (perspective != null) {
+ String perspectiveId= perspective.getId();
+
+ if (fCurrentPerspective == null || fCurrentPerspective != perspectiveId) {
+ fCurrentPerspective= perspectiveId;
+
+ fImplementation= new RubyTypeHover();
+ fImplementation.setEditor(fEditor);
+ }
+ }
+ }
+ }
+
+ /*
+ * @see IInformationProvider#getSubject(ITextViewer, int)
+ */
+ public IRegion getSubject(ITextViewer textViewer, int offset) {
+
+ if (textViewer != null)
+ return RubyWordFinder.findWord(textViewer.getDocument(), offset);
+
+ return null;
+ }
+
+ /*
+ * @see IInformationProvider#getInformation(ITextViewer, IRegion)
+ */
+ public String getInformation(ITextViewer textViewer, IRegion subject) {
+ if (fImplementation != null) {
+ String s= fImplementation.getHoverInfo(textViewer, subject);
+ if (s != null && s.trim().length() > 0) {
+ return s;
+ }
+ }
+
+ return null;
+ }
+
+ /*
+ * @see IInformationProviderExtension2#getInformationPresenterControlCreator()
+ * @since 3.1
+ */
+ public IInformationControlCreator getInformationPresenterControlCreator() {
+ if (fPresenterControlCreator == null) {
+ fPresenterControlCreator= new AbstractReusableInformationControlCreator() {
+
+ /*
+ * @see org.eclipse.jdt.internal.ui.text.java.hover.AbstractReusableInformationControlCreator#doCreateInformationControl(org.eclipse.swt.widgets.Shell)
+ */
+ public IInformationControl doCreateInformationControl(Shell parent) {
+ int shellStyle= SWT.RESIZE | SWT.TOOL;
+ int style= SWT.V_SCROLL | SWT.H_SCROLL;
+ if (BrowserInformationControl.isAvailable(parent))
+ return new BrowserInformationControl(parent, shellStyle, style);
+ else
+ return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
+ }
+ };
+ }
+ return fPresenterControlCreator;
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyTypeHover.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyTypeHover.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyTypeHover.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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.rubypeople.rdt.internal.ui.text.ruby.hover;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.ui.IEditorPart;
+import org.rubypeople.rdt.ui.text.ruby.hover.IRubyEditorTextHover;
+
+
+public class RubyTypeHover implements IRubyEditorTextHover {
+
+ private IRubyEditorTextHover fProblemHover;
+ private IRubyEditorTextHover fRubydocHover;
+
+ public RubyTypeHover() {
+ fProblemHover= new ProblemHover();
+ fRubydocHover= new CommentHoverProvider();
+ }
+
+ /*
+ * @see IRubyEditorTextHover#setEditor(IEditorPart)
+ */
+ public void setEditor(IEditorPart editor) {
+ fProblemHover.setEditor(editor);
+ fRubydocHover.setEditor(editor);
+ }
+
+ /*
+ * @see ITextHover#getHoverRegion(ITextViewer, int)
+ */
+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+ return fRubydocHover.getHoverRegion(textViewer, offset);
+ }
+
+ /*
+ * @see ITextHover#getHoverInfo(ITextViewer, IRegion)
+ */
+ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+ String hoverInfo= fProblemHover.getHoverInfo(textViewer, hoverRegion);
+ if (hoverInfo != null)
+ return hoverInfo;
+
+ return fRubydocHover.getHoverInfo(textViewer, hoverRegion);
+ }
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -7,5 +7,11 @@
* (value <code>"org.rubypeople.rdt.ui.actions.Open"</code>).
*/
public static final String OPEN= "org.rubypeople.rdt.ui.actions.Open"; //$NON-NLS-1$
+
+ /**
+ * Edit menu: name of standard Show Rubydoc global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.ShowRubyDoc"</code>).
+ */
+ public static final String SHOW_RUBY_DOC= "org.rubypeople.rdt.ui.actions.ShowRubyDoc"; //$NON-NLS-1$
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-05-29 13:21:21 UTC (rev 2546)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2007-05-29 13:22:45 UTC (rev 2547)
@@ -16,6 +16,9 @@
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.formatter.MultiPassContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.information.IInformationPresenter;
+import org.eclipse.jface.text.information.IInformationProvider;
+import org.eclipse.jface.text.information.InformationPresenter;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.quickassist.IQuickAssistAssistant;
@@ -63,6 +66,7 @@
import org.rubypeople.rdt.internal.ui.text.ruby.RubyTokenScanner;
import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyEditorTextHoverDescriptor;
import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyEditorTextHoverProxy;
+import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyInformationProvider;
public class RubySourceViewerConfiguration extends TextSourceViewerConfiguration {
@@ -302,12 +306,48 @@
*/
public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
return new IInformationControlCreator() {
-
public IInformationControl createInformationControl(Shell parent) {
return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true));
}
};
}
+
+ /*
+ * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
+ * @since 2.0
+ */
+ public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
+ InformationPresenter presenter= new InformationPresenter(getInformationPresenterControlCreator(sourceViewer));
+ presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
+
+ // Register information provider
+ IInformationProvider provider= new RubyInformationProvider(getEditor());
+ String[] contentTypes= getConfiguredContentTypes(sourceViewer);
+ for (int i= 0; i < contentTypes.length; i++)
+ presenter.setInformationProvider(provider, contentTypes[i]);
+
+ presenter.setSizeConstraints(60, 10, true, true);
+ return presenter;
+ }
+
+ /**
+ * Returns the information presenter control creator. The creator is a factory creating the
+ * presenter controls for the given source viewer. This implementation always returns a creator
+ * for <code>DefaultInformationControl</code> instances.
+ *
+ * @param sourceViewer the source viewer to be configured by this configuration
+ * @return an information control creator
+ * @since 2.1
+ */
+ private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) {
+ return new IInformationControlCreator() {
+ public IInformationControl createInformationControl(Shell parent) {
+ int shellStyle= SWT.RESIZE | SWT.TOOL;
+ int style= SWT.V_SCROLL | SWT.H_SCROLL;
+ return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false));
+ }
+ };
+ }
/**
* Returns the editor in which the configured viewer(s) will reside.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|