Skip to content

Commit 8d55fc8

Browse files
committed
oh my god did this really take two hours?
1 parent 925fcd2 commit 8d55fc8

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

app/src/processing/app/ui/Editor.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ public abstract class Editor extends JFrame implements RunnerListener {
131131
/** Menu Actions updated on the opening of the edit menu. */
132132
protected List<UpdatableAction> editMenuUpdatable = new ArrayList<>();
133133

134+
protected FindNextAction findNextAction;
135+
protected FindPreviousAction findPreviousAction;
136+
134137
/** The currently selected tab's undo manager and caret positions*/
135138
private UndoManager undo;
136139
// maintain caret position during undo operations
@@ -788,15 +791,15 @@ protected JMenu buildEditMenu() {
788791
});
789792
menu.add(item);
790793

791-
UpdatableAction action;
792-
item = Toolkit.newJMenuItem(action = new FindNextAction(), 'G');
793-
editMenuUpdatable.add(action);
794+
item = Toolkit.newJMenuItem(findNextAction = new FindNextAction(), 'G');
795+
editMenuUpdatable.add(findNextAction);
794796
menu.add(item);
795797

796-
item = Toolkit.newJMenuItemShift(action = new FindPreviousAction(), 'G');
797-
editMenuUpdatable.add(action);
798+
item = Toolkit.newJMenuItemShift(findPreviousAction = new FindPreviousAction(), 'G');
799+
editMenuUpdatable.add(findPreviousAction);
798800
menu.add(item);
799801

802+
UpdatableAction action;
800803
item = Toolkit.newJMenuItem(action = new SelectionForFindAction(), 'E');
801804
editMenuUpdatable.add(action);
802805
menu.add(item);

app/src/processing/app/ui/FindReplace.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ public FindReplace(Editor editor) {
179179
replaceButton.addActionListener(e -> replace());
180180
replaceAllButton.addActionListener(e -> replaceAll());
181181
replaceAndFindButton.addActionListener(e -> replaceAndFindNext());
182-
findButton.addActionListener(e -> findNext());
183-
previousButton.addActionListener(e -> findPrevious());
182+
183+
// findButton.addActionListener(e -> findNext());
184+
// previousButton.addActionListener(e -> findPrevious());
185+
Toolkit.applyAction(editor.findNextAction, findButton);
186+
Toolkit.applyAction(editor.findPreviousAction, previousButton);
184187

185188
getRootPane().setDefaultButton(findButton);
186189

app/src/processing/app/ui/Toolkit.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
import javax.swing.Action;
5858
import javax.swing.ImageIcon;
59+
import javax.swing.JButton;
5960
import javax.swing.JCheckBoxMenuItem;
6061
import javax.swing.JComponent;
6162
import javax.swing.JMenu;
@@ -188,7 +189,10 @@ static public JMenuItem newJMenuItem(String title, int what) {
188189
*/
189190
static public JMenuItem newJMenuItem(Action action, int what) {
190191
JMenuItem menuItem = new JMenuItem(action);
191-
menuItem.setAccelerator(KeyStroke.getKeyStroke(what, SHORTCUT_KEY_MASK));
192+
// Use putValue() instead of setAccelerator() to work with applyAction()
193+
// menuItem.setAccelerator(KeyStroke.getKeyStroke(what, SHORTCUT_KEY_MASK));
194+
action.putValue(Action.ACCELERATOR_KEY,
195+
KeyStroke.getKeyStroke(what, SHORTCUT_KEY_MASK));
192196
return menuItem;
193197
}
194198

@@ -208,7 +212,10 @@ static public JMenuItem newJMenuItemShift(String title, int what) {
208212
*/
209213
static public JMenuItem newJMenuItemShift(Action action, int what) {
210214
JMenuItem menuItem = new JMenuItem(action);
211-
menuItem.setAccelerator(KeyStroke.getKeyStroke(what, SHORTCUT_SHIFT_KEY_MASK));
215+
// Use putValue() instead of setAccelerator() to work with applyAction()
216+
// menuItem.setAccelerator(KeyStroke.getKeyStroke(what, SHORTCUT_SHIFT_KEY_MASK));
217+
action.putValue(Action.ACCELERATOR_KEY,
218+
KeyStroke.getKeyStroke(what, SHORTCUT_SHIFT_KEY_MASK));
212219
return menuItem;
213220
}
214221

@@ -514,6 +521,21 @@ static public int getMenuItemIndex(JMenu menu, JMenuItem item) {
514521
}
515522

516523

524+
/**
525+
* Apply an Action from something else (i.e. a JMenuItem) to a JButton.
526+
* Swing is so absof*ckinglutely convoluted sometimes. Do we really need
527+
* half a dozen lines of boilerplate to apply a key shortcut to a button?
528+
*/
529+
static public void applyAction(Action action, JButton button) {
530+
button.setAction(action);
531+
// use an arbitrary but unique name
532+
String name = String.valueOf(action.hashCode());
533+
button.getActionMap().put(name, action);
534+
button.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
535+
.put((KeyStroke) action.getValue(Action.ACCELERATOR_KEY), name);
536+
}
537+
538+
517539
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
518540

519541

todo.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ X Help Menu disabled on OS X (looks like a JVM bug)
33
X https://github.com/processing/processing/issues/4353#issuecomment-237715947
44
X https://github.com/processing/processing4/issues/617
55
X https://github.com/processing/processing4/issues/638
6+
X make ctrl-g (and ctrl-shift-g) work inside the Find window
67

78
contributed
89
X “Cannot find a class or type named ‘PApplet’” error
@@ -114,8 +115,6 @@ o seems to be out of sync/unavailable data based on more recent contrib change
114115
X should be resolved with more recent changes
115116

116117

117-
_ make ctrl-g work inside the find window
118-
119118
_ export to IntelliJ? how tricky?
120119
_ just copy jars to /lib?
121120
_ point to binaries in /Applications/Processing.app? (no)

0 commit comments

Comments
 (0)