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