mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-26 20:54:22 +01:00
Refactor boardMenu creation
This commit is part of https://github.com/arduino/Arduino/pull/7120 by @sandeepmistry
This commit is contained in:
parent
a1e43ce490
commit
d0b74b0263
@ -116,6 +116,8 @@ public class Base {
|
||||
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
|
||||
Editor activeEditor;
|
||||
|
||||
private static JMenu boardMenu;
|
||||
|
||||
// these menus are shared so that the board and serial port selections
|
||||
// are the same for all windows (since the board and serial port that are
|
||||
// actually used are determined by the preferences, which are shared)
|
||||
@ -1342,6 +1344,29 @@ public class Base {
|
||||
private static String priorPlatformFolder;
|
||||
private static boolean newLibraryImported;
|
||||
|
||||
public void selectTargetBoard(TargetBoard targetBoard) {
|
||||
for (int i = 0; i < boardMenu.getItemCount(); i++) {
|
||||
JMenuItem menuItem = boardMenu.getItem(i);
|
||||
if (!(menuItem instanceof JRadioButtonMenuItem)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem) menuItem);
|
||||
if (targetBoard.getName().equals(radioButtonMenuItem.getText())) {
|
||||
radioButtonMenuItem.setSelected(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
BaseNoGui.selectBoard(targetBoard);
|
||||
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, targetBoard, 1);
|
||||
|
||||
onBoardOrPortChange();
|
||||
rebuildImportMenu(Editor.importMenu);
|
||||
rebuildExamplesMenu(Editor.examplesMenu);
|
||||
rebuildProgrammerMenu();
|
||||
}
|
||||
|
||||
public void onBoardOrPortChange() {
|
||||
BaseNoGui.onBoardOrPortChange();
|
||||
|
||||
@ -1435,7 +1460,7 @@ public class Base {
|
||||
boardsCustomMenus = new LinkedList<>();
|
||||
|
||||
// The first custom menu is the "Board" selection submenu
|
||||
JMenu boardMenu = new JMenu(tr("Board"));
|
||||
boardMenu = new JMenu(tr("Board"));
|
||||
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
|
||||
MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);
|
||||
|
||||
@ -1568,13 +1593,7 @@ public class Base {
|
||||
@SuppressWarnings("serial")
|
||||
Action action = new AbstractAction(board.getName()) {
|
||||
public void actionPerformed(ActionEvent actionevent) {
|
||||
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
|
||||
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
|
||||
|
||||
onBoardOrPortChange();
|
||||
rebuildImportMenu(Editor.importMenu);
|
||||
rebuildExamplesMenu(Editor.examplesMenu);
|
||||
rebuildProgrammerMenu();
|
||||
selectTargetBoard((TargetBoard) getValue("b"));
|
||||
}
|
||||
};
|
||||
action.putValue("b", board);
|
||||
|
Loading…
x
Reference in New Issue
Block a user