source: josm/trunk/src/org/openstreetmap/josm/gui/io/RecentlyOpenedFilesMenu.java@ 3758

Last change on this file since 3758 was 3758, checked in by stoecker, 13 years ago

fix help topics

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.io;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.event.ActionEvent;
8import java.io.File;
9import java.util.Collection;
10import java.util.Collections;
11import javax.swing.AbstractAction;
12import javax.swing.JMenu;
13import javax.swing.JMenuItem;
14import javax.swing.JSeparator;
15import javax.swing.event.MenuEvent;
16import javax.swing.event.MenuListener;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.actions.OpenFileAction.OpenFileTask;
20import org.openstreetmap.josm.tools.ImageProvider;
21
22/**
23 * Show list of recently opened files
24 */
25public class RecentlyOpenedFilesMenu extends JMenu {
26 ClearAction clearAction;
27
28 public RecentlyOpenedFilesMenu() {
29 super(tr("Open Recent"));
30 setToolTipText(tr("List of recently opened files"));
31 setIcon(ImageProvider.get("openrecent.png"));
32 putClientProperty("help", ht("/Action/OpenRecent"));
33
34 // build dynamically
35 addMenuListener(new MenuListener() {
36 @Override
37 public void menuSelected(MenuEvent e) {
38 rebuild();
39 }
40
41 @Override
42 public void menuDeselected(MenuEvent e) {
43 }
44
45 @Override
46 public void menuCanceled(MenuEvent e) {
47 }
48 });
49 }
50
51 private void rebuild() {
52 removeAll();
53 Collection<String> fileHistory = Main.pref.getCollection("file-open.history");
54
55 for (final String file : fileHistory) {
56 add(new AbstractAction() {
57 {
58 putValue(NAME, file);
59 putValue("help", ht("/Action/OpenRecent"));
60 }
61 @Override
62 public void actionPerformed(ActionEvent e) {
63 File f = new File(file);
64 OpenFileTask task = new OpenFileTask(Collections.singletonList(f), null);
65 task.setRecordHistory(true);
66 Main.worker.submit(task);
67 }
68 });
69 }
70 add(new JSeparator());
71 if (clearAction == null) {
72 clearAction = new ClearAction();
73 }
74 JMenuItem clearItem = new JMenuItem(clearAction);
75 clearItem.setEnabled(!fileHistory.isEmpty());
76 add(clearItem);
77 }
78
79 private static class ClearAction extends AbstractAction {
80
81 public ClearAction() {
82 super(tr("Clear"));
83 putValue(SHORT_DESCRIPTION, tr("Clear the list of recently opened files"));
84 putValue("help", ht("/Action/OpenRecent"));
85 }
86
87 @Override
88 public void actionPerformed(ActionEvent e) {
89 Main.pref.putCollection("file-open.history", null);
90 }
91 }
92}
Note: See TracBrowser for help on using the repository browser.