Skip to content

Commit acc477a

Browse files
committed
Other refinement in TargetBoard
1 parent 51c36c7 commit acc477a

File tree

4 files changed

+63
-87
lines changed

4 files changed

+63
-87
lines changed

app/src/processing/app/Base.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,14 +1270,11 @@ public void actionPerformed(ActionEvent actionevent) {
12701270
String title = customMenus.get(menuId);
12711271
JMenu menu = makeOrGetBoardMenu(toolsMenu, _(title));
12721272

1273-
//Map<String, PreferencesMap> customMenu = customMenus.subTree(menuId).firstLevelMap();
1274-
if (board.hasMenuOptions(menuId)) {
1275-
//if (customMenu.containsKey(boardId)) {
1276-
//PreferencesMap boardCustomMenu = customMenu.get(boardId);
1277-
PreferencesMap boardCustomMenu = board.getMenuOptions(menuId);
1273+
if (board.hasMenu(menuId)) {
1274+
PreferencesMap boardCustomMenu = board.getMenuLabels(menuId);
12781275
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
12791276
i++;
1280-
for (String customMenuOption : boardCustomMenu.topLevelKeySet()) {
1277+
for (String customMenuOption : boardCustomMenu.keySet()) {
12811278
@SuppressWarnings("serial")
12821279
Action subAction = new AbstractAction(_(boardCustomMenu.get(customMenuOption))) {
12831280
public void actionPerformed(ActionEvent e) {
@@ -1936,22 +1933,18 @@ static public PreferencesMap getBoardPreferences() {
19361933
TargetPlatform target = getTargetPlatform();
19371934
String boardId = Preferences.get("board");
19381935
TargetBoard board = target.getBoard(boardId);
1939-
PreferencesMap boardPreferences = new PreferencesMap(board.getPreferences());
1940-
PreferencesMap customMenus = target.getCustomMenus();
1941-
for (String menuId : customMenus.keySet()) {
1942-
PreferencesMap boardCustomMenu = board.getMenuOptions(menuId);
1943-
String selectedCustomMenuEntry = Preferences.get("custom_" + menuId);
1944-
if (boardCustomMenu != null && boardCustomMenu.size() > 0 &&
1945-
selectedCustomMenuEntry != null &&
1946-
selectedCustomMenuEntry.startsWith(boardId)) {
1947-
String menuEntryId = selectedCustomMenuEntry
1948-
.substring(selectedCustomMenuEntry.indexOf("_") + 1);
1949-
boardPreferences.putAll(boardCustomMenu.subTree(menuEntryId));
1950-
boardPreferences.put("name", boardPreferences.get("name") + ", " +
1951-
boardCustomMenu.get(menuEntryId));
1952-
}
1953-
}
1954-
return boardPreferences;
1936+
PreferencesMap prefs = new PreferencesMap(board.getPreferences());
1937+
for (String menuId : target.getCustomMenusKeys()) {
1938+
String entry = Preferences.get("custom_" + menuId);
1939+
if (board.hasMenu(menuId) && entry != null &&
1940+
entry.startsWith(boardId)) {
1941+
String selectionId = entry.substring(entry.indexOf("_") + 1);
1942+
prefs.putAll(board.getMenuConfiguration(menuId, selectionId));
1943+
prefs.put("name", prefs.get("name") + ", " +
1944+
board.getMenuLabel(menuId, selectionId));
1945+
}
1946+
}
1947+
return prefs;
19551948
}
19561949

19571950
static public File getPortableFolder() {

app/src/processing/app/debug/TargetBoard.java

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,52 @@ public PreferencesMap getPreferences() {
5353
return prefs;
5454
}
5555

56-
public void setMenuOptions(String menuId, PreferencesMap _menuOptions) {
57-
menuOptions.put(menuId, _menuOptions);
56+
/**
57+
* Check if the board has a sub menu.
58+
*
59+
* @param menuId
60+
* The menu ID to check
61+
* @return
62+
*/
63+
public boolean hasMenu(String menuId) {
64+
return menuOptions.containsKey(menuId);
5865
}
5966

60-
public PreferencesMap getMenuOptions(String menuId) {
61-
return menuOptions.get(menuId);
67+
/**
68+
* Returns the options available on a specific menu
69+
*
70+
* @param menuId
71+
* The menu ID
72+
* @return
73+
*/
74+
public PreferencesMap getMenuLabels(String menuId) {
75+
return menuOptions.get(menuId).topLevelMap();
6276
}
6377

64-
public boolean hasMenuOptions(String menuId) {
65-
return menuOptions.containsKey(menuId);
78+
/**
79+
* Returns the label of the specified option in the specified menu
80+
*
81+
* @param menuId
82+
* The menu ID
83+
* @param selectionId
84+
* The option ID
85+
* @return
86+
*/
87+
public String getMenuLabel(String menuId, String selectionId) {
88+
return getMenuLabels(menuId).get(selectionId);
89+
}
90+
91+
/**
92+
* Returns the configuration parameters to override (as a PreferenceMap) when
93+
* the specified option in the specified menu is selected
94+
*
95+
* @param menuId
96+
* The menu ID
97+
* @param selectionId
98+
* The option ID
99+
* @return
100+
*/
101+
public PreferencesMap getMenuConfiguration(String menuId, String selectionId) {
102+
return menuOptions.get(menuId).subTree(selectionId);
66103
}
67104
}

app/src/processing/app/debug/TargetPlatform.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.util.LinkedHashMap;
3232
import java.util.Map;
33+
import java.util.Set;
3334

3435
import processing.app.helpers.PreferencesMap;
3536

@@ -131,6 +132,10 @@ public PreferencesMap getCustomMenus() {
131132
return customMenus;
132133
}
133134

135+
public Set<String> getCustomMenusKeys() {
136+
return customMenus.keySet();
137+
}
138+
134139
public Map<String, PreferencesMap> getProgrammers() {
135140
return programmers;
136141
}

app/src/processing/app/helpers/PreferencesMap.java

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.io.FileNotFoundException;
2929
import java.io.IOException;
3030
import java.io.InputStream;
31-
import java.util.Collection;
3231
import java.util.LinkedHashMap;
3332
import java.util.LinkedHashSet;
3433
import java.util.Map;
@@ -155,64 +154,6 @@ public PreferencesMap topLevelMap() {
155154
return res;
156155
}
157156

158-
/**
159-
* Returns the values of all the top level pairs of the current mapping. E.g.
160-
* the folowing mapping:<br />
161-
*
162-
* <pre>
163-
* Map (
164-
* alpha = Alpha
165-
* alpha.some.keys = v1
166-
* alpha.other.keys = v2
167-
* beta = Beta
168-
* beta.some.keys = v3
169-
* )
170-
* </pre>
171-
*
172-
* will generate the following result:
173-
*
174-
* <pre>
175-
* Collection (
176-
* Alpha
177-
* Beta
178-
* )
179-
* </pre>
180-
*
181-
* @return
182-
*/
183-
public Collection<String> topLevelValues() {
184-
return topLevelMap().values();
185-
}
186-
187-
/**
188-
* Returns a key set of all the top level pairs of the current mapping. E.g.
189-
* the folowing mapping:<br />
190-
*
191-
* <pre>
192-
* Map (
193-
* alpha = Alpha
194-
* alpha.some.keys = v1
195-
* alpha.other.keys = v2
196-
* beta = Beta
197-
* beta.some.keys = v3
198-
* )
199-
* </pre>
200-
*
201-
* will generate the following result:
202-
*
203-
* <pre>
204-
* Set (
205-
* alpha
206-
* beta
207-
* )
208-
* </pre>
209-
*
210-
* @return
211-
*/
212-
public Set<String> topLevelKeySet() {
213-
return topLevelMap().keySet();
214-
}
215-
216157
/**
217158
* Create a new Map<String, PreferenceMap> where keys are the first level of
218159
* the current mapping. Top level pairs are discarded. E.g. the folowing

0 commit comments

Comments
 (0)