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.IEditorPart; 16 import org.eclipse.ui.IViewReference; 17 import org.eclipse.ui.IWorkbenchPage; 18 import org.eclipse.ui.IWorkbenchPartReference; 19 import org.eclipse.ui.IWorkbenchWindow; 20 21 24 public class ActivateEditorAction extends PageEventAction { 25 26 private int accelerator; 27 28 33 public ActivateEditorAction(IWorkbenchWindow window) { 34 super(WorkbenchMessages.ActivateEditorAction_text, window); 35 setToolTipText(WorkbenchMessages.ActivateEditorAction_toolTip); 36 updateState(); 38 window.getWorkbench().getHelpSystem().setHelp(this, 39 IWorkbenchHelpContextIds.ACTIVATE_EDITOR_ACTION); 40 setActionDefinitionId("org.eclipse.ui.window.activateEditor"); } 42 43 public void pageActivated(IWorkbenchPage page) { 44 super.pageActivated(page); 45 updateState(); 46 } 47 48 public void pageClosed(IWorkbenchPage page) { 49 super.pageClosed(page); 50 updateState(); 51 } 52 53 56 public void runWithEvent(Event e) { 57 if (getWorkbenchWindow() == null) { 58 return; 60 } 61 accelerator = e.detail; 62 IWorkbenchPage page = getActivePage(); 63 if (page != null) { 64 IEditorPart part = page.getActiveEditor(); if (part != null) { 66 page.activate(part); 67 part.setFocus(); 68 } else { 69 IWorkbenchPartReference ref = page.getActivePartReference(); 70 if (ref instanceof IViewReference) { 71 if (((WorkbenchPage) page).isFastView((IViewReference) ref)) { 72 ((WorkbenchPage) page) 73 .toggleFastView((IViewReference) ref); 74 } 75 } 76 } 77 } 78 } 79 80 83 public void updateState() { 84 IWorkbenchPage page = getActivePage(); 85 setEnabled(page != null); 86 } 87 88 public int getAccelerator() { 89 int accelerator = this.accelerator; 90 accelerator = accelerator & ~SWT.CTRL; 91 accelerator = accelerator & ~SWT.SHIFT; 92 accelerator = accelerator & ~SWT.ALT; 93 return accelerator; 94 } 95 } 96 97 | Popular Tags |