Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 7595 Details for
Bug 18338
Run/Debug in the context menu
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Experimental Code, part one
org.eclipse.debug.ui.contextuallaunch.patch (text/plain), 20.34 KB, created by
Chris Tilt
on 2004-01-27 14:22:24 EST
(
hide
)
Description:
Experimental Code, part one
Filename:
MIME Type:
Creator:
Chris Tilt
Created:
2004-01-27 14:22:24 EST
Size:
20.34 KB
patch
obsolete
>Index: plugin.properties >=================================================================== >retrieving revision 1.103 >diff -u -r1.103 plugin.properties >--- plugin.properties 16 Jan 2004 18:38:18 -0000 1.103 >+++ plugin.properties 27 Jan 2004 19:09:18 -0000 >@@ -187,3 +187,10 @@ > BreakpointMarkerPreference.label= Breakpoints > > SourceContainerPresentationsName = Source Container Presentations >+ >+#---Chris' work in progress >+LaunchActions.label=Launch >+RunAsMenu.label=&Run As >+DebugAsMenu.label=&Debug As >+LaunchMenu.label=&Run >+LaunchActionsMenu.label=&Launch Actions >Index: plugin.xml >=================================================================== >retrieving revision 1.171 >diff -u -r1.171 plugin.xml >--- plugin.xml 16 Jan 2004 18:38:18 -0000 1.171 >+++ plugin.xml 27 Jan 2004 19:09:19 -0000 >@@ -1413,5 +1413,51 @@ > id="org.eclipse.debug.ui.workingSetComparator"> > </launchConfigurationComparator> > </extension> >+<!-- ========================================= --> >+<!-- Contextual Launch Menu (Work in Progress) --> >+<!-- ========================================= --> >+ <extension >+ point="org.eclipse.ui.popupMenus"> >+ <objectContribution >+ objectClass="org.eclipse.core.resources.IResource" >+ adaptable="true" >+ id="org.eclipse.debug.ui.contextualLaunch"> >+ <action >+ label="%LaunchMenu.label" >+ style="pulldown" >+ class="org.eclipse.debug.internal.ui.actions.ContextualLaunchObjectActionDelegate" >+ menubarPath="additions" >+ enablesFor="1" >+ id="org.eclipse.debug.ui.contextualLaunch.submenu"> >+ </action> >+ <!-- dead stuff that was experimentation >+ <menu >+ label="%LaunchMenu.label" >+ path="additions" >+ id="contextualLaunch.popupMenu"> >+ <separator >+ name="launchGroup"> >+ </separator> >+ </menu> >+ <menu >+ label="%DebugAsMenu.label" >+ path="contextualLaunch.popupMenu/launchGroup" >+ id="contextualLaunch.debugAs.menu"> >+ <separator >+ name="debugAsGroup"> >+ </separator> >+ </menu> >+ <menu >+ label="%RunAsMenu.label" >+ path="contextualLaunch.popupMenu/launchGroup" >+ id="contextualLaunch.runAs.menu"> >+ <separator >+ name="runAsGroup"> >+ </separator> >+ </menu> >+--> >+ </objectContribution> >+ </extension> >+<!-- End Contextual Run Menu (Work in Progress) --> > > </plugin> >Index: schema/launchShortcuts.exsd >=================================================================== >retrieving revision 1.6 >diff -u -r1.6 launchShortcuts.exsd >--- schema/launchShortcuts.exsd 9 Jun 2003 16:43:59 -0000 1.6 >+++ schema/launchShortcuts.exsd 27 Jan 2004 19:09:23 -0000 >@@ -49,6 +49,7 @@ > <complexType> > <sequence> > <element ref="perspective" minOccurs="0" maxOccurs="unbounded"/> >+ <element ref="filter" minOccurs="0" maxOccurs="unbounded"/> > </sequence> > <attribute name="id" type="string" use="required"> > <annotation> >@@ -106,6 +107,20 @@ > </documentation> > </annotation> > </attribute> >+ <attribute name="contextLabel" type="string"> >+ <annotation> >+ <documentation> >+ an optional attribute that specifies the label to appear in the contextual launch menu (if this shortcut is not filtered according to the rules described in the filterClass attribute). If unspecified, the <samp>label</samp> attribute will be used instead. >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="filterClass" type="string"> >+ <annotation> >+ <documentation> >+ an optional attribute that specifies the fully qualified path of a Java class that implements the <samp>org.eclipse.ui.IActionFilter</samp> interface. The testAttribute() method is called with the selected resource and the name/value pair specified by subsequent filter elements. If all return values of all filter elements are true, the shortcut will appear in the contextual launch menu of the selected resource. If the filterClass attribute is not specifies, the shortcut will not appear in the contextual launch menu. If the filterClass is specified, but no filter elements are found, the shortcut will appear in the menu. >+ </documentation> >+ </annotation> >+ </attribute> > </complexType> > </element> > >@@ -121,6 +136,30 @@ > </complexType> > </element> > >+ <element name="filter"> >+ <annotation> >+ <documentation> >+ specifies the name/value pair that will be tested for boolean true/false by calling the <samp>org.eclipse.ui.IActionFilter:testAttribute()</samp> method of the class specified by the <samp>filterClass</samp> attribute of the parent <samp>shortcut</samp> element. If all filters return a true value, the shortcut will be visible in the contextual launch menu. >+ </documentation> >+ </annotation> >+ <complexType> >+ <attribute name="name" type="string" use="required"> >+ <annotation> >+ <documentation> >+ specifies the name of the filter property. >+ </documentation> >+ </annotation> >+ </attribute> >+ <attribute name="value" type="string" use="required"> >+ <annotation> >+ <documentation> >+ specifies the expected value of the filter property. >+ </documentation> >+ </annotation> >+ </attribute> >+ </complexType> >+ </element> >+ > <annotation> > <appInfo> > <meta.section type="examples"/> >@@ -165,9 +204,9 @@ > </appInfo> > <documentation> > <p> >-<a href="hglegal.htm"> >- <img SRC="ngibmcpy.gif" >- ALT="Copyright (c) 2000, 2003 IBM Corporation and others. All Rights Reserved." >+<a href="hglegal.htm"> >+ <img SRC="ngibmcpy.gif" >+ ALT="Copyright (c) 2000, 2003 IBM Corporation and others. All Rights Reserved." > BORDER=0 height=14 width=324></a> > </p> > </documentation> >Index: ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java >=================================================================== >retrieving revision 1.44 >diff -u -r1.44 LaunchConfigurationManager.java >--- ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java 9 Dec 2003 23:39:28 -0000 1.44 >+++ ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java 27 Jan 2004 19:09:24 -0000 >@@ -512,11 +512,11 @@ > > /** > * Returns all launch shortcuts defined for the given perspective, >- * or <code>null</code> if none >+ * empty list if none. > * > * @param perpsective perspective identifier > * @return all launch shortcuts defined for the given perspective, >- * or <code>null</code> if none >+ * empty list if none. > */ > public List getLaunchShortcuts(String perpsective, String category) { > if (fLaunchShortcutsByPerspective == null) { >@@ -538,7 +538,7 @@ > } > List list = (List)fLaunchShortcutsByPerspective.get(perpsective); > if (list == null) { >- return null; >+ return new ArrayList(); > } else { > return filterShortcuts(list, category); > } >Index: ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java >=================================================================== >retrieving revision 1.7 >diff -u -r1.7 LaunchShortcutExtension.java >--- ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java 10 Mar 2003 21:56:23 -0000 1.7 >+++ ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java 27 Jan 2004 19:09:24 -0000 >@@ -23,8 +23,10 @@ > import org.eclipse.core.runtime.IConfigurationElement; > import org.eclipse.debug.internal.ui.DebugUIPlugin; > import org.eclipse.debug.ui.ILaunchShortcut; >+import org.eclipse.debug.ui.Pair; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.ui.IActionFilter; > import org.eclipse.ui.IEditorPart; > > >@@ -37,6 +39,8 @@ > private List fPerspectives = null; > private ILaunchShortcut fDelegate = null; > private Set fModes = null; >+ private IActionFilter fActionFilter = null; >+ private /* <Pair> */ List fFilters = null; > > /** > * The configuration element defining this tab. >@@ -86,6 +90,50 @@ > return getConfigurationElement().getAttribute("label"); //$NON-NLS-1$ > } > >+ /** >+ * Returns the contextual launch label of this shortcut >+ * >+ * @return the contextual label of this shortcut, or <code>null</code> if not >+ * specified >+ */ >+ public String getContextLabel() { >+ return getConfigurationElement().getAttribute("contextLabel"); //$NON-NLS-1$ >+ } >+ >+ /** >+ * Returns the filter class of this shortcut. >+ * >+ * @return the filter class of this shortcut., or <code>null</code> if not >+ * specified >+ */ >+ public IActionFilter getFilterClass() { >+ if (fActionFilter == null) { >+ try { >+ fActionFilter = (IActionFilter)fConfig.createExecutableExtension("filterClass"); //$NON-NLS-1$ >+ } catch (CoreException e) { >+ // silently ignore because filterClass is optional >+ // DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), LaunchConfigurationsMessages.getString("LaunchShortcutExtension.Error_4"), LaunchConfigurationsMessages.getString("LaunchShortcutExtension.Unable_to_use_launch_shortcut_5"), e.getStatus()); //$NON-NLS-1$ //$NON-NLS-2$ >+ } >+ } >+ return fActionFilter; >+ } >+ /** >+ * Returns all of the filter elements of this shortcut as a List of String Pairs. >+ * >+ * @return all of the filter elements of this shortcut., or <code>null</code> if not >+ * specified >+ */ >+ public /* <Pair> */ List getFilters() { >+ if (fFilters == null) { >+ IConfigurationElement[] filters = getConfigurationElement().getChildren("filter"); //$NON-NLS-1$ >+ fFilters = new ArrayList(filters.length); >+ for (int i = 0; i < filters.length; i++) { >+ fFilters.add(new Pair(filters[i].getAttribute("name"), >+ filters[i].getAttribute("value"))); //$NON-NLS-1$ >+ } >+ } >+ return fFilters; >+ } > /** > * Returns the id of this shortcut > * >Index: ui/org/eclipse/debug/internal/ui/actions/ContextualLaunchObjectActionDelegate.java >=================================================================== >RCS file: ui/org/eclipse/debug/internal/ui/actions/ContextualLaunchObjectActionDelegate.java >diff -N ui/org/eclipse/debug/internal/ui/actions/ContextualLaunchObjectActionDelegate.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/debug/internal/ui/actions/ContextualLaunchObjectActionDelegate.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,261 @@ >+/* >+ * Created on Jan 24, 2004 >+ * >+ * To change the template for this generated file go to >+ * Window - Preferences - Java - Code Generation - Code and Comments >+ */ >+package org.eclipse.debug.internal.ui.actions; >+ >+import java.util.Iterator; >+import java.util.List; >+ >+import org.eclipse.debug.internal.ui.DebugUIPlugin; >+import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; >+import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; >+import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; >+import org.eclipse.debug.ui.Pair; >+import org.eclipse.jface.action.Action; >+import org.eclipse.jface.action.ActionContributionItem; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.action.IMenuCreator; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.MenuAdapter; >+import org.eclipse.swt.events.MenuEvent; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Menu; >+import org.eclipse.swt.widgets.MenuItem; >+import org.eclipse.ui.IActionFilter; >+import org.eclipse.ui.IObjectActionDelegate; >+import org.eclipse.ui.IPerspectiveDescriptor; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.help.WorkbenchHelp; >+ >+/** >+ * @author Administrator >+ * >+ * To change the template for this generated type comment go to >+ * Window - Preferences - Java - Code Generation - Code and Comments >+ */ >+public class ContextualLaunchObjectActionDelegate >+ implements >+ IObjectActionDelegate, >+ IMenuCreator { >+ >+ /* >+ * The launch groups for which we should check for applicable configurations. >+ * Should we get this programmatically from the plugin.xml file? >+ */ >+ private static String[] fLaunchGroups = {"org.eclipse.debug.ui.launchGroup.run", >+ "org.eclipse.debug.ui.launchGroup.debug", >+ "org.eclipse.debug.ui.launchGroup.profile"}; >+ >+ private ISelection fSelection; >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) >+ */ >+ public void setActivePart(IAction action, IWorkbenchPart targetPart) { >+ // We don't have a need for the active part. >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.action.IMenuCreator#dispose() >+ */ >+ public void dispose() { >+ // nothing to do >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control) >+ */ >+ public Menu getMenu(Control parent) { >+ // never called >+ return null; >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu) >+ */ >+ public Menu getMenu(Menu parent) { >+ //Create the new menu. The menu will get filled when it is about to be shown. see fillMenu(Menu). >+ Menu menu = new Menu(parent); >+ /** >+ * Add listener to repopulate the menu each time >+ * it is shown because MenuManager.update(boolean, boolean) >+ * doesn't dispose pulldown ActionContribution items for each popup menu. >+ */ >+ menu.addMenuListener(new MenuAdapter() { >+ public void menuShown(MenuEvent e) { >+ Menu m = (Menu)e.widget; >+ MenuItem[] items = m.getItems(); >+ for (int i=0; i < items.length; i++) { >+ items[i].dispose(); >+ } >+ fillMenu(m); >+ } >+ }); >+ return menu; >+ } >+ >+ private int fCount = 0; >+ /** >+ * Fill pull down menu with the pages of the JTabbedPane >+ */ >+ protected void fillMenu(Menu menu) { >+ // lookup appropriate launch config types and build launch actions for them. >+ // Retrieve the current perspective and the registered shortcuts >+ String activePerspID = getActivePerspectiveID(); >+ if (activePerspID == null) { >+ return; >+ } >+ for (int i=0; i<fLaunchGroups.length; i++) { >+ String launchGroupIdentifier = fLaunchGroups[i]; >+ boolean needsGroupSeparator = true; >+ List shortcuts = getLaunchConfigurationManager().getLaunchShortcuts(activePerspID, getCategory(launchGroupIdentifier)); >+ Iterator iter = shortcuts.iterator(); >+ while (iter.hasNext()) { >+ LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next(); >+ if (isApplicable(ext, launchGroupIdentifier)) { >+ if (i != 0 && needsGroupSeparator) { >+ // except for the first group, add separator before non-empty menu groups >+ {new MenuItem(menu, SWT.SEPARATOR);} >+ needsGroupSeparator = false; >+ } >+ populateMenu(launchGroupIdentifier, ext, menu); >+ } >+ } >+ } >+ } >+ /* >+ * return true if this shortcut should appear in the contextual launch menu >+ */ >+ private boolean isApplicable(LaunchShortcutExtension ext, String launchGroupIdentifier) { >+ boolean hasMode = ext.getModes().contains(getMode(launchGroupIdentifier)); >+ // check that shortcut has a mode for the launch group and there is a resource selected >+ if (!hasMode || fSelection == null) { >+ return false; >+ } >+ // return false if there isn't a filter class or there are no filters specified by the shortcut >+ IActionFilter actionFilter = ext.getFilterClass(); >+ List filters = ext.getFilters(); >+ if (actionFilter == null || filters.isEmpty()) { >+ return false; >+ } >+ boolean accumulator = false; >+ Iterator iter = filters.listIterator(); >+ while (iter.hasNext()) { >+ Pair pair = (Pair) iter.next(); >+ String name = (String)pair.fFirst; >+ String value= (String)pair.fSecond; >+ Object target = (Object) fSelection; >+ // any filter that returns false makes the shortcut non-visible >+ if (!actionFilter.testAttribute(target,name,value)) { >+ return false; >+ } >+ } >+ return true; >+ } >+ /** >+ * Add the shortcut to the menu. >+ */ >+ private void populateMenu(String launchGroupIdentifier, LaunchShortcutExtension ext, Menu menu) { >+ String mode = getMode(launchGroupIdentifier); >+ LaunchShortcutAction action = new LaunchShortcutAction(mode, ext); >+ action.setActionDefinitionId(ext.getId()); >+ String helpContextId = ext.getHelpContextId(); >+ if (helpContextId != null) { >+ WorkbenchHelp.setHelp(action, helpContextId); >+ } >+ createMenuAction(menu, action, mode, ext.getContextLabel()); >+ } >+ >+ private void createMenuAction(Menu parent, IAction action, String mode, String contextLabel) { >+ // replace default action label with context label if specified. >+ String label = (contextLabel != null) ? contextLabel : action.getText(); >+ // if it's not simple "run" mode, append mode to label >+ label += ("run".equals(mode)) ? "" : " ("+mode+")"; >+ action.setText(label); >+ ActionContributionItem item= new ActionContributionItem(action); >+ item.fill(parent, -1); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) >+ */ >+ public void run(IAction action) { >+ // Never called because we become a menu. >+ } >+ >+ IAction delegateAction; >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) >+ */ >+ public void selectionChanged(IAction action, ISelection selection) { >+ if (((IStructuredSelection) selection).size() != 1) >+ action.setEnabled(false); // Can only handle one resource at a time >+ else { >+ if (action instanceof Action) { >+ if (delegateAction != action) { >+ delegateAction = (Action) action; >+ delegateAction.setMenuCreator(this); >+ } >+ action.setEnabled(true); >+ fSelection = selection; >+ } else { >+ action.setEnabled(false); >+ } >+ } >+ } >+ >+/** >+ * Return the ID of the currently active perspective, or <code>null</code> >+ * if there is none. >+ */ >+private String getActivePerspectiveID() { >+ IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow(); >+ if (window != null) { >+ IWorkbenchPage page = window.getActivePage(); >+ if (page != null) { >+ IPerspectiveDescriptor persp = page.getPerspective(); >+ if (persp != null) { >+ return persp.getId(); >+ } >+ } >+ } >+ return null; >+} /** >+ * Returns the launch configuration manager. >+* >+* @return launch configuration manager >+*/ >+private LaunchConfigurationManager getLaunchConfigurationManager() { >+return DebugUIPlugin.getDefault().getLaunchConfigurationManager(); >+} >+/** >+ * Returns the launch group associatd with this action. >+ * >+ * @return the launch group associatd with this action >+ */ >+private LaunchGroupExtension getLaunchGroup(String fLaunchGroupIdentifier) { >+ return getLaunchConfigurationManager().getLaunchGroup(fLaunchGroupIdentifier); >+} >+/** >+ * Returns the mode of this action - run or debug >+ * >+ * @return the mode of this action - run or debug >+ */ >+private String getMode(String fLaunchGroupIdentifier) { >+ return getLaunchGroup(fLaunchGroupIdentifier).getMode(); >+} >+ >+/** >+ * Returns the category of this action - possibly <code>null</code> >+ * >+ * @return the category of this action - possibly <code>null</code> >+ */ >+private String getCategory(String fLaunchGroupIdentifier) { >+ return getLaunchGroup(fLaunchGroupIdentifier).getCategory(); >+} >+ >+} >Index: ui/org/eclipse/debug/ui/Pair.java >=================================================================== >RCS file: ui/org/eclipse/debug/ui/Pair.java >diff -N ui/org/eclipse/debug/ui/Pair.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ ui/org/eclipse/debug/ui/Pair.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,22 @@ >+/* >+ * Created on Jan 25, 2004 >+ * >+ * To change the template for this generated file go to >+ * Window - Preferences - Java - Code Generation - Code and Comments >+ */ >+package org.eclipse.debug.ui; >+ >+/** >+ * @author Administrator >+ * >+ * To change the template for this generated type comment go to >+ * Window - Preferences - Java - Code Generation - Code and Comments >+ */ >+public class Pair { >+ public Object fFirst = null; >+ public Object fSecond = null; >+ public Pair(Object first, Object second) { >+ fFirst = first; >+ fSecond = second; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 18338
:
7595
|
7596
|
7597
|
7621
|
7622
|
7723
|
7724