|
30 | 30 |
|
31 | 31 | import javax.swing.*;
|
32 | 32 |
|
| 33 | +import processing.app.debug.TargetBoard; |
33 | 34 | import processing.app.debug.TargetPackage;
|
34 | 35 | import processing.app.debug.TargetPlatform;
|
| 36 | +import processing.app.debug.TargetPlatformException; |
35 | 37 | import processing.app.helpers.FileUtils;
|
36 |
| -import processing.app.helpers.Maps; |
37 | 38 | import processing.app.helpers.PreferencesMap;
|
38 | 39 | import processing.app.helpers.filefilters.OnlyDirs;
|
39 | 40 | import processing.app.helpers.filefilters.OnlyFilesWithExtension;
|
40 | 41 | import processing.app.javax.swing.filechooser.FileNameExtensionFilter;import processing.app.packages.Library;
|
41 | 42 | import processing.app.packages.LibraryList;
|
42 |
| -import processing.app.tools.MapWithSubkeys; |
43 | 43 | import processing.app.tools.ZipDeflater;
|
44 | 44 | import processing.core.*;
|
45 | 45 | import static processing.app.I18n._;
|
@@ -116,7 +116,6 @@ public class Base {
|
116 | 116 | static File portableFolder = null;
|
117 | 117 | static final String portableSketchbookFolder = "sketchbook";
|
118 | 118 |
|
119 |
| - |
120 | 119 | static public void main(String args[]) throws Exception {
|
121 | 120 | initPlatform();
|
122 | 121 |
|
@@ -290,6 +289,11 @@ public Base(String[] args) throws Exception {
|
290 | 289 | packages = new HashMap<String, TargetPackage>();
|
291 | 290 | loadHardware(getHardwareFolder());
|
292 | 291 | loadHardware(getSketchbookHardwareFolder());
|
| 292 | + if (packages.size() == 0) { |
| 293 | + System.out.println(_("No valid configured cores found! Exiting...")); |
| 294 | + System.exit(3); |
| 295 | + } |
| 296 | + |
293 | 297 | // Setup board-dependent variables.
|
294 | 298 | onBoardOrPortChange();
|
295 | 299 |
|
@@ -1180,7 +1184,7 @@ public void onBoardOrPortChange() {
|
1180 | 1184 | try {
|
1181 | 1185 | libraries = scanLibraries(librariesFolders);
|
1182 | 1186 | } catch (IOException e) {
|
1183 |
| - showWarning(_("Error"), _("Error reading preferences"), e); |
| 1187 | + showWarning(_("Error"), _("Error loading libraries"), e); |
1184 | 1188 | }
|
1185 | 1189 | String currentArch = Base.getTargetPlatform().getName();
|
1186 | 1190 | libraries = libraries.filterByArchitecture(currentArch);
|
@@ -1224,87 +1228,86 @@ public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) {
|
1224 | 1228 | // For every package cycle through all platform
|
1225 | 1229 | for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
1226 | 1230 | String platformName = targetPlatform.getName();
|
1227 |
| - Map<String, PreferencesMap> boards = targetPlatform.getBoards(); |
| 1231 | + PreferencesMap customMenus = targetPlatform.getCustomMenus(); |
1228 | 1232 |
|
1229 | 1233 | if (targetPlatform.getPreferences().get("name") == null || targetPlatform.getBoards().isEmpty()) {
|
1230 | 1234 | continue;
|
1231 | 1235 | }
|
1232 | 1236 |
|
1233 | 1237 | // Add a title for each group of boards
|
1234 |
| - if (!first) { |
| 1238 | + if (!first) |
1235 | 1239 | boardsMenu.add(new JSeparator());
|
1236 |
| - } |
1237 | 1240 | first = false;
|
1238 | 1241 |
|
1239 | 1242 | JMenuItem separator = new JMenuItem(_(targetPlatform.getPreferences().get("name")));
|
1240 | 1243 | separator.setEnabled(false);
|
1241 | 1244 | boardsMenu.add(separator);
|
1242 | 1245 |
|
1243 | 1246 | // For every platform cycle through all boards
|
1244 |
| - for (final String boardID : targetPlatform.getBoards().keySet()) { |
| 1247 | + for (TargetBoard board : targetPlatform.getBoards().values()) { |
1245 | 1248 | // Setup a menu item for the current board
|
1246 |
| - String boardName = boards.get(boardID).get("name"); |
| 1249 | + String boardName = board.getName(); |
| 1250 | + String boardId = board.getId(); |
1247 | 1251 | @SuppressWarnings("serial")
|
1248 | 1252 | Action action = new AbstractAction(boardName) {
|
1249 | 1253 | public void actionPerformed(ActionEvent actionevent) {
|
1250 | 1254 | selectBoard((String) getValue("b"), editor);
|
1251 | 1255 | }
|
1252 | 1256 | };
|
1253 |
| - action.putValue("b", packageName + ":" + platformName + ":" + boardID); |
| 1257 | + action.putValue("b", packageName + ":" + platformName + ":" + boardId); |
1254 | 1258 |
|
1255 | 1259 | JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
|
1256 | 1260 | boardsMenu.add(item);
|
1257 | 1261 | boardsButtonGroup.add(item);
|
1258 | 1262 |
|
1259 |
| - if (selBoard.equals(boardID) && selPackage.equals(packageName) |
| 1263 | + if (selBoard.equals(boardId) && selPackage.equals(packageName) |
1260 | 1264 | && selPlatform.equals(platformName)) {
|
1261 | 1265 | menuItemsToClickAfterStartup.add(item);
|
1262 | 1266 | }
|
1263 | 1267 |
|
1264 |
| - if (targetPlatform.getCustomMenus() != null) { |
1265 |
| - List<String> customMenuIDs = new LinkedList<String>(targetPlatform.getCustomMenus().getKeys()); |
1266 |
| - for (int i = 0; i < customMenuIDs.size(); i++) { |
1267 |
| - final String customMenuID = customMenuIDs.get(i); |
1268 |
| - JMenu menu = makeOrGetBoardMenu(toolsMenu, _(targetPlatform.getCustomMenus().getValueOf(customMenuID))); |
1269 |
| - MapWithSubkeys customMenu = targetPlatform.getCustomMenus().get(customMenuID); |
1270 |
| - if (customMenu.getKeys().contains(boardID)) { |
1271 |
| - MapWithSubkeys boardCustomMenu = customMenu.get(boardID); |
1272 |
| - 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 |
1273 |
| - for (final String customMenuOption : boardCustomMenu.getKeys()) { |
1274 |
| - @SuppressWarnings("serial") |
1275 |
| - Action subAction = new AbstractAction(_(boardCustomMenu.getValueOf(customMenuOption))) { |
1276 |
| - |
1277 |
| - public void actionPerformed(ActionEvent e) { |
1278 |
| - Preferences.set("target_package", (String) getValue("package")); |
1279 |
| - Preferences.set("target_platform", (String) getValue("platform")); |
1280 |
| - Preferences.set("board", (String) getValue("board")); |
1281 |
| - Preferences.set("custom_" + customMenuID, boardID + "_" + (String) getValue("custom_menu_option")); |
1282 |
| - |
1283 |
| - filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex); |
1284 |
| - |
1285 |
| - onBoardOrPortChange(); |
1286 |
| - Sketch.buildSettingChanged(); |
1287 |
| - rebuildImportMenu(Editor.importMenu, editor); |
1288 |
| - rebuildExamplesMenu(Editor.examplesMenu); |
1289 |
| - } |
1290 |
| - }; |
1291 |
| - subAction.putValue("board", boardID); |
1292 |
| - subAction.putValue("custom_menu_option", customMenuOption); |
1293 |
| - subAction.putValue("package", packageName); |
1294 |
| - subAction.putValue("platform", platformName); |
1295 |
| - |
1296 |
| - if (!buttonGroupsMap.containsKey(customMenuID)) { |
1297 |
| - buttonGroupsMap.put(customMenuID, new ButtonGroup()); |
| 1268 | + int i = 0; |
| 1269 | + for (final String customMenuId : customMenus.topLevelKeySet()) { |
| 1270 | + String title = customMenus.get(customMenuId); |
| 1271 | + JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title)); |
| 1272 | + |
| 1273 | + Map<String, PreferencesMap> customMenu = customMenus.subTree(customMenuId).firstLevelMap(); |
| 1274 | + if (customMenu.containsKey(boardId)) { |
| 1275 | + PreferencesMap boardCustomMenu = customMenu.get(boardId); |
| 1276 | + 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 |
| 1277 | + i++; |
| 1278 | + for (String customMenuOption : boardCustomMenu.topLevelKeySet()) { |
| 1279 | + @SuppressWarnings("serial") |
| 1280 | + Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) { |
| 1281 | + public void actionPerformed(ActionEvent e) { |
| 1282 | + Preferences.set("target_package", (String) getValue("package")); |
| 1283 | + Preferences.set("target_platform", (String) getValue("platform")); |
| 1284 | + Preferences.set("board", (String) getValue("board")); |
| 1285 | + Preferences.set("custom_" + customMenuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option")); |
| 1286 | + |
| 1287 | + filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex); |
| 1288 | + |
| 1289 | + onBoardOrPortChange(); |
| 1290 | + Sketch.buildSettingChanged(); |
| 1291 | + rebuildImportMenu(Editor.importMenu, editor); |
| 1292 | + rebuildExamplesMenu(Editor.examplesMenu); |
1298 | 1293 | }
|
| 1294 | + }; |
| 1295 | + subAction.putValue("board", boardId); |
| 1296 | + subAction.putValue("custom_menu_option", customMenuOption); |
| 1297 | + subAction.putValue("package", packageName); |
| 1298 | + subAction.putValue("platform", platformName); |
| 1299 | + |
| 1300 | + if (!buttonGroupsMap.containsKey(customMenuId)) { |
| 1301 | + buttonGroupsMap.put(customMenuId, new ButtonGroup()); |
| 1302 | + } |
1299 | 1303 |
|
1300 |
| - item = new JRadioButtonMenuItem(subAction); |
1301 |
| - menu.add(item); |
1302 |
| - buttonGroupsMap.get(customMenuID).add(item); |
| 1304 | + item = new JRadioButtonMenuItem(subAction); |
| 1305 | + menu.add(item); |
| 1306 | + buttonGroupsMap.get(customMenuId).add(item); |
1303 | 1307 |
|
1304 |
| - String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuID); |
1305 |
| - if (selBoard.equals(boardID) && (boardID + "_" + customMenuOption).equals(selectedCustomMenuEntry)) { |
1306 |
| - menuItemsToClickAfterStartup.add(item); |
1307 |
| - } |
| 1308 | + String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuId); |
| 1309 | + if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) { |
| 1310 | + menuItemsToClickAfterStartup.add(item); |
1308 | 1311 | }
|
1309 | 1312 | }
|
1310 | 1313 | }
|
@@ -1604,7 +1607,13 @@ protected void loadHardware(File folder) {
|
1604 | 1607 | if (target.equals("tools"))
|
1605 | 1608 | continue;
|
1606 | 1609 | File subfolder = new File(folder, target);
|
1607 |
| - packages.put(target, new TargetPackage(target, subfolder)); |
| 1610 | + |
| 1611 | + try { |
| 1612 | + packages.put(target, new TargetPackage(target, subfolder)); |
| 1613 | + } catch (TargetPlatformException e) { |
| 1614 | + System.out.println("WARNING: Error loading hardware folder " + target); |
| 1615 | + System.out.println(" " + e.getMessage()); |
| 1616 | + } |
1608 | 1617 | }
|
1609 | 1618 | }
|
1610 | 1619 |
|
@@ -1921,19 +1930,18 @@ static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
|
1921 | 1930 | return getTargetPlatform(pack, Preferences.get("target_platform"));
|
1922 | 1931 | }
|
1923 | 1932 |
|
1924 |
| - static public Map<String, String> getBoardPreferences() { |
| 1933 | + static public PreferencesMap getBoardPreferences() { |
1925 | 1934 | TargetPlatform target = getTargetPlatform();
|
1926 | 1935 | String board = Preferences.get("board");
|
1927 |
| - Map<String, String> boardPreferences = Maps.merge(target.getBoards().get(board), new LinkedHashMap<String, String>()); |
1928 |
| - if (target.getCustomMenus() != null) { |
1929 |
| - for (String customMenuID : target.getCustomMenus().getKeys()) { |
1930 |
| - MapWithSubkeys boardCustomMenu = target.getCustomMenus().get(customMenuID).get(board); |
1931 |
| - String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuID); |
1932 |
| - if (boardCustomMenu != null && selectedCustomMenuEntry != null && selectedCustomMenuEntry.startsWith(board)) { |
1933 |
| - String menuEntryId = selectedCustomMenuEntry.substring(selectedCustomMenuEntry.indexOf("_") + 1); |
1934 |
| - Maps.merge(boardCustomMenu.get(menuEntryId).getValues(), boardPreferences); |
1935 |
| - boardPreferences.put("name", boardPreferences.get("name") + ", " + boardCustomMenu.getValueOf(menuEntryId)); |
1936 |
| - } |
| 1936 | + PreferencesMap boardPreferences = new PreferencesMap(target.getBoard(board).getPreferences()); |
| 1937 | + PreferencesMap customMenus = target.getCustomMenus(); |
| 1938 | + for (String customMenuID : customMenus.topLevelKeySet()) { |
| 1939 | + PreferencesMap boardCustomMenu = customMenus.subTree(customMenuID).subTree(board); |
| 1940 | + String selectedCustomMenuEntry = Preferences.get("custom_" + customMenuID); |
| 1941 | + if (boardCustomMenu.size() > 0 && selectedCustomMenuEntry != null && selectedCustomMenuEntry.startsWith(board)) { |
| 1942 | + String menuEntryId = selectedCustomMenuEntry.substring(selectedCustomMenuEntry.indexOf("_") + 1); |
| 1943 | + boardPreferences.putAll(boardCustomMenu.subTree(menuEntryId)); |
| 1944 | + boardPreferences.put("name", boardPreferences.get("name") + ", " + boardCustomMenu.get(menuEntryId)); |
1937 | 1945 | }
|
1938 | 1946 | }
|
1939 | 1947 | return boardPreferences;
|
|
0 commit comments