|
From: <caw...@us...> - 2006-12-21 18:03:00
|
Revision: 1718
http://svn.sourceforge.net/rubyeclipse/?rev=1718&view=rev
Author: cawilliams
Date: 2006-12-21 10:02:58 -0800 (Thu, 21 Dec 2006)
Log Message:
-----------
Add a menu item/action to "Add a Ruby nature" to an existing project. This is useful for existing Java projects where we'd like to use some ruby scripts. (So a lot of JRuby projects and also our own plugins).
This fixes problems where opening a ruby script inside a Java project made RDT throw runtime exceptions (because it did a check for Ruby nature on the project).
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.xml
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/AddRubyNatureAction.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-21 16:35:14 UTC (rev 1717)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2006-12-21 18:02:58 UTC (rev 1718)
@@ -580,6 +580,14 @@
id="exportRdoc">
</action>
<action
+ definitionId="org.rubypeople.rdt.ui.add.rubynature"
+ label="Add Ruby Nature"
+ helpContextId="org.rubypeople.rdt.ui.add_ruby_nature_action"
+ class="org.rubypeople.rdt.internal.ui.actions.AddRubyNatureAction"
+ menubarPath="project/additions"
+ id="addRubyNature">
+ </action>
+ <action
definitionId="org.rubypeople.rdt.ui.edit.text.ruby.uncomment"
label="%UncommentAction.label"
menubarPath="org.rubypeople.rdt.ui.ruby.menu/editGroup"
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/AddRubyNatureAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/AddRubyNatureAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/AddRubyNatureAction.java 2006-12-21 18:02:58 UTC (rev 1718)
@@ -0,0 +1,89 @@
+package org.rubypeople.rdt.internal.ui.actions;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+
+public class AddRubyNatureAction implements IWorkbenchWindowActionDelegate {
+
+ private Shell fCurrentShell;
+
+ private ISelection fSelection;
+
+ public void dispose() {
+ }
+
+ public void init(IWorkbenchWindow window) {
+ fCurrentShell = window.getShell();
+ }
+
+ public void run(IAction action) {
+ IResource resource = findSelectedResource();
+ if (resource == null) {
+ MessageDialog
+ .openInformation(
+ fCurrentShell.getShell(),
+ "No project selected",
+ "Please select a project or resource for the addition of a ruby nature to the enclosing project.");
+ return;
+ }
+ try {
+ RubyCore.addRubyNature(resource.getProject(), null);
+ } catch (CoreException e) {
+ MessageDialog.openInformation(fCurrentShell.getShell(),
+ "Unable to add ruby nature", e.getMessage());
+ }
+ }
+
+ private IResource findSelectedResource() {
+ // the first shot is the selection
+ if (fSelection instanceof IStructuredSelection) {
+ IStructuredSelection selection = (IStructuredSelection) fSelection;
+ Object first = selection.getFirstElement();
+ if (first instanceof IResource) {
+ return ((IResource) first);
+ }
+ }
+
+ // the second is to check the active editor
+ // this behaviour is similar to the RubyApplicationShortcut, which also
+ // takes a selection in the navigator or the active editor to determine
+ // which
+ // ruby file to launch
+ IWorkbenchPage page = RubyPlugin.getActivePage();
+ if (page == null) {
+ return null;
+ }
+ IEditorPart editor = page.getActiveEditor();
+ if (editor == null) {
+ return null;
+ }
+ IEditorInput input = editor.getEditorInput();
+ if (input == null) {
+ return null;
+ }
+ IRubyElement rubyElement = (IRubyElement) input
+ .getAdapter(IRubyElement.class);
+ if (rubyElement == null) {
+ return null;
+ }
+ return rubyElement.getResource();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ fSelection = selection;
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|