mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
When using cores from other packages also the referenced platforms.txt is imported
See #1157
This commit is contained in:
@ -293,6 +293,8 @@ public class Base {
|
|||||||
System.out.println(_("No valid configured cores found! Exiting..."));
|
System.out.println(_("No valid configured cores found! Exiting..."));
|
||||||
System.exit(3);
|
System.exit(3);
|
||||||
}
|
}
|
||||||
|
for (TargetPackage pack : packages.values())
|
||||||
|
pack.resolveReferencedPlatforms(packages);
|
||||||
|
|
||||||
// Setup board-dependent variables.
|
// Setup board-dependent variables.
|
||||||
onBoardOrPortChange();
|
onBoardOrPortChange();
|
||||||
@ -407,8 +409,9 @@ public class Base {
|
|||||||
* sketch that was used (if any), and restores other Editor settings.
|
* sketch that was used (if any), and restores other Editor settings.
|
||||||
* The complement to "storePreferences", this is called when the
|
* The complement to "storePreferences", this is called when the
|
||||||
* application is first launched.
|
* application is first launched.
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected boolean restoreSketches() {
|
protected boolean restoreSketches() throws Exception {
|
||||||
// figure out window placement
|
// figure out window placement
|
||||||
|
|
||||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||||
@ -668,8 +671,9 @@ public class Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new untitled document in a new sketch window.
|
* Create a new untitled document in a new sketch window.
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void handleNew() {
|
public void handleNew() throws Exception {
|
||||||
try {
|
try {
|
||||||
String path = createNewUntitled();
|
String path = createNewUntitled();
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
@ -737,8 +741,9 @@ public class Base {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompt for a sketch to open, and open it in a new window.
|
* Prompt for a sketch to open, and open it in a new window.
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public void handleOpenPrompt() {
|
public void handleOpenPrompt() throws Exception {
|
||||||
// get the frontmost window frame for placing file dialog
|
// get the frontmost window frame for placing file dialog
|
||||||
FileDialog fd = new FileDialog(activeEditor,
|
FileDialog fd = new FileDialog(activeEditor,
|
||||||
_("Open an Arduino sketch..."),
|
_("Open an Arduino sketch..."),
|
||||||
@ -773,13 +778,14 @@ public class Base {
|
|||||||
* @param path Path to the pde file for the sketch in question
|
* @param path Path to the pde file for the sketch in question
|
||||||
* @return the Editor object, so that properties (like 'untitled')
|
* @return the Editor object, so that properties (like 'untitled')
|
||||||
* can be set by the caller
|
* can be set by the caller
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public Editor handleOpen(String path) {
|
public Editor handleOpen(String path) throws Exception {
|
||||||
return handleOpen(path, nextEditorLocation());
|
return handleOpen(path, nextEditorLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected Editor handleOpen(String path, int[] location) {
|
protected Editor handleOpen(String path, int[] location) throws Exception {
|
||||||
// System.err.println("entering handleOpen " + path);
|
// System.err.println("entering handleOpen " + path);
|
||||||
|
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
@ -1011,7 +1017,11 @@ public class Base {
|
|||||||
item = Editor.newJMenuItem(_("Open..."), 'O');
|
item = Editor.newJMenuItem(_("Open..."), 'O');
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
handleOpenPrompt();
|
try {
|
||||||
|
handleOpenPrompt();
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu.add(item);
|
menu.add(item);
|
||||||
@ -1076,17 +1086,17 @@ public class Base {
|
|||||||
importMenu.add(addLibraryMenuItem);
|
importMenu.add(addLibraryMenuItem);
|
||||||
|
|
||||||
// Split between user supplied libraries and IDE libraries
|
// Split between user supplied libraries and IDE libraries
|
||||||
TargetPlatform targetPlatform = getTargetPlatform();
|
TargetBoard board = getTargetBoard();
|
||||||
if (targetPlatform != null) {
|
|
||||||
|
if (board != null) {
|
||||||
LibraryList ideLibs = getIDELibs();
|
LibraryList ideLibs = getIDELibs();
|
||||||
LibraryList userLibs = getUserLibs();
|
LibraryList userLibs = getUserLibs();
|
||||||
try {
|
try {
|
||||||
// Find the current target. Get the platform, and then select the
|
// Find the current target. Get the platform, and then select the
|
||||||
// correct name and core path.
|
// correct name and core path.
|
||||||
PreferencesMap prefs = targetPlatform.getPreferences();
|
PreferencesMap prefs = board.getMergedPlatformPreferences();
|
||||||
String targetname = prefs.get("name");
|
String platformName = prefs.get("name");
|
||||||
|
JMenuItem platformItem = new JMenuItem(_(platformName));
|
||||||
JMenuItem platformItem = new JMenuItem(_(targetname));
|
|
||||||
platformItem.setEnabled(false);
|
platformItem.setEnabled(false);
|
||||||
importMenu.add(platformItem);
|
importMenu.add(platformItem);
|
||||||
if (ideLibs.size() > 0) {
|
if (ideLibs.size() > 0) {
|
||||||
@ -1186,7 +1196,7 @@ public class Base {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
showWarning(_("Error"), _("Error loading libraries"), e);
|
showWarning(_("Error"), _("Error loading libraries"), e);
|
||||||
}
|
}
|
||||||
String currentArch = Base.getTargetPlatform().getName();
|
String currentArch = Base.getTargetPlatform().getId();
|
||||||
libraries = libraries.filterByArchitecture(currentArch);
|
libraries = libraries.filterByArchitecture(currentArch);
|
||||||
|
|
||||||
// Populate importToLibraryTable
|
// Populate importToLibraryTable
|
||||||
@ -1208,12 +1218,8 @@ public class Base {
|
|||||||
editor.onBoardOrPortChange();
|
editor.onBoardOrPortChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) {
|
public void rebuildBoardsMenu(JMenu toolsMenu, Editor editor) throws Exception {
|
||||||
JMenu boardsMenu = makeOrGetBoardMenu(toolsMenu, _("Board"));
|
JMenu boardsMenu = getBoardCustomMenu();
|
||||||
|
|
||||||
String selPackage = Preferences.get("target_package");
|
|
||||||
String selPlatform = Preferences.get("target_platform");
|
|
||||||
String selBoard = Preferences.get("board");
|
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
|
|
||||||
@ -1222,93 +1228,72 @@ public class Base {
|
|||||||
ButtonGroup boardsButtonGroup = new ButtonGroup();
|
ButtonGroup boardsButtonGroup = new ButtonGroup();
|
||||||
Map<String, ButtonGroup> buttonGroupsMap = new HashMap<String, ButtonGroup>();
|
Map<String, ButtonGroup> buttonGroupsMap = new HashMap<String, ButtonGroup>();
|
||||||
|
|
||||||
|
// Generate custom menus for all platforms
|
||||||
|
for (TargetPackage targetPackage : packages.values()) {
|
||||||
|
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
||||||
|
PreferencesMap customMenus = targetPlatform.getCustomMenus();
|
||||||
|
for (String menuId : customMenus.keySet()) {
|
||||||
|
String title = customMenus.get(menuId);
|
||||||
|
makeBoardCustomMenu(toolsMenu, _(title));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Cycle through all packages
|
// Cycle through all packages
|
||||||
for (TargetPackage targetPackage : packages.values()) {
|
for (TargetPackage targetPackage : packages.values()) {
|
||||||
String packageName = targetPackage.getName();
|
|
||||||
// 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 platformLabel = targetPlatform.getPreferences().get("name");
|
||||||
|
if (platformLabel == null || targetPlatform.getBoards().isEmpty()) {
|
||||||
if (targetPlatform.getPreferences().get("name") == null || targetPlatform.getBoards().isEmpty()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a title for each group of boards
|
// Add a separator from the previous platform
|
||||||
if (!first)
|
if (!first)
|
||||||
boardsMenu.add(new JSeparator());
|
boardsMenu.add(new JSeparator());
|
||||||
first = false;
|
first = false;
|
||||||
|
|
||||||
JMenuItem separator = new JMenuItem(_(targetPlatform.getPreferences().get("name")));
|
// Add a title for each platform
|
||||||
|
JMenuItem separator = new JMenuItem(_(platformLabel));
|
||||||
separator.setEnabled(false);
|
separator.setEnabled(false);
|
||||||
boardsMenu.add(separator);
|
boardsMenu.add(separator);
|
||||||
|
|
||||||
// For every platform cycle through all boards
|
// Cycle through all boards of this platform
|
||||||
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
for (TargetBoard board : targetPlatform.getBoards().values()) {
|
||||||
// Setup a menu item for the current board
|
JMenuItem item = createBoardMenusAndCustomMenus(
|
||||||
String boardName = board.getName();
|
editor,
|
||||||
String boardId = board.getId();
|
menuItemsToClickAfterStartup,
|
||||||
@SuppressWarnings("serial")
|
buttonGroupsMap,
|
||||||
Action action = new AbstractAction(boardName) {
|
board, targetPlatform, targetPackage);
|
||||||
public void actionPerformed(ActionEvent actionevent) {
|
|
||||||
selectBoard((String) getValue("b"), editor);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
action.putValue("b", packageName + ":" + platformName + ":" + boardId);
|
|
||||||
|
|
||||||
JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
|
|
||||||
boardsMenu.add(item);
|
boardsMenu.add(item);
|
||||||
boardsButtonGroup.add(item);
|
boardsButtonGroup.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cycle through all boards of referenced platforms
|
||||||
|
for (TargetPackage pack : packages.values()) {
|
||||||
|
if (pack == targetPackage)
|
||||||
|
continue;
|
||||||
|
for (TargetPlatform platf : pack.getPlatforms().values()) {
|
||||||
|
if (!platf.getId().equals(targetPlatform.getId()))
|
||||||
|
continue;
|
||||||
|
boolean firstRefBoardBlock = true;
|
||||||
|
for (TargetBoard board : platf.getBoards().values()) {
|
||||||
|
if (board.getReferencedPackageId() == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (selBoard.equals(boardId) && selPackage.equals(packageName)
|
// Add a separator from the previous platform
|
||||||
&& selPlatform.equals(platformName)) {
|
if (firstRefBoardBlock)
|
||||||
menuItemsToClickAfterStartup.add(item);
|
boardsMenu.add(new JSeparator());
|
||||||
}
|
firstRefBoardBlock = false;
|
||||||
|
|
||||||
PreferencesMap customMenus = targetPlatform.getCustomMenus();
|
JMenuItem item = createBoardMenusAndCustomMenus(
|
||||||
int i = 0;
|
editor,
|
||||||
for (final String menuId : customMenus.keySet()) {
|
menuItemsToClickAfterStartup,
|
||||||
String title = customMenus.get(menuId);
|
buttonGroupsMap,
|
||||||
JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title));
|
board, platf,
|
||||||
|
pack);
|
||||||
if (board.hasMenu(menuId)) {
|
boardsMenu.add(item);
|
||||||
PreferencesMap boardCustomMenu = board.getMenuLabels(menuId);
|
boardsButtonGroup.add(item);
|
||||||
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.keySet()) {
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Preferences.set("target_package", (String) getValue("package"));
|
|
||||||
Preferences.set("target_platform", (String) getValue("platform"));
|
|
||||||
Preferences.set("board", (String) getValue("board"));
|
|
||||||
Preferences.set("custom_" + menuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option"));
|
|
||||||
|
|
||||||
filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex);
|
|
||||||
|
|
||||||
onBoardOrPortChange();
|
|
||||||
Sketch.buildSettingChanged();
|
|
||||||
rebuildImportMenu(Editor.importMenu, editor);
|
|
||||||
rebuildExamplesMenu(Editor.examplesMenu);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
subAction.putValue("board", boardId);
|
|
||||||
subAction.putValue("custom_menu_option", customMenuOption);
|
|
||||||
subAction.putValue("package", packageName);
|
|
||||||
subAction.putValue("platform", platformName);
|
|
||||||
|
|
||||||
if (!buttonGroupsMap.containsKey(menuId)) {
|
|
||||||
buttonGroupsMap.put(menuId, new ButtonGroup());
|
|
||||||
}
|
|
||||||
|
|
||||||
item = new JRadioButtonMenuItem(subAction);
|
|
||||||
menu.add(item);
|
|
||||||
buttonGroupsMap.get(menuId).add(item);
|
|
||||||
|
|
||||||
String selectedCustomMenuEntry = Preferences.get("custom_" + menuId);
|
|
||||||
if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) {
|
|
||||||
menuItemsToClickAfterStartup.add(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1325,6 +1310,87 @@ public class Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JRadioButtonMenuItem createBoardMenusAndCustomMenus(
|
||||||
|
final Editor editor,
|
||||||
|
List<JMenuItem> menuItemsToClickAfterStartup,
|
||||||
|
Map<String, ButtonGroup> buttonGroupsMap,
|
||||||
|
TargetBoard board, TargetPlatform targetPlatform, TargetPackage targetPackage)
|
||||||
|
throws Exception {
|
||||||
|
String selPackage = Preferences.get("target_package");
|
||||||
|
String selPlatform = Preferences.get("target_platform");
|
||||||
|
String selBoard = Preferences.get("board");
|
||||||
|
|
||||||
|
String boardId = board.getId();
|
||||||
|
String packageName = targetPackage.getId();
|
||||||
|
String platformName = targetPlatform.getId();
|
||||||
|
|
||||||
|
// Setup a menu item for the current board
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
Action action = new AbstractAction(board.getName()) {
|
||||||
|
public void actionPerformed(ActionEvent actionevent) {
|
||||||
|
selectBoard((String) getValue("b"), editor);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
action.putValue("b", packageName + ":" + platformName + ":" + boardId);
|
||||||
|
|
||||||
|
JRadioButtonMenuItem item = new JRadioButtonMenuItem(action);
|
||||||
|
|
||||||
|
if (selBoard.equals(boardId) && selPackage.equals(packageName)
|
||||||
|
&& selPlatform.equals(platformName)) {
|
||||||
|
menuItemsToClickAfterStartup.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
PreferencesMap customMenus = targetPlatform.getCustomMenus();
|
||||||
|
for (final String menuId : customMenus.keySet()) {
|
||||||
|
String title = customMenus.get(menuId);
|
||||||
|
JMenu menu = getBoardCustomMenu(_(title));
|
||||||
|
|
||||||
|
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.keySet()) {
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Preferences.set("target_package", (String) getValue("package"));
|
||||||
|
Preferences.set("target_platform", (String) getValue("platform"));
|
||||||
|
Preferences.set("board", (String) getValue("board"));
|
||||||
|
Preferences.set("custom_" + menuId, (String) getValue("board") + "_" + (String) getValue("custom_menu_option"));
|
||||||
|
|
||||||
|
filterVisibilityOfSubsequentBoardMenus((String) getValue("board"), currentIndex);
|
||||||
|
|
||||||
|
onBoardOrPortChange();
|
||||||
|
Sketch.buildSettingChanged();
|
||||||
|
rebuildImportMenu(Editor.importMenu, editor);
|
||||||
|
rebuildExamplesMenu(Editor.examplesMenu);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
subAction.putValue("board", boardId);
|
||||||
|
subAction.putValue("custom_menu_option", customMenuOption);
|
||||||
|
subAction.putValue("package", packageName);
|
||||||
|
subAction.putValue("platform", platformName);
|
||||||
|
|
||||||
|
if (!buttonGroupsMap.containsKey(menuId)) {
|
||||||
|
buttonGroupsMap.put(menuId, new ButtonGroup());
|
||||||
|
}
|
||||||
|
|
||||||
|
JRadioButtonMenuItem subItem = new JRadioButtonMenuItem(subAction);
|
||||||
|
menu.add(subItem);
|
||||||
|
buttonGroupsMap.get(menuId).add(subItem);
|
||||||
|
|
||||||
|
String selectedCustomMenuEntry = Preferences.get("custom_" + menuId);
|
||||||
|
if (selBoard.equals(boardId) && (boardId + "_" + customMenuOption).equals(selectedCustomMenuEntry)) {
|
||||||
|
menuItemsToClickAfterStartup.add(subItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
private static void filterVisibilityOfSubsequentBoardMenus(String boardID, int fromIndex) {
|
private static void filterVisibilityOfSubsequentBoardMenus(String boardID, int fromIndex) {
|
||||||
for (int i = fromIndex; i < Editor.boardsMenus.size(); i++) {
|
for (int i = fromIndex; i < Editor.boardsMenus.size(); i++) {
|
||||||
JMenu menu = Editor.boardsMenus.get(i);
|
JMenu menu = Editor.boardsMenus.get(i);
|
||||||
@ -1353,18 +1419,24 @@ public class Base {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JMenu makeOrGetBoardMenu(JMenu toolsMenu, String label) {
|
private JMenu makeBoardCustomMenu(JMenu toolsMenu, String label) {
|
||||||
for (JMenu menu : Editor.boardsMenus) {
|
|
||||||
if (label.equals(menu.getText())) {
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
JMenu menu = new JMenu(label);
|
JMenu menu = new JMenu(label);
|
||||||
Editor.boardsMenus.add(menu);
|
Editor.boardsMenus.add(menu);
|
||||||
toolsMenu.add(menu);
|
toolsMenu.add(menu);
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JMenu getBoardCustomMenu() throws Exception {
|
||||||
|
return getBoardCustomMenu(_("Board"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private JMenu getBoardCustomMenu(String label) throws Exception {
|
||||||
|
for (JMenu menu : Editor.boardsMenus)
|
||||||
|
if (label.equals(menu.getText()))
|
||||||
|
return menu;
|
||||||
|
throw new Exception("Custom menu not found!");
|
||||||
|
}
|
||||||
|
|
||||||
private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) {
|
private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) {
|
||||||
JMenuItem firstVisible = null;
|
JMenuItem firstVisible = null;
|
||||||
for (int i = 0; i < menu.getItemCount(); i++) {
|
for (int i = 0; i < menu.getItemCount(); i++) {
|
||||||
@ -1418,7 +1490,7 @@ public class Base {
|
|||||||
for (TargetPackage targetPackage : packages.values()) {
|
for (TargetPackage targetPackage : packages.values()) {
|
||||||
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
for (TargetPlatform targetPlatform : targetPackage.platforms()) {
|
||||||
for (String programmer : targetPlatform.getProgrammers().keySet()) {
|
for (String programmer : targetPlatform.getProgrammers().keySet()) {
|
||||||
String id = targetPackage.getName() + ":" + programmer;
|
String id = targetPackage.getId() + ":" + programmer;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
AbstractAction action = new AbstractAction(targetPlatform
|
AbstractAction action = new AbstractAction(targetPlatform
|
||||||
@ -1496,7 +1568,11 @@ public class Base {
|
|||||||
if (replace) {
|
if (replace) {
|
||||||
handleOpenReplace(path);
|
handleOpenReplace(path);
|
||||||
} else {
|
} else {
|
||||||
handleOpen(path);
|
try {
|
||||||
|
handleOpen(path);
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
showWarning(_("Sketch Does Not Exist"),
|
showWarning(_("Sketch Does Not Exist"),
|
||||||
@ -1930,16 +2006,15 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static public PreferencesMap getBoardPreferences() {
|
static public PreferencesMap getBoardPreferences() {
|
||||||
TargetPlatform target = getTargetPlatform();
|
TargetBoard board = getTargetBoard();
|
||||||
String boardId = Preferences.get("board");
|
|
||||||
TargetBoard board = target.getBoard(boardId);
|
|
||||||
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
|
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
|
||||||
for (String menuId : target.getCustomMenusKeys()) {
|
for (String menuId : board.getMenuIds()) {
|
||||||
String entry = Preferences.get("custom_" + menuId);
|
String entry = Preferences.get("custom_" + menuId);
|
||||||
if (board.hasMenu(menuId) && entry != null &&
|
if (board.hasMenu(menuId) && entry != null &&
|
||||||
entry.startsWith(boardId)) {
|
entry.startsWith(board.getId())) {
|
||||||
String selectionId = entry.substring(entry.indexOf("_") + 1);
|
String selectionId = entry.substring(entry.indexOf("_") + 1);
|
||||||
prefs.putAll(board.getMenuConfiguration(menuId, selectionId));
|
prefs.putAll(board.getMenuPreferences(menuId, selectionId));
|
||||||
prefs.put("name", prefs.get("name") + ", " +
|
prefs.put("name", prefs.get("name") + ", " +
|
||||||
board.getMenuLabel(menuId, selectionId));
|
board.getMenuLabel(menuId, selectionId));
|
||||||
}
|
}
|
||||||
@ -1947,6 +2022,11 @@ public class Base {
|
|||||||
return prefs;
|
return prefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TargetBoard getTargetBoard() {
|
||||||
|
String boardId = Preferences.get("board");
|
||||||
|
return getTargetPlatform().getBoard(boardId);
|
||||||
|
}
|
||||||
|
|
||||||
static public File getPortableFolder() {
|
static public File getPortableFolder() {
|
||||||
return portableFolder;
|
return portableFolder;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
Runnable exportAppHandler;
|
Runnable exportAppHandler;
|
||||||
|
|
||||||
|
|
||||||
public Editor(Base ibase, String path, int[] location) {
|
public Editor(Base ibase, String path, int[] location) throws Exception {
|
||||||
super("Arduino");
|
super("Arduino");
|
||||||
this.base = ibase;
|
this.base = ibase;
|
||||||
|
|
||||||
@ -476,7 +476,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||||
|
|
||||||
|
|
||||||
protected void buildMenuBar() {
|
protected void buildMenuBar() throws Exception {
|
||||||
JMenuBar menubar = new JMenuBar();
|
JMenuBar menubar = new JMenuBar();
|
||||||
menubar.add(buildFileMenu());
|
menubar.add(buildFileMenu());
|
||||||
menubar.add(buildEditMenu());
|
menubar.add(buildEditMenu());
|
||||||
@ -494,7 +494,11 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
item = newJMenuItem(_("New"), 'N');
|
item = newJMenuItem(_("New"), 'N');
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
base.handleNew();
|
try {
|
||||||
|
base.handleNew();
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fileMenu.add(item);
|
fileMenu.add(item);
|
||||||
@ -502,7 +506,11 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
item = Editor.newJMenuItem(_("Open..."), 'O');
|
item = Editor.newJMenuItem(_("Open..."), 'O');
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
base.handleOpenPrompt();
|
try {
|
||||||
|
base.handleOpenPrompt();
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
fileMenu.add(item);
|
fileMenu.add(item);
|
||||||
@ -662,7 +670,7 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected JMenu buildToolsMenu() {
|
protected JMenu buildToolsMenu() throws Exception {
|
||||||
toolsMenu = new JMenu(_("Tools"));
|
toolsMenu = new JMenu(_("Tools"));
|
||||||
JMenu menu = toolsMenu;
|
JMenu menu = toolsMenu;
|
||||||
JMenuItem item;
|
JMenuItem item;
|
||||||
@ -690,6 +698,11 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
|
|
||||||
if (boardsMenus == null) {
|
if (boardsMenus == null) {
|
||||||
boardsMenus = new LinkedList<JMenu>();
|
boardsMenus = new LinkedList<JMenu>();
|
||||||
|
|
||||||
|
JMenu boardsMenu = new JMenu(_("Board"));
|
||||||
|
Editor.boardsMenus.add(boardsMenu);
|
||||||
|
toolsMenu.add(boardsMenu);
|
||||||
|
|
||||||
base.rebuildBoardsMenu(toolsMenu, this);
|
base.rebuildBoardsMenu(toolsMenu, this);
|
||||||
//Debug: rebuild imports
|
//Debug: rebuild imports
|
||||||
importMenu.removeAll();
|
importMenu.removeAll();
|
||||||
|
@ -335,9 +335,13 @@ public class EditorToolbar extends JComponent implements MouseInputListener, Key
|
|||||||
|
|
||||||
case NEW:
|
case NEW:
|
||||||
if (shiftPressed) {
|
if (shiftPressed) {
|
||||||
editor.base.handleNew();
|
try {
|
||||||
|
editor.base.handleNew();
|
||||||
|
} catch (Exception e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
editor.base.handleNewReplace();
|
editor.base.handleNewReplace();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -132,12 +132,13 @@ public class Compiler implements MessageConsumer {
|
|||||||
throw re;
|
throw re;
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
TargetBoard targetBoard = Base.getTargetBoard();
|
||||||
|
TargetPlatform targetPlatform = targetBoard.getContainerPlatform();
|
||||||
|
|
||||||
// Merge all the global preference configuration in order of priority
|
// Merge all the global preference configuration in order of priority
|
||||||
PreferencesMap p = new PreferencesMap();
|
PreferencesMap p = new PreferencesMap();
|
||||||
p.putAll(Preferences.getMap());
|
p.putAll(Preferences.getMap());
|
||||||
p.putAll(targetPlatform.getPreferences());
|
p.putAll(targetBoard.getMergedPlatformPreferences());
|
||||||
p.putAll(Base.getBoardPreferences());
|
p.putAll(Base.getBoardPreferences());
|
||||||
for (String k : p.keySet()) {
|
for (String k : p.keySet()) {
|
||||||
if (p.get(k) == null)
|
if (p.get(k) == null)
|
||||||
@ -146,28 +147,23 @@ public class Compiler implements MessageConsumer {
|
|||||||
|
|
||||||
p.put("build.path", _buildPath);
|
p.put("build.path", _buildPath);
|
||||||
p.put("build.project_name", _primaryClassName);
|
p.put("build.project_name", _primaryClassName);
|
||||||
targetArch = targetPlatform.getName();
|
targetArch = targetPlatform.getId();
|
||||||
p.put("build.arch", targetArch.toUpperCase());
|
p.put("build.arch", targetArch.toUpperCase());
|
||||||
|
|
||||||
if (!p.containsKey("compiler.path"))
|
if (!p.containsKey("compiler.path"))
|
||||||
p.put("compiler.path", Base.getAvrBasePath());
|
p.put("compiler.path", Base.getAvrBasePath());
|
||||||
|
|
||||||
// Core folder
|
// Core folder
|
||||||
String core = p.get("build.core");
|
TargetPlatform tp = targetBoard.getReferencedPlatform();
|
||||||
TargetPlatform tp;
|
if (tp == null)
|
||||||
if (!core.contains(":")) {
|
tp = targetBoard.getContainerPlatform();
|
||||||
tp = targetPlatform;
|
|
||||||
} else {
|
|
||||||
String[] split = core.split(":", 2);
|
|
||||||
tp = Base.getTargetPlatform(split[0], Preferences.get("target_platform"));
|
|
||||||
core = split[1];
|
|
||||||
}
|
|
||||||
File coreFolder = new File(tp.getFolder(), "cores");
|
File coreFolder = new File(tp.getFolder(), "cores");
|
||||||
|
String core = p.get("build.core");
|
||||||
coreFolder = new File(coreFolder, core);
|
coreFolder = new File(coreFolder, core);
|
||||||
p.put("build.core.path", coreFolder.getAbsolutePath());
|
p.put("build.core.path", coreFolder.getAbsolutePath());
|
||||||
|
|
||||||
// System Folder
|
// System Folder
|
||||||
File systemFolder = targetPlatform.getFolder();
|
File systemFolder = tp.getFolder();
|
||||||
systemFolder = new File(systemFolder, "system");
|
systemFolder = new File(systemFolder, "system");
|
||||||
p.put("build.system.path", systemFolder.getAbsolutePath());
|
p.put("build.system.path", systemFolder.getAbsolutePath());
|
||||||
|
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package processing.app.debug;
|
package processing.app.debug;
|
||||||
|
|
||||||
|
import static processing.app.I18n._;
|
||||||
|
import static processing.app.I18n.format;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
@ -10,6 +14,11 @@ public class TargetBoard {
|
|||||||
private String id;
|
private String id;
|
||||||
private PreferencesMap prefs;
|
private PreferencesMap prefs;
|
||||||
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
|
private Map<String, PreferencesMap> menuOptions = new LinkedHashMap<String, PreferencesMap>();
|
||||||
|
private TargetPlatform containerPlatform;
|
||||||
|
|
||||||
|
private String referencedPackageId;
|
||||||
|
private TargetPlatform referencedPlatform;
|
||||||
|
private TargetPackage referencedPackage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a TargetBoard based on preferences passed as argument.
|
* Create a TargetBoard based on preferences passed as argument.
|
||||||
@ -17,13 +26,23 @@ public class TargetBoard {
|
|||||||
* @param _prefs
|
* @param _prefs
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TargetBoard(String _id, PreferencesMap _prefs) {
|
public TargetBoard(String _id, PreferencesMap _prefs, TargetPlatform parent) {
|
||||||
|
containerPlatform = parent;
|
||||||
id = _id;
|
id = _id;
|
||||||
prefs = new PreferencesMap(_prefs);
|
prefs = new PreferencesMap(_prefs);
|
||||||
|
|
||||||
|
// Setup sub-menus
|
||||||
PreferencesMap menus = prefs.firstLevelMap().get("menu");
|
PreferencesMap menus = prefs.firstLevelMap().get("menu");
|
||||||
if (menus != null)
|
if (menus != null)
|
||||||
menuOptions = menus.firstLevelMap();
|
menuOptions = menus.firstLevelMap();
|
||||||
|
|
||||||
|
// Setup referenced platform
|
||||||
|
String core = prefs.get("build.core");
|
||||||
|
if (core.contains(":")) {
|
||||||
|
String[] split = core.split(":");
|
||||||
|
referencedPackageId = split[0];
|
||||||
|
prefs.put("build.core", split[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,6 +63,15 @@ public class TargetBoard {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the package this board refers to
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getReferencedPackageId() {
|
||||||
|
return referencedPackageId;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the full preferences map of the board with a given identifier
|
* Get the full preferences map of the board with a given identifier
|
||||||
*
|
*
|
||||||
@ -88,6 +116,10 @@ public class TargetBoard {
|
|||||||
return getMenuLabels(menuId).get(selectionId);
|
return getMenuLabels(menuId).get(selectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> getMenuIds() {
|
||||||
|
return menuOptions.keySet();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the configuration parameters to override (as a PreferenceMap) when
|
* Returns the configuration parameters to override (as a PreferenceMap) when
|
||||||
* the specified option in the specified menu is selected
|
* the specified option in the specified menu is selected
|
||||||
@ -98,7 +130,46 @@ public class TargetBoard {
|
|||||||
* The option ID
|
* The option ID
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public PreferencesMap getMenuConfiguration(String menuId, String selectionId) {
|
public PreferencesMap getMenuPreferences(String menuId, String selectionId) {
|
||||||
return menuOptions.get(menuId).subTree(selectionId);
|
return menuOptions.get(menuId).subTree(selectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TargetPlatform getContainerPlatform() {
|
||||||
|
return containerPlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
|
||||||
|
throws Exception {
|
||||||
|
if (referencedPackageId == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!packages.containsKey(referencedPackageId))
|
||||||
|
throw new Exception(
|
||||||
|
format(_("Can't find referenced package ({1}) for board {0}"), id,
|
||||||
|
referencedPackageId));
|
||||||
|
referencedPackage = packages.get(referencedPackageId);
|
||||||
|
|
||||||
|
Map<String, TargetPlatform> platforms = referencedPackage.getPlatforms();
|
||||||
|
|
||||||
|
String ourPlatformId = getContainerPlatform().getId();
|
||||||
|
if (!platforms.containsKey(ourPlatformId))
|
||||||
|
throw new Exception(
|
||||||
|
format(_("Can't find referenced package ({1}) for board {0}"), id,
|
||||||
|
referencedPackageId));
|
||||||
|
referencedPlatform = platforms.get(ourPlatformId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TargetPlatform getReferencedPlatform() {
|
||||||
|
return referencedPlatform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PreferencesMap getMergedPlatformPreferences() {
|
||||||
|
PreferencesMap res = new PreferencesMap();
|
||||||
|
if (referencedPlatform != null)
|
||||||
|
res.putAll(referencedPlatform.getPreferences());
|
||||||
|
if (containerPlatform.getPreferences() != null)
|
||||||
|
res.putAll(containerPlatform.getPreferences());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -32,23 +32,22 @@ import processing.app.helpers.filefilters.OnlyDirs;
|
|||||||
|
|
||||||
public class TargetPackage {
|
public class TargetPackage {
|
||||||
|
|
||||||
private String name;
|
private String id;
|
||||||
|
|
||||||
Map<String, TargetPlatform> platforms = new LinkedHashMap<String, TargetPlatform>();
|
Map<String, TargetPlatform> platforms = new LinkedHashMap<String, TargetPlatform>();
|
||||||
|
|
||||||
public TargetPackage(String packageName, File packageFolder)
|
public TargetPackage(String _id, File _folder) throws TargetPlatformException {
|
||||||
throws TargetPlatformException {
|
id = _id;
|
||||||
name = packageName;
|
|
||||||
|
|
||||||
File[] folders = packageFolder.listFiles(new OnlyDirs());
|
File[] folders = _folder.listFiles(new OnlyDirs());
|
||||||
if (folders == null)
|
if (folders == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (File folder : folders) {
|
for (File subFolder : folders) {
|
||||||
if (!folder.exists() || !folder.canRead())
|
if (!subFolder.exists() || !subFolder.canRead())
|
||||||
continue;
|
continue;
|
||||||
String arch = folder.getName();
|
String arch = subFolder.getName();
|
||||||
TargetPlatform platform = new TargetPlatform(arch, folder);
|
TargetPlatform platform = new TargetPlatform(arch, subFolder, this);
|
||||||
platforms.put(arch, platform);
|
platforms.put(arch, platform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +64,13 @@ public class TargetPackage {
|
|||||||
return platforms.get(platform);
|
return platforms.get(platform);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
|
||||||
return name;
|
throws Exception {
|
||||||
|
for (TargetPlatform platform : getPlatforms().values())
|
||||||
|
platform.resolveReferencedPlatforms(packages);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,9 @@ import processing.app.helpers.PreferencesMap;
|
|||||||
|
|
||||||
public class TargetPlatform {
|
public class TargetPlatform {
|
||||||
|
|
||||||
private String name;
|
private String id;
|
||||||
private File folder;
|
private File folder;
|
||||||
|
private TargetPackage containerPackage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains preferences for every defined board
|
* Contains preferences for every defined board
|
||||||
@ -59,10 +60,12 @@ public class TargetPlatform {
|
|||||||
*/
|
*/
|
||||||
private PreferencesMap customMenus = new PreferencesMap();
|
private PreferencesMap customMenus = new PreferencesMap();
|
||||||
|
|
||||||
public TargetPlatform(String _name, File _folder)
|
public TargetPlatform(String _name, File _folder, TargetPackage parent)
|
||||||
throws TargetPlatformException {
|
throws TargetPlatformException {
|
||||||
name = _name;
|
|
||||||
|
id = _name;
|
||||||
folder = _folder;
|
folder = _folder;
|
||||||
|
containerPackage = parent;
|
||||||
|
|
||||||
// If there is no boards.txt, this is not a valid 1.5 hardware folder
|
// If there is no boards.txt, this is not a valid 1.5 hardware folder
|
||||||
File boardsFile = new File(folder, "boards.txt");
|
File boardsFile = new File(folder, "boards.txt");
|
||||||
@ -85,7 +88,7 @@ public class TargetPlatform {
|
|||||||
// Create boards
|
// Create boards
|
||||||
for (String id : boardsPreferences.keySet()) {
|
for (String id : boardsPreferences.keySet()) {
|
||||||
PreferencesMap preferences = boardsPreferences.get(id);
|
PreferencesMap preferences = boardsPreferences.get(id);
|
||||||
TargetBoard board = new TargetBoard(id, preferences);
|
TargetBoard board = new TargetBoard(id, preferences, this);
|
||||||
boards.put(id, board);
|
boards.put(id, board);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -116,8 +119,8 @@ public class TargetPlatform {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getId() {
|
||||||
return name;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getFolder() {
|
public File getFolder() {
|
||||||
@ -132,7 +135,7 @@ public class TargetPlatform {
|
|||||||
return customMenus;
|
return customMenus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getCustomMenusKeys() {
|
public Set<String> getCustomMenuIds() {
|
||||||
return customMenus.keySet();
|
return customMenus.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,4 +158,22 @@ public class TargetPlatform {
|
|||||||
public TargetBoard getBoard(String boardId) {
|
public TargetBoard getBoard(String boardId) {
|
||||||
return boards.get(boardId);
|
return boards.get(boardId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TargetPackage getContainerPackage() {
|
||||||
|
return containerPackage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resolveReferencedPlatforms(Map<String, TargetPackage> packages)
|
||||||
|
throws Exception {
|
||||||
|
for (TargetBoard board : getBoards().values())
|
||||||
|
board.resolveReferencedPlatforms(packages);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
String res = "TargetPlatform: name=" + id + " boards={\n";
|
||||||
|
for (String boardId : boards.keySet())
|
||||||
|
res += " " + boardId + " = " + boards.get(boardId) + "\n";
|
||||||
|
return res + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,11 @@ public class ThinkDifferent implements ApplicationListener {
|
|||||||
public void handleOpenFile(ApplicationEvent ae) {
|
public void handleOpenFile(ApplicationEvent ae) {
|
||||||
// System.out.println("got open file event " + ae.getFilename());
|
// System.out.println("got open file event " + ae.getFilename());
|
||||||
String filename = ae.getFilename();
|
String filename = ae.getFilename();
|
||||||
base.handleOpen(filename);
|
try {
|
||||||
|
base.handleOpen(filename);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
ae.setHandled(true);
|
ae.setHandled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user