mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
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).
This commit is contained in:
parent
2f5375d523
commit
a3ba935a57
@ -292,17 +292,14 @@ public class EditorHeader extends JComponent {
|
|||||||
Sketch sketch = editor.getSketch();
|
Sketch sketch = editor.getSketch();
|
||||||
if (sketch != null) {
|
if (sketch != null) {
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
int i = 0;
|
||||||
ActionListener jumpListener = new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
editor.getSketch().setCurrentCode(e.getActionCommand());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
for (SketchCode code : sketch.getCodes()) {
|
for (SketchCode code : sketch.getCodes()) {
|
||||||
|
final int index = i++;
|
||||||
item = new JMenuItem(code.isExtension(sketch.getDefaultExtension()) ?
|
item = new JMenuItem(code.isExtension(sketch.getDefaultExtension()) ?
|
||||||
code.getPrettyName() : code.getFileName());
|
code.getPrettyName() : code.getFileName());
|
||||||
item.setActionCommand(code.getFileName());
|
item.addActionListener((ActionEvent e) -> {
|
||||||
item.addActionListener(jumpListener);
|
editor.getSketch().setCurrentCode(index);
|
||||||
|
});
|
||||||
menu.add(item);
|
menu.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user