mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-21 15:54:39 +01:00
Implement "Recently Used Boards" Menu
This commit is contained in:
parent
7a9234c304
commit
b7152b27e1
@ -122,6 +122,13 @@ public class Base {
|
||||
private List<JMenu> boardsCustomMenus;
|
||||
private List<JMenuItem> programmerMenus;
|
||||
|
||||
// these variables help rebuild the "recently used boards"
|
||||
// menu on board selection
|
||||
private HashMap<String, JMenuItem> recentBoardItems;
|
||||
private List<JMenuItem> recentBoardsToClear = new LinkedList<>();;
|
||||
private JMenu boardMenu;
|
||||
private int recentBoardsJMenuIndex;
|
||||
|
||||
private PdeKeywords pdeKeywords;
|
||||
private final List<JMenuItem> recentSketchesMenuItems = new LinkedList<>();
|
||||
|
||||
@ -1360,6 +1367,26 @@ public class Base {
|
||||
}
|
||||
}
|
||||
|
||||
// Update recent boards list in preferences
|
||||
List<String> newRecentBoardIds = new ArrayList<String>();
|
||||
String currentBoard = PreferencesData.get("board");
|
||||
for (String recentBoard : PreferencesData.getCollection("recent.boards")){
|
||||
if (!recentBoard.equals(currentBoard)) {
|
||||
newRecentBoardIds.add(recentBoard);
|
||||
}
|
||||
}
|
||||
newRecentBoardIds.add(0, currentBoard);
|
||||
if (newRecentBoardIds.size() == 6) {
|
||||
newRecentBoardIds.remove(5);
|
||||
}
|
||||
PreferencesData.setCollection("recent.boards", newRecentBoardIds);
|
||||
try {
|
||||
rebuildRecentBoardsList();
|
||||
} catch (Exception e) {
|
||||
//TODO show error
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Update editors status bar
|
||||
for (Editor editor : editors) {
|
||||
editor.onBoardOrPortChange();
|
||||
@ -1433,9 +1460,10 @@ public class Base {
|
||||
|
||||
public void rebuildBoardsMenu() throws Exception {
|
||||
boardsCustomMenus = new LinkedList<>();
|
||||
recentBoardItems = new HashMap<String, JMenuItem>();
|
||||
|
||||
// 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);
|
||||
|
||||
@ -1458,6 +1486,16 @@ public class Base {
|
||||
}));
|
||||
boardsCustomMenus.add(boardMenu);
|
||||
|
||||
// Insert recently used boards menu and remember index for insertion later
|
||||
if (PreferencesData.has("recent.boards")) {
|
||||
// Insert menu label
|
||||
boardMenu.add(new JSeparator());
|
||||
JMenuItem label = new JMenuItem(tr("Recently Used Boards"));
|
||||
label.setEnabled(false);
|
||||
boardMenu.add(label);
|
||||
recentBoardsJMenuIndex = boardMenu.getItemCount();
|
||||
}
|
||||
|
||||
// If there are no platforms installed we are done
|
||||
if (BaseNoGui.packages.size() == 0)
|
||||
return;
|
||||
@ -1555,6 +1593,23 @@ public class Base {
|
||||
return platform.getId() + "_" + platform.getFolder();
|
||||
}
|
||||
|
||||
// clear the previous menu items from the "recently used boards"
|
||||
// menu and repopulate with updated items
|
||||
private void rebuildRecentBoardsList() throws Exception {
|
||||
Collection<String> recentBoardIds = new LinkedList<>();
|
||||
recentBoardIds = PreferencesData.getCollection("recent.boards");
|
||||
int idxAdv = 0;
|
||||
for (JMenuItem itemToClear : recentBoardsToClear) {
|
||||
boardMenu.remove(itemToClear);
|
||||
}
|
||||
recentBoardsToClear.clear();
|
||||
for (String boardId : recentBoardIds) {
|
||||
boardMenu.add(recentBoardItems.get(boardId), recentBoardsJMenuIndex+idxAdv);
|
||||
recentBoardsToClear.add(recentBoardItems.get(boardId));
|
||||
idxAdv++;
|
||||
}
|
||||
}
|
||||
|
||||
private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
|
||||
final List<JMenu> boardsCustomMenus, List<JMenuItem> menuItemsToClickAfterStartup,
|
||||
Map<String, ButtonGroup> buttonGroupsMap,
|
||||
@ -1585,6 +1640,21 @@ public class Base {
|
||||
|
||||
JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
|
||||
|
||||
// create an action for the "recent boards" copy of this menu item
|
||||
// which clicks the original menu item
|
||||
Action actionClone = new AbstractAction(board.getName()) {
|
||||
public void actionPerformed(ActionEvent actionevent) {
|
||||
item.setSelected(true);
|
||||
item.getAction().actionPerformed(new ActionEvent(this, -1, ""));
|
||||
}
|
||||
};
|
||||
|
||||
// create a menu item for the "recent boards" menu
|
||||
JMenuItem itemClone = new JMenuItem(actionClone);
|
||||
|
||||
// populate list of menuitem copies
|
||||
recentBoardItems.put(boardId, itemClone);
|
||||
|
||||
if (selBoard.equals(boardId) && selPackage.equals(packageName)
|
||||
&& selPlatform.equals(platformName)) {
|
||||
menuItemsToClickAfterStartup.add(item);
|
||||
|
Loading…
x
Reference in New Issue
Block a user