diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 687a21f6d..2950ade52 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -75,12 +75,6 @@ public class Base { static File buildFolder; - // these are static because they're used by Sketch - static private File examplesFolder; - static private File toolsFolder; - - static private List librariesFolders; - // classpath for all known libraries for p5 // (both those in the p5/libs folder and those with lib subfolders // found in the sketchbook) @@ -1161,7 +1155,7 @@ public class Base { // Add each of the subfolders of examples directly to the menu try { - boolean found = addSketches(menu, examplesFolder, true); + boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), true); if (found) menu.addSeparator(); } catch (IOException e) { e.printStackTrace(); @@ -1245,7 +1239,7 @@ public class Base { menu.removeAll(); // Add examples from distribution "example" folder - boolean found = addSketches(menu, examplesFolder, false); + boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), false); if (found) menu.addSeparator(); // Add examples from libraries @@ -1275,39 +1269,7 @@ public class Base { } public void onBoardOrPortChange() { - TargetPlatform targetPlatform = getTargetPlatform(); - if (targetPlatform == null) - return; - - // Calculate paths for libraries and examples - examplesFolder = getContentFile("examples"); - toolsFolder = getContentFile("tools"); - - File platformFolder = targetPlatform.getFolder(); - librariesFolders = new ArrayList(); - librariesFolders.add(getContentFile("libraries")); - String core = getBoardPreferences().get("build.core"); - if (core.contains(":")) { - String referencedCore = core.split(":")[0]; - TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId()); - if (referencedPlatform != null) { - File referencedPlatformFolder = referencedPlatform.getFolder(); - librariesFolders.add(new File(referencedPlatformFolder, "libraries")); - } - } - librariesFolders.add(new File(platformFolder, "libraries")); - librariesFolders.add(getSketchbookLibrariesFolder()); - - // Scan for libraries in each library folder. - // Libraries located in the latest folders on the list can override - // other libraries with the same name. - try { - BaseNoGui.scanAndUpdateLibraries(librariesFolders); - } catch (IOException e) { - showWarning(_("Error"), _("Error loading libraries"), e); - } - - BaseNoGui.populateImportToLibraryTable(); + BaseNoGui.onBoardOrPortChange(); // Update editors status bar for (Editor editor : editors) @@ -1897,22 +1859,22 @@ public class Base { static public String getExamplesPath() { - return examplesFolder.getAbsolutePath(); + return BaseNoGui.getExamplesPath(); } static public List getLibrariesPath() { - return librariesFolders; + return BaseNoGui.getLibrariesPath(); } static public File getToolsFolder() { - return toolsFolder; + return BaseNoGui.getToolsFolder(); } static public String getToolsPath() { - return toolsFolder.getAbsolutePath(); + return BaseNoGui.getToolsPath(); } @@ -1994,19 +1956,7 @@ public class Base { static public File getSketchbookLibrariesFolder() { - File libdir = new File(getSketchbookFolder(), "libraries"); - if (!libdir.exists()) { - try { - libdir.mkdirs(); - File readme = new File(libdir, "readme.txt"); - FileWriter freadme = new FileWriter(readme); - freadme.write(_("For information on installing libraries, see: " + - "http://arduino.cc/en/Guide/Libraries\n")); - freadme.close(); - } catch (Exception e) { - } - } - return libdir; + return BaseNoGui.getSketchbookLibrariesFolder(); } diff --git a/app/src/processing/app/BaseNoGui.java b/app/src/processing/app/BaseNoGui.java index 815e96b9f..d62ce1682 100644 --- a/app/src/processing/app/BaseNoGui.java +++ b/app/src/processing/app/BaseNoGui.java @@ -4,8 +4,10 @@ import static processing.app.I18n._; import java.io.File; import java.io.FileInputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; @@ -47,12 +49,18 @@ public class BaseNoGui { private static DiscoveryManager discoveryManager = new DiscoveryManager(); + // these are static because they're used by Sketch + static private File examplesFolder; + static private File toolsFolder; + // maps #included files to their library folder public static Map importToLibraryTable; // maps library name to their library folder static private LibraryList libraries; + static private List librariesFolders; + static UserNotifier notifier = new BasicUserNotifier(); static public Map packages; @@ -137,6 +145,14 @@ public class BaseNoGui { return discoveryManager; } + static public File getExamplesFolder() { + return examplesFolder; + } + + static public String getExamplesPath() { + return examplesFolder.getAbsolutePath(); + } + static public File getHardwareFolder() { // calculate on the fly because it's needed by Preferences.init() to find // the boards.txt and programmers.txt preferences files (which happens @@ -152,6 +168,10 @@ public class BaseNoGui { return libraries; } + static public List getLibrariesPath() { + return librariesFolders; + } + /** * Return an InputStream for a file inside the Processing lib folder. */ @@ -218,6 +238,22 @@ public class BaseNoGui { return new File(getSketchbookFolder(), "hardware"); } + static public File getSketchbookLibrariesFolder() { + File libdir = new File(getSketchbookFolder(), "libraries"); + if (!libdir.exists()) { + try { + libdir.mkdirs(); + File readme = new File(libdir, "readme.txt"); + FileWriter freadme = new FileWriter(readme); + freadme.write(_("For information on installing libraries, see: " + + "http://arduino.cc/en/Guide/Libraries\n")); + freadme.close(); + } catch (Exception e) { + } + } + return libdir; + } + public static TargetBoard getTargetBoard() { String boardId = PreferencesData.get("board"); return getTargetPlatform().getBoard(boardId); @@ -249,6 +285,14 @@ public class BaseNoGui { return p.get(platformName); } + static public File getToolsFolder() { + return toolsFolder; + } + + static public String getToolsPath() { + return toolsFolder.getAbsolutePath(); + } + static public LibraryList getUserLibs() { if (libraries == null) return new LibraryList(); @@ -370,6 +414,42 @@ public class BaseNoGui { return PApplet.join(contents, "\n"); } + static public void onBoardOrPortChange() { + TargetPlatform targetPlatform = getTargetPlatform(); + if (targetPlatform == null) + return; + + // Calculate paths for libraries and examples + examplesFolder = getContentFile("examples"); + toolsFolder = getContentFile("tools"); + + File platformFolder = targetPlatform.getFolder(); + librariesFolders = new ArrayList(); + librariesFolders.add(getContentFile("libraries")); + String core = getBoardPreferences().get("build.core"); + if (core.contains(":")) { + String referencedCore = core.split(":")[0]; + TargetPlatform referencedPlatform = getTargetPlatform(referencedCore, targetPlatform.getId()); + if (referencedPlatform != null) { + File referencedPlatformFolder = referencedPlatform.getFolder(); + librariesFolders.add(new File(referencedPlatformFolder, "libraries")); + } + } + librariesFolders.add(new File(platformFolder, "libraries")); + librariesFolders.add(getSketchbookLibrariesFolder()); + + // Scan for libraries in each library folder. + // Libraries located in the latest folders on the list can override + // other libraries with the same name. + try { + scanAndUpdateLibraries(librariesFolders); + } catch (IOException e) { + showWarning(_("Error"), _("Error loading libraries"), e); + } + + populateImportToLibraryTable(); + } + static public void populateImportToLibraryTable() { // Populate importToLibraryTable importToLibraryTable = new HashMap();