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