1 19 20 21 package org.netbeans.core.windows.actions; 22 23 24 import org.netbeans.core.windows.Constants; 25 import org.netbeans.core.windows.ModeImpl; 26 import org.netbeans.core.windows.WindowManagerImpl; 27 import org.openide.util.NbBundle; 28 import org.openide.util.WeakListeners; 29 import org.openide.windows.TopComponent; 30 31 import javax.swing.*; 32 import java.beans.PropertyChangeEvent ; 33 import java.beans.PropertyChangeListener ; 34 import java.util.Iterator ; 35 36 37 40 public class SwitchToRecentDocumentAction extends AbstractAction 41 implements PropertyChangeListener { 42 43 public SwitchToRecentDocumentAction() { 44 putValue(Action.NAME, NbBundle.getMessage(SwitchToRecentDocumentAction.class, "CTL_SwitchToRecentDocumentAction")); 45 TopComponent.getRegistry().addPropertyChangeListener( 46 WeakListeners.propertyChange(this, TopComponent.getRegistry())); 47 updateEnabled(); 48 } 49 50 51 public void actionPerformed(java.awt.event.ActionEvent ev) { 52 WindowManagerImpl wm = WindowManagerImpl.getInstance(); 53 TopComponent[] tcs = wm.getRecentViewList(); 54 55 if(tcs.length == 0) { 56 return; 57 } 58 59 for(int i = 0; i < tcs.length; i++) { 60 TopComponent tc = (TopComponent)tcs[i]; 61 62 ModeImpl mode = (ModeImpl)wm.findMode(tc); 63 if(mode == null) { 64 continue; 65 } 66 67 if(mode.getKind() == Constants.MODE_KIND_EDITOR) { 68 if(mode != wm.getCurrentMaximizedMode()) { 70 wm.switchMaximizedMode(null); 71 } 72 tc.requestActive(); 73 break; 74 } 75 } 76 } 77 78 public void propertyChange(PropertyChangeEvent evt) { 79 if(TopComponent.Registry.PROP_OPENED.equals(evt.getPropertyName())) { 80 updateEnabled(); 81 } 82 } 83 84 private void updateEnabled() { 85 for(Iterator it = WindowManagerImpl.getInstance().getModes().iterator(); it.hasNext(); ) { 86 ModeImpl mode = (ModeImpl)it.next(); 87 if(mode.getKind() == Constants.MODE_KIND_EDITOR 88 && !mode.getOpenedTopComponents().isEmpty()) { 89 setEnabled(true); 90 return; 91 } 92 } 93 setEnabled(false); 94 } 95 } 96 97 | Popular Tags |