mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
Moved onBoardOrPortChange() and related members/methods from Base to BaseNoGui.
This commit is contained in:
parent
8687a78db5
commit
abe6ff5f32
@ -75,12 +75,6 @@ public class Base {
|
|||||||
|
|
||||||
static File buildFolder;
|
static File buildFolder;
|
||||||
|
|
||||||
// these are static because they're used by Sketch
|
|
||||||
static private File examplesFolder;
|
|
||||||
static private File toolsFolder;
|
|
||||||
|
|
||||||
static private List<File> librariesFolders;
|
|
||||||
|
|
||||||
// classpath for all known libraries for p5
|
// classpath for all known libraries for p5
|
||||||
// (both those in the p5/libs folder and those with lib subfolders
|
// (both those in the p5/libs folder and those with lib subfolders
|
||||||
// found in the sketchbook)
|
// found in the sketchbook)
|
||||||
@ -1161,7 +1155,7 @@ public class Base {
|
|||||||
|
|
||||||
// Add each of the subfolders of examples directly to the menu
|
// Add each of the subfolders of examples directly to the menu
|
||||||
try {
|
try {
|
||||||
boolean found = addSketches(menu, examplesFolder, true);
|
boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), true);
|
||||||
if (found) menu.addSeparator();
|
if (found) menu.addSeparator();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -1245,7 +1239,7 @@ public class Base {
|
|||||||
menu.removeAll();
|
menu.removeAll();
|
||||||
|
|
||||||
// Add examples from distribution "example" folder
|
// Add examples from distribution "example" folder
|
||||||
boolean found = addSketches(menu, examplesFolder, false);
|
boolean found = addSketches(menu, BaseNoGui.getExamplesFolder(), false);
|
||||||
if (found) menu.addSeparator();
|
if (found) menu.addSeparator();
|
||||||
|
|
||||||
// Add examples from libraries
|
// Add examples from libraries
|
||||||
@ -1275,39 +1269,7 @@ public class Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onBoardOrPortChange() {
|
public void onBoardOrPortChange() {
|
||||||
TargetPlatform targetPlatform = getTargetPlatform();
|
BaseNoGui.onBoardOrPortChange();
|
||||||
if (targetPlatform == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Calculate paths for libraries and examples
|
|
||||||
examplesFolder = getContentFile("examples");
|
|
||||||
toolsFolder = getContentFile("tools");
|
|
||||||
|
|
||||||
File platformFolder = targetPlatform.getFolder();
|
|
||||||
librariesFolders = new ArrayList<File>();
|
|
||||||
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();
|
|
||||||
|
|
||||||
// Update editors status bar
|
// Update editors status bar
|
||||||
for (Editor editor : editors)
|
for (Editor editor : editors)
|
||||||
@ -1897,22 +1859,22 @@ public class Base {
|
|||||||
|
|
||||||
|
|
||||||
static public String getExamplesPath() {
|
static public String getExamplesPath() {
|
||||||
return examplesFolder.getAbsolutePath();
|
return BaseNoGui.getExamplesPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static public List<File> getLibrariesPath() {
|
static public List<File> getLibrariesPath() {
|
||||||
return librariesFolders;
|
return BaseNoGui.getLibrariesPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static public File getToolsFolder() {
|
static public File getToolsFolder() {
|
||||||
return toolsFolder;
|
return BaseNoGui.getToolsFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static public String getToolsPath() {
|
static public String getToolsPath() {
|
||||||
return toolsFolder.getAbsolutePath();
|
return BaseNoGui.getToolsPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1994,19 +1956,7 @@ public class Base {
|
|||||||
|
|
||||||
|
|
||||||
static public File getSketchbookLibrariesFolder() {
|
static public File getSketchbookLibrariesFolder() {
|
||||||
File libdir = new File(getSketchbookFolder(), "libraries");
|
return BaseNoGui.getSketchbookLibrariesFolder();
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,8 +4,10 @@ import static processing.app.I18n._;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -47,12 +49,18 @@ public class BaseNoGui {
|
|||||||
|
|
||||||
private static DiscoveryManager discoveryManager = new DiscoveryManager();
|
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
|
// maps #included files to their library folder
|
||||||
public static Map<String, Library> importToLibraryTable;
|
public static Map<String, Library> importToLibraryTable;
|
||||||
|
|
||||||
// maps library name to their library folder
|
// maps library name to their library folder
|
||||||
static private LibraryList libraries;
|
static private LibraryList libraries;
|
||||||
|
|
||||||
|
static private List<File> librariesFolders;
|
||||||
|
|
||||||
static UserNotifier notifier = new BasicUserNotifier();
|
static UserNotifier notifier = new BasicUserNotifier();
|
||||||
|
|
||||||
static public Map<String, TargetPackage> packages;
|
static public Map<String, TargetPackage> packages;
|
||||||
@ -137,6 +145,14 @@ public class BaseNoGui {
|
|||||||
return discoveryManager;
|
return discoveryManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public File getExamplesFolder() {
|
||||||
|
return examplesFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public String getExamplesPath() {
|
||||||
|
return examplesFolder.getAbsolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
static public File getHardwareFolder() {
|
static public File getHardwareFolder() {
|
||||||
// calculate on the fly because it's needed by Preferences.init() to find
|
// calculate on the fly because it's needed by Preferences.init() to find
|
||||||
// the boards.txt and programmers.txt preferences files (which happens
|
// the boards.txt and programmers.txt preferences files (which happens
|
||||||
@ -152,6 +168,10 @@ public class BaseNoGui {
|
|||||||
return libraries;
|
return libraries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public List<File> getLibrariesPath() {
|
||||||
|
return librariesFolders;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an InputStream for a file inside the Processing lib folder.
|
* Return an InputStream for a file inside the Processing lib folder.
|
||||||
*/
|
*/
|
||||||
@ -218,6 +238,22 @@ public class BaseNoGui {
|
|||||||
return new File(getSketchbookFolder(), "hardware");
|
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() {
|
public static TargetBoard getTargetBoard() {
|
||||||
String boardId = PreferencesData.get("board");
|
String boardId = PreferencesData.get("board");
|
||||||
return getTargetPlatform().getBoard(boardId);
|
return getTargetPlatform().getBoard(boardId);
|
||||||
@ -249,6 +285,14 @@ public class BaseNoGui {
|
|||||||
return p.get(platformName);
|
return p.get(platformName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public File getToolsFolder() {
|
||||||
|
return toolsFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public String getToolsPath() {
|
||||||
|
return toolsFolder.getAbsolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
static public LibraryList getUserLibs() {
|
static public LibraryList getUserLibs() {
|
||||||
if (libraries == null)
|
if (libraries == null)
|
||||||
return new LibraryList();
|
return new LibraryList();
|
||||||
@ -370,6 +414,42 @@ public class BaseNoGui {
|
|||||||
return PApplet.join(contents, "\n");
|
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<File>();
|
||||||
|
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() {
|
static public void populateImportToLibraryTable() {
|
||||||
// Populate importToLibraryTable
|
// Populate importToLibraryTable
|
||||||
importToLibraryTable = new HashMap<String, Library>();
|
importToLibraryTable = new HashMap<String, Library>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user