mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-18 07:52:14 +01:00
Refactored board specific options into TargetBoard
This commit is contained in:
parent
3c01c5ff77
commit
eed4a43b54
@ -1228,7 +1228,6 @@ public class Base {
|
||||
// For every package cycle through all platform
|
||||
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
||||
String platformName = targetPlatform.getName();
|
||||
PreferencesMap customMenus = targetPlatform.getCustomMenus();
|
||||
|
||||
if (targetPlatform.getPreferences().get("name") == null || targetPlatform.getBoards().isEmpty()) {
|
||||
continue;
|
||||
@ -1265,14 +1264,17 @@ public class Base {
|
||||
menuItemsToClickAfterStartup.add(item);
|
||||
}
|
||||
|
||||
PreferencesMap customMenus = targetPlatform.getCustomMenus();
|
||||
int i = 0;
|
||||
for (final String customMenuId : customMenus.topLevelKeySet()) {
|
||||
String title = customMenus.get(customMenuId);
|
||||
for (final String menuId : customMenus.keySet()) {
|
||||
String title = customMenus.get(menuId);
|
||||
JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title));
|
||||
|
||||
Map<String, PreferencesMap> customMenu = customMenus.subTree(customMenuId).firstLevelMap();
|
||||
if (customMenu.containsKey(boardId)) {
|
||||
PreferencesMap boardCustomMenu = customMenu.get(boardId);
|
||||
//Map<String, PreferencesMap> customMenu = customMenus.subTree(menuId).firstLevelMap();
|
||||
if (board.hasMenuOptions(menuId)) {
|
||||
//if (customMenu.containsKey(boardId)) {
|
||||
//PreferencesMap boardCustomMenu = customMenu.get(boardId);
|
||||
PreferencesMap boardCustomMenu = board.getMenuOptions(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()) {
|
||||
@ -1282,7 +1284,7 @@ public class Base {
|
||||
Preferences.set("target_package", (String) getValue("package"));
|
||||
Preferences.set("target_platform", (String) getValue("platform"));
|
||||
Preferences.set("board", (String) getValue("board"));
|
||||
Preferences.set("custom_" + customMenuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option"));
|
||||
Preferences.set("custom_" + menuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option"));
|
||||
|
||||
filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex);
|
||||
|
||||
@ -1297,15 +1299,15 @@ public class Base {
|
||||
subAction.putValue("package", packageName);
|
||||
subAction.putValue("platform", platformName);
|
||||
|
||||
if (!buttonGroupsMap.containsKey(customMenuId)) {
|
||||
buttonGroupsMap.put(customMenuId, new ButtonGroup());
|
||||
if (!buttonGroupsMap.containsKey(menuId)) {
|
||||
buttonGroupsMap.put(menuId, new ButtonGroup());
|
||||
}
|
||||
|
||||
item = new JRadioButtonMenuItem(subAction);
|
||||
menu.add(item);
|
||||
buttonGroupsMap.get(customMenuId).add(item);
|
||||
buttonGroupsMap.get(menuId).add(item);
|
||||
|
||||
String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuId);
|
||||
String selectedCustomMenuEntry = Preferences.get("custom_" + menuId);
|
||||
if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) {
|
||||
menuItemsToClickAfterStartup.add(item);
|
||||
}
|
||||
@ -1932,16 +1934,21 @@ public class Base {
|
||||
|
||||
static public PreferencesMap getBoardPreferences() {
|
||||
TargetPlatform target = getTargetPlatform();
|
||||
String board = Preferences.get("board");
|
||||
PreferencesMap boardPreferences = new PreferencesMap(target.getBoard(board).getPreferences());
|
||||
String boardId = Preferences.get("board");
|
||||
TargetBoard board = target.getBoard(boardId);
|
||||
PreferencesMap boardPreferences = new PreferencesMap(board.getPreferences());
|
||||
PreferencesMap customMenus = target.getCustomMenus();
|
||||
for (String customMenuID : customMenus.topLevelKeySet()) {
|
||||
PreferencesMap boardCustomMenu = customMenus.subTree(customMenuID).subTree(board);
|
||||
String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuID);
|
||||
if (boardCustomMenu.size() > 0 && selectedCustomMenuEntry != null && selectedCustomMenuEntry.startsWith(board)) {
|
||||
String menuEntryId = selectedCustomMenuEntry.substring(selectedCustomMenuEntry.indexOf("_") + 1);
|
||||
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));
|
||||
boardPreferences.put("name", boardPreferences.get("name") + ", " +
|
||||
boardCustomMenu.get(menuEntryId));
|
||||
}
|
||||
}
|
||||
return boardPreferences;
|
||||
|
@ -1,11 +1,15 @@
|
||||
package processing.app.debug;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
|
||||
public class TargetBoard {
|
||||
|
||||
String id;
|
||||
PreferencesMap prefs;
|
||||
private String id;
|
||||
private PreferencesMap prefs;
|
||||
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
|
||||
|
||||
/**
|
||||
* Create a TargetBoard based on preferences passed as argument.
|
||||
@ -44,4 +48,16 @@ public class TargetBoard {
|
||||
public PreferencesMap getPreferences() {
|
||||
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) {
|
||||
return menuOptions.containsKey(menuId);
|
||||
}
|
||||
}
|
||||
|
@ -53,6 +53,9 @@ public class TargetPlatform {
|
||||
*/
|
||||
private PreferencesMap preferences = new PreferencesMap();
|
||||
|
||||
/**
|
||||
* Contains labels for top level menus
|
||||
*/
|
||||
private PreferencesMap customMenus = new PreferencesMap();
|
||||
|
||||
public TargetPlatform(String _name, File _folder)
|
||||
@ -69,19 +72,41 @@ public class TargetPlatform {
|
||||
|
||||
// Load boards
|
||||
try {
|
||||
PreferencesMap p = new PreferencesMap(boardsFile);
|
||||
Map<String, PreferencesMap> boardsPreferences = p.firstLevelMap();
|
||||
Map<String, PreferencesMap> boardsPreferences = new PreferencesMap(
|
||||
boardsFile).firstLevelMap();
|
||||
|
||||
// Create custom menus using the key "menu" and its subkeys
|
||||
if (boardsPreferences.containsKey("menu")) {
|
||||
customMenus = new PreferencesMap(boardsPreferences.get("menu"));
|
||||
// Create custom menus for this platform
|
||||
PreferencesMap menus = boardsPreferences.get("menu");
|
||||
boardsPreferences.remove("menu");
|
||||
if (menus != null)
|
||||
customMenus = menus.topLevelMap();
|
||||
|
||||
// Create maps for every menu option:
|
||||
// - a Map that pairs a specific menu option (e.g. "cpu") to
|
||||
// - a Map that pairs a specific board (e.g. "duemilanove") to
|
||||
// - a PrefenceMap with all the options that overrides default
|
||||
// configuration values
|
||||
Map<String, Map<String, PreferencesMap>> subMenus = new LinkedHashMap<String, Map<String, PreferencesMap>>();
|
||||
for (String id : customMenus.keySet()) {
|
||||
subMenus.put(id, menus.subTree(id).firstLevelMap());
|
||||
}
|
||||
|
||||
// Create boards
|
||||
for (String id : boardsPreferences.keySet()) {
|
||||
PreferencesMap preferences = boardsPreferences.get(id);
|
||||
boards.put(id, new TargetBoard(id, preferences));
|
||||
TargetBoard board = new TargetBoard(id, preferences);
|
||||
|
||||
if (menus != null) {
|
||||
// Build custom menu for the specified board
|
||||
PreferencesMap boardCustomMenu = new PreferencesMap();
|
||||
for (String menuId : customMenus.keySet()) {
|
||||
// Check if the board has option for this custom menu
|
||||
if (subMenus.get(menuId).containsKey(id))
|
||||
// Add specific custom menu to the board
|
||||
board.setMenuOptions(menuId, subMenus.get(menuId).get(id));
|
||||
}
|
||||
}
|
||||
boards.put(id, board);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new TargetPlatformException(format(_("Error loading {0}"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user