1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.ui.IWorkbenchPage; 14 import org.eclipse.ui.IWorkbenchPart; 15 import org.eclipse.ui.IWorkbenchWindow; 16 17 20 public class CloseAllAction extends PageEventAction { 21 22 27 public CloseAllAction(IWorkbenchWindow window) { 28 super(WorkbenchMessages.CloseAllAction_text, window); 29 setToolTipText(WorkbenchMessages.CloseAllAction_toolTip); 30 setEnabled(false); 31 setId("closeAll"); updateState(); 33 window.getWorkbench().getHelpSystem().setHelp(this, 34 IWorkbenchHelpContextIds.CLOSE_ALL_ACTION); 35 setActionDefinitionId("org.eclipse.ui.file.closeAll"); } 37 38 41 public void pageActivated(IWorkbenchPage page) { 42 super.pageActivated(page); 43 updateState(); 44 } 45 46 49 public void pageClosed(IWorkbenchPage page) { 50 super.pageClosed(page); 51 updateState(); 52 } 53 54 57 public void partClosed(IWorkbenchPart part) { 58 super.partClosed(part); 59 updateState(); 60 } 61 62 65 public void partOpened(IWorkbenchPart part) { 66 super.partOpened(part); 67 updateState(); 68 } 69 70 73 public void run() { 74 if (getWorkbenchWindow() == null) { 75 return; 77 } 78 IWorkbenchPage page = getActivePage(); 79 if (page != null) { 80 page.closeAllEditors(true); 81 } 82 } 83 84 87 private void updateState() { 88 IWorkbenchPage page = getActivePage(); 89 if (page != null) { 90 setEnabled(page.getEditorReferences().length >= 1); 91 } else { 92 setEnabled(false); 93 } 94 } 95 } 96 | Popular Tags |