1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.ui.IEditorPart; 14 import org.eclipse.ui.IPropertyListener; 15 import org.eclipse.ui.IWorkbenchPartConstants; 16 import org.eclipse.ui.IWorkbenchWindow; 17 import org.eclipse.ui.internal.tweaklets.TabBehaviour; 18 import org.eclipse.ui.internal.tweaklets.Tweaklets; 19 20 24 public class PinEditorAction extends ActiveEditorAction { 25 private IPropertyListener propListener = new IPropertyListener() { 26 public void propertyChanged(Object source, int propId) { 27 if (propId == WorkbenchPartReference.INTERNAL_PROPERTY_PINNED) { 28 WorkbenchPartReference ref = (WorkbenchPartReference)source; 29 setChecked(ref.isPinned()); 30 } else if (propId == IWorkbenchPartConstants.PROP_DIRTY) { 31 if (((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).autoPinOnDirty()) { 32 WorkbenchPartReference ref = (WorkbenchPartReference) source; 33 if (ref.isDirty()) { 34 ref.setPinned(true); 35 } 36 } 37 } 38 } 39 }; 40 41 44 public PinEditorAction(IWorkbenchWindow window) { 45 super(WorkbenchMessages.PinEditorAction_text, window); 46 setActionDefinitionId("org.eclipse.ui.window.pinEditor"); setToolTipText(WorkbenchMessages.PinEditorAction_toolTip); 48 setId("org.eclipse.ui.internal.PinEditorAction"); setImageDescriptor(WorkbenchImages 52 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR)); 53 setDisabledImageDescriptor(WorkbenchImages 54 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR_DISABLED)); 55 } 56 57 60 public void run() { 61 if (getWorkbenchWindow() == null) { 62 return; 64 } 65 IEditorPart editor = getActiveEditor(); 66 if (editor != null) { 67 WorkbenchPartReference ref = getReference(editor); 68 ref.setPinned(isChecked()); 69 } 70 } 71 72 private WorkbenchPartReference getReference(IEditorPart editor) { 73 return (WorkbenchPartReference)((EditorSite)editor.getSite()).getPartReference(); 74 } 75 76 79 protected void updateState() { 80 if (getWorkbenchWindow() == null || getActivePage() == null) { 81 setChecked(false); 82 setEnabled(false); 83 return; 84 } 85 86 IEditorPart editor = getActiveEditor(); 87 boolean enabled = (editor != null); 88 setEnabled(enabled); 89 if (enabled) { 90 setChecked(getReference(editor).isPinned()); 91 } else { 92 setChecked(false); 93 } 94 } 95 96 99 protected void editorActivated(IEditorPart part) { 100 super.editorActivated(part); 101 if (part != null) { 102 getReference(part).addInternalPropertyListener(propListener); 103 } 104 } 105 106 109 protected void editorDeactivated(IEditorPart part) { 110 super.editorDeactivated(part); 111 if (part != null) { 112 getReference(part).removeInternalPropertyListener(propListener); 113 } 114 } 115 116 119 public void dispose() { 120 editorDeactivated(getActiveEditor()); 122 super.dispose(); 123 } 124 } 125 | Popular Tags |