1 11 package org.eclipse.ui.internal.actions; 12 13 import org.eclipse.jface.action.ActionContributionItem; 14 import org.eclipse.jface.preference.IPreferenceStore; 15 import org.eclipse.jface.util.IPropertyChangeListener; 16 import org.eclipse.jface.util.PropertyChangeEvent; 17 import org.eclipse.ui.IWorkbenchWindow; 18 import org.eclipse.ui.internal.IPreferenceConstants; 19 import org.eclipse.ui.internal.PinEditorAction; 20 import org.eclipse.ui.internal.WorkbenchPlugin; 21 import org.eclipse.ui.internal.tweaklets.TabBehaviour; 22 import org.eclipse.ui.internal.tweaklets.Tweaklets; 23 24 30 public class PinEditorContributionItem extends ActionContributionItem { 31 private IWorkbenchWindow window = null; 32 33 private boolean reuseEditors = false; 34 35 private IPropertyChangeListener prefListener = new IPropertyChangeListener() { 36 public void propertyChange(PropertyChangeEvent event) { 37 if (event.getProperty().equals( 38 IPreferenceConstants.REUSE_EDITORS_BOOLEAN)) { 39 if (getParent() != null) { 40 IPreferenceStore store = WorkbenchPlugin.getDefault() 41 .getPreferenceStore(); 42 reuseEditors = store 43 .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN) 44 || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction(); 45 setVisible(reuseEditors); 46 getParent().markDirty(); 47 if (window.getShell() != null 48 && !window.getShell().isDisposed()) { 49 window.getShell().getDisplay().syncExec(new Runnable () { 51 public void run() { 52 getParent().update(false); 53 } 54 }); 55 } 56 } 57 } 58 } 59 }; 60 61 64 public PinEditorContributionItem(PinEditorAction action, 65 IWorkbenchWindow window) { 66 super(action); 67 68 if (window == null) { 69 throw new IllegalArgumentException (); 70 } 71 this.window = window; 72 73 IPreferenceStore store = WorkbenchPlugin.getDefault().getPreferenceStore(); 74 reuseEditors = store 75 .getBoolean(IPreferenceConstants.REUSE_EDITORS_BOOLEAN) 76 || ((TabBehaviour)Tweaklets.get(TabBehaviour.KEY)).alwaysShowPinAction(); 77 setVisible(reuseEditors); 78 WorkbenchPlugin.getDefault().getPreferenceStore() 79 .addPropertyChangeListener(prefListener); 80 } 81 82 85 public boolean isVisible() { 86 return super.isVisible() && reuseEditors; 88 } 89 90 93 public void dispose() { 94 super.dispose(); 95 WorkbenchPlugin.getDefault().getPreferenceStore() 96 .removePropertyChangeListener(prefListener); 97 } 98 } 99 | Popular Tags |