1 11 package org.eclipse.ui.internal.ide.actions; 12 13 import org.eclipse.jface.action.Action; 14 import org.eclipse.jface.action.IMenuManager; 15 import org.eclipse.jface.bindings.TriggerSequence; 16 import org.eclipse.ui.IWorkbench; 17 import org.eclipse.ui.PlatformUI; 18 import org.eclipse.ui.actions.QuickMenuCreator; 19 import org.eclipse.ui.keys.IBindingService; 20 21 27 public abstract class QuickMenuAction extends Action { 28 29 private QuickMenuCreator creator = new QuickMenuCreator() { 30 protected void fillMenu(IMenuManager menu) { 31 QuickMenuAction.this.fillMenu(menu); 32 } 33 }; 34 35 41 public QuickMenuAction(String commandId) { 42 setId(commandId); 43 setActionDefinitionId(commandId); 44 } 45 46 49 public void run() { 50 creator.createMenu(); 51 } 52 53 56 public void dispose() { 57 if (creator != null) { 58 creator.dispose(); 59 creator = null; 60 } 61 } 62 63 68 protected abstract void fillMenu(IMenuManager menu); 69 70 76 public String getShortCutString() { 77 final IWorkbench workbench = PlatformUI.getWorkbench(); 78 final IBindingService bindingService = (IBindingService) workbench 79 .getAdapter(IBindingService.class); 80 final TriggerSequence[] activeBindings = bindingService 81 .getActiveBindingsFor(getActionDefinitionId()); 82 if (activeBindings.length > 0) { 83 return activeBindings[0].format(); 84 } 85 86 return null; 87 } 88 } 89 | Popular Tags |