Skip to content

Commit a3ba935

Browse files
Slightly simplify EditorHeader tab selection menu items
Previously, this would use a single ActionListener object, and pass the filename of the file to switch to in the action command. This means that whenever switching the filename needs to be looked up. This commit instead uses a lambda to capture the index of the tab to switch to for every tab (so it uses a different ActionListener for each tab).
1 parent 2f5375d commit a3ba935

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

app/src/processing/app/EditorHeader.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,14 @@ public void rebuildMenu() {
292292
Sketch sketch = editor.getSketch();
293293
if (sketch != null) {
294294
menu.addSeparator();
295-
296-
ActionListener jumpListener = new ActionListener() {
297-
public void actionPerformed(ActionEvent e) {
298-
editor.getSketch().setCurrentCode(e.getActionCommand());
299-
}
300-
};
295+
int i = 0;
301296
for (SketchCode code : sketch.getCodes()) {
297+
final int index = i++;
302298
item = new JMenuItem(code.isExtension(sketch.getDefaultExtension()) ?
303299
code.getPrettyName() : code.getFileName());
304-
item.setActionCommand(code.getFileName());
305-
item.addActionListener(jumpListener);
300+
item.addActionListener((ActionEvent e) -> {
301+
editor.getSketch().setCurrentCode(index);
302+
});
306303
menu.add(item);
307304
}
308305
}

0 commit comments

Comments
 (0)