Skip to content

Commit 4443911

Browse files
bitroncmaglie
authored andcommitted
Moved getBoardPreferences() and related methods from Base to BaseNoGui (work in progress).
1 parent 4c1b187 commit 4443911

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

app/src/processing/app/Base.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,20 +2091,7 @@ static public TargetPlatform getCurrentTargetPlatformFromPackage(String pack) {
20912091
}
20922092

20932093
static public PreferencesMap getBoardPreferences() {
2094-
TargetBoard board = getTargetBoard();
2095-
2096-
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
2097-
for (String menuId : board.getMenuIds()) {
2098-
String entry = Preferences.get("custom_" + menuId);
2099-
if (board.hasMenu(menuId) && entry != null &&
2100-
entry.startsWith(board.getId())) {
2101-
String selectionId = entry.substring(entry.indexOf("_") + 1);
2102-
prefs.putAll(board.getMenuPreferences(menuId, selectionId));
2103-
prefs.put("name", prefs.get("name") + ", " +
2104-
board.getMenuLabel(menuId, selectionId));
2105-
}
2106-
}
2107-
return prefs;
2094+
return BaseNoGui.getBoardPreferences();
21082095
}
21092096

21102097
public static TargetBoard getTargetBoard() {

app/src/processing/app/BaseNoGui.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import java.util.HashMap;
88
import java.util.Map;
99

10+
import processing.app.debug.TargetBoard;
1011
import processing.app.debug.TargetPackage;
1112
import processing.app.debug.TargetPlatform;
1213
import processing.app.debug.TargetPlatformException;
1314
import processing.app.helpers.OSUtils;
15+
import processing.app.helpers.PreferencesMap;
1416
import processing.app.helpers.filefilters.OnlyDirs;
1517

1618
public class BaseNoGui {
@@ -54,6 +56,23 @@ static public String getAvrBasePath() {
5456
return path;
5557
}
5658

59+
static public PreferencesMap getBoardPreferences() {
60+
TargetBoard board = getTargetBoard();
61+
62+
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
63+
for (String menuId : board.getMenuIds()) {
64+
String entry = Preferences.get("custom_" + menuId);
65+
if (board.hasMenu(menuId) && entry != null &&
66+
entry.startsWith(board.getId())) {
67+
String selectionId = entry.substring(entry.indexOf("_") + 1);
68+
prefs.putAll(board.getMenuPreferences(menuId, selectionId));
69+
prefs.put("name", prefs.get("name") + ", " +
70+
board.getMenuLabel(menuId, selectionId));
71+
}
72+
}
73+
return prefs;
74+
}
75+
5776
static public File getContentFile(String name) {
5877
String path = System.getProperty("user.dir");
5978

@@ -99,6 +118,11 @@ static public File getSketchbookHardwareFolder() {
99118
return new File(getSketchbookFolder(), "hardware");
100119
}
101120

121+
public static TargetBoard getTargetBoard() {
122+
String boardId = Preferences.get("board");
123+
return getTargetPlatform().getBoard(boardId);
124+
}
125+
102126
/**
103127
* Returns the currently selected TargetPlatform.
104128
*

app/src/processing/app/debug/Compiler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
178178
String _primaryClassName)
179179
throws RunnerException {
180180

181-
if (Base.getBoardPreferences() == null) {
181+
if (BaseNoGui.getBoardPreferences() == null) {
182182
RunnerException re = new RunnerException(
183183
_("No board selected; please choose a board from the Tools > Board menu."));
184184
re.hideStackTrace();
@@ -188,12 +188,12 @@ private PreferencesMap createBuildPreferences(String _buildPath,
188188
// Check if the board needs a platform from another package
189189
TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform();
190190
TargetPlatform corePlatform = null;
191-
PreferencesMap boardPreferences = Base.getBoardPreferences();
191+
PreferencesMap boardPreferences = BaseNoGui.getBoardPreferences();
192192
String core = boardPreferences.get("build.core");
193193
if (core.contains(":")) {
194194
String[] split = core.split(":");
195195
core = split[1];
196-
corePlatform = Base.getTargetPlatform(split[0], targetPlatform.getId());
196+
corePlatform = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId());
197197
if (corePlatform == null) {
198198
RunnerException re = new RunnerException(I18n
199199
.format(_("Selected board depends on '{0}' core (not installed)."),
@@ -209,7 +209,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
209209
if (corePlatform != null)
210210
p.putAll(corePlatform.getPreferences());
211211
p.putAll(targetPlatform.getPreferences());
212-
p.putAll(Base.getBoardPreferences());
212+
p.putAll(BaseNoGui.getBoardPreferences());
213213
for (String k : p.keySet()) {
214214
if (p.get(k) == null)
215215
p.put(k, "");
@@ -250,7 +250,7 @@ private PreferencesMap createBuildPreferences(String _buildPath,
250250
t = targetPlatform;
251251
} else {
252252
String[] split = variant.split(":", 2);
253-
t = Base.getTargetPlatform(split[0], targetPlatform.getId());
253+
t = BaseNoGui.getTargetPlatform(split[0], targetPlatform.getId());
254254
variant = split[1];
255255
}
256256
File variantFolder = new File(t.getFolder(), "variants");

0 commit comments

Comments
 (0)