|
From: <caw...@us...> - 2007-09-11 19:11:22
|
Revision: 3138
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3138&view=rev
Author: cawilliams
Date: 2007-09-11 12:11:07 -0700 (Tue, 11 Sep 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ExternalRubyDocumentProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/RubyUI.java
Modified: trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF 2007-09-11 16:11:51 UTC (rev 3137)
+++ trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF 2007-09-11 19:11:07 UTC (rev 3138)
@@ -15,6 +15,7 @@
org.rubypeople.rdt.internal.ui.compare,
org.rubypeople.rdt.internal.ui.dialogs,
org.rubypeople.rdt.internal.ui.infoviews,
+ org.rubypeople.rdt.internal.ui.packageview,
org.rubypeople.rdt.internal.ui.preferences,
org.rubypeople.rdt.internal.ui.preferences.formatter,
org.rubypeople.rdt.internal.ui.resourcesview,
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java 2007-09-11 16:11:51 UTC (rev 3137)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java 2007-09-11 19:11:07 UTC (rev 3138)
@@ -16,6 +16,8 @@
import org.rubypeople.rdt.core.ICodeAssist;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceRange;
+import org.rubypeople.rdt.core.ISourceReference;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
@@ -185,4 +187,37 @@
return result;
}
+ public static IRubyElement resolveEnclosingElement(RubyEditor editor, ITextSelection selection) throws RubyModelException {
+ return resolveEnclosingElement(getInput(editor), selection);
+ }
+
+ public static IRubyElement resolveEnclosingElement(IRubyElement input, ITextSelection selection) throws RubyModelException {
+ IRubyElement atOffset= null;
+ if (input instanceof IRubyScript) {
+ IRubyScript cunit= (IRubyScript)input;
+ RubyModelUtil.reconcile(cunit);
+ atOffset= cunit.getElementAt(selection.getOffset());
+ } else {
+ return null;
+ }
+ if (atOffset == null) {
+ return input;
+ } else {
+ int selectionEnd= selection.getOffset() + selection.getLength();
+ IRubyElement result= atOffset;
+ if (atOffset instanceof ISourceReference) {
+ ISourceRange range= ((ISourceReference)atOffset).getSourceRange();
+ while (range.getOffset() + range.getLength() < selectionEnd) {
+ result= result.getParent();
+ if (! (result instanceof ISourceReference)) {
+ result= input;
+ break;
+ }
+ range= ((ISourceReference)result).getSourceRange();
+ }
+ }
+ return result;
+ }
+ }
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java 2007-09-11 16:11:51 UTC (rev 3137)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java 2007-09-11 19:11:07 UTC (rev 3138)
@@ -47,6 +47,15 @@
public class EditorUtility {
/**
+ * Opens a Ruby editor for an element such as <code>IRubyElement</code>, <code>IFile</code>, or <code>IStorage</code>.
+ * The editor is activated by default.
+ * @return the IEditorPart or null if wrong element type or opening failed
+ */
+ public static IEditorPart openInEditor(Object inputElement) throws RubyModelException, PartInitException {
+ return openInEditor(inputElement, true);
+ }
+
+ /**
* Opens a Ruby editor for an element (IRubyElement, IFile, IStorage...)
* @return the IEditorPart or null if wrong element type or opening failed
*/
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ExternalRubyDocumentProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ExternalRubyDocumentProvider.java 2007-09-11 16:11:51 UTC (rev 3137)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ExternalRubyDocumentProvider.java 2007-09-11 19:11:07 UTC (rev 3138)
@@ -9,12 +9,11 @@
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.ui.internal.editors.text.WorkspaceOperationRunner;
import org.eclipse.ui.texteditor.AbstractDocumentProvider;
-import org.rubypeople.rdt.internal.ui.RubyUIMessages;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.RubyUIMessages;
import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
import org.rubypeople.rdt.ui.text.RubyTextTools;
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/RubyUI.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/RubyUI.java 2007-09-11 16:11:51 UTC (rev 3137)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/RubyUI.java 2007-09-11 19:11:07 UTC (rev 3138)
@@ -15,6 +15,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.dialogs.SelectionDialog;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.rubypeople.rdt.core.IRubyElement;
@@ -299,4 +300,19 @@
dialog.setFilter(filter);
return dialog;
}
+
+ /**
+ * Opens a Ruby editor on the given Ruby element. The element can be a ruby script.
+ * If there already is an open Ruby editor for the given element, it is returned.
+ *
+ * @param element the input element; a ruby script
+ * (<code>IRubyScript</code>)
+ * @return the editor, or </code>null</code> if wrong element type or opening failed
+ * @exception PartInitException if the editor could not be initialized
+ * @exception RubyModelException if this element does not exist or if an
+ * exception occurs while accessing its underlying resource
+ */
+ public static IEditorPart openInEditor(IRubyElement element) throws RubyModelException, PartInitException {
+ return EditorUtility.openInEditor(element);
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|