Source code: macos/menu/ShowRecentMenu.java
1 /*
2 * :tabSize=8:indentSize=8:noTabs=false:
3 * :folding=explicit:collapseFolds=1:
4 *
5 * ShowRecentMenu.java
6 * Copyright (C) 2002 Kris Kopicki
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 macos.menu;
24
25 //{{{ Imports
26 import java.awt.event.*;
27 import java.io.File;
28 import java.util.List;
29 import javax.swing.*;
30 import javax.swing.event.*;
31 import org.gjt.sp.jedit.*;
32 import org.gjt.sp.jedit.browser.*;
33 import macos.*;
34 //}}}
35
36 public class ShowRecentMenu extends JMenu implements MenuListener
37 {
38 //{{{ Constructor
39 public ShowRecentMenu()
40 {
41 super(jEdit.getProperty("MacOSPlugin.menu.recent.label"));
42 addMenuListener(this);
43 } //}}}
44
45 //{{{ construct() method
46 private void construct()
47 {
48 List recent = BufferHistory.getHistory();
49 JMenuItem item;
50 File file;
51 int max = recent.size();
52 int min = max - 20;
53
54 if (max == 0)
55 {
56 item = new JMenuItem(jEdit.getProperty("MacOSPlugin.menu.recent.none"));
57 item.setEnabled(false);
58 add(item);
59 return;
60 }
61
62 if (min < 0)
63 min = 0;
64
65 for (int i=max-1; i >= min ; i--)
66 {
67 file = new File(((BufferHistory.Entry)recent.get(i)).path);
68 item = new ShowRecentMenuItem(file.getName(),file.getPath());
69 item.setIcon(FileCellRenderer.fileIcon);
70 add(item);
71 }
72 } //}}}
73
74 //{{{ menuSelected() method
75 public void menuSelected(MenuEvent e)
76 {
77 construct();
78 } //}}}
79
80 //{{{ menuDeselected() method
81 public void menuDeselected(MenuEvent e)
82 {
83 removeAll();
84 } //}}}
85
86 //{{{ menuCanceled() method
87 public void menuCanceled(MenuEvent e)
88 {
89 } //}}}
90
91 //{{{ ShowRecentMenuItem class
92 class ShowRecentMenuItem extends JMenuItem
93 {
94 String path;
95
96 public ShowRecentMenuItem(String name, String path)
97 {
98 super(name);
99 this.path = path;
100 addActionListener(new ShowFileAction());
101 }
102
103 class ShowFileAction implements ActionListener
104 {
105 public void actionPerformed(ActionEvent e)
106 {
107 MacOSActions.showInFinder(path);
108 }
109 }
110 } //}}}
111 }