|
From: <caw...@us...> - 2007-08-08 14:10:22
|
Revision: 2936
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=2936&view=rev
Author: cawilliams
Date: 2007-08-08 07:10:19 -0700 (Wed, 08 Aug 2007)
Log Message:
-----------
add Ruby Resources view as possible option for "show in" on Ruby Editor
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/resourcesview/RubyResourcesView.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ActionMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ShowInPackageViewAction.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2007-08-08 14:08:55 UTC (rev 2935)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2007-08-08 14:10:19 UTC (rev 2936)
@@ -186,6 +186,7 @@
<perspectiveShortcut
id="org.rubypeople.rdt.ui.RubyBrowsingPerspective">
</perspectiveShortcut>
+ <showInPart id="org.rubypeople.rdt.ui.ViewRubyResources"/>
</perspectiveExtension>
<perspectiveExtension
targetID="org.rubypeople.rdt.ui.RubyBrowsingPerspective">
@@ -631,6 +632,12 @@
id="org.rubypeople.rdt.ui.navigate.ruby.open.structure">
</command>
<command
+ name="%ActionDefinition.showInPackageView.name"
+ description="%ActionDefinition.showInPackageView.description"
+ categoryId="org.eclipse.ui.category.navigate"
+ id="org.rubypeople.rdt.ui.edit.text.ruby.show.in.ruby.resources.view">
+ </command>
+ <command
name="%ActionDefinition.toggleComment.name"
description="%ActionDefinition.toggleComment.description"
categoryId="org.rubypeople.rdt.ui.category.source"
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/resourcesview/RubyResourcesView.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/resourcesview/RubyResourcesView.java 2007-08-08 14:08:55 UTC (rev 2935)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/resourcesview/RubyResourcesView.java 2007-08-08 14:10:19 UTC (rev 2936)
@@ -12,6 +12,10 @@
package org.rubypeople.rdt.internal.ui.resourcesview;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
@@ -19,10 +23,17 @@
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.part.IShowInTarget;
+import org.eclipse.ui.part.ShowInContext;
import org.eclipse.ui.views.navigator.ResourceNavigator;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.RubyViewerFilter;
+import org.rubypeople.rdt.internal.ui.rubyeditor.ExternalRubyFileEditorInput;
+import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyScriptEditorInput;
+import org.rubypeople.rdt.ui.RubyUI;
-public class RubyResourcesView extends ResourceNavigator {
+public class RubyResourcesView extends ResourceNavigator implements IShowInTarget {
private static String IS_RUBY_FILES_ONLY_MEMENTO_KEY = "isRubyFilesOnlyFilterActivated";
private boolean isRubyFilesOnlyFilterActivated = false; // default value if
@@ -82,4 +93,96 @@
}
super.editorActivated(editor) ;
}
+
+ public static RubyResourcesView openInActivePerspective() {
+ try {
+ return (RubyResourcesView)RubyPlugin.getActivePage().showView(RubyUI.ID_RUBY_RESOURCE_VIEW);
+ } catch(PartInitException pe) {
+ return null;
+ }
+ }
+
+ public boolean tryToReveal(Object element) {
+ if (revealElementOrParent(element))
+ return true;
+ return false;
+ }
+
+ private boolean revealElementOrParent(Object element) {
+ if (revealAndVerify(element))
+ return true;
+ element= getVisibleParent(element);
+ if (element != null) {
+ if (revealAndVerify(element))
+ return true;
+ if (element instanceof IRubyElement) {
+ IResource resource= ((IRubyElement)element).getResource();
+ if (resource != null) {
+ if (revealAndVerify(resource))
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private boolean revealAndVerify(Object element) {
+ if (element == null)
+ return false;
+ selectReveal(new StructuredSelection(element));
+ return ! getSite().getSelectionProvider().getSelection().isEmpty();
+ }
+
+ private Object getVisibleParent(Object object) {
+ if (object == null)
+ return null;
+ if (!(object instanceof IRubyElement))
+ return object;
+ IRubyElement element2= (IRubyElement) object;
+ switch (element2.getElementType()) {
+ case IRubyElement.IMPORT_DECLARATION:
+ case IRubyElement.IMPORT_CONTAINER:
+ case IRubyElement.TYPE:
+ case IRubyElement.METHOD:
+ case IRubyElement.FIELD:
+ // select parent script
+ element2= (IRubyElement)element2.getOpenable();
+ break;
+ case IRubyElement.RUBY_MODEL:
+ element2= null;
+ break;
+ }
+ return element2;
+ }
+
+ public boolean show(ShowInContext context) {
+ ISelection selection= context.getSelection();
+ if (selection instanceof IStructuredSelection) {
+ // fix for 64634 Navigate/Show in/Package Explorer doesn't work
+ IStructuredSelection structuredSelection= ((IStructuredSelection) selection);
+ if (structuredSelection.size() == 1 && tryToReveal(structuredSelection.getFirstElement()))
+ return true;
+ }
+
+ Object input= context.getInput();
+ if (input instanceof IEditorInput) {
+ Object elementOfInput= getElementOfInput((IEditorInput)context.getInput());
+ return elementOfInput != null && tryToReveal(elementOfInput);
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the element contained in the EditorInput
+ */
+ Object getElementOfInput(IEditorInput input) {
+ if (input instanceof IRubyScriptEditorInput)
+ return ((IRubyScriptEditorInput)input).getRubyScript();
+ else if (input instanceof IFileEditorInput)
+ return ((IFileEditorInput)input).getFile();
+ else if (input instanceof ExternalRubyFileEditorInput)
+ return ((ExternalRubyFileEditorInput)input).getStorage();
+ return null;
+ }
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2007-08-08 14:08:55 UTC (rev 2935)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2007-08-08 14:10:19 UTC (rev 2936)
@@ -8,7 +8,6 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ProjectScope;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
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-08-08 14:08:55 UTC (rev 2935)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java 2007-08-08 14:10:19 UTC (rev 2936)
@@ -133,6 +133,7 @@
import org.rubypeople.rdt.ui.actions.OpenEditorActionGroup;
import org.rubypeople.rdt.ui.actions.RubyActionGroup;
import org.rubypeople.rdt.ui.actions.RubySearchActionGroup;
+import org.rubypeople.rdt.ui.actions.ShowInPackageViewAction;
import org.rubypeople.rdt.ui.actions.SurroundWithBeginRescueAction;
import org.rubypeople.rdt.ui.text.folding.IRubyFoldingStructureProvider;
import org.rubypeople.rdt.ui.text.folding.IRubyFoldingStructureProviderExtension;
@@ -276,6 +277,10 @@
WorkbenchHelp.setHelp(action, IRubyHelpContextIds.TOGGLE_COMMENT_ACTION);
configureToggleCommentAction();
+ action= new ShowInPackageViewAction(this);
+ action.setActionDefinitionId(IRubyEditorActionDefinitionIds.SHOW_IN_RUBY_RESOURCES_VIEW);
+ setAction("ShowInPackageView", action); //$NON-NLS-1$
+
action= new GotoMatchingBracketAction(this);
action.setActionDefinitionId(IRubyEditorActionDefinitionIds.GOTO_MATCHING_BRACKET);
setAction(GotoMatchingBracketAction.GOTO_MATCHING_BRACKET, action);
@@ -757,8 +762,7 @@
}
protected void editorContextMenuAboutToShow(IMenuManager menu) {
- super.editorContextMenuAboutToShow(menu);
-
+ super.editorContextMenuAboutToShow(menu);
menu.insertAfter(IContextMenuConstants.GROUP_OPEN, new GroupMarker(IContextMenuConstants.GROUP_SHOW));
ActionContext context= new ActionContext(getSelectionProvider().getSelection());
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ActionMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ActionMessages.java 2007-08-08 14:08:55 UTC (rev 2935)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ActionMessages.java 2007-08-08 14:10:19 UTC (rev 2936)
@@ -12,6 +12,11 @@
public static String SurroundWithBeginRescueAction_dialog_title;
public static String QuickMenuAction_menuTextWithShortcut;
+ public static String ShowInPackageViewAction_label;
+ public static String ShowInPackageViewAction_description;
+ public static String ShowInPackageViewAction_tooltip;
+ public static String ShowInPackageViewAction_error_message;
+ public static String ShowInPackageViewAction_dialog_title;
static {
NLS.initializeMessages(BUNDLE_NAME, ActionMessages.class);
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java 2007-08-08 14:08:55 UTC (rev 2935)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java 2007-08-08 14:10:19 UTC (rev 2936)
@@ -173,4 +173,11 @@
*/
public static final String OPEN_HIERARCHY= "org.rubypeople.rdt.ui.edit.text.ruby.open.hierarchy"; //$NON-NLS-1$
+
+ /**
+ * Action definition ID of the navigate -> show in ruby resources view action
+ * (value <code>"org.rubypeople.rdt.ui.edit.text.ruby.show.in.ruby.resources.view"</code>).
+ */
+ public static final String SHOW_IN_RUBY_RESOURCES_VIEW= "org.rubypeople.rdt.ui.edit.text.ruby.show.in.ruby.resources.view"; //$NON-NLS-1$
+
}
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-08-08 14:08:55 UTC (rev 2935)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-08-08 14:10:19 UTC (rev 2936)
@@ -96,5 +96,9 @@
*/
public static final String FIND_WRITE_ACCESS_IN_WORKING_SET= "org.rubypeople.rdt.ui.actions.WriteAccessInWorkingSet"; //$NON-NLS-1$
-
+ /**
+ * Navigate menu: name of standard Show in Ruby Resources View global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.ShowInRubyResourcesView"</code>).
+ */
+ public static final String SHOW_IN_RESOURCES_VIEW= "org.rubypeople.rdt.ui.actions.ShowInRubyResourcesView"; //$NON-NLS-1$
}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ShowInPackageViewAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ShowInPackageViewAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ShowInPackageViewAction.java 2007-08-08 14:10:19 UTC (rev 2936)
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * 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.ui.actions;
+
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IOpenable;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.actions.SelectionConverter;
+import org.rubypeople.rdt.internal.ui.resourcesview.RubyResourcesView;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+/**
+ * This action reveals the currently selected Ruby element in the
+ * package explorer.
+ * <p>
+ * The action is applicable to selections containing elements of type
+ * <code>IRubyElement</code>.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ * @since 2.0
+ */
+public class ShowInPackageViewAction extends SelectionDispatchAction {
+
+ private RubyEditor fEditor;
+
+ /**
+ * Creates a new <code>ShowInPackageViewAction</code>. The action requires
+ * that the selection provided by the site's selection provider is of type
+ * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
+ *
+ * @param site the site providing context information for this action
+ */
+ public ShowInPackageViewAction(IWorkbenchSite site) {
+ super(site);
+ setText(ActionMessages.ShowInPackageViewAction_label);
+ setDescription(ActionMessages.ShowInPackageViewAction_description);
+ setToolTipText(ActionMessages.ShowInPackageViewAction_tooltip);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.SHOW_IN_PACKAGEVIEW_ACTION);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ */
+ public ShowInPackageViewAction(RubyEditor editor) {
+ this(editor.getEditorSite());
+ fEditor= editor;
+ setEnabled(SelectionConverter.canOperateOn(fEditor));
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on SelectionDispatchAction.
+ */
+ public void selectionChanged(ITextSelection selection) {
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on SelectionDispatchAction.
+ */
+ public void selectionChanged(IStructuredSelection selection) {
+ setEnabled(checkEnabled(selection));
+ }
+
+ private boolean checkEnabled(IStructuredSelection selection) {
+ if (selection.size() != 1)
+ return false;
+ return selection.getFirstElement() instanceof IRubyElement;
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on SelectionDispatchAction.
+ */
+ public void run(ITextSelection selection) {
+ try {
+ IRubyElement element= SelectionConverter.getElementAtOffset(fEditor);
+ if (element != null)
+ run(element);
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ String message= ActionMessages.ShowInPackageViewAction_error_message;
+ ErrorDialog.openError(getShell(), getDialogTitle(), message, e.getStatus());
+ }
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on SelectionDispatchAction.
+ */
+ public void run(IStructuredSelection selection) {
+ if (!checkEnabled(selection))
+ return;
+ run((IRubyElement)selection.getFirstElement());
+ }
+
+ /*
+ * No Rubydoc. The method should be internal but can't be changed since
+ * we shipped it with a public visibility
+ */
+ public void run(IRubyElement element) {
+ if (element == null)
+ return;
+
+ // reveal the top most element only
+ IOpenable openable= element.getOpenable();
+ if (openable instanceof IRubyElement)
+ element= (IRubyElement)openable;
+
+ RubyResourcesView view= RubyResourcesView.openInActivePerspective();
+ view.tryToReveal(element);
+ }
+
+ private static String getDialogTitle() {
+ return ActionMessages.ShowInPackageViewAction_dialog_title;
+ }
+}
Property changes on: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ShowInPackageViewAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|