Skip to content

Commit f481268

Browse files
committed
Refactor boardMenu creation
This commit is part of #7120 by @sandeepmistry
1 parent 4bbd63a commit f481268

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

Diff for: app/src/processing/app/Base.java

+26-7
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public class Base {
116116
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
117117
Editor activeEditor;
118118

119+
private static JMenu boardMenu;
120+
119121
// these menus are shared so that the board and serial port selections
120122
// are the same for all windows (since the board and serial port that are
121123
// actually used are determined by the preferences, which are shared)
@@ -1332,6 +1334,28 @@ public void rebuildExamplesMenu(JMenu menu) {
13321334
private static String priorPlatformFolder;
13331335
private static boolean newLibraryImported;
13341336

1337+
public void selectTargetBoard(TargetBoard targetBoard) {
1338+
for (int i = 0; i < boardMenu.getItemCount(); i++) {
1339+
JMenuItem menuItem = boardMenu.getItem(i);
1340+
if (!(menuItem instanceof JRadioButtonMenuItem)) {
1341+
continue;
1342+
}
1343+
1344+
JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem) menuItem);
1345+
if (targetBoard.getName().equals(radioButtonMenuItem.getText())) {
1346+
radioButtonMenuItem.setSelected(true);
1347+
break;
1348+
}
1349+
}
1350+
1351+
BaseNoGui.selectBoard(targetBoard);
1352+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, targetBoard, 1);
1353+
1354+
onBoardOrPortChange();
1355+
rebuildImportMenu(Editor.importMenu);
1356+
rebuildExamplesMenu(Editor.examplesMenu);
1357+
}
1358+
13351359
public void onBoardOrPortChange() {
13361360
BaseNoGui.onBoardOrPortChange();
13371361

@@ -1425,7 +1449,7 @@ public void rebuildBoardsMenu() throws Exception {
14251449
boardsCustomMenus = new LinkedList<>();
14261450

14271451
// The first custom menu is the "Board" selection submenu
1428-
JMenu boardMenu = new JMenu(tr("Board"));
1452+
boardMenu = new JMenu(tr("Board"));
14291453
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
14301454
MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);
14311455

@@ -1534,12 +1558,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15341558
@SuppressWarnings("serial")
15351559
Action action = new AbstractAction(board.getName()) {
15361560
public void actionPerformed(ActionEvent actionevent) {
1537-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1538-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
1539-
1540-
onBoardOrPortChange();
1541-
rebuildImportMenu(Editor.importMenu);
1542-
rebuildExamplesMenu(Editor.examplesMenu);
1561+
selectTargetBoard((TargetBoard) getValue("b"));
15431562
}
15441563
};
15451564
action.putValue("b", board);

0 commit comments

Comments
 (0)