|
Lines 15-29
Link Here
|
| 15 |
import java.util.List; |
15 |
import java.util.List; |
| 16 |
import java.util.Set; |
16 |
import java.util.Set; |
| 17 |
|
17 |
|
|
|
18 |
import org.eclipse.core.expressions.EvaluationContext; |
| 19 |
import org.eclipse.core.expressions.Expression; |
| 20 |
import org.eclipse.core.expressions.IEvaluationContext; |
| 18 |
import org.eclipse.core.resources.IResource; |
21 |
import org.eclipse.core.resources.IResource; |
| 19 |
import org.eclipse.core.runtime.IExtension; |
22 |
import org.eclipse.core.runtime.CoreException; |
| 20 |
import org.eclipse.core.runtime.IPluginDescriptor; |
|
|
| 21 |
import org.eclipse.debug.internal.ui.DebugUIPlugin; |
23 |
import org.eclipse.debug.internal.ui.DebugUIPlugin; |
| 22 |
import org.eclipse.debug.internal.ui.Pair; |
|
|
| 23 |
import org.eclipse.debug.internal.ui.StringMatcher; |
| 24 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; |
24 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; |
| 25 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; |
25 |
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; |
| 26 |
import org.eclipse.debug.ui.ILaunchFilter; |
|
|
| 27 |
import org.eclipse.jface.action.Action; |
26 |
import org.eclipse.jface.action.Action; |
| 28 |
import org.eclipse.jface.action.ActionContributionItem; |
27 |
import org.eclipse.jface.action.ActionContributionItem; |
| 29 |
import org.eclipse.jface.action.IAction; |
28 |
import org.eclipse.jface.action.IAction; |
|
Lines 62-68
Link Here
|
| 62 |
IObjectActionDelegate, |
61 |
IObjectActionDelegate, |
| 63 |
IMenuCreator { |
62 |
IMenuCreator { |
| 64 |
|
63 |
|
| 65 |
private IResource fSelection; |
64 |
private IStructuredSelection fSelection; |
| 66 |
|
65 |
|
| 67 |
/* |
66 |
/* |
| 68 |
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) |
67 |
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) |
|
Lines 121-140
Link Here
|
| 121 |
public void selectionChanged(IAction action, ISelection selection) { |
120 |
public void selectionChanged(IAction action, ISelection selection) { |
| 122 |
// if the selection is an IResource, save it and enable our action |
121 |
// if the selection is an IResource, save it and enable our action |
| 123 |
if (selection instanceof IStructuredSelection) { |
122 |
if (selection instanceof IStructuredSelection) { |
| 124 |
IStructuredSelection ss = (IStructuredSelection) selection; |
123 |
if (action instanceof Action) { |
| 125 |
if (ss.size() == 1 && action instanceof Action) { |
|
|
| 126 |
if (delegateAction != action) { |
124 |
if (delegateAction != action) { |
| 127 |
delegateAction = (Action) action; |
125 |
delegateAction = (Action) action; |
| 128 |
delegateAction.setMenuCreator(this); |
126 |
delegateAction.setMenuCreator(this); |
| 129 |
} |
127 |
} |
| 130 |
Object object = ss.getFirstElement(); // already tested size above |
128 |
// save selection and enable our menu |
| 131 |
if(object instanceof IResource) { |
129 |
fSelection = (IStructuredSelection) selection; |
| 132 |
fSelection = (IResource)object; |
130 |
action.setEnabled(true); |
| 133 |
if (fSelection.getType() == IResource.FILE) { |
131 |
return; |
| 134 |
action.setEnabled(true); |
|
|
| 135 |
return; |
| 136 |
} |
| 137 |
} |
| 138 |
} |
132 |
} |
| 139 |
} |
133 |
} |
| 140 |
action.setEnabled(false); |
134 |
action.setEnabled(false); |
|
Lines 153-158
Link Here
|
| 153 |
* Fill pull down menu with the pages of the JTabbedPane |
147 |
* Fill pull down menu with the pages of the JTabbedPane |
| 154 |
*/ |
148 |
*/ |
| 155 |
protected void fillMenu(Menu menu) { |
149 |
protected void fillMenu(Menu menu) { |
|
|
150 |
IEvaluationContext context = createContext(); |
| 151 |
|
| 156 |
// lookup appropriate launch config types and build launch actions for them. |
152 |
// lookup appropriate launch config types and build launch actions for them. |
| 157 |
// Retrieve the current perspective and the registered shortcuts |
153 |
// Retrieve the current perspective and the registered shortcuts |
| 158 |
String activePerspID = getActivePerspectiveID(); |
154 |
String activePerspID = getActivePerspectiveID(); |
|
Lines 167-174
Link Here
|
| 167 |
List filteredShortCuts = new ArrayList(10); |
163 |
List filteredShortCuts = new ArrayList(10); |
| 168 |
while (iter.hasNext()) { |
164 |
while (iter.hasNext()) { |
| 169 |
LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next(); |
165 |
LaunchShortcutExtension ext = (LaunchShortcutExtension) iter.next(); |
| 170 |
if (isApplicable(ext)) { |
166 |
try { |
| 171 |
filteredShortCuts.add(ext); |
167 |
if (isApplicable(ext, context)) { |
|
|
168 |
filteredShortCuts.add(ext); |
| 169 |
} |
| 170 |
} catch (CoreException e) { |
| 171 |
// bogus XML Expression Language provided. |
| 172 |
// TODO provide entry in the log? |
| 172 |
} |
173 |
} |
| 173 |
} |
174 |
} |
| 174 |
iter = filteredShortCuts.iterator(); |
175 |
iter = filteredShortCuts.iterator(); |
|
Lines 189-247
Link Here
|
| 189 |
item.fill(menu, -1); |
190 |
item.fill(menu, -1); |
| 190 |
} |
191 |
} |
| 191 |
} |
192 |
} |
| 192 |
|
|
|
| 193 |
private ILaunchFilter getFilterClassIfLoaded(LaunchShortcutExtension ext) { |
| 194 |
IExtension extensionPoint = ext.getConfigurationElement().getDeclaringExtension(); |
| 195 |
IPluginDescriptor pluginDescriptor = extensionPoint.getDeclaringPluginDescriptor(); |
| 196 |
if (pluginDescriptor.isPluginActivated()) { |
| 197 |
ILaunchFilter filter = ext.getFilterClass(); |
| 198 |
return filter; |
| 199 |
} else { |
| 200 |
return null; |
| 201 |
} |
| 202 |
} |
| 203 |
/* (non-javadoc) |
| 204 |
* Apply contextFilters for this extension to decide visibility. |
| 205 |
* |
| 206 |
* @return true if this shortcut should appear in the contextual launch menu |
| 207 |
*/ |
| 208 |
private boolean isApplicable(LaunchShortcutExtension ext) { |
| 209 |
String nameFilterPattern = ext.getNameFilter(); |
| 210 |
boolean nameMatches = false; |
| 211 |
if (nameFilterPattern != null) { |
| 212 |
StringMatcher sm = new StringMatcher(nameFilterPattern, true, false); |
| 213 |
nameMatches = sm.match(fSelection.getName()); |
| 214 |
if (!nameMatches) { |
| 215 |
// return now to avoid loading the filterClass |
| 216 |
return false; |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
// Only loaded plugins will be used, so the launchFilter is null if the filterClass is not loaded |
| 221 |
ILaunchFilter launchFilter = getFilterClassIfLoaded(ext); |
| 222 |
if (launchFilter == null) { |
| 223 |
// no launch filter available, just use nameMatches (see bug# 51420) |
| 224 |
return nameMatches; |
| 225 |
} |
| 226 |
|
193 |
|
| 227 |
List filters = ext.getFilters(); |
194 |
/** |
| 228 |
if (filters.isEmpty()) { |
195 |
* @return an Evaluation context with default variable = selection |
| 229 |
return false; |
196 |
*/ |
| 230 |
} |
197 |
private IEvaluationContext createContext() { |
| 231 |
Iterator iter = filters.listIterator(); |
198 |
// create a default evaluation context with default variable of the user selection |
|
|
199 |
List selection = getSelection(); |
| 200 |
IEvaluationContext context = new EvaluationContext(null, selection); |
| 201 |
context.addVariable("selection", selection); //$NON-NLS-1$ |
| 202 |
|
| 203 |
return context; |
| 204 |
} |
| 205 |
|
| 206 |
/** |
| 207 |
* @return current selection as a List of IResource elements. |
| 208 |
*/ |
| 209 |
private List getSelection() { |
| 210 |
ArrayList result = new ArrayList(); |
| 211 |
Iterator iter = fSelection.iterator(); |
| 232 |
while (iter.hasNext()) { |
212 |
while (iter.hasNext()) { |
| 233 |
Pair pair = (Pair) iter.next(); |
213 |
IResource selection = (IResource) iter.next(); |
| 234 |
String name = pair.firstAsString(); |
214 |
result.add(selection); |
| 235 |
String value= pair.secondAsString(); |
|
|
| 236 |
// any filter that returns false makes the shortcut non-visible |
| 237 |
if (!launchFilter.testAttribute(fSelection,name,value)) { |
| 238 |
return false; |
| 239 |
} |
| 240 |
} |
215 |
} |
| 241 |
return true; |
216 |
return result; |
| 242 |
} |
217 |
} |
| 243 |
/* Add the shortcut to the context menu's launch submenu. |
218 |
|
| 244 |
* |
219 |
/** |
|
|
220 |
* Evaluate the enablement logic in the contextualLaunch |
| 221 |
* element description. A true result means that we should |
| 222 |
* include this shortcut in the context menu. |
| 223 |
* @return true iff shortcut should appear in context menu |
| 224 |
*/ |
| 225 |
private boolean isApplicable(LaunchShortcutExtension ext, IEvaluationContext context) throws CoreException { |
| 226 |
// evaluate the enablement logic in the contextual launch description |
| 227 |
Expression expr = ext.getContextualLaunchEnablementExpression(); |
| 228 |
return ext.evalContextualLaunchEnablementExpression(context, expr); |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* Add the shortcut to the context menu's launch submenu. |
| 245 |
*/ |
233 |
*/ |
| 246 |
private void populateMenu(String mode, LaunchShortcutExtension ext, Menu menu) { |
234 |
private void populateMenu(String mode, LaunchShortcutExtension ext, Menu menu) { |
| 247 |
LaunchShortcutAction action = new LaunchShortcutAction(mode, ext); |
235 |
LaunchShortcutAction action = new LaunchShortcutAction(mode, ext); |
|
Lines 258-288
Link Here
|
| 258 |
item.fill(menu, -1); |
246 |
item.fill(menu, -1); |
| 259 |
} |
247 |
} |
| 260 |
|
248 |
|
| 261 |
/** |
249 |
/** |
| 262 |
* Return the ID of the currently active perspective. |
250 |
* Return the ID of the currently active perspective. |
| 263 |
* |
251 |
* |
| 264 |
* @return the active perspective ID or <code>null</code> if there is none. |
252 |
* @return the active perspective ID or <code>null</code> if there is none. |
| 265 |
*/ |
253 |
*/ |
| 266 |
private String getActivePerspectiveID() { |
254 |
private String getActivePerspectiveID() { |
| 267 |
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow(); |
255 |
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow(); |
| 268 |
if (window != null) { |
256 |
if (window != null) { |
| 269 |
IWorkbenchPage page = window.getActivePage(); |
257 |
IWorkbenchPage page = window.getActivePage(); |
| 270 |
if (page != null) { |
258 |
if (page != null) { |
| 271 |
IPerspectiveDescriptor persp = page.getPerspective(); |
259 |
IPerspectiveDescriptor persp = page.getPerspective(); |
| 272 |
if (persp != null) { |
260 |
if (persp != null) { |
| 273 |
return persp.getId(); |
261 |
return persp.getId(); |
|
|
262 |
} |
| 274 |
} |
263 |
} |
| 275 |
} |
264 |
} |
|
|
265 |
return null; |
| 266 |
} |
| 267 |
/** |
| 268 |
* Returns the launch configuration manager. |
| 269 |
* |
| 270 |
* @return launch configuration manager |
| 271 |
*/ |
| 272 |
private LaunchConfigurationManager getLaunchConfigurationManager() { |
| 273 |
return DebugUIPlugin.getDefault().getLaunchConfigurationManager(); |
| 276 |
} |
274 |
} |
| 277 |
return null; |
|
|
| 278 |
} |
| 279 |
/** |
| 280 |
* Returns the launch configuration manager. |
| 281 |
* |
| 282 |
* @return launch configuration manager |
| 283 |
*/ |
| 284 |
private LaunchConfigurationManager getLaunchConfigurationManager() { |
| 285 |
return DebugUIPlugin.getDefault().getLaunchConfigurationManager(); |
| 286 |
} |
| 287 |
|
275 |
|
| 288 |
} |
276 |
} |