Source code: org/gjt/sp/jedit/menu/FavoritesProvider.java
1 /*
2 * FavoritesProvider.java - Favorites list menu
3 * :tabSize=8:indentSize=8:noTabs=false:
4 * :folding=explicit:collapseFolds=1:
5 *
6 * Copyright (C) 2003 Slava Pestov
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23 package org.gjt.sp.jedit.menu;
24
25 //{{{ Imports
26 import javax.swing.event.*;
27 import javax.swing.*;
28 import java.awt.event.*;
29 import org.gjt.sp.jedit.browser.*;
30 import org.gjt.sp.jedit.io.*;
31 import org.gjt.sp.jedit.*;
32 //}}}
33
34 public class FavoritesProvider implements DynamicMenuProvider
35 {
36 //{{{ updateEveryTime() method
37 public boolean updateEveryTime()
38 {
39 return false;
40 } //}}}
41
42 //{{{ update() method
43 public void update(JMenu menu)
44 {
45 final View view = GUIUtilities.getView(menu);
46
47 //{{{ ActionListeners
48 ActionListener fileListener = new ActionListener()
49 {
50 public void actionPerformed(ActionEvent evt)
51 {
52 jEdit.openFile(view,evt.getActionCommand());
53 }
54 };
55
56 ActionListener dirListener = new ActionListener()
57 {
58 public void actionPerformed(ActionEvent evt)
59 {
60 VFSBrowser.browseDirectory(view,
61 evt.getActionCommand());
62 }
63 }; //}}}
64
65 VFS.DirectoryEntry[] favorites
66 = 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 MiscUtilities.quicksort(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 VFS.DirectoryEntry favorite
85 = favorites[i];
86 JMenuItem mi = new JMenuItem(favorite.path);
87 mi.setIcon(FileCellRenderer
88 .getIconForFile(
89 favorite,false));
90 if(favorite.type ==
91 VFS.DirectoryEntry.FILE)
92 {
93 mi.addActionListener(fileListener);
94 }
95 else
96 {
97 mi.addActionListener(dirListener);
98 }
99 menu.add(mi);
100 }
101 }
102 } //}}}
103
104 //{{{ Private members
105 private String dir;
106 //}}}
107 }