|
From: Markus B. <mba...@us...> - 2005-09-19 21:48:44
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32477/src/org/rubypeople/rdt/internal/ui/actions Modified Files: GenerateRdocAction.java Log Message: if there is no resource selected, check the active editor for its connected resource and call the rdoc generation on its project (behaviour similar to ApplicationShortcuts) Index: GenerateRdocAction.java =================================================================== RCS file: /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/GenerateRdocAction.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** GenerateRdocAction.java 18 Sep 2005 18:46:10 -0000 1.1 --- GenerateRdocAction.java 19 Sep 2005 21:48:07 -0000 1.2 *************** *** 3,11 **** --- 3,17 ---- import org.eclipse.core.resources.IResource; 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.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.rdocexport.RDocUtility; *************** *** 23,34 **** } ! public void run(IAction action) { ! IStructuredSelection selection = null; if (fSelection instanceof IStructuredSelection) { ! selection = (IStructuredSelection) fSelection; Object first = selection.getFirstElement(); ! if (first instanceof IResource) { ! RDocUtility.generateDocumentation((IResource) first); ! } } } --- 29,70 ---- } ! private void showNoSelectionMessage() { ! MessageDialog.openInformation( ! fCurrentShell.getShell(), ! "No ruby project selected", ! "Please select a ruby project or resource for the generation of Rdoc."); ! return; ! } ! ! 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 run(IAction action) { ! IResource resource = this.findSelectedResource() ; ! if (resource == null) { ! showNoSelectionMessage(); ! } ! else { ! RDocUtility.generateDocumentation(resource); } } |