01: /*
02: * :tabSize=8:indentSize=8:noTabs=false:
03: * :folding=explicit:collapseFolds=1:
04: *
05: * ShowBufferMenu.java
06: * Copyright (C) 2002 Kris Kopicki
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 macos.menu;
24:
25: //{{{ Imports
26: import java.awt.event.*;
27: import java.io.File;
28: import javax.swing.*;
29: import javax.swing.event.*;
30: import org.gjt.sp.jedit.*;
31: import org.gjt.sp.jedit.browser.*;
32: import macos.*;
33:
34: //}}}
35:
36: public class ShowBufferMenu extends JMenu implements MenuListener {
37: //{{{ Constructor
38: public ShowBufferMenu() {
39: super (jEdit.getProperty("MacOSPlugin.menu.buffers.label"));
40: addMenuListener(this );
41: } //}}}
42:
43: //{{{ construct() method
44: private void construct() {
45: JMenuItem item;
46: removeAll();
47:
48: Buffer[] buffs = jEdit.getBuffers();
49: for (int i = 0; i < buffs.length; i++) {
50: if (!buffs[i].isUntitled()) {
51: item = add(new ShowBufferMenuItem(buffs[i].getName(),
52: buffs[i].getPath()));
53: item.setIcon(FileCellRenderer.fileIcon);
54: add(item);
55: }
56: }
57:
58: if (getItemCount() == 0) {
59: item = new JMenuItem(jEdit
60: .getProperty("MacOSPlugin.menu.buffers.none"));
61: item.setEnabled(false);
62: add(item);
63: }
64: } //}}}
65:
66: //{{{ menuSelected() method
67: public void menuSelected(MenuEvent e) {
68: construct();
69: } //}}}
70:
71: //{{{ menuDeselected() method
72: public void menuDeselected(MenuEvent e) {
73: } //}}}
74:
75: //{{{ menuCanceled() method
76: public void menuCanceled(MenuEvent e) {
77: } //}}}
78:
79: //{{{ ShowBufferMenuItem class
80: class ShowBufferMenuItem extends JMenuItem {
81: String path;
82:
83: public ShowBufferMenuItem(String name, String path) {
84: super (name);
85: this .path = path;
86: addActionListener(new ShowFileAction());
87: }
88:
89: class ShowFileAction implements ActionListener {
90: public void actionPerformed(ActionEvent e) {
91: MacOSActions.showInFinder(path);
92: }
93: }
94: } //}}}
95: }
|