1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.ui.IPerspectiveDescriptor; 14 import org.eclipse.ui.IPerspectiveListener; 15 import org.eclipse.ui.IWorkbenchPage; 16 import org.eclipse.ui.IWorkbenchWindow; 17 18 22 public class ToggleEditorsVisibilityAction extends PerspectiveAction implements 23 IPerspectiveListener { 24 25 28 public void perspectiveActivated(IWorkbenchPage page, 29 IPerspectiveDescriptor perspective) { 30 if (page.isEditorAreaVisible()) { 31 setText(WorkbenchMessages.ToggleEditor_hideEditors); 32 } else { 33 setText(WorkbenchMessages.ToggleEditor_showEditors); 34 } 35 } 36 37 40 public void perspectiveChanged(IWorkbenchPage page, 41 IPerspectiveDescriptor perspective, String changeId) { 42 if (changeId == IWorkbenchPage.CHANGE_RESET 43 || changeId == IWorkbenchPage.CHANGE_EDITOR_AREA_HIDE 44 || changeId == IWorkbenchPage.CHANGE_EDITOR_AREA_SHOW) { 45 if (page.isEditorAreaVisible()) { 46 setText(WorkbenchMessages.ToggleEditor_hideEditors); 47 } else { 48 setText(WorkbenchMessages.ToggleEditor_showEditors); 49 } 50 } 51 } 52 53 58 public ToggleEditorsVisibilityAction(IWorkbenchWindow window) { 59 super(window); 60 setText(WorkbenchMessages.ToggleEditor_hideEditors); 61 setActionDefinitionId("org.eclipse.ui.window.hideShowEditors"); setToolTipText(WorkbenchMessages.ToggleEditor_toolTip); 64 window.getWorkbench().getHelpSystem().setHelp(this, 65 IWorkbenchHelpContextIds.TOGGLE_EDITORS_VISIBILITY_ACTION); 66 window.addPerspectiveListener(this); 67 } 68 69 72 protected void run(IWorkbenchPage page, IPerspectiveDescriptor persp) { 73 boolean visible = page.isEditorAreaVisible(); 74 if (visible) { 75 page.setEditorAreaVisible(false); 76 setText(WorkbenchMessages.ToggleEditor_showEditors); 77 } else { 78 page.setEditorAreaVisible(true); 79 setText(WorkbenchMessages.ToggleEditor_hideEditors); 80 } 81 } 82 83 86 public void dispose() { 87 if (getWindow() != null) { 88 getWindow().removePerspectiveListener(this); 89 } 90 super.dispose(); 91 } 92 93 } 94 | Popular Tags |