1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.widgets.Event; 15 import org.eclipse.ui.IWorkbenchPart; 16 import org.eclipse.ui.IWorkbenchWindow; 17 import org.eclipse.ui.actions.ActionFactory; 18 import org.eclipse.ui.actions.PartEventAction; 19 20 24 public class ShowPartPaneMenuAction extends PartEventAction implements 25 ActionFactory.IWorkbenchAction { 26 27 31 private IWorkbenchWindow workbenchWindow; 32 33 private int accelerator; 34 35 40 public ShowPartPaneMenuAction(IWorkbenchWindow window) { 41 super(""); if (window == null) { 43 throw new IllegalArgumentException (); 44 } 45 this.workbenchWindow = window; 46 initText(); 48 workbenchWindow.getPartService().addPartListener(this); 49 workbenchWindow.getWorkbench().getHelpSystem().setHelp(this, 50 IWorkbenchHelpContextIds.SHOW_PART_PANE_MENU_ACTION); 51 setActionDefinitionId("org.eclipse.ui.window.showSystemMenu"); } 53 54 57 protected void initText() { 58 setText(WorkbenchMessages.ShowPartPaneMenuAction_text); 59 setToolTipText(WorkbenchMessages.ShowPartPaneMenuAction_toolTip); 60 } 61 62 65 protected void showMenu(PartPane pane) { 66 pane.showSystemMenu(); 67 } 68 69 72 protected void updateState() { 73 setEnabled(getActivePart() != null); 74 } 75 76 79 public void runWithEvent(Event e) { 80 if (workbenchWindow == null) { 81 return; 83 } 84 accelerator = e.detail; 85 IWorkbenchPart part = getActivePart(); 86 if (part != null) { 87 showMenu(((PartSite) part.getSite()).getPane()); 88 } 89 } 90 91 94 public void partOpened(IWorkbenchPart part) { 95 super.partOpened(part); 96 updateState(); 97 } 98 99 102 public void partClosed(IWorkbenchPart part) { 103 super.partClosed(part); 104 updateState(); 105 } 106 107 110 public void partActivated(IWorkbenchPart part) { 111 super.partActivated(part); 112 updateState(); 113 } 114 115 118 public void partDeactivated(IWorkbenchPart part) { 119 super.partDeactivated(part); 120 updateState(); 121 } 122 123 public int getAccelerator() { 124 int accelerator = this.accelerator; 125 accelerator = accelerator & ~SWT.CTRL; 126 accelerator = accelerator & ~SWT.SHIFT; 127 accelerator = accelerator & ~SWT.ALT; 128 return accelerator; 129 } 130 131 134 public void dispose() { 135 if (workbenchWindow == null) { 136 return; 138 } 139 workbenchWindow.getPartService().removePartListener(this); 140 workbenchWindow = null; 141 } 142 143 } 144 145 | Popular Tags |