|
From: <caw...@us...> - 2006-12-22 18:32:34
|
Revision: 1729
http://svn.sourceforge.net/rubyeclipse/?rev=1729&view=rev
Author: cawilliams
Date: 2006-12-22 10:32:30 -0800 (Fri, 22 Dec 2006)
Log Message:
-----------
apply part of murphee's patch - adding an extension point for hyperlinkProviders (they provide IHyperlinks)
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/text/ruby/hover/RiDocHoverProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyCodeTextHover.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/extensions/ITextHoverProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/schema/hyperlinkProvider.exsd
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/hyperlinks/IHyperlinkProvider.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.properties 2006-12-22 18:31:03 UTC (rev 1728)
+++ trunk/org.rubypeople.rdt.ui/plugin.properties 2006-12-22 18:32:30 UTC (rev 1729)
@@ -6,6 +6,8 @@
Plugin.name=Ruby Development Tools UI
providerName=RubyPeople, Inc.
+hyperlinkProvider=Hyperlink provider
+
# Browsing
Browsing.perspectiveName= Ruby Browsing
Browsing.viewCategoryName= Ruby Browsing
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-22 18:31:03 UTC (rev 1728)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-22 18:32:30 UTC (rev 1729)
@@ -3,6 +3,7 @@
<plugin>
<extension-point id="textHoverProvider" name="%textHoverProvider" schema="schema/textHoverProvider.exsd"/>
+ <extension-point id="hyperlinkProvider" name="%hyperlinkProvider" schema="schema/hyperlinkProvider.exsd"/>
<extension-point id="foldingStructureProviders" name="%foldingStructureProviders" schema="schema/foldingStructureProviders.exsd"/>
<extension-point id="editorPopupExtender" name="%editorPopupExtender" schema="schema/org.rubypeople.rdt.ui.editorPopupExtender.exsd"/>
<extension-point id="rubyTemplateProvider" name="Ruby template provider" schema="schema/rubyTemplateProvider.exsd"/>
Added: trunk/org.rubypeople.rdt.ui/schema/hyperlinkProvider.exsd
===================================================================
--- trunk/org.rubypeople.rdt.ui/schema/hyperlinkProvider.exsd (rev 0)
+++ trunk/org.rubypeople.rdt.ui/schema/hyperlinkProvider.exsd 2006-12-22 18:32:30 UTC (rev 1729)
@@ -0,0 +1,102 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.rubypeople.rdt.ui">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.rubypeople.rdt.ui" id="hyperlinkProvider" name="HyperLink Provider"/>
+ </appInfo>
+ <documentation>
+ Provides the detector and behavior for Code Browsing Hyperlinks.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="hyperlinkProvider"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="hyperlinkProvider">
+ <complexType>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+ The class that implements org.rubypeople.rdt.ui.extensions.IHyperlinkProvider.
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="java" basedOn="org.rubypeople.rdt.ui.extensions.IHyperlinkProvider"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+</schema>
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java 2006-12-22 18:32:30 UTC (rev 1729)
@@ -0,0 +1,125 @@
+package org.rubypeople.rdt.internal.ui.text.hyperlinks;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ide.IDE;
+import org.jruby.ast.Node;
+import org.rubypeople.rdt.core.IMember;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceRange;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.codeassist.SelectionEngine;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.text.RubyWordFinder;
+import org.rubypeople.rdt.ui.IWorkingCopyManager;
+import org.rubypeople.rdt.ui.text.hyperlinks.IHyperlinkProvider;
+
+public class RubyElementsHyperlinkProvider implements IHyperlinkProvider {
+
+ public RubyElementsHyperlinkProvider (){}
+
+ class RubyElementsHyperlink implements IHyperlink {
+ private IRegion fRegion;
+ private final IEditorInput fEditorInput;
+ private final IRubyElement[] fElements;
+
+ public RubyElementsHyperlink(IEditorInput editorInput, IRegion region, String symbol, IRubyElement[] elements) {
+ this.fEditorInput = editorInput;
+// fRegion = new Region(region.getOffset(), 5);
+ fRegion = region;
+ this.fElements = elements;
+ }
+
+ public IRegion getHyperlinkRegion() {
+ return fRegion;
+ }
+
+ public String getHyperlinkText() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getTypeLabel() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+ public void open() {
+ try {
+ // FIXME Check for first element which is an instanceof of IMember, don't just try to access the first element!
+ if(fElements != null && fElements.length > 0){
+ ISourceRange sourceRange = ((IMember) fElements[0]).getSourceRange();
+ IFile file = null;
+ if (fEditorInput instanceof IFileEditorInput) {
+ IFileEditorInput fileInput = (IFileEditorInput) fEditorInput;
+ file = fileInput.getFile();
+ }
+ openFileAndLocation(sourceRange, file);
+ }
+ } catch (PartInitException e) {
+ RubyPlugin.log(e);
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ } catch (CoreException e) {
+ RubyPlugin.log(e);
+ }
+ }
+
+ private void openFileAndLocation(ISourceRange sourceRange, IFile file)
+ throws PartInitException, CoreException {
+ if (file == null) {
+ return;
+ }
+ if (sourceRange == null) {
+ return;
+ }
+ IEditorPart editorPart = IDE.openEditor(PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage(), file, true);
+
+ IMarker mark = file.createMarker(IMarker.TEXT);
+ mark.setAttribute(IMarker.CHAR_START, sourceRange.getOffset());
+ mark.setAttribute(IMarker.CHAR_END, sourceRange.getOffset()
+ + sourceRange.getLength());
+ IDE.gotoMarker(editorPart, mark);
+ mark.delete();
+ IDE.gotoMarker(editorPart, mark);
+ }
+
+ }
+
+
+ public IHyperlink getHyperlink(IEditorInput input, ITextViewer textViewer, Node node,
+ IRegion region, boolean canShowMultipleHyperlinks) {
+ IRegion newRegion = RubyWordFinder.findWord(textViewer.getDocument(), region.getOffset());
+ try {
+ String symbol = textViewer.getDocument().get(newRegion.getOffset(), newRegion.getLength());
+ // Let's see if this is a RubyElement
+ SelectionEngine engine = new SelectionEngine();
+ IWorkingCopyManager manager = RubyPlugin.getDefault().getWorkingCopyManager();
+ IRubyScript script = manager.getWorkingCopy(input);
+ IRubyElement[] elements = engine.select(script, newRegion.getOffset(), newRegion.getOffset() + newRegion.getLength());
+ if(elements == null){
+ return null;
+ }
+ if(elements.length > 0){
+ // TODO: check if it's a RubyElement, if not, return null
+ return new RubyElementsHyperlink(input, newRegion, symbol, elements);
+ }
+ return null;
+ } catch (Exception e) {
+ RubyPlugin.log(e);
+ }
+ return null;
+ }
+}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java 2006-12-22 18:31:03 UTC (rev 1728)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RiDocHoverProvider.java 2006-12-22 18:32:30 UTC (rev 1729)
@@ -12,6 +12,7 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.ui.IEditorInput;
import org.rubypeople.rdt.internal.launching.RubyRuntime;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.launching.IInterpreter;
@@ -20,7 +21,7 @@
public class RiDocHoverProvider implements ITextHoverProvider {
- public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion){
+ public String getHoverInfo(IEditorInput input, ITextViewer textViewer, IRegion hoverRegion){
IPath riPath = new Path( RubyPlugin.getDefault().getPreferenceStore().getString( PreferenceConstants.RI_PATH ) );
List args = new ArrayList();
args.add(0, riPath.toString());
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyCodeTextHover.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyCodeTextHover.java 2006-12-22 18:31:03 UTC (rev 1728)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/hover/RubyCodeTextHover.java 2006-12-22 18:32:30 UTC (rev 1729)
@@ -11,6 +11,7 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.ui.texteditor.ITextEditor;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.ui.extensions.ITextHoverProvider;
@@ -38,7 +39,7 @@
if(extensions.size() > 0){
for(int i=0; i< extensions.size(); i++){
ITextHoverProvider currentProvider = (ITextHoverProvider) extensions.get(i);
- String hoverText = currentProvider.getHoverInfo(textViewer, hoverRegion);
+ String hoverText = currentProvider.getHoverInfo(getEditor().getEditorInput(), textViewer, hoverRegion);
if(hoverText != null){
return hoverText;
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/extensions/ITextHoverProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/extensions/ITextHoverProvider.java 2006-12-22 18:31:03 UTC (rev 1728)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/extensions/ITextHoverProvider.java 2006-12-22 18:32:30 UTC (rev 1729)
@@ -2,6 +2,8 @@
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
/**
@@ -13,9 +15,10 @@
public interface ITextHoverProvider {
/**
*
+ * @param input
* @param textViewer the ITextViewer that shows this hover
* @param hoverRegion the region that was preselected by the Ruby Hover system
* @return the hover text OR null if no text was found
*/
- public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion);
+ public String getHoverInfo(IEditorInput input, ITextViewer textViewer, IRegion hoverRegion);
}
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 2006-12-22 18:31:03 UTC (rev 1728)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/RubySourceViewerConfiguration.java 2006-12-22 18:32:30 UTC (rev 1729)
@@ -55,6 +55,7 @@
import org.rubypeople.rdt.internal.ui.text.RubyReconciler;
import org.rubypeople.rdt.internal.ui.text.comment.CommentFormattingStrategy;
import org.rubypeople.rdt.internal.ui.text.comment.RubyCommentAutoIndentStrategy;
+import org.rubypeople.rdt.internal.ui.text.hyperlinks.RubyHyperLinkDetector;
import org.rubypeople.rdt.internal.ui.text.ruby.AbstractRubyScanner;
import org.rubypeople.rdt.internal.ui.text.ruby.RubyCodeScanner;
import org.rubypeople.rdt.internal.ui.text.ruby.RubyCompletionProcessor;
@@ -62,7 +63,6 @@
import org.rubypeople.rdt.internal.ui.text.ruby.RubyReconcilingStrategy;
import org.rubypeople.rdt.internal.ui.text.ruby.SingleTokenRubyCodeScanner;
import org.rubypeople.rdt.internal.ui.text.ruby.hover.RubyCodeTextHover;
-import org.rubypeople.rdt.ui.text.hyperlinks.RubyHyperLinkDetector;
public class RubySourceViewerConfiguration extends
TextSourceViewerConfiguration {
@@ -540,6 +540,7 @@
String contentType) {
if (fRubyTextHover == null) {
fRubyTextHover = new RubyCodeTextHover();
+ fRubyTextHover.setEditor(getEditor());
}
return fRubyTextHover;
}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/hyperlinks/IHyperlinkProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/hyperlinks/IHyperlinkProvider.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/text/hyperlinks/IHyperlinkProvider.java 2006-12-22 18:32:30 UTC (rev 1729)
@@ -0,0 +1,11 @@
+package org.rubypeople.rdt.ui.text.hyperlinks;
+
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.IEditorInput;
+import org.jruby.ast.Node;
+
+public interface IHyperlinkProvider {
+ public IHyperlink getHyperlink(IEditorInput input,ITextViewer textViewer, Node node, IRegion region, boolean canShowMultipleHyperlinks);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|