Moved getBoardPreferences() and related methods from Base to BaseNoGui (work in progress).

This commit is contained in:
Claudio Indellicati 2014-08-21 13:38:28 +02:00 committed by Cristian Maglie
parent 4c1b187313
commit 4443911746
3 changed files with 30 additions and 19 deletions

View File

@ -2091,20 +2091,7 @@ public class Base {
}
static public PreferencesMap getBoardPreferences() {
TargetBoard board = getTargetBoard();
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
for (String menuId : board.getMenuIds()) {
String entry = Preferences.get("custom_" + menuId);
if (board.hasMenu(menuId) && entry != null &&
entry.startsWith(board.getId())) {
String selectionId = entry.substring(entry.indexOf("_") + 1);
prefs.putAll(board.getMenuPreferences(menuId, selectionId));
prefs.put("name", prefs.get("name") + ", " +
board.getMenuLabel(menuId, selectionId));
}
}
return prefs;
return BaseNoGui.getBoardPreferences();
}
public static TargetBoard getTargetBoard() {

View File

@ -7,10 +7,12 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import processing.app.debug.TargetBoard;
import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform;
import processing.app.debug.TargetPlatformException;
import processing.app.helpers.OSUtils;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.filefilters.OnlyDirs;
public class BaseNoGui {
@ -54,6 +56,23 @@ public class BaseNoGui {
return path;
}
static public PreferencesMap getBoardPreferences() {
TargetBoard board = getTargetBoard();
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
for (String menuId : board.getMenuIds()) {
String entry = Preferences.get("custom_" + menuId);
if (board.hasMenu(menuId) && entry != null &&
entry.startsWith(board.getId())) {
String selectionId = entry.substring(entry.indexOf("_") + 1);
prefs.putAll(board.getMenuPreferences(menuId, selectionId));
prefs.put("name", prefs.get("name") + ", " +
board.getMenuLabel(menuId, selectionId));
}
}
return prefs;
}
static public File getContentFile(String name) {
String path = System.getProperty("user.dir");
@ -99,6 +118,11 @@ public class BaseNoGui {
return new File(getSketchbookFolder(), "hardware");
}
public static TargetBoard getTargetBoard() {
String boardId = Preferences.get("board");
return getTargetPlatform().getBoard(boardId);
}
/**
* Returns the currently selected TargetPlatform.
*

View File

@ -178,7 +178,7 @@ public class Compiler implements MessageConsumer {
String _primaryClassName)
throws RunnerException {
if (Base.getBoardPreferences() == null) {
if (BaseNoGui.getBoardPreferences() == null) {
RunnerException re = new RunnerException(
_("No board selected; please choose a board from the Tools > Board menu."));
re.hideStackTrace();
@ -188,12 +188,12 @@ public class Compiler implements MessageConsumer {
// Check if the board needs a platform from another package
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
TargetPlatform corePlatform = null;
PreferencesMap boardPreferences = Base.getBoardPreferences();
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
String core = boardPreferences.get("build.core");
if (core.contains(":")) {
String[] split = core.split(":");
core = split[1];
corePlatform = Base.getTargetPlatform(split[0], targetPlatform.getId());
corePlatform = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId());
if (corePlatform == null) {
RunnerException re = new RunnerException(I18n
.format(_("Selected board depends on '{0}' core (not installed)."),
@ -209,7 +209,7 @@ public class Compiler implements MessageConsumer {
if (corePlatform != null)
p.putAll(corePlatform.getPreferences());
p.putAll(targetPlatform.getPreferences());
p.putAll(Base.getBoardPreferences());
p.putAll(BaseNoGui.getBoardPreferences());
for (String k : p.keySet()) {
if (p.get(k) == null)
p.put(k, "");
@ -250,7 +250,7 @@ public class Compiler implements MessageConsumer {
t = targetPlatform;
} else {
String[] split = variant.split(":", 2);
t = Base.getTargetPlatform(split[0], targetPlatform.getId());
t = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId());
variant = split[1];
}
File variantFolder = new File(t.getFolder(), "variants");