Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 18338 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+7 lines)
Lines 187-189 Link Here
187
BreakpointMarkerPreference.label= Breakpoints
187
BreakpointMarkerPreference.label= Breakpoints
188
188
189
SourceContainerPresentationsName = Source Container Presentations
189
SourceContainerPresentationsName = Source Container Presentations
190
191
#---Chris' work in progress
192
LaunchActions.label=Launch
193
RunAsMenu.label=&Run As
194
DebugAsMenu.label=&Debug As
195
LaunchMenu.label=&Run
196
LaunchActionsMenu.label=&Launch Actions
(-)plugin.xml (+46 lines)
Lines 1413-1417 Link Here
1413
            id="org.eclipse.debug.ui.workingSetComparator">
1413
            id="org.eclipse.debug.ui.workingSetComparator">
1414
      </launchConfigurationComparator>
1414
      </launchConfigurationComparator>
1415
   </extension>
1415
   </extension>
1416
<!-- ========================================= -->
1417
<!-- Contextual Launch Menu (Work in Progress) -->
1418
<!-- ========================================= -->
1419
   <extension
1420
         point="org.eclipse.ui.popupMenus">
1421
      <objectContribution
1422
            objectClass="org.eclipse.core.resources.IResource"
1423
            adaptable="true"
1424
            id="org.eclipse.debug.ui.contextualLaunch">
1425
        <action
1426
               label="%LaunchMenu.label"
1427
               style="pulldown"
1428
               class="org.eclipse.debug.internal.ui.actions.ContextualLaunchObjectActionDelegate"
1429
               menubarPath="additions"
1430
               enablesFor="1"
1431
               id="org.eclipse.debug.ui.contextualLaunch.submenu">
1432
         </action>
1433
 <!-- dead stuff that was experimentation
1434
		<menu
1435
				label="%LaunchMenu.label"
1436
				path="additions"
1437
				id="contextualLaunch.popupMenu">
1438
			<separator
1439
				name="launchGroup">
1440
			</separator>
1441
		</menu>
1442
    	 <menu
1443
				label="%DebugAsMenu.label"
1444
				path="contextualLaunch.popupMenu/launchGroup"
1445
				id="contextualLaunch.debugAs.menu">
1446
			<separator
1447
				name="debugAsGroup">
1448
			</separator>
1449
		 </menu>
1450
		<menu
1451
				label="%RunAsMenu.label"
1452
				path="contextualLaunch.popupMenu/launchGroup"
1453
				id="contextualLaunch.runAs.menu">
1454
			<separator
1455
				name="runAsGroup">
1456
			</separator>
1457
		 </menu>
1458
-->
1459
      </objectContribution>
1460
	</extension>
1461
<!-- End Contextual Run Menu (Work in Progress) -->
1416
1462
1417
</plugin>
1463
</plugin>
(-)schema/launchShortcuts.exsd (-3 / +42 lines)
Lines 49-54 Link Here
49
      <complexType>
49
      <complexType>
50
         <sequence>
50
         <sequence>
51
            <element ref="perspective" minOccurs="0" maxOccurs="unbounded"/>
51
            <element ref="perspective" minOccurs="0" maxOccurs="unbounded"/>
52
            <element ref="filter" minOccurs="0" maxOccurs="unbounded"/>
52
         </sequence>
53
         </sequence>
53
         <attribute name="id" type="string" use="required">
54
         <attribute name="id" type="string" use="required">
54
            <annotation>
55
            <annotation>
Lines 106-111 Link Here
106
               </documentation>
107
               </documentation>
107
            </annotation>
108
            </annotation>
108
         </attribute>
109
         </attribute>
110
         <attribute name="contextLabel" type="string">
111
            <annotation>
112
               <documentation>
113
                  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 &lt;samp&gt;label&lt;/samp&gt; attribute will be used instead.
114
               </documentation>
115
            </annotation>
116
         </attribute>
117
         <attribute name="filterClass" type="string">
118
            <annotation>
119
               <documentation>
120
                  an optional attribute that specifies the fully qualified path of a Java class that implements the &lt;samp&gt;org.eclipse.ui.IActionFilter&lt;/samp&gt; 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.
121
               </documentation>
122
            </annotation>
123
         </attribute>
109
      </complexType>
124
      </complexType>
110
   </element>
125
   </element>
111
126
Lines 121-126 Link Here
121
      </complexType>
136
      </complexType>
122
   </element>
137
   </element>
123
138
139
   <element name="filter">
140
      <annotation>
141
         <documentation>
142
            specifies the name/value pair that will be tested for boolean true/false by calling the &lt;samp&gt;org.eclipse.ui.IActionFilter:testAttribute()&lt;/samp&gt; method of the class specified by the &lt;samp&gt;filterClass&lt;/samp&gt; attribute of the parent &lt;samp&gt;shortcut&lt;/samp&gt; element. If all filters return a true value, the shortcut will be visible in the contextual launch menu.
143
         </documentation>
144
      </annotation>
145
      <complexType>
146
         <attribute name="name" type="string" use="required">
147
            <annotation>
148
               <documentation>
149
                  specifies the name of the filter property.
150
               </documentation>
151
            </annotation>
152
         </attribute>
153
         <attribute name="value" type="string" use="required">
154
            <annotation>
155
               <documentation>
156
                  specifies the expected value of the filter property.
157
               </documentation>
158
            </annotation>
159
         </attribute>
160
      </complexType>
161
   </element>
162
124
   <annotation>
163
   <annotation>
125
      <appInfo>
164
      <appInfo>
126
         <meta.section type="examples"/>
165
         <meta.section type="examples"/>
Lines 165-173 Link Here
165
      </appInfo>
204
      </appInfo>
166
      <documentation>
205
      <documentation>
167
         &lt;p&gt;
206
         &lt;p&gt;
168
&lt;a href="hglegal.htm"&gt;
207
&lt;a href=&quot;hglegal.htm&quot;&gt;
169
 &lt;img SRC="ngibmcpy.gif"
208
 &lt;img SRC=&quot;ngibmcpy.gif&quot;
170
   ALT="Copyright (c) 2000, 2003 IBM Corporation and others. All Rights Reserved."
209
   ALT=&quot;Copyright (c) 2000, 2003 IBM Corporation and others. All Rights Reserved.&quot;
171
   BORDER=0 height=14 width=324&gt;&lt;/a&gt;
210
   BORDER=0 height=14 width=324&gt;&lt;/a&gt;
172
&lt;/p&gt;
211
&lt;/p&gt;
173
      </documentation>
212
      </documentation>
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchConfigurationManager.java (-3 / +3 lines)
Lines 512-522 Link Here
512
	
512
	
513
	/**
513
	/**
514
	 * Returns all launch shortcuts defined for the given perspective,
514
	 * Returns all launch shortcuts defined for the given perspective,
515
	 * or <code>null</code> if none
515
	 * empty list if none.
516
	 * 
516
	 * 
517
	 * @param perpsective perspective identifier
517
	 * @param perpsective perspective identifier
518
	 * @return all launch shortcuts defined for the given perspective,
518
	 * @return all launch shortcuts defined for the given perspective,
519
	 * or <code>null</code> if none
519
	 * empty list if none.
520
	 */
520
	 */
521
	public List getLaunchShortcuts(String perpsective, String category) {
521
	public List getLaunchShortcuts(String perpsective, String category) {
522
		if (fLaunchShortcutsByPerspective == null) {
522
		if (fLaunchShortcutsByPerspective == null) {
Lines 538-544 Link Here
538
		}
538
		}
539
		List list = (List)fLaunchShortcutsByPerspective.get(perpsective); 
539
		List list = (List)fLaunchShortcutsByPerspective.get(perpsective); 
540
		if (list == null) {
540
		if (list == null) {
541
			return null;
541
			return new ArrayList();
542
		} else {
542
		} else {
543
			return filterShortcuts(list, category);
543
			return filterShortcuts(list, category);
544
		}
544
		}
(-)ui/org/eclipse/debug/internal/ui/launchConfigurations/LaunchShortcutExtension.java (+48 lines)
Lines 23-30 Link Here
23
import org.eclipse.core.runtime.IConfigurationElement;
23
import org.eclipse.core.runtime.IConfigurationElement;
24
import org.eclipse.debug.internal.ui.DebugUIPlugin;
24
import org.eclipse.debug.internal.ui.DebugUIPlugin;
25
import org.eclipse.debug.ui.ILaunchShortcut;
25
import org.eclipse.debug.ui.ILaunchShortcut;
26
import org.eclipse.debug.ui.Pair;
26
import org.eclipse.jface.resource.ImageDescriptor;
27
import org.eclipse.jface.resource.ImageDescriptor;
27
import org.eclipse.jface.viewers.ISelection;
28
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.ui.IActionFilter;
28
import org.eclipse.ui.IEditorPart;
30
import org.eclipse.ui.IEditorPart;
29
31
30
32
Lines 37-42 Link Here
37
	private List fPerspectives = null;
39
	private List fPerspectives = null;
38
	private ILaunchShortcut fDelegate = null;
40
	private ILaunchShortcut fDelegate = null;
39
	private Set fModes = null;
41
	private Set fModes = null;
42
	private IActionFilter fActionFilter = null;
43
	private /* <Pair> */ List fFilters = null;
40
	
44
	
41
	/**
45
	/**
42
	 * The configuration element defining this tab.
46
	 * The configuration element defining this tab.
Lines 86-91 Link Here
86
		return getConfigurationElement().getAttribute("label"); //$NON-NLS-1$
90
		return getConfigurationElement().getAttribute("label"); //$NON-NLS-1$
87
	}
91
	}
88
	
92
	
93
	/**
94
	 * Returns the contextual launch label of this shortcut
95
	 * 
96
	 * @return the contextual label of this shortcut, or <code>null</code> if not
97
	 *  specified
98
	 */
99
	public String getContextLabel() {
100
		return getConfigurationElement().getAttribute("contextLabel"); //$NON-NLS-1$
101
	}
102
	
103
	/**
104
	 * Returns the filter class of this shortcut.
105
	 * 
106
	 * @return the filter class of this shortcut., or <code>null</code> if not
107
	 *  specified
108
	 */
109
	public IActionFilter getFilterClass() {
110
		if (fActionFilter == null) {
111
			try {
112
				fActionFilter = (IActionFilter)fConfig.createExecutableExtension("filterClass"); //$NON-NLS-1$
113
			} catch (CoreException e) {
114
				// silently ignore because filterClass is optional
115
				// 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$
116
			}
117
		}
118
		return fActionFilter;
119
	}
120
	/**
121
	 * Returns all of the filter elements of this shortcut as a List of String Pairs.
122
	 * 
123
	 * @return all of the filter elements of this shortcut., or <code>null</code> if not
124
	 *  specified
125
	 */
126
	public /* <Pair> */ List getFilters() {
127
		if (fFilters == null) {
128
			IConfigurationElement[] filters = getConfigurationElement().getChildren("filter"); //$NON-NLS-1$
129
			fFilters = new ArrayList(filters.length);
130
			for (int i = 0; i < filters.length; i++) {
131
				fFilters.add(new Pair(filters[i].getAttribute("name"),
132
						filters[i].getAttribute("value"))); //$NON-NLS-1$
133
			}
134
		}
135
		return fFilters;
136
	}
89
	/**
137
	/**
90
	 * Returns the id of this shortcut
138
	 * Returns the id of this shortcut
91
	 * 
139
	 * 
(-)ui/org/eclipse/debug/internal/ui/actions/ContextualLaunchObjectActionDelegate.java (+261 lines)
Added Link Here
1
/*
2
 * Created on Jan 24, 2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
package org.eclipse.debug.internal.ui.actions;
8
9
import java.util.Iterator;
10
import java.util.List;
11
12
import org.eclipse.debug.internal.ui.DebugUIPlugin;
13
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
14
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
15
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension;
16
import org.eclipse.debug.ui.Pair;
17
import org.eclipse.jface.action.Action;
18
import org.eclipse.jface.action.ActionContributionItem;
19
import org.eclipse.jface.action.IAction;
20
import org.eclipse.jface.action.IMenuCreator;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.events.MenuAdapter;
25
import org.eclipse.swt.events.MenuEvent;
26
import org.eclipse.swt.widgets.Control;
27
import org.eclipse.swt.widgets.Menu;
28
import org.eclipse.swt.widgets.MenuItem;
29
import org.eclipse.ui.IActionFilter;
30
import org.eclipse.ui.IObjectActionDelegate;
31
import org.eclipse.ui.IPerspectiveDescriptor;
32
import org.eclipse.ui.IWorkbenchPage;
33
import org.eclipse.ui.IWorkbenchPart;
34
import org.eclipse.ui.IWorkbenchWindow;
35
import org.eclipse.ui.help.WorkbenchHelp;
36
37
/**
38
 * @author Administrator
39
 *
40
 * To change the template for this generated type comment go to
41
 * Window - Preferences - Java - Code Generation - Code and Comments
42
 */
43
public class ContextualLaunchObjectActionDelegate
44
		implements
45
			IObjectActionDelegate,
46
			IMenuCreator {
47
48
	/*
49
	 * The launch groups for which we should check for applicable configurations.
50
	 * Should we get this programmatically from the plugin.xml file?
51
	 */
52
	private static String[] fLaunchGroups = {"org.eclipse.debug.ui.launchGroup.run",
53
											 "org.eclipse.debug.ui.launchGroup.debug",
54
											 "org.eclipse.debug.ui.launchGroup.profile"};
55
	
56
	private ISelection fSelection;
57
	
58
	/* (non-Javadoc)
59
	 * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
60
	 */
61
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
62
		// We don't have a need for the active part.
63
	}
64
	/* (non-Javadoc)
65
	 * @see org.eclipse.jface.action.IMenuCreator#dispose()
66
	 */
67
	public void dispose() {
68
		// nothing to do
69
	}
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control)
72
	 */
73
	public Menu getMenu(Control parent) {
74
		// never called
75
		return null;
76
	}
77
	/* (non-Javadoc)
78
	 * @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
79
	 */
80
	public Menu getMenu(Menu parent) {
81
		//Create the new menu. The menu will get filled when it is about to be shown. see fillMenu(Menu).
82
		Menu menu = new Menu(parent);
83
		/**
84
		 * Add listener to repopulate the menu each time
85
		 * it is shown because MenuManager.update(boolean, boolean) 
86
		 * doesn't dispose pulldown ActionContribution items for each popup menu.
87
		 */
88
		menu.addMenuListener(new MenuAdapter() {
89
			public void menuShown(MenuEvent e) {
90
				Menu m = (Menu)e.widget;
91
				MenuItem[] items = m.getItems();
92
				for (int i=0; i < items.length; i++) {
93
					items[i].dispose();
94
				}
95
				fillMenu(m);
96
			}
97
		});
98
		return menu;
99
	}
100
101
	private int fCount = 0;
102
	/**
103
	 * Fill pull down menu with the pages of the JTabbedPane
104
	 */
105
	protected void fillMenu(Menu menu) {
106
		// lookup appropriate launch config types and build launch actions for them.
107
		// Retrieve the current perspective and the registered shortcuts
108
		String activePerspID = getActivePerspectiveID();
109
		if (activePerspID == null) {
110
			return;
111
		}
112
		for (int i=0; i<fLaunchGroups.length; i++) {
113
			String launchGroupIdentifier = fLaunchGroups[i];
114
			boolean needsGroupSeparator = true;
115
			List shortcuts = getLaunchConfigurationManager().getLaunchShortcuts(activePerspID, getCategory(launchGroupIdentifier));
116
			Iterator iter = shortcuts.iterator();
117
			while (iter.hasNext()) {
118
				LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next();
119
				if (isApplicable(ext, launchGroupIdentifier)) {
120
					if (i != 0 && needsGroupSeparator) {
121
						// except for the first group, add separator before non-empty menu groups
122
						{new MenuItem(menu, SWT.SEPARATOR);}
123
						needsGroupSeparator = false;
124
					}
125
					populateMenu(launchGroupIdentifier, ext, menu);
126
				}
127
			}
128
		}
129
	}
130
	/*
131
 	 * return true if this shortcut should appear in the contextual launch menu
132
	 */
133
	private boolean isApplicable(LaunchShortcutExtension ext, String launchGroupIdentifier) {
134
		boolean hasMode = ext.getModes().contains(getMode(launchGroupIdentifier));
135
		// check that shortcut has a mode for the launch group and there is a resource selected
136
		if (!hasMode || fSelection == null) {
137
			return false;
138
		}
139
		// return false if there isn't a filter class or there are no filters specified by the shortcut
140
		IActionFilter actionFilter = ext.getFilterClass();
141
		List filters = ext.getFilters();
142
		if (actionFilter == null || filters.isEmpty()) {
143
			return false;
144
		}
145
		boolean accumulator = false;
146
		Iterator iter = filters.listIterator();
147
		while (iter.hasNext()) {
148
			Pair pair = (Pair) iter.next();
149
			String name = (String)pair.fFirst;
150
			String value= (String)pair.fSecond;
151
			Object target = (Object) fSelection;
152
			// any filter that returns false makes the shortcut non-visible
153
			if (!actionFilter.testAttribute(target,name,value)) {
154
				return false;
155
			}
156
		}
157
		return true;
158
	}
159
	/**
160
	 * Add the shortcut to the menu.
161
	 */
162
	private void populateMenu(String launchGroupIdentifier, LaunchShortcutExtension ext, Menu menu) {
163
		String mode = getMode(launchGroupIdentifier);
164
		LaunchShortcutAction action = new LaunchShortcutAction(mode, ext);
165
		action.setActionDefinitionId(ext.getId());
166
		String helpContextId = ext.getHelpContextId();
167
		if (helpContextId != null) {
168
			WorkbenchHelp.setHelp(action, helpContextId);
169
		}
170
		createMenuAction(menu, action, mode, ext.getContextLabel());
171
	}
172
173
	private void createMenuAction(Menu parent, IAction action, String mode, String contextLabel) {
174
		// replace default action label with context label if specified.
175
		String label = (contextLabel != null) ? contextLabel : action.getText();
176
		// if it's not simple "run" mode, append mode to label
177
		label += ("run".equals(mode)) ? "" : " ("+mode+")";
178
		action.setText(label);
179
		ActionContributionItem item= new ActionContributionItem(action);
180
		item.fill(parent, -1);
181
	}
182
183
	/* (non-Javadoc)
184
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
185
	 */
186
	public void run(IAction action) {
187
		// Never called because we become a menu.
188
	}
189
	
190
	IAction delegateAction;
191
	/* (non-Javadoc)
192
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
193
	 */
194
	public void selectionChanged(IAction action, ISelection selection) {
195
		if (((IStructuredSelection) selection).size() != 1)
196
			action.setEnabled(false);	// Can only handle one resource at a time
197
		else {
198
			if (action instanceof Action) {
199
				if (delegateAction != action) {
200
					delegateAction = (Action) action;
201
					delegateAction.setMenuCreator(this);
202
				}
203
				action.setEnabled(true);
204
				fSelection = selection;
205
			} else {
206
				action.setEnabled(false);
207
			}
208
		}
209
	}
210
211
/**
212
 * Return the ID of the currently active perspective, or <code>null</code>
213
 * if there is none.
214
 */
215
private String getActivePerspectiveID() {
216
	IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow();
217
	if (window != null) {
218
		IWorkbenchPage page = window.getActivePage();
219
		if (page != null) {
220
			IPerspectiveDescriptor persp = page.getPerspective();
221
			if (persp != null) {
222
				return persp.getId();
223
			}
224
		}
225
	}
226
	return null;
227
}	/**
228
 * Returns the launch configuration manager.
229
*
230
* @return launch configuration manager
231
*/
232
private LaunchConfigurationManager getLaunchConfigurationManager() {
233
return DebugUIPlugin.getDefault().getLaunchConfigurationManager();
234
}
235
/**
236
 * Returns the launch group associatd with this action.
237
 * 
238
 * @return the launch group associatd with this action
239
 */
240
private LaunchGroupExtension getLaunchGroup(String fLaunchGroupIdentifier) {
241
	return getLaunchConfigurationManager().getLaunchGroup(fLaunchGroupIdentifier);
242
}
243
/**
244
 * Returns the mode of this action - run or debug 
245
 * 
246
 * @return the mode of this action - run or debug
247
 */
248
private String getMode(String fLaunchGroupIdentifier) {
249
	return getLaunchGroup(fLaunchGroupIdentifier).getMode();
250
}
251
252
/**
253
 * Returns the category of this action - possibly <code>null</code>
254
 *
255
 * @return the category of this action - possibly <code>null</code>
256
 */
257
private String getCategory(String fLaunchGroupIdentifier) {
258
	return getLaunchGroup(fLaunchGroupIdentifier).getCategory();
259
}
260
261
}
(-)ui/org/eclipse/debug/ui/Pair.java (+22 lines)
Added Link Here
1
/*
2
 * Created on Jan 25, 2004
3
 *
4
 * To change the template for this generated file go to
5
 * Window - Preferences - Java - Code Generation - Code and Comments
6
 */
7
package org.eclipse.debug.ui;
8
9
/**
10
 * @author Administrator
11
 *
12
 * To change the template for this generated type comment go to
13
 * Window - Preferences - Java - Code Generation - Code and Comments
14
 */
15
public class Pair {
16
	public Object fFirst = null;
17
	public Object fSecond = null;
18
	public Pair(Object first, Object second) {
19
		fFirst = first;
20
		fSecond = second;
21
	}
22
}

Return to bug 18338