diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index c1f378db0..d42ce7854 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1270,14 +1270,11 @@ public class Base { String title = customMenus.get(menuId); JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title)); - //Map customMenu = customMenus.subTree(menuId).firstLevelMap(); - if (board.hasMenuOptions(menuId)) { - //if (customMenu.containsKey(boardId)) { - //PreferencesMap boardCustomMenu = customMenu.get(boardId); - PreferencesMap boardCustomMenu = board.getMenuOptions(menuId); + if (board.hasMenu(menuId)) { + PreferencesMap boardCustomMenu = board.getMenuLabels(menuId); final int currentIndex = i + 1 + 1; //plus 1 to skip the first board menu, plus 1 to keep the custom menu next to this one i++; - for (String customMenuOption : boardCustomMenu.topLevelKeySet()) { + for (String customMenuOption : boardCustomMenu.keySet()) { @SuppressWarnings("serial") Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) { public void actionPerformed(ActionEvent e) { @@ -1936,22 +1933,18 @@ public class Base { TargetPlatform target = getTargetPlatform(); String boardId = Preferences.get("board"); TargetBoard board = target.getBoard(boardId); - PreferencesMap boardPreferences = new PreferencesMap(board.getPreferences()); - PreferencesMap customMenus = target.getCustomMenus(); - for (String menuId : customMenus.keySet()) { - PreferencesMap boardCustomMenu = board.getMenuOptions(menuId); - String selectedCustomMenuEntry = Preferences.get("custom_" + menuId); - if (boardCustomMenu != null && boardCustomMenu.size() > 0 && - selectedCustomMenuEntry != null && - selectedCustomMenuEntry.startsWith(boardId)) { - String menuEntryId = selectedCustomMenuEntry - .substring(selectedCustomMenuEntry.indexOf("_") + 1); - boardPreferences.putAll(boardCustomMenu.subTree(menuEntryId)); - boardPreferences.put("name", boardPreferences.get("name") + ", " + - boardCustomMenu.get(menuEntryId)); + PreferencesMap prefs = new PreferencesMap(board.getPreferences()); + for (String menuId : target.getCustomMenusKeys()) { + String entry = Preferences.get("custom_" + menuId); + if (board.hasMenu(menuId) && entry != null && + entry.startsWith(boardId)) { + String selectionId = entry.substring(entry.indexOf("_") + 1); + prefs.putAll(board.getMenuConfiguration(menuId, selectionId)); + prefs.put("name", prefs.get("name") + ", " + + board.getMenuLabel(menuId, selectionId)); } } - return boardPreferences; + return prefs; } static public File getPortableFolder() { diff --git a/app/src/processing/app/debug/TargetBoard.java b/app/src/processing/app/debug/TargetBoard.java index 44b0def01..958c1f2d5 100644 --- a/app/src/processing/app/debug/TargetBoard.java +++ b/app/src/processing/app/debug/TargetBoard.java @@ -53,15 +53,52 @@ public class TargetBoard { return prefs; } - public void setMenuOptions(String menuId, PreferencesMap _menuOptions) { - menuOptions.put(menuId, _menuOptions); - } - - public PreferencesMap getMenuOptions(String menuId) { - return menuOptions.get(menuId); - } - - public boolean hasMenuOptions(String menuId) { + /** + * Check if the board has a sub menu. + * + * @param menuId + * The menu ID to check + * @return + */ + public boolean hasMenu(String menuId) { return menuOptions.containsKey(menuId); } + + /** + * Returns the options available on a specific menu + * + * @param menuId + * The menu ID + * @return + */ + public PreferencesMap getMenuLabels(String menuId) { + return menuOptions.get(menuId).topLevelMap(); + } + + /** + * Returns the label of the specified option in the specified menu + * + * @param menuId + * The menu ID + * @param selectionId + * The option ID + * @return + */ + public String getMenuLabel(String menuId, String selectionId) { + return getMenuLabels(menuId).get(selectionId); + } + + /** + * Returns the configuration parameters to override (as a PreferenceMap) when + * the specified option in the specified menu is selected + * + * @param menuId + * The menu ID + * @param selectionId + * The option ID + * @return + */ + public PreferencesMap getMenuConfiguration(String menuId, String selectionId) { + return menuOptions.get(menuId).subTree(selectionId); + } } diff --git a/app/src/processing/app/debug/TargetPlatform.java b/app/src/processing/app/debug/TargetPlatform.java index 2bca7a460..ea72f79fb 100644 --- a/app/src/processing/app/debug/TargetPlatform.java +++ b/app/src/processing/app/debug/TargetPlatform.java @@ -30,6 +30,7 @@ import java.io.File; import java.io.IOException; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import processing.app.helpers.PreferencesMap; @@ -131,6 +132,10 @@ public class TargetPlatform { return customMenus; } + public Set getCustomMenusKeys() { + return customMenus.keySet(); + } + public Map getProgrammers() { return programmers; } diff --git a/app/src/processing/app/helpers/PreferencesMap.java b/app/src/processing/app/helpers/PreferencesMap.java index 23640875e..e4729c166 100644 --- a/app/src/processing/app/helpers/PreferencesMap.java +++ b/app/src/processing/app/helpers/PreferencesMap.java @@ -28,7 +28,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.Collection; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; @@ -155,64 +154,6 @@ public class PreferencesMap extends LinkedHashMap { return res; } - /** - * Returns the values of all the top level pairs of the current mapping. E.g. - * the folowing mapping:
- * - *
-   * Map (
-   *     alpha = Alpha
-   *     alpha.some.keys = v1
-   *     alpha.other.keys = v2
-   *     beta = Beta
-   *     beta.some.keys = v3
-   *   )
-   * 
- * - * will generate the following result: - * - *
-   * Collection (
-   *     Alpha
-   *     Beta
-   *   )
-   * 
- * - * @return - */ - public Collection topLevelValues() { - return topLevelMap().values(); - } - - /** - * Returns a key set of all the top level pairs of the current mapping. E.g. - * the folowing mapping:
- * - *
-   * Map (
-   *     alpha = Alpha
-   *     alpha.some.keys = v1
-   *     alpha.other.keys = v2
-   *     beta = Beta
-   *     beta.some.keys = v3
-   *   )
-   * 
- * - * will generate the following result: - * - *
-   * Set (
-   *     alpha
-   *     beta
-   *   )
-   * 
- * - * @return - */ - public Set topLevelKeySet() { - return topLevelMap().keySet(); - } - /** * Create a new Map where keys are the first level of * the current mapping. Top level pairs are discarded. E.g. the folowing