Skip to content

Commit c851f47

Browse files
committed
fixed board and custom menus order
removed readBoardsOrder
1 parent 9b7f473 commit c851f47

File tree

4 files changed

+19
-63
lines changed

4 files changed

+19
-63
lines changed

app/src/processing/app/Base.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) {
11461146
String platformName = targetPlatform.getName();
11471147
Map<String, PreferencesMap> boards = targetPlatform.getBoards();
11481148

1149-
if (targetPlatform.getPreferences().get("name") == null || targetPlatform.getOrderedBoards().isEmpty()) {
1149+
if (targetPlatform.getPreferences().get("name") == null || targetPlatform.getBoards().isEmpty()) {
11501150
continue;
11511151
}
11521152

@@ -1161,7 +1161,7 @@ public void rebuildBoardsMenu(JMenu toolsMenu, final Editor editor) {
11611161
boardsMenu.add(separator);
11621162

11631163
// For every platform cycle through all boards
1164-
for (final String boardID : targetPlatform.getOrderedBoards()) {
1164+
for (final String boardID : targetPlatform.getBoards().keySet()) {
11651165

11661166
PreferencesMap boardAttributes = boards.get(boardID);
11671167

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@
2424
package processing.app.debug;
2525

2626
import java.io.File;
27-
import java.util.ArrayList;
2827
import java.util.HashMap;
29-
import java.util.List;
3028
import java.util.Map;
3129

3230
import processing.app.helpers.PreferencesMap;
3331
import processing.app.tools.MapWithSubkeys;
34-
import processing.core.PApplet;
3532

3633
public class TargetPlatform {
3734
private String name;
3835
private File folder;
3936
private Map<String, PreferencesMap> boards;
40-
private List<String> boardsOrder;
4137
private Map<String, PreferencesMap> programmers;
4238
private PreferencesMap preferences;
4339
private MapWithSubkeys customMenus;
@@ -47,7 +43,6 @@ public TargetPlatform(String _name, File _folder) {
4743
name = _name;
4844
folder = _folder;
4945
boards = new HashMap<String, PreferencesMap>();
50-
boardsOrder = new ArrayList<String>();
5146
programmers = new HashMap<String, PreferencesMap>();
5247
preferences = new PreferencesMap();
5348

@@ -59,7 +54,6 @@ public TargetPlatform(String _name, File _folder) {
5954
boards = boardPreferences.createFirstLevelMap();
6055
customMenus = MapWithSubkeys.createFrom(boards.get("menu"));
6156
boards.remove("menu");
62-
boardsOrder = readBoardsOrder(boardsFile);
6357
}
6458
} catch (Exception e) {
6559
e.printStackTrace();
@@ -87,32 +81,6 @@ public TargetPlatform(String _name, File _folder) {
8781
}
8882
}
8983

90-
/**
91-
* Loads the ordered list of boards as they appears on the boards.txt file
92-
*
93-
* @param boardsFile
94-
* @return
95-
*/
96-
private List<String> readBoardsOrder(File boardsFile) {
97-
String[] strings = PApplet.loadStrings(boardsFile);
98-
99-
List<String> res = new ArrayList<String>();
100-
String latestBoard = "-";
101-
for (String s : strings) {
102-
int dot = s.indexOf('.');
103-
if (dot == -1)
104-
continue;
105-
String board = s.substring(0, dot);
106-
if (board.equals(latestBoard))
107-
continue;
108-
if (!boards.containsKey(board))
109-
continue;
110-
latestBoard = board;
111-
res.add(board);
112-
}
113-
return res;
114-
}
115-
11684
public String getName() {
11785
return name;
11886
}
@@ -129,10 +97,6 @@ public MapWithSubkeys getCustomMenus() {
12997
return customMenus;
13098
}
13199

132-
public List<String> getOrderedBoards() {
133-
return boardsOrder;
134-
}
135-
136100
public Map<String, PreferencesMap> getProgrammers() {
137101
return programmers;
138102
}

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

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,17 @@
2828
import java.io.FileNotFoundException;
2929
import java.io.IOException;
3030
import java.io.InputStream;
31-
import java.util.HashMap;
32-
import java.util.HashSet;
33-
import java.util.Hashtable;
34-
import java.util.Map;
35-
import java.util.Set;
31+
import java.util.*;
3632

3733
import processing.app.Base;
3834
import processing.core.PApplet;
3935

40-
public class PreferencesMap extends HashMap<String, String> {
36+
public class PreferencesMap extends LinkedHashMap<String, String> {
4137

42-
public PreferencesMap(Hashtable<String, String> table) {
38+
public PreferencesMap(Map<String, String> table) {
4339
super(table);
4440
}
4541

46-
public PreferencesMap(PreferencesMap prefs) {
47-
super(prefs);
48-
}
49-
5042
public PreferencesMap() {
5143
super();
5244
}
@@ -86,18 +78,18 @@ public void load(InputStream input) throws IOException {
8678
Set<String> keys = new HashSet<String>(keySet());
8779

8880
// Override keys that have OS specific versions
89-
for (String k : keys) {
81+
for (String key : keys) {
9082
boolean replace = false;
91-
if (Base.isLinux() && k.endsWith(".linux"))
83+
if (Base.isLinux() && key.endsWith(".linux"))
9284
replace = true;
93-
if (Base.isWindows() && k.endsWith(".windows"))
85+
if (Base.isWindows() && key.endsWith(".windows"))
9486
replace = true;
95-
if (Base.isMacOS() && k.endsWith(".macos"))
87+
if (Base.isMacOS() && key.endsWith(".macos"))
9688
replace = true;
9789
if (replace) {
98-
int dot = k.lastIndexOf('.');
99-
String overridenKey = k.substring(0, dot);
100-
put(overridenKey, get(k));
90+
int dot = key.lastIndexOf('.');
91+
String overridenKey = key.substring(0, dot);
92+
put(overridenKey, get(key));
10193
}
10294
}
10395
}
@@ -129,7 +121,7 @@ public void load(InputStream input) throws IOException {
129121
* @return
130122
*/
131123
public Map<String, PreferencesMap> createFirstLevelMap() {
132-
Map<String, PreferencesMap> res = new HashMap<String, PreferencesMap>();
124+
Map<String, PreferencesMap> res = new LinkedHashMap<String, PreferencesMap>();
133125
for (String key : keySet()) {
134126
int dot = key.indexOf('.');
135127
if (dot == -1)

app/src/processing/app/tools/MapWithSubkeys.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package processing.app.tools;
22

3-
import java.util.Collection;
4-
import java.util.HashMap;
5-
import java.util.Map;
3+
import java.util.*;
64
import java.util.Map.Entry;
75

86
public class MapWithSubkeys {
@@ -35,8 +33,8 @@ public static MapWithSubkeys createFrom(Map<String, String> input) {
3533
private final Map<String, MapWithSubkeys> maps;
3634

3735
public MapWithSubkeys() {
38-
this.values = new HashMap<String, String>();
39-
this.maps = new HashMap<String, MapWithSubkeys>();
36+
this.values = new LinkedHashMap<String, String>();
37+
this.maps = new LinkedHashMap<String, MapWithSubkeys>();
4038
}
4139

4240
public Collection<String> getKeys() {
@@ -53,9 +51,11 @@ public String getValueOf(String key) {
5351

5452
public MapWithSubkeys get(String key) {
5553
if (!maps.containsKey(key)) {
56-
put(key, null);
5754
maps.put(key, new MapWithSubkeys());
5855
}
56+
if (!values.containsKey(key)) {
57+
put(key, null);
58+
}
5959
return maps.get(key);
6060
}
6161

0 commit comments

Comments
 (0)