diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 7aced028e..9041bc0c5 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -86,6 +86,11 @@ public class Base { List editors = Collections.synchronizedList(new ArrayList()); Editor activeEditor; + // 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) + static List boardsCustomMenus; + static public void main(String args[]) throws Exception { System.setProperty("awt.useSystemAAFontSettings", "on"); System.setProperty("swing.aatext", "true"); @@ -238,7 +243,8 @@ public class Base { splashScreenHelper.splashText(_("Initializing packages...")); BaseNoGui.initPackages(); splashScreenHelper.splashText(_("Preparing boards...")); - + rebuildBoardsMenu(); + // Setup board-dependent variables. onBoardOrPortChange(); @@ -1114,37 +1120,47 @@ public class Base { ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) { @Override protected void onIndexesUpdated() throws Exception { - BaseNoGui.reloadAllHardware(); + BaseNoGui.initPackages(); + rebuildBoardsMenu(); setIndexer(BaseNoGui.indexer); } }; managerUI.setIndexer(BaseNoGui.indexer); managerUI.setVisible(true); + // Installer dialog is modal, waits here until closed + + // Reload all boards (that may have been installed/updated/removed) + try { + BaseNoGui.initPackages(); + rebuildBoardsMenu(); + onBoardOrPortChange(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } - public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception { - JMenu boardsMenu = getBoardCustomMenu(); + public void rebuildBoardsMenu() throws Exception { + boardsCustomMenus = new LinkedList(); + // The first custom menu is the "Board" selection submenu + JMenu boardMenu = new JMenu(_("Board")); + MenuScroller.setScrollerFor(boardMenu); @SuppressWarnings("serial") Action runInstaller = new AbstractAction("Install boards...") { public void actionPerformed(ActionEvent actionevent) { openInstallBoardDialog(); } }; - boardsMenu.add(new JMenuItem(runInstaller)); + boardMenu.add(new JMenuItem(runInstaller)); + boardsCustomMenus.add(boardMenu); - // If there are no platforms installed skip menu creation + // If there are no platforms installed we are done if (BaseNoGui.packages.size() == 0) return; - - boardsMenu.add(new JSeparator()); - boolean first = true; - - List menuItemsToClickAfterStartup = new LinkedList(); - - ButtonGroup boardsButtonGroup = new ButtonGroup(); - Map buttonGroupsMap = new HashMap(); + // Separate "Install boards..." command from installed boards + boardMenu.add(new JSeparator()); // Generate custom menus for all platforms Set titles = new HashSet(); @@ -1152,25 +1168,32 @@ public class Base { for (TargetPlatform targetPlatform : targetPackage.platforms()) titles.addAll(targetPlatform.getCustomMenus().values()); } - for (String title : titles) - makeBoardCustomMenu(toolsMenu, _(title)); - + for (String title : titles) { + boardsCustomMenus.add(new JMenu(_(title))); + } + + List menuItemsToClickAfterStartup = new LinkedList(); + + ButtonGroup boardsButtonGroup = new ButtonGroup(); + Map buttonGroupsMap = new HashMap(); + // Cycle through all packages + boolean first = true; for (TargetPackage targetPackage : BaseNoGui.packages.values()) { // For every package cycle through all platform for (TargetPlatform targetPlatform : targetPackage.platforms()) { // Add a separator from the previous platform if (!first) - boardsMenu.add(new JSeparator()); + boardMenu.add(new JSeparator()); first = false; // Add a title for each platform - String platformLabel = targetPlatform.getPreferences().get("name"); + String platformLabel = targetPlatform.getPreferences().get("name"); if (platformLabel != null && !targetPlatform.getBoards().isEmpty()) { JMenuItem menuLabel = new JMenuItem(_(platformLabel)); menuLabel.setEnabled(false); - boardsMenu.add(menuLabel); + boardMenu.add(menuLabel); } // Cycle through all boards of this platform @@ -1178,14 +1201,14 @@ public class Base { JMenuItem item = createBoardMenusAndCustomMenus(menuItemsToClickAfterStartup, buttonGroupsMap, board, targetPlatform, targetPackage); - boardsMenu.add(item); + boardMenu.add(item); boardsButtonGroup.add(item); } } } if (menuItemsToClickAfterStartup.isEmpty()) { - menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardsMenu)); + menuItemsToClickAfterStartup.add(selectFirstEnabledMenuItem(boardMenu)); } for (JMenuItem menuItemToClick : menuItemsToClickAfterStartup) { @@ -1265,9 +1288,10 @@ public class Base { return item; } - private static void filterVisibilityOfSubsequentBoardMenus(TargetBoard board, int fromIndex) { - for (int i = fromIndex; i < Editor.boardsMenus.size(); i++) { - JMenu menu = Editor.boardsMenus.get(i); + private static void filterVisibilityOfSubsequentBoardMenus(TargetBoard board, + int fromIndex) { + for (int i = fromIndex; i < boardsCustomMenus.size(); i++) { + JMenu menu = boardsCustomMenus.get(i); for (int m = 0; m < menu.getItemCount(); m++) { JMenuItem menuItem = menu.getItem(m); menuItem.setVisible(menuItem.getAction().getValue("board").equals(board)); @@ -1293,19 +1317,8 @@ public class Base { return false; } - private JMenu makeBoardCustomMenu(JMenu toolsMenu, String label) { - JMenu menu = new JMenu(label); - Editor.boardsMenus.add(menu); - toolsMenu.add(menu); - return menu; - } - - private JMenu getBoardCustomMenu() throws Exception { - return getBoardCustomMenu(_("Board")); - } - private JMenu getBoardCustomMenu(String label) throws Exception { - for (JMenu menu : Editor.boardsMenus) + for (JMenu menu : boardsCustomMenus) if (label.equals(menu.getText())) return menu; throw new Exception("Custom menu not found!"); @@ -1760,6 +1773,10 @@ public class Base { return BaseNoGui.getBoardPreferences(); } + public static List getBoardsCustomMenus() { + return boardsCustomMenus; + } + static public File getPortableFolder() { return BaseNoGui.getPortableFolder(); } diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 852ae0bc1..e4de635a5 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -109,10 +109,6 @@ public class Editor extends JFrame implements RunnerListener { static JMenu examplesMenu; static JMenu importMenu; - // 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) - static List boardsMenus; static JMenu serialMenu; static AbstractMonitor serialMonitor; @@ -195,7 +191,7 @@ public class Editor extends JFrame implements RunnerListener { fileMenu.insert(examplesMenu, 3); sketchMenu.insert(importMenu, 4); int offset = 0; - for (JMenu menu : boardsMenus) { + for (JMenu menu : Base.getBoardsCustomMenus()) { toolsMenu.insert(menu, numTools + offset); offset++; } @@ -209,7 +205,7 @@ public class Editor extends JFrame implements RunnerListener { fileMenu.remove(sketchbookMenu); fileMenu.remove(examplesMenu); sketchMenu.remove(importMenu); - for (JMenu menu : boardsMenus) { + for (JMenu menu : Base.getBoardsCustomMenus()) { toolsMenu.remove(menu); } toolsMenu.remove(serialMenu); @@ -684,53 +680,41 @@ public class Editor extends JFrame implements RunnerListener { protected JMenu buildToolsMenu() throws Exception { toolsMenu = new JMenu(_("Tools")); - JMenu menu = toolsMenu; - JMenuItem item; - addInternalTools(menu); + addInternalTools(toolsMenu); - item = newJMenuItemShift(_("Serial Monitor"), 'M'); + JMenuItem item = newJMenuItemShift(_("Serial Monitor"), 'M'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleSerial(); } }); - menu.add(item); + toolsMenu.add(item); - addTools(menu, Base.getToolsFolder()); + addTools(toolsMenu, Base.getToolsFolder()); File sketchbookTools = new File(Base.getSketchbookFolder(), "tools"); - addTools(menu, sketchbookTools); + addTools(toolsMenu, sketchbookTools); - menu.addSeparator(); + toolsMenu.addSeparator(); - numTools = menu.getItemCount(); + numTools = toolsMenu.getItemCount(); // XXX: DAM: these should probably be implemented using the Tools plugin // API, if possible (i.e. if it supports custom actions, etc.) - if (boardsMenus == null) { - boardsMenus = new LinkedList(); - - JMenu boardsMenu = new JMenu(_("Board")); - MenuScroller.setScrollerFor(boardsMenu); - Editor.boardsMenus.add(boardsMenu); - toolsMenu.add(boardsMenu); - - base.rebuildBoardsMenu(toolsMenu, this); - //Debug: rebuild imports - importMenu.removeAll(); - base.rebuildImportMenu(importMenu); + for (JMenu menu : Base.getBoardsCustomMenus()) { + toolsMenu.add(menu); } if (serialMenu == null) serialMenu = new JMenu(_("Port")); populatePortMenu(); - menu.add(serialMenu); - menu.addSeparator(); + toolsMenu.add(serialMenu); + toolsMenu.addSeparator(); JMenu programmerMenu = new JMenu(_("Programmer")); base.rebuildProgrammerMenu(programmerMenu); - menu.add(programmerMenu); + toolsMenu.add(programmerMenu); item = new JMenuItem(_("Burn Bootloader")); item.addActionListener(new ActionListener() { @@ -738,9 +722,9 @@ public class Editor extends JFrame implements RunnerListener { handleBurnBootloader(); } }); - menu.add(item); + toolsMenu.add(item); - menu.addMenuListener(new MenuListener() { + toolsMenu.addMenuListener(new MenuListener() { public void menuCanceled(MenuEvent e) {} public void menuDeselected(MenuEvent e) {} public void menuSelected(MenuEvent e) { @@ -749,7 +733,7 @@ public class Editor extends JFrame implements RunnerListener { } }); - return menu; + return toolsMenu; } diff --git a/arduino-core/src/processing/app/BaseNoGui.java b/arduino-core/src/processing/app/BaseNoGui.java index 41cfc815e..06f892746 100644 --- a/arduino-core/src/processing/app/BaseNoGui.java +++ b/arduino-core/src/processing/app/BaseNoGui.java @@ -587,10 +587,6 @@ public class BaseNoGui { } static public void initPackages() throws Exception { - reloadAllHardware(); - } - - static public void reloadAllHardware() throws Exception { indexer = new ContributionsIndexer(BaseNoGui.getSettingsFolder()); File indexFile = indexer.getIndexFile(); if (!indexFile.isFile()) {