01: /*
02: * FavoritesProvider.java - Favorites list menu
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 2003 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * 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.*;
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:
34: //}}}
35:
36: public class FavoritesProvider implements DynamicMenuProvider {
37: //{{{ updateEveryTime() method
38: public boolean updateEveryTime() {
39: return false;
40: } //}}}
41:
42: //{{{ update() method
43: public void update(JMenu menu) {
44: final View view = GUIUtilities.getView(menu);
45:
46: //{{{ ActionListeners
47: ActionListener fileListener = new ActionListener() {
48: public void actionPerformed(ActionEvent evt) {
49: jEdit.openFile(view, evt.getActionCommand());
50: }
51: };
52:
53: ActionListener dirListener = new ActionListener() {
54: public void actionPerformed(ActionEvent evt) {
55: VFSBrowser
56: .browseDirectory(view, evt.getActionCommand());
57: }
58: }; //}}}
59:
60: VFSFile[] favorites = FavoritesVFS.getFavorites();
61: if (favorites.length == 0) {
62: JMenuItem mi = new JMenuItem(jEdit
63: .getProperty("vfs.browser.favorites"
64: + ".no-favorites.label"));
65: mi.setEnabled(false);
66: menu.add(mi);
67: } else {
68: Arrays
69: .sort(
70: favorites,
71: new VFS.DirectoryEntryCompare(
72: jEdit
73: .getBooleanProperty("vfs.browser.sortMixFilesAndDirs"),
74: jEdit
75: .getBooleanProperty("vfs.browser.sortIgnoreCase")));
76: for (int i = 0; i < favorites.length; i++) {
77: VFSFile favorite = favorites[i];
78: JMenuItem mi = new JMenuItem(favorite.getPath());
79: mi.setIcon(FileCellRenderer.getIconForFile(favorite,
80: false));
81: if (favorite.getType() == VFSFile.FILE) {
82: mi.addActionListener(fileListener);
83: } else {
84: mi.addActionListener(dirListener);
85: }
86: menu.add(mi);
87: }
88: }
89: } //}}}
90: }
|