Skip to content

Commit 2f8e766

Browse files
committed
Reordered boards menu
1 parent b2f1bce commit 2f8e766

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

app/src/processing/app/Base.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,10 @@ public void rebuildBoardsMenu(JMenu menu) {
11131113
String selBoard = Preferences.get("board");
11141114

11151115
menu.removeAll();
1116+
boolean first = true;
1117+
11161118
ButtonGroup group = new ButtonGroup();
1119+
11171120
// Cycle through all packages
11181121
for (TargetPackage targetPackage : packages.values()) {
11191122
String packageName = targetPackage.getName();
@@ -1123,8 +1126,16 @@ public void rebuildBoardsMenu(JMenu menu) {
11231126
String platformName = targetPlatform.getName();
11241127
Map<String, PreferencesMap> boards = targetPlatform.getBoards();
11251128

1126-
// For every platform cycle throug all boards
1127-
for (String board : boards.keySet()) {
1129+
// Add a title for each group of boards
1130+
if (!first)
1131+
menu.add(new JSeparator());
1132+
first = false;
1133+
JMenuItem separator = new JMenuItem(targetPlatform.getPreferences().get("name"));
1134+
separator.setEnabled(false);
1135+
menu.add(separator);
1136+
1137+
// For every platform cycle through all boards
1138+
for (String board : targetPlatform.getOrderedBoards()) {
11281139

11291140
// Setup a menu item for the current board
11301141
String boardName = boards.get(board).get("name");

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

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

2626
import java.io.File;
27+
import java.util.ArrayList;
2728
import java.util.HashMap;
29+
import java.util.List;
2830
import java.util.Map;
2931

3032
import processing.app.helpers.PreferencesMap;
33+
import processing.core.PApplet;
3134

3235
public class TargetPlatform {
3336
private String name;
3437
private File folder;
3538
private Map<String, PreferencesMap> boards;
39+
private List<String> boardsOrder;
3640
private Map<String, PreferencesMap> programmers;
3741
private PreferencesMap preferences;
3842

@@ -50,6 +54,7 @@ public TargetPlatform(String _name, File _folder) {
5054
PreferencesMap boardPreferences = new PreferencesMap();
5155
boardPreferences.load(boardsFile);
5256
boards = boardPreferences.createFirstLevelMap();
57+
boardsOrder = readBoardsOrder(boardsFile);
5358
}
5459
} catch (Exception e) {
5560
System.err.println("Error loading boards from boards.txt: " + e);
@@ -76,6 +81,32 @@ public TargetPlatform(String _name, File _folder) {
7681
}
7782
}
7883

84+
/**
85+
* Loads the ordered list of boards as they appears on the boards.txt file
86+
*
87+
* @param boardsFile
88+
* @return
89+
*/
90+
private List<String> readBoardsOrder(File boardsFile) {
91+
String[] strings = PApplet.loadStrings(boardsFile);
92+
93+
List<String> res = new ArrayList<String>();
94+
String latestBoard = "-";
95+
for (String s : strings) {
96+
int dot = s.indexOf('.');
97+
if (dot == -1)
98+
continue;
99+
String board = s.substring(0, dot);
100+
if (board.equals(latestBoard))
101+
continue;
102+
if (!boards.containsKey(board))
103+
continue;
104+
latestBoard = board;
105+
res.add(board);
106+
}
107+
return res;
108+
}
109+
79110
public String getName() {
80111
return name;
81112
}
@@ -87,6 +118,10 @@ public File getFolder() {
87118
public Map<String, PreferencesMap> getBoards() {
88119
return boards;
89120
}
121+
122+
public List<String> getOrderedBoards() {
123+
return boardsOrder;
124+
}
90125

91126
public Map<String, PreferencesMap> getProgrammers() {
92127
return programmers;

hardware/arduino/avr/platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# AVR compile variables
33
# ---------------------
44

5-
name=Arduino
5+
name=Arduino AVR Boards
66
# Default "compiler.path" is correct, change only if you want to overidde the initial value
77
#compiler.path={ide.path}/tools/avr/bin/..
88
compiler.c.cmd=avr-gcc

hardware/arduino/sam/platform.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SAM3 compile variables
33
# ---------------------
44

5-
name=Atmel SAM3
5+
name=Arduino ARM (32-bits) Boards
66
compiler.path={runtime.ide.path}/hardware/tools/g++_arm_none_eabi/bin/
77
#compiler.path=C:/arm-none-eabi-gcc-4_6/bin/
88
compiler.c.cmd=arm-none-eabi-gcc

0 commit comments

Comments
 (0)