| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -881,13 +881,8 @@ protected JMenu buildEditMenu() { | |||
| 881 | 881 | undoItem = Toolkit.newJMenuItem(undoAction = new UndoAction(), 'Z'); | |
| 882 | 882 | menu.add(undoItem); | |
| 883 | 883 | ||
| 884 | - // Gotta follow them interface guidelines | ||
| 885 | - // http://code.google.com/p/processing/issues/detail?id=363 | ||
| 886 | - if (Platform.isWindows()) { | ||
| 887 | - redoItem = Toolkit.newJMenuItem(redoAction = new RedoAction(), 'Y'); | ||
| 888 | - } else { // Linux and OS X | ||
| 889 | - redoItem = Toolkit.newJMenuItemShift(redoAction = new RedoAction(), 'Z'); | ||
| 890 | - } | ||
| 884 | + redoItem = new JMenuItem(redoAction = new RedoAction()); | ||
| 885 | + redoItem.setAccelerator(Toolkit.getKeyStrokeExt("menu.edit.redo")); | ||
| 891 | 886 | menu.add(redoItem); | |
| 892 | 887 | ||
| 893 | 888 | menu.addSeparator(); | |
@@ -956,27 +951,23 @@ public void actionPerformed(ActionEvent e) { | |||
| 956 | 951 | }); | |
| 957 | 952 | menu.add(item); | |
| 958 | 953 | ||
| 959 | - item = Toolkit.newJMenuItem(Language.text("menu.edit.comment_uncomment"), | ||
| 960 | - Language.text("menu.edit.comment_uncomment.keystroke")); | ||
| 954 | + item = Toolkit.newJMenuItemExt("menu.edit.comment_uncomment"); | ||
| 961 | 955 | item.addActionListener(new ActionListener() { | |
| 962 | 956 | public void actionPerformed(ActionEvent e) { | |
| 963 | 957 | handleCommentUncomment(); | |
| 964 | 958 | } | |
| 965 | 959 | }); | |
| 966 | 960 | menu.add(item); | |
| 967 | 961 | ||
| 968 | - item = Toolkit.newJMenuItem("\u2192 " + Language.text("menu.edit.increase_indent"), | ||
| 969 | - Language.text("menu.edit.increase_indent.keystroke")); | ||
| 970 | - | ||
| 962 | + item = Toolkit.newJMenuItemExt("menu.edit.increase_indent"); | ||
| 971 | 963 | item.addActionListener(new ActionListener() { | |
| 972 | 964 | public void actionPerformed(ActionEvent e) { | |
| 973 | 965 | handleIndentOutdent(true); | |
| 974 | 966 | } | |
| 975 | 967 | }); | |
| 976 | 968 | menu.add(item); | |
| 977 | 969 | ||
| 978 | - item = Toolkit.newJMenuItem("\u2190 " + Language.text("menu.edit.decrease_indent"), | ||
| 979 | - Language.text("menu.edit.decrease_indent.keystroke")); | ||
| 970 | + item = Toolkit.newJMenuItemExt("menu.edit.decrease_indent"); | ||
| 980 | 971 | item.addActionListener(new ActionListener() { | |
| 981 | 972 | public void actionPerformed(ActionEvent e) { | |
| 982 | 973 | handleIndentOutdent(false); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -494,51 +494,29 @@ public void actionPerformed(ActionEvent e) { | |||
| 494 | 494 | ||
| 495 | 495 | // KeyEvent.VK_LEFT and VK_RIGHT will make Windows beep | |
| 496 | 496 | ||
| 497 | - final String prevTab = Language.text("editor.header.previous_tab"); | ||
| 498 | - if (Platform.isLinux()) { | ||
| 499 | - item = Toolkit.newJMenuItem(prevTab, KeyEvent.VK_PAGE_UP); | ||
| 500 | - } else { | ||
| 501 | - //item = Toolkit.newJMenuItemAlt(prevTab, KeyEvent.VK_LEFT); | ||
| 502 | - item = Toolkit.newJMenuItem(prevTab, Language.text("editor.header.previous_tab.keystroke")); | ||
| 503 | - } | ||
| 497 | + mapKey = "editor.header.previous_tab"; | ||
| 498 | + item = Toolkit.newJMenuItemExt(mapKey); | ||
| 504 | 499 | action = new AbstractAction() { | |
| 505 | 500 | @Override | |
| 506 | 501 | public void actionPerformed(ActionEvent e) { | |
| 507 | 502 | editor.getSketch().handlePrevCode(); | |
| 508 | 503 | } | |
| 509 | 504 | }; | |
| 510 | - mapKey = "editor.header.previous_tab"; | ||
| 511 | - if (Platform.isLinux()) { | ||
| 512 | - keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, Toolkit.SHORTCUT_KEY_MASK); | ||
| 513 | - } else { | ||
| 514 | - //keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, Toolkit.SHORTCUT_ALT_KEY_MASK); | ||
| 515 | - keyStroke = KeyStroke.getKeyStroke(Language.text("editor.header.previous_tab.keystroke")); | ||
| 516 | - } | ||
| 505 | + keyStroke = item.getAccelerator(); | ||
| 517 | 506 | inputMap.put(keyStroke, mapKey); | |
| 518 | 507 | actionMap.put(mapKey, action); | |
| 519 | 508 | item.addActionListener(action); | |
| 520 | 509 | menu.add(item); | |
| 521 | 510 | ||
| 522 | - final String nextTab = Language.text("editor.header.next_tab"); | ||
| 523 | - if (Platform.isLinux()) { | ||
| 524 | - item = Toolkit.newJMenuItem(nextTab, KeyEvent.VK_PAGE_DOWN); | ||
| 525 | - } else { | ||
| 526 | - //item = Toolkit.newJMenuItemAlt(nextTab, KeyEvent.VK_RIGHT); | ||
| 527 | - item = Toolkit.newJMenuItem(nextTab, Language.text("editor.header.next_tab.keystroke")); | ||
| 528 | - } | ||
| 511 | + mapKey = "editor.header.next_tab"; | ||
| 512 | + item = Toolkit.newJMenuItemExt(mapKey); | ||
| 529 | 513 | action = new AbstractAction() { | |
| 530 | 514 | @Override | |
| 531 | 515 | public void actionPerformed(ActionEvent e) { | |
| 532 | 516 | editor.getSketch().handleNextCode(); | |
| 533 | 517 | } | |
| 534 | 518 | }; | |
| 535 | - mapKey = "editor.header.next_tab"; | ||
| 536 | - if (Platform.isLinux()) { | ||
| 537 | - keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, Toolkit.SHORTCUT_KEY_MASK); | ||
| 538 | - } else { | ||
| 539 | - //keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, Toolkit.SHORTCUT_ALT_KEY_MASK); | ||
| 540 | - keyStroke = KeyStroke.getKeyStroke(Language.text("editor.header.next_tab.keystroke")); | ||
| 541 | - } | ||
| 519 | + keyStroke = item.getAccelerator(); | ||
| 542 | 520 | inputMap.put(keyStroke, mapKey); | |
| 543 | 521 | actionMap.put(mapKey, action); | |
| 544 | 522 | item.addActionListener(action); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,6 +103,8 @@ public class Toolkit { | |||
| 103 | 103 | static public final KeyStroke WINDOW_CLOSE_KEYSTROKE = | |
| 104 | 104 | KeyStroke.getKeyStroke('W', SHORTCUT_KEY_MASK); | |
| 105 | 105 | ||
| 106 | + static final String BAD_KEYSTROKE = | ||
| 107 | + "'%s' is not understood, please re-read the Java reference for KeyStroke"; | ||
| 106 | 108 | ||
| 107 | 109 | /** | |
| 108 | 110 | * Standardized width for buttons. Mac OS X 10.3 wants 70 as its default, | |
@@ -118,16 +120,36 @@ static public int getButtonWidth() { | |||
| 118 | 120 | ||
| 119 | 121 | ||
| 120 | 122 | /** | |
| 121 | - * A software engineer, somewhere, needs to have their abstraction | ||
| 122 | - * taken away. Who crafts the sort of API that would require a | ||
| 123 | - * five-line helper function just to set the shortcut key for a | ||
| 124 | - * menu item? | ||
| 123 | + * Return the correct KeyStroke per locale and platform. | ||
| 124 | + * Also checks for any additional overrides in preferences.txt. | ||
| 125 | + * @param base the localization key for the menu item | ||
| 126 | + * (.keystroke and .platform will be added to the end) | ||
| 127 | + * @return KeyStroke for base + .keystroke + .platform | ||
| 128 | + * (or the value from preferences) or null if none found | ||
| 125 | 129 | */ | |
| 126 | - static public JMenuItem newJMenuItem(String title, int what) { | ||
| 127 | - JMenuItem menuItem = new JMenuItem(title); | ||
| 128 | - int modifiers = awtToolkit.getMenuShortcutKeyMask(); | ||
| 129 | - menuItem.setAccelerator(KeyStroke.getKeyStroke(what, modifiers)); | ||
| 130 | - return menuItem; | ||
| 130 | + static public KeyStroke getKeyStrokeExt(String base) { | ||
| 131 | + String key = base + ".keystroke"; | ||
| 132 | + | ||
| 133 | + // see if there's an override in preferences.txt | ||
| 134 | + String sequence = Preferences.get(key); | ||
| 135 | + if (sequence != null) { | ||
| 136 | + KeyStroke ks = KeyStroke.getKeyStroke(sequence); | ||
| 137 | + if (ks != null) { | ||
| 138 | + return ks; // user did good, we're all set | ||
| 139 | + | ||
| 140 | + } else { | ||
| 141 | + System.err.format(BAD_KEYSTROKE, sequence); | ||
| 142 | + } | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + sequence = Language.text(key + "." + Platform.getName()); | ||
| 146 | + KeyStroke ks = KeyStroke.getKeyStroke(sequence); | ||
| 147 | + if (ks == null) { | ||
| 148 | + // this can only happen if user has screwed up their language files | ||
| 149 | + System.err.format(BAD_KEYSTROKE, sequence); | ||
| 150 | + //return KeyStroke.getKeyStroke(0, 0); // badness | ||
| 151 | + } | ||
| 152 | + return ks; | ||
| 131 | 153 | } | |
| 132 | 154 | ||
| 133 | 155 | ||
@@ -138,22 +160,30 @@ static public JMenuItem newJMenuItem(String title, int what) { | |||
| 138 | 160 | * @param sequence the name, as outlined by the KeyStroke API | |
| 139 | 161 | * @param fallback what to use if getKeyStroke() comes back null | |
| 140 | 162 | */ | |
| 141 | - static public JMenuItem newJMenuItem(String title, | ||
| 142 | - String sequence) { | ||
| 143 | - JMenuItem menuItem = new JMenuItem(title); | ||
| 144 | - KeyStroke ks = KeyStroke.getKeyStroke(sequence); | ||
| 163 | + static public JMenuItem newJMenuItemExt(String base) { | ||
| 164 | + JMenuItem menuItem = new JMenuItem(Language.text(base)); | ||
| 165 | + KeyStroke ks = getKeyStrokeExt(base); // will print error if necessary | ||
| 145 | 166 | if (ks != null) { | |
| 146 | 167 | menuItem.setAccelerator(ks); | |
| 147 | - | ||
| 148 | - } else { | ||
| 149 | - System.err.println("'" + sequence + "' is not understood, " + | ||
| 150 | - "pleae re-read the Java reference for KeyStroke"); | ||
| 151 | - //ks = KeyStroke.getKeyStroke(fallback); | ||
| 152 | 168 | } | |
| 153 | 169 | return menuItem; | |
| 154 | 170 | } | |
| 155 | 171 | ||
| 156 | 172 | ||
| 173 | + /** | ||
| 174 | + * A software engineer, somewhere, needs to have their abstraction | ||
| 175 | + * taken away. Who crafts the sort of API that would require a | ||
| 176 | + * five-line helper function just to set the shortcut key for a | ||
| 177 | + * menu item? | ||
| 178 | + */ | ||
| 179 | + static public JMenuItem newJMenuItem(String title, int what) { | ||
| 180 | + JMenuItem menuItem = new JMenuItem(title); | ||
| 181 | + int modifiers = awtToolkit.getMenuShortcutKeyMask(); | ||
| 182 | + menuItem.setAccelerator(KeyStroke.getKeyStroke(what, modifiers)); | ||
| 183 | + return menuItem; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + | ||
| 157 | 187 | /** | |
| 158 | 188 | * @param action: use an Action, which sets the title, reaction | |
| 159 | 189 | * and enabled-ness all by itself. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,6 +31,9 @@ menu.file.quit = Quit | |||
| 31 | 31 | menu.edit = Edit | |
| 32 | 32 | menu.edit.undo = Undo | |
| 33 | 33 | menu.edit.redo = Redo | |
| 34 | + menu.edit.redo.keystroke.macosx = shift meta pressed Z | ||
| 35 | + menu.edit.redo.keystroke.windows = meta pressed Y | ||
| 36 | + menu.edit.redo.keystroke.linux = shift ctrl pressed Z | ||
| 34 | 37 | menu.edit.action.addition = addition | |
| 35 | 38 | menu.edit.action.deletion = deletion | |
| 36 | 39 | menu.edit.cut = Cut | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1384,8 +1384,7 @@ public void actionPerformed(ActionEvent e) { | |||
| 1384 | 1384 | // }); | |
| 1385 | 1385 | // debugMenu.add(item); | |
| 1386 | 1386 | ||
| 1387 | - item = Toolkit.newJMenuItem(Language.text("menu.debug.step"), | ||
| 1388 | - Language.text("menu.debug.step.keystroke")); | ||
| 1387 | + item = Toolkit.newJMenuItemExt("menu.debug.step"); | ||
| 1389 | 1388 | item.addActionListener(new ActionListener() { | |
| 1390 | 1389 | public void actionPerformed(ActionEvent e) { | |
| 1391 | 1390 | handleStep(0); | |
@@ -1394,8 +1393,7 @@ public void actionPerformed(ActionEvent e) { | |||
| 1394 | 1393 | debugMenu.add(item); | |
| 1395 | 1394 | item.setEnabled(false); | |
| 1396 | 1395 | ||
| 1397 | - item = Toolkit.newJMenuItem(Language.text("menu.debug.step_into"), | ||
| 1398 | - Language.text("menu.debug.step_into.keystroke")); | ||
| 1396 | + item = Toolkit.newJMenuItemExt("menu.debug.step_into"); | ||
| 1399 | 1397 | item.addActionListener(new ActionListener() { | |
| 1400 | 1398 | public void actionPerformed(ActionEvent e) { | |
| 1401 | 1399 | handleStep(ActionEvent.SHIFT_MASK); | |
@@ -1404,8 +1402,7 @@ public void actionPerformed(ActionEvent e) { | |||
| 1404 | 1402 | debugMenu.add(item); | |
| 1405 | 1403 | item.setEnabled(false); | |
| 1406 | 1404 | ||
| 1407 | - item = Toolkit.newJMenuItem(Language.text("menu.debug.step_out"), | ||
| 1408 | - Language.text("menu.debug.step_out.keystroke")); | ||
| 1405 | + item = Toolkit.newJMenuItemExt("menu.debug.step_out"); | ||
| 1409 | 1406 | item.addActionListener(new ActionListener() { | |
| 1410 | 1407 | public void actionPerformed(ActionEvent e) { | |
| 1411 | 1408 | handleStep(ActionEvent.ALT_MASK); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,7 @@ | |||
| 1 | 1 | 0268 (3.5.2) | |
| 2 | 2 | _ shortcuts not working on Windows/Linux (using meta) | |
| 3 | 3 | _ https://github.com/processing/processing/issues/5763 | |
| 4 | + _ update https://github.com/processing/processing/wiki/Localization#shortcuts-and-key-bindings | ||
| 4 | 5 | ||
| 5 | 6 | ||
| 6 | 7 | _ Find in Reference disabled for various keywords (draw, for, if, catch, while) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments