Skip to content

Commit 0096b38

Browse files
committed
Refactor boardMenu creation
This commit is part of #7120 by @sandeepmistry
1 parent 0e45f4e commit 0096b38

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
@@ -117,6 +117,8 @@ public class Base {
117117
List<Editor> editors = Collections.synchronizedList(new ArrayList<Editor>());
118118
Editor activeEditor;
119119

120+
private static JMenu boardMenu;
121+
120122
// these menus are shared so that the board and serial port selections
121123
// are the same for all windows (since the board and serial port that are
122124
// actually used are determined by the preferences, which are shared)
@@ -1313,6 +1315,28 @@ public void rebuildExamplesMenu(JMenu menu) {
13131315
private static String priorPlatformFolder;
13141316
private static boolean newLibraryImported;
13151317

1318+
public void selectTargetBoard(TargetBoard targetBoard) {
1319+
for (int i = 0; i < boardMenu.getItemCount(); i++) {
1320+
JMenuItem menuItem = boardMenu.getItem(i);
1321+
if (!(menuItem instanceof JRadioButtonMenuItem)) {
1322+
continue;
1323+
}
1324+
1325+
JRadioButtonMenuItem radioButtonMenuItem = ((JRadioButtonMenuItem) menuItem);
1326+
if (targetBoard.getName().equals(radioButtonMenuItem.getText())) {
1327+
radioButtonMenuItem.setSelected(true);
1328+
break;
1329+
}
1330+
}
1331+
1332+
BaseNoGui.selectBoard(targetBoard);
1333+
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, targetBoard, 1);
1334+
1335+
onBoardOrPortChange();
1336+
rebuildImportMenu(Editor.importMenu);
1337+
rebuildExamplesMenu(Editor.examplesMenu);
1338+
}
1339+
13161340
public void onBoardOrPortChange() {
13171341
BaseNoGui.onBoardOrPortChange();
13181342

@@ -1406,7 +1430,7 @@ public void rebuildBoardsMenu() throws Exception {
14061430
boardsCustomMenus = new LinkedList<>();
14071431

14081432
// The first custom menu is the "Board" selection submenu
1409-
JMenu boardMenu = new JMenu(tr("Board"));
1433+
boardMenu = new JMenu(tr("Board"));
14101434
boardMenu.putClientProperty("removeOnWindowDeactivation", true);
14111435
MenuScroller.setScrollerFor(boardMenu).setTopFixedCount(1);
14121436

@@ -1512,12 +1536,7 @@ private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
15121536
@SuppressWarnings("serial")
15131537
Action action = new AbstractAction(board.getName()) {
15141538
public void actionPerformed(ActionEvent actionevent) {
1515-
BaseNoGui.selectBoard((TargetBoard) getValue("b"));
1516-
filterVisibilityOfSubsequentBoardMenus(boardsCustomMenus, (TargetBoard) getValue("b"), 1);
1517-
1518-
onBoardOrPortChange();
1519-
rebuildImportMenu(Editor.importMenu);
1520-
rebuildExamplesMenu(Editor.examplesMenu);
1539+
selectTargetBoard((TargetBoard) getValue("b"));
15211540
}
15221541
};
15231542
action.putValue("b", board);

0 commit comments

Comments
 (0)