• R/O
  • SSH
  • HTTPS

提交

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

OmegaT のメニューバーにフォルダーツリー参照用のメニューを追加します。


Commit MetaInfo

修訂8 (tree)
時間2013-08-16 22:36:16
作者yu-tang

Log Message

allow to open folder with enter key.

Change Summary

差異

--- trunk/src/org/omegat/plugin/foldermenu/MenuManager.java (revision 7)
+++ trunk/src/org/omegat/plugin/foldermenu/MenuManager.java (revision 8)
@@ -32,14 +32,15 @@
3232 public class MenuManager {
3333
3434 private JMenu root;
35- private JMenu projectRoot;
35+ private JMenu currentProject;
3636
3737 public MenuManager() {
3838 root = getRootMenu(L10n.getFoldersMenuLabel()); // Folders menu
39+ root.addMenuKeyListener(Submenu.getMenuKeyListener()); // for opening folder with enter key
3940
4041 // ProjectRoot
4142 try {
42- projectRoot = Submenu.create(L10n.getProjectRootMenuLabel(), root);
43+ currentProject = Submenu.create(L10n.getProjectRootMenuLabel(), root);
4344 } catch (IOException ex) {
4445 Log.log(ex);
4546 return;
@@ -61,7 +62,7 @@
6162 public void createProjectItems() {
6263 File rootDir = new File(Core.getProject().getProjectProperties().getProjectRoot());
6364 try {
64- Submenu.associate(projectRoot, rootDir);
65+ Submenu.associate(currentProject, rootDir);
6566 } catch (IOException ex) {
6667 Log.log(ex);
6768 }
@@ -68,8 +69,7 @@
6869 }
6970
7071 public void removeAllProjectItems() {
71- //projectRoot.removeChildren();
72- Submenu.removeChildren(projectRoot);
72+ Submenu.removeChildren(currentProject);
7373 }
7474
7575 private JMenu getRootMenu(String labelString) {
--- trunk/src/org/omegat/plugin/foldermenu/FolderMenu.java (revision 7)
+++ trunk/src/org/omegat/plugin/foldermenu/FolderMenu.java (revision 8)
@@ -27,7 +27,7 @@
2727 /**
2828 * easy access to project folders from menu
2929 *
30- * TODO アイテムを含むフォルダーをキーボード操作で開けるように
30+ * TODO refactoring Submenu module
3131 *
3232 * @author Yu Tang
3333 */
@@ -47,9 +47,7 @@
4747 }
4848
4949 @Override
50- public void onApplicationShutdown() {
51- //
52- }
50+ public void onApplicationShutdown() { /* do nothing */ }
5351
5452 @Override
5553 public void onProjectChanged(PROJECT_CHANGE_TYPE eventType) {
--- trunk/src/org/omegat/plugin/foldermenu/VersionInfo.java (revision 7)
+++ trunk/src/org/omegat/plugin/foldermenu/VersionInfo.java (revision 8)
@@ -26,7 +26,7 @@
2626
2727 private static final String APP_NAME = "FolderMenu";
2828 private static final String APP_VERSION = "0.2";
29- private static final String APP_BUILD = "20130815";
29+ private static final String APP_BUILD = "20130816";
3030 private static final String APP_AUTHOR = "Yu-Tang";
3131
3232 public static void main(String[] args) {
--- trunk/src/org/omegat/plugin/foldermenu/Submenu.java (revision 7)
+++ trunk/src/org/omegat/plugin/foldermenu/Submenu.java (revision 8)
@@ -19,6 +19,7 @@
1919 import java.awt.Desktop;
2020 import java.awt.event.ActionEvent;
2121 import java.awt.event.ActionListener;
22+import java.awt.event.KeyEvent;
2223 import java.awt.event.MouseEvent;
2324 import java.awt.event.MouseListener;
2425 import java.io.File;
@@ -29,7 +30,11 @@
2930 import javax.swing.Icon;
3031 import javax.swing.JMenu;
3132 import javax.swing.JMenuItem;
33+import javax.swing.MenuElement;
34+import javax.swing.MenuSelectionManager;
3235 import javax.swing.event.MenuEvent;
36+import javax.swing.event.MenuKeyEvent;
37+import javax.swing.event.MenuKeyListener;
3338 import javax.swing.event.MenuListener;
3439 import javax.swing.filechooser.FileSystemView;
3540 import org.omegat.core.Core;
@@ -49,12 +54,13 @@
4954 fs = FileSystemView.getFileSystemView();
5055 ff = new FileFilter() {
5156
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+ }
5661
57- };
62+ };
63+
5864 al = new ActionListener() {
5965
6066 @Override
@@ -63,6 +69,33 @@
6369 }
6470
6571 };
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+
6699 mol = new MouseListener() {
67100
68101 @Override
@@ -74,16 +107,16 @@
74107 }
75108
76109 @Override
77- public void mousePressed(MouseEvent e) { /* ignore */ }
110+ public void mousePressed(MouseEvent e) { /* do nothing */ }
78111
79112 @Override
80- public void mouseReleased(MouseEvent e) { /* ignore */ }
113+ public void mouseReleased(MouseEvent e) { /* do nothing */ }
81114
82115 @Override
83- public void mouseEntered(MouseEvent e) { /* ignore */ }
116+ public void mouseEntered(MouseEvent e) { /* do nothing */ }
84117
85118 @Override
86- public void mouseExited(MouseEvent e) { /* ignore */ }
119+ public void mouseExited(MouseEvent e) { /* do nothing */ }
87120
88121 };
89122
@@ -110,7 +143,7 @@
110143 }
111144
112145 @Override
113- public void menuCanceled(MenuEvent e) { /* ignore */ }
146+ public void menuCanceled(MenuEvent e) { /* do nothing */ }
114147
115148 };
116149
@@ -174,6 +207,10 @@
174207 public static ActionListener getActionListener() {
175208 return al;
176209 }
210+
211+ public static MenuKeyListener getMenuKeyListener() {
212+ return mkl;
213+ }
177214
178215 public static MouseListener getMouseListener() {
179216 return mol;
@@ -236,34 +273,34 @@
236273 }
237274
238275 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);
246277 }
247278
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);
254281 }
255282
256283 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+
261292 m.addMenuListener(getMenuListener());
262293 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+
264301 return m;
265302 }
266-
303+
267304 private static void prepare(File folder, JMenu menu, File[] filteredListFiles) throws IOException {
268305 if (menu.getItemCount() > 0) {
269306 // submenus are already created
@@ -289,9 +326,10 @@
289326 }
290327
291328 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;
297335 }