1 11 package org.eclipse.debug.internal.ui.actions; 12 13 14 import java.util.List ; 15 16 import org.eclipse.core.expressions.EvaluationContext; 17 import org.eclipse.core.expressions.Expression; 18 import org.eclipse.core.expressions.IEvaluationContext; 19 import org.eclipse.core.runtime.CoreException; 20 import org.eclipse.debug.internal.ui.DebugUIPlugin; 21 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchShortcutExtension; 22 import org.eclipse.jface.action.Action; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.ui.IEditorPart; 26 import org.eclipse.ui.IWorkbenchPage; 27 import org.eclipse.ui.IWorkbenchWindow; 28 29 32 public class LaunchShortcutAction extends Action { 33 34 private String fMode; 35 private LaunchShortcutExtension fShortcut; 36 37 38 41 public LaunchShortcutAction(String mode, LaunchShortcutExtension shortcut) { 42 super(shortcut.getLabel(), shortcut.getImageDescriptor()); 43 fMode = mode; 44 fShortcut = shortcut; 45 updateEnablement(); 46 } 47 48 53 public void run() { 54 IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow(); 55 if (wb != null) { 56 IWorkbenchPage page = wb.getActivePage(); 57 if (page != null) { 58 if (page.getActivePart() == page.getActiveEditor()) { 59 IEditorPart editor = page.getActiveEditor(); 60 if (editor != null) { 61 fShortcut.launch(editor, fMode); 62 } 63 } else { 64 ISelection selection = page.getSelection(); 65 if (selection instanceof IStructuredSelection) { 66 fShortcut.launch(selection, fMode); 67 } 68 } 69 } 70 } 71 } 72 73 77 private void updateEnablement() { 78 IWorkbenchWindow wb = DebugUIPlugin.getActiveWorkbenchWindow(); 79 boolean enabled = false; 80 if (wb != null) { 81 IWorkbenchPage page = wb.getActivePage(); 82 if (page != null) { 83 ISelection selection = page.getSelection(); 84 if (selection instanceof IStructuredSelection) { 85 IStructuredSelection structuredSelection = (IStructuredSelection)selection; 86 try { 87 Expression expression = fShortcut.getShortcutEnablementExpression(); 89 if (expression == null) { 90 enabled = !structuredSelection.isEmpty(); 91 } else { 92 List list = structuredSelection.toList(); 93 IEvaluationContext context = new EvaluationContext(null, list); 94 context.addVariable("selection", list); enabled = fShortcut.evalEnablementExpression(context, expression); 96 } 97 } catch (CoreException e) { 98 } 99 } else { 100 IEditorPart editor = page.getActiveEditor(); 101 if (editor != null) { 102 enabled = true; 103 } 104 } 105 } 106 } 107 setEnabled(enabled); 108 } 109 110 } 111 | Popular Tags |