OmegaT のメニューバーにフォルダーツリー参照用のメニューを追加します。
allow to open folder with enter key.
@@ -32,14 +32,15 @@ | ||
32 | 32 | public class MenuManager { |
33 | 33 | |
34 | 34 | private JMenu root; |
35 | - private JMenu projectRoot; | |
35 | + private JMenu currentProject; | |
36 | 36 | |
37 | 37 | public MenuManager() { |
38 | 38 | root = getRootMenu(L10n.getFoldersMenuLabel()); // Folders menu |
39 | + root.addMenuKeyListener(Submenu.getMenuKeyListener()); // for opening folder with enter key | |
39 | 40 | |
40 | 41 | // ProjectRoot |
41 | 42 | try { |
42 | - projectRoot = Submenu.create(L10n.getProjectRootMenuLabel(), root); | |
43 | + currentProject = Submenu.create(L10n.getProjectRootMenuLabel(), root); | |
43 | 44 | } catch (IOException ex) { |
44 | 45 | Log.log(ex); |
45 | 46 | return; |
@@ -61,7 +62,7 @@ | ||
61 | 62 | public void createProjectItems() { |
62 | 63 | File rootDir = new File(Core.getProject().getProjectProperties().getProjectRoot()); |
63 | 64 | try { |
64 | - Submenu.associate(projectRoot, rootDir); | |
65 | + Submenu.associate(currentProject, rootDir); | |
65 | 66 | } catch (IOException ex) { |
66 | 67 | Log.log(ex); |
67 | 68 | } |
@@ -68,8 +69,7 @@ | ||
68 | 69 | } |
69 | 70 | |
70 | 71 | public void removeAllProjectItems() { |
71 | - //projectRoot.removeChildren(); | |
72 | - Submenu.removeChildren(projectRoot); | |
72 | + Submenu.removeChildren(currentProject); | |
73 | 73 | } |
74 | 74 | |
75 | 75 | private JMenu getRootMenu(String labelString) { |
@@ -27,7 +27,7 @@ | ||
27 | 27 | /** |
28 | 28 | * easy access to project folders from menu |
29 | 29 | * |
30 | - * TODO アイテムを含むフォルダーをキーボード操作で開けるように | |
30 | + * TODO refactoring Submenu module | |
31 | 31 | * |
32 | 32 | * @author Yu Tang |
33 | 33 | */ |
@@ -47,9 +47,7 @@ | ||
47 | 47 | } |
48 | 48 | |
49 | 49 | @Override |
50 | - public void onApplicationShutdown() { | |
51 | - // | |
52 | - } | |
50 | + public void onApplicationShutdown() { /* do nothing */ } | |
53 | 51 | |
54 | 52 | @Override |
55 | 53 | public void onProjectChanged(PROJECT_CHANGE_TYPE eventType) { |
@@ -26,7 +26,7 @@ | ||
26 | 26 | |
27 | 27 | private static final String APP_NAME = "FolderMenu"; |
28 | 28 | private static final String APP_VERSION = "0.2"; |
29 | - private static final String APP_BUILD = "20130815"; | |
29 | + private static final String APP_BUILD = "20130816"; | |
30 | 30 | private static final String APP_AUTHOR = "Yu-Tang"; |
31 | 31 | |
32 | 32 | public static void main(String[] args) { |
@@ -19,6 +19,7 @@ | ||
19 | 19 | import java.awt.Desktop; |
20 | 20 | import java.awt.event.ActionEvent; |
21 | 21 | import java.awt.event.ActionListener; |
22 | +import java.awt.event.KeyEvent; | |
22 | 23 | import java.awt.event.MouseEvent; |
23 | 24 | import java.awt.event.MouseListener; |
24 | 25 | import java.io.File; |
@@ -29,7 +30,11 @@ | ||
29 | 30 | import javax.swing.Icon; |
30 | 31 | import javax.swing.JMenu; |
31 | 32 | import javax.swing.JMenuItem; |
33 | +import javax.swing.MenuElement; | |
34 | +import javax.swing.MenuSelectionManager; | |
32 | 35 | import javax.swing.event.MenuEvent; |
36 | +import javax.swing.event.MenuKeyEvent; | |
37 | +import javax.swing.event.MenuKeyListener; | |
33 | 38 | import javax.swing.event.MenuListener; |
34 | 39 | import javax.swing.filechooser.FileSystemView; |
35 | 40 | import org.omegat.core.Core; |
@@ -49,12 +54,13 @@ | ||
49 | 54 | fs = FileSystemView.getFileSystemView(); |
50 | 55 | ff = new FileFilter() { |
51 | 56 | |
52 | - @Override | |
53 | - public boolean accept(File file) { | |
54 | - return !file.getName().startsWith(".") && !file.isHidden(); | |
55 | - } | |
57 | + @Override | |
58 | + public boolean accept(File file) { | |
59 | + return !file.getName().startsWith(".") && !file.isHidden(); | |
60 | + } | |
56 | 61 | |
57 | - }; | |
62 | + }; | |
63 | + | |
58 | 64 | al = new ActionListener() { |
59 | 65 | |
60 | 66 | @Override |
@@ -63,6 +69,33 @@ | ||
63 | 69 | } |
64 | 70 | |
65 | 71 | }; |
72 | + | |
73 | + mkl = new MenuKeyListener() { | |
74 | + | |
75 | + @Override | |
76 | + public void menuKeyTyped(MenuKeyEvent e) { /* do nothing */ } | |
77 | + | |
78 | + @Override | |
79 | + public void menuKeyPressed(MenuKeyEvent e) { | |
80 | + if (e.getKeyCode() == KeyEvent.VK_ENTER) { | |
81 | + MenuSelectionManager manager = e.getMenuSelectionManager(); | |
82 | + MenuElement[] selectedPath = manager.getSelectedPath(); | |
83 | + MenuElement selection = selectedPath[selectedPath.length-1]; | |
84 | + if (selection instanceof JMenu) { | |
85 | + JMenu menu = (JMenu) selection; | |
86 | + if (menu.isEnabled()) { | |
87 | + manager.clearSelectedPath(); | |
88 | + open(menu.getActionCommand()); | |
89 | + } | |
90 | + } | |
91 | + } | |
92 | + } | |
93 | + | |
94 | + @Override | |
95 | + public void menuKeyReleased(MenuKeyEvent e) { /* do nothing */ } | |
96 | + | |
97 | + }; | |
98 | + | |
66 | 99 | mol = new MouseListener() { |
67 | 100 | |
68 | 101 | @Override |
@@ -74,16 +107,16 @@ | ||
74 | 107 | } |
75 | 108 | |
76 | 109 | @Override |
77 | - public void mousePressed(MouseEvent e) { /* ignore */ } | |
110 | + public void mousePressed(MouseEvent e) { /* do nothing */ } | |
78 | 111 | |
79 | 112 | @Override |
80 | - public void mouseReleased(MouseEvent e) { /* ignore */ } | |
113 | + public void mouseReleased(MouseEvent e) { /* do nothing */ } | |
81 | 114 | |
82 | 115 | @Override |
83 | - public void mouseEntered(MouseEvent e) { /* ignore */ } | |
116 | + public void mouseEntered(MouseEvent e) { /* do nothing */ } | |
84 | 117 | |
85 | 118 | @Override |
86 | - public void mouseExited(MouseEvent e) { /* ignore */ } | |
119 | + public void mouseExited(MouseEvent e) { /* do nothing */ } | |
87 | 120 | |
88 | 121 | }; |
89 | 122 |
@@ -110,7 +143,7 @@ | ||
110 | 143 | } |
111 | 144 | |
112 | 145 | @Override |
113 | - public void menuCanceled(MenuEvent e) { /* ignore */ } | |
146 | + public void menuCanceled(MenuEvent e) { /* do nothing */ } | |
114 | 147 | |
115 | 148 | }; |
116 | 149 |
@@ -174,6 +207,10 @@ | ||
174 | 207 | public static ActionListener getActionListener() { |
175 | 208 | return al; |
176 | 209 | } |
210 | + | |
211 | + public static MenuKeyListener getMenuKeyListener() { | |
212 | + return mkl; | |
213 | + } | |
177 | 214 | |
178 | 215 | public static MouseListener getMouseListener() { |
179 | 216 | return mol; |
@@ -236,34 +273,34 @@ | ||
236 | 273 | } |
237 | 274 | |
238 | 275 | private static JMenu createMenu(File folder) throws IOException { |
239 | - JMenu m = new JMenu(folder.getName()); | |
240 | - m.setIcon(Submenu.getIcon(folder)); | |
241 | - m.setActionCommand(folder.getCanonicalPath()); | |
242 | - m.addMenuListener(getMenuListener()); | |
243 | - m.addMouseListener(getMouseListener()); | |
244 | - m.setEnabled(true); | |
245 | - return m; | |
276 | + return createMenu(folder, null); | |
246 | 277 | } |
247 | 278 | |
248 | - private static JMenu createMenu(String label) { | |
249 | - JMenu m = new JMenu(); | |
250 | - Mnemonics.setLocalizedText(m, label); | |
251 | - m.addMenuListener(getMenuListener()); | |
252 | - m.addMouseListener(getMouseListener()); | |
253 | - return m; | |
279 | + private static JMenu createMenu(String label) throws IOException { | |
280 | + return createMenu(null, label); | |
254 | 281 | } |
255 | 282 | |
256 | 283 | private static JMenu createMenu(File folder, String label) throws IOException { |
257 | - JMenu m = new JMenu(); | |
258 | - Mnemonics.setLocalizedText(m, label); | |
259 | - m.setIcon(Submenu.getIcon(folder)); | |
260 | - m.setActionCommand(folder.getCanonicalPath()); | |
284 | + JMenu m; | |
285 | + if (label == null) { | |
286 | + m = new JMenu(folder.getName()); | |
287 | + } else { | |
288 | + m = new JMenu(); | |
289 | + Mnemonics.setLocalizedText(m, label); | |
290 | + } | |
291 | + | |
261 | 292 | m.addMenuListener(getMenuListener()); |
262 | 293 | m.addMouseListener(getMouseListener()); |
263 | - m.setEnabled(true); | |
294 | + | |
295 | + if (folder != null) { | |
296 | + m.setIcon(getIcon(folder)); | |
297 | + m.setActionCommand(folder.getCanonicalPath()); | |
298 | + m.setEnabled(true); | |
299 | + } | |
300 | + | |
264 | 301 | return m; |
265 | 302 | } |
266 | - | |
303 | + | |
267 | 304 | private static void prepare(File folder, JMenu menu, File[] filteredListFiles) throws IOException { |
268 | 305 | if (menu.getItemCount() > 0) { |
269 | 306 | // submenus are already created |
@@ -289,9 +326,10 @@ | ||
289 | 326 | } |
290 | 327 | |
291 | 328 | private static final FileSystemView fs; |
292 | - private static final FileFilter ff; | |
293 | - private static final ActionListener al; | |
294 | - private static final MouseListener mol; | |
295 | - private static final MenuListener mel; | |
296 | - private static final Comparator comp; | |
329 | + private static final FileFilter ff; | |
330 | + private static final ActionListener al; | |
331 | + private static final MenuKeyListener mkl; | |
332 | + private static final MouseListener mol; | |
333 | + private static final MenuListener mel; | |
334 | + private static final Comparator comp; | |
297 | 335 | } |