1 22 23 package org.gjt.sp.jedit.menu; 24 25 import javax.swing.*; 27 import java.awt.event.*; 28 import java.util.Arrays ; 29 30 import org.gjt.sp.jedit.browser.*; 31 import org.gjt.sp.jedit.io.*; 32 import org.gjt.sp.jedit.*; 33 35 public class FavoritesProvider implements DynamicMenuProvider 36 { 37 public boolean updateEveryTime() 39 { 40 return false; 41 } 43 public void update(JMenu menu) 45 { 46 final View view = GUIUtilities.getView(menu); 47 48 ActionListener fileListener = new ActionListener() 50 { 51 public void actionPerformed(ActionEvent evt) 52 { 53 jEdit.openFile(view,evt.getActionCommand()); 54 } 55 }; 56 57 ActionListener dirListener = new ActionListener() 58 { 59 public void actionPerformed(ActionEvent evt) 60 { 61 VFSBrowser.browseDirectory(view, 62 evt.getActionCommand()); 63 } 64 }; 66 VFSFile[] favorites = FavoritesVFS.getFavorites(); 67 if(favorites.length == 0) 68 { 69 JMenuItem mi = new JMenuItem( 70 jEdit.getProperty( 71 "vfs.browser.favorites" 72 + ".no-favorites.label")); 73 mi.setEnabled(false); 74 menu.add(mi); 75 } 76 else 77 { 78 Arrays.sort(favorites, 79 new VFS.DirectoryEntryCompare( 80 jEdit.getBooleanProperty("vfs.browser.sortMixFilesAndDirs"), 81 jEdit.getBooleanProperty("vfs.browser.sortIgnoreCase"))); 82 for(int i = 0; i < favorites.length; i++) 83 { 84 VFSFile favorite = favorites[i]; 85 JMenuItem mi = new JMenuItem( 86 favorite.getPath()); 87 mi.setIcon(FileCellRenderer 88 .getIconForFile( 89 favorite,false)); 90 if(favorite.getType() == VFSFile.FILE) 91 { 92 mi.addActionListener(fileListener); 93 } 94 else 95 { 96 mi.addActionListener(dirListener); 97 } 98 menu.add(mi); 99 } 100 } 101 } } 103 | Popular Tags |