1 22 23 package org.gjt.sp.jedit.menu; 24 25 import javax.swing.*; 27 import java.awt.event.*; 28 import java.util.Vector ; 29 import java.util.Collections ; 30 31 import org.gjt.sp.jedit.browser.*; 32 import org.gjt.sp.jedit.gui.HistoryModel; 33 import org.gjt.sp.jedit.*; 34 36 public class RecentDirectoriesProvider implements DynamicMenuProvider 37 { 38 public boolean updateEveryTime() 40 { 41 return true; 42 } 44 public void update(JMenu menu) 46 { 47 final View view = GUIUtilities.getView(menu); 48 49 ActionListener actionListener = new ActionListener() 51 { 52 public void actionPerformed(ActionEvent evt) 53 { 54 VFSBrowser.browseDirectory(view,evt.getActionCommand()); 55 56 view.getStatus().setMessage(null); 57 } 58 }; 60 MouseListener mouseListener = new MouseAdapter() 62 { 63 public void mouseEntered(MouseEvent evt) 64 { 65 view.getStatus().setMessage( 66 ((JMenuItem)evt.getSource()) 67 .getActionCommand()); 68 } 69 70 public void mouseExited(MouseEvent evt) 71 { 72 view.getStatus().setMessage(null); 73 } 74 }; 76 HistoryModel model = HistoryModel.getModel("vfs.browser.path"); 77 if(model.getSize() == 0) 78 { 79 JMenuItem menuItem = new JMenuItem( 80 jEdit.getProperty("no-recent-dirs.label")); 81 menuItem.setEnabled(false); 82 menu.add(menuItem); 83 return; 84 } 85 86 boolean sort = jEdit.getBooleanProperty("sortRecent"); 87 88 int maxItems = jEdit.getIntegerProperty("menu.spillover",20); 89 90 Vector menuItems = new Vector (); 91 92 for(int i = 0; i < model.getSize(); i++) 93 { 94 String path = model.getItem(i); 95 JMenuItem menuItem = new JMenuItem(MiscUtilities.getFileName(path)); 96 menuItem.setActionCommand(path); 97 menuItem.addActionListener(actionListener); 98 menuItem.addMouseListener(mouseListener); 99 menuItem.setIcon(FileCellRenderer.dirIcon); 100 101 if(sort) 102 menuItems.addElement(menuItem); 103 else 104 { 105 if(menu.getMenuComponentCount() >= maxItems 106 && i != model.getSize() - 1) 107 { 108 JMenu newMenu = new JMenu( 109 jEdit.getProperty("common.more")); 110 menu.add(newMenu); 111 menu = newMenu; 112 } 113 114 menu.add(menuItem); 115 } 116 } 117 118 if(sort) 119 { 120 Collections.sort(menuItems, 121 new MiscUtilities.MenuItemCompare()); 122 for(int i = 0; i < menuItems.size(); i++) 123 { 124 if(menu.getMenuComponentCount() >= maxItems 125 && i != 0) 126 { 127 JMenu newMenu = new JMenu( 128 jEdit.getProperty("common.more")); 129 menu.add(newMenu); 130 menu = newMenu; 131 } 132 133 menu.add((JMenuItem)menuItems.elementAt(i)); 134 } 135 } 136 } } 138 | Popular Tags |