Skip to content

Commit fa26825

Browse files
committed
Majority of non Compiler.java changes made.
1 parent 41600a2 commit fa26825

File tree

5 files changed

+102
-5
lines changed

5 files changed

+102
-5
lines changed

app/src/processing/app/Base.java

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,20 @@ public void rebuildImportMenu(JMenu importMenu) {
956956
importToLibraryTable = new HashMap<String, File>();
957957

958958
// Add from the "libraries" subfolder in the Processing directory
959+
//Choose which library to add by chip platform
960+
959961
try {
960-
addLibraries(importMenu, librariesFolder);
962+
//Find the current target. Get the platform, and then select the correct name and core path.
963+
String platformname = this.getBoardPreferences().get("platform");
964+
String targetname = this.getPlatformPreferences(platformname).get("name");
965+
String libraryPath = this.getPlatformPreferences(platformname).get("library.core.path");
966+
967+
JMenuItem platformItem = new JMenuItem(targetname);
968+
platformItem.setEnabled(false);
969+
importMenu.add(platformItem);
970+
importMenu.addSeparator();
971+
addLibraries(importMenu, getCoreLibraries(libraryPath));
972+
961973
} catch (IOException e) {
962974
e.printStackTrace();
963975
}
@@ -1005,6 +1017,8 @@ public void actionPerformed(ActionEvent actionevent) {
10051017
//System.out.println("Switching to " + target + ":" + board);
10061018
Preferences.set("target", (String) getValue("target"));
10071019
Preferences.set("board", (String) getValue("board"));
1020+
//Debug: created new imports menu based on board
1021+
rebuildImportMenu(activeEditor.importMenu);
10081022
}
10091023
};
10101024
action.putValue("target", target.getName());
@@ -1518,6 +1532,10 @@ static public File getHardwareFolder() {
15181532
return getContentFile("hardware");
15191533
}
15201534

1535+
//Get the core libraries
1536+
static public File getCoreLibraries(String path) {
1537+
return getContentFile(path);
1538+
}
15211539

15221540
static public String getHardwarePath() {
15231541
return getHardwareFolder().getAbsolutePath();
@@ -1538,7 +1556,32 @@ static public Target getTarget() {
15381556
return Base.targetsTable.get(Preferences.get("target"));
15391557
}
15401558

1541-
1559+
1560+
static public Map<String, String> getPlatformPreferences() {
1561+
Target target = getTarget();
1562+
//if (target == null) return new LinkedHashMap();
1563+
Map map = target.getPlatforms();
1564+
/*
1565+
if (map == null)
1566+
{
1567+
System.err.println("Error loading platforms preference from Target");
1568+
System.exit(0);
1569+
}
1570+
*/
1571+
//if (map == null) return new LinkedHashMap();
1572+
map = (Map) map.get(Preferences.get("platform"));
1573+
//if (map == null) return new LinkedHashMap();
1574+
return map;
1575+
}
1576+
1577+
//Get a specific platform
1578+
static public Map<String, String> getPlatformPreferences(String platformname) {
1579+
Target target = getTarget();
1580+
Map map = target.getPlatforms();
1581+
map = (Map) map.get(platformname);
1582+
return map;
1583+
}
1584+
15421585
static public Map<String, String> getBoardPreferences() {
15431586
Target target = getTarget();
15441587
if (target == null) return new LinkedHashMap();

app/src/processing/app/Editor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,9 @@ public void actionPerformed(ActionEvent e) {
684684
if (boardsMenu == null) {
685685
boardsMenu = new JMenu("Board");
686686
base.rebuildBoardsMenu(boardsMenu);
687+
//Debug: rebuild imports
688+
importMenu.removeAll();
689+
base.rebuildImportMenu(importMenu);
687690
}
688691
menu.add(boardsMenu);
689692

app/src/processing/app/Preferences.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,4 +776,22 @@ static public SyntaxStyle getStyle(String what /*, String dflt*/) {
776776

777777
return new SyntaxStyle(color, italic, bold);
778778
}
779+
780+
//get a Map of the Preferences
781+
static public Map<String, String> getMap()
782+
{
783+
Map globalpreferences = new LinkedHashMap();
784+
Enumeration e = table.keys();
785+
786+
while (e.hasMoreElements())
787+
{
788+
String key = (String) e.nextElement();
789+
//System.out.println("Key: " + key + "Val: " + table.get(key));
790+
String value = (String) table.get(key);
791+
globalpreferences.put(key, value );
792+
}
793+
794+
return globalpreferences;
795+
}
796+
779797
}

app/src/processing/app/Sketch.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,10 +1328,14 @@ public String preprocess(String buildPath, PdePreprocessor preprocessor) throws
13281328
// grab the imports from the code just preproc'd
13291329

13301330
importedLibraries = new ArrayList<File>();
1331-
1331+
//Remember to clear library path before building it.
1332+
libraryPath = "";
13321333
for (String item : preprocessor.getExtraImports()) {
13331334
File libFolder = (File) Base.importToLibraryTable.get(item);
13341335

1336+
File libFolder = (File) Base.importToLibraryTable.get(item);
1337+
//Debug libraryPath
1338+
13351339
if (libFolder != null && !importedLibraries.contains(libFolder)) {
13361340
importedLibraries.add(libFolder);
13371341
//classPath += Compiler.contentsToClassPath(libFolder);

app/src/processing/app/debug/Target.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,21 @@
2929
import java.util.*;
3030

3131
import processing.app.Preferences;
32+
//import processing.app.Base;
3233

3334
public class Target {
3435
private String name;
3536
private File folder;
3637
private Map boards;
3738
private Map programmers;
38-
39+
private Map platforms;
40+
3941
public Target(String name, File folder) {
4042
this.name = name;
4143
this.folder = folder;
4244
this.boards = new LinkedHashMap();
4345
this.programmers = new LinkedHashMap();
46+
this.platforms = new LinkedHashMap();
4447

4548
File boardsFile = new File(folder, "boards.txt");
4649
try {
@@ -60,6 +63,28 @@ public Target(String name, File folder) {
6063
System.err.println("Error loading boards from " + boardsFile + ": " + e);
6164
}
6265

66+
File platformsFile = new File(folder,"platforms.txt");
67+
try
68+
{
69+
if(platformsFile.exists()){
70+
Map platformPreferences = new LinkedHashMap();
71+
Preferences.load(new FileInputStream(platformsFile), platformPreferences);
72+
for(Object k : platformPreferences.keySet())
73+
{
74+
String key=(String) k;
75+
String platform=key.substring(0,key.indexOf('.'));
76+
if (!platforms.containsKey(platform)) platforms.put(platform, new HashMap());
77+
((Map) platforms.get(platform)).put(key.substring(key.indexOf('.') + 1),platformPreferences.get(key));
78+
}
79+
}
80+
} catch (Exception e) {
81+
System.err.println("Error loading platforms from " +
82+
platformsFile + ": " + e);
83+
// System.exit(0);
84+
85+
}
86+
87+
6388
File programmersFile = new File(folder, "programmers.txt");
6489
try {
6590
if (programmersFile.exists()) {
@@ -88,4 +113,8 @@ public Map<String, Map<String, String>> getBoards() {
88113
public Map<String, Map<String, String>> getProgrammers() {
89114
return programmers;
90115
}
91-
}
116+
public Map<String, Map<String, String>> getPlatforms() {
117+
return platforms;
118+
}
119+
120+
}

0 commit comments

Comments
 (0)