mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Adding support for user-installed libraries in the "libraries" sub-directory of the sketchbook folder.
This commit is contained in:
parent
07feaca3a1
commit
c2cac3e75d
@ -34,7 +34,7 @@ import javax.swing.*;
|
|||||||
*/
|
*/
|
||||||
public class LibraryManager {
|
public class LibraryManager {
|
||||||
|
|
||||||
private File libDir;
|
private File coreLibDir, userLibDir;
|
||||||
private List libraries = new ArrayList();
|
private List libraries = new ArrayList();
|
||||||
private Target target;
|
private Target target;
|
||||||
|
|
||||||
@ -44,9 +44,11 @@ public class LibraryManager {
|
|||||||
public LibraryManager() throws IOException
|
public LibraryManager() throws IOException
|
||||||
{
|
{
|
||||||
String userDir = System.getProperty("user.dir") + File.separator;
|
String userDir = System.getProperty("user.dir") + File.separator;
|
||||||
libDir = new File(
|
coreLibDir = new File(
|
||||||
((!Base.isMacOS()) ? "" : userDir) + "hardware" + File.separator +
|
((!Base.isMacOS()) ? "" : userDir) + "hardware" + File.separator +
|
||||||
"libraries");
|
"libraries");
|
||||||
|
userLibDir =
|
||||||
|
new File(Sketchbook.getSketchbookPath() + File.separator + "libraries");
|
||||||
target = new Target(
|
target = new Target(
|
||||||
System.getProperty("user.dir") + File.separator + "hardware" +
|
System.getProperty("user.dir") + File.separator + "hardware" +
|
||||||
File.separator + "cores",
|
File.separator + "cores",
|
||||||
@ -70,9 +72,15 @@ public class LibraryManager {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
libraries.clear();
|
libraries.clear();
|
||||||
File[] libs = libDir.listFiles(onlyDirs);
|
File[] userLibs = userLibDir.listFiles(onlyDirs);
|
||||||
for(int i = 0; i < libs.length; ++i){
|
if (userLibs != null) {
|
||||||
libraries.add(new Library(this, libs[i]));
|
for(int i = 0; i < userLibs.length; ++i){
|
||||||
|
libraries.add(new Library(this, userLibs[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File[] coreLibs = coreLibDir.listFiles(onlyDirs);
|
||||||
|
for(int i = 0; i < coreLibs.length; ++i){
|
||||||
|
libraries.add(new Library(this, coreLibs[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2238,6 +2238,7 @@ public class Sketch {
|
|||||||
public boolean isReadOnly() {
|
public boolean isReadOnly() {
|
||||||
String apath = folder.getAbsolutePath();
|
String apath = folder.getAbsolutePath();
|
||||||
if (apath.startsWith(Sketchbook.examplesPath) ||
|
if (apath.startsWith(Sketchbook.examplesPath) ||
|
||||||
|
apath.startsWith(Sketchbook.userLibrariesPath) ||
|
||||||
apath.startsWith(Sketchbook.librariesPath)) {
|
apath.startsWith(Sketchbook.librariesPath)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
@ -68,6 +68,9 @@ public class Sketchbook {
|
|||||||
|
|
||||||
static File librariesFolder;
|
static File librariesFolder;
|
||||||
static String librariesPath;
|
static String librariesPath;
|
||||||
|
|
||||||
|
static File userLibrariesFolder;
|
||||||
|
static String userLibrariesPath;
|
||||||
|
|
||||||
// maps imported packages to their library folder
|
// maps imported packages to their library folder
|
||||||
static Hashtable importToLibraryTable = new Hashtable();
|
static Hashtable importToLibraryTable = new Hashtable();
|
||||||
@ -131,11 +134,14 @@ public class Sketchbook {
|
|||||||
//System.out.println("resetting sketchbook path");
|
//System.out.println("resetting sketchbook path");
|
||||||
File sketchbookFolder = Base.getDefaultSketchbookFolder();
|
File sketchbookFolder = Base.getDefaultSketchbookFolder();
|
||||||
//System.out.println("default is " + sketchbookFolder);
|
//System.out.println("default is " + sketchbookFolder);
|
||||||
Preferences.set("sketchbook.path",
|
sketchbookPath = sketchbookFolder.getAbsolutePath();
|
||||||
sketchbookFolder.getAbsolutePath());
|
Preferences.set("sketchbook.path", sketchbookPath);
|
||||||
|
|
||||||
if (!sketchbookFolder.exists()) sketchbookFolder.mkdirs();
|
if (!sketchbookFolder.exists()) sketchbookFolder.mkdirs();
|
||||||
}
|
}
|
||||||
|
userLibrariesFolder = new File(sketchbookPath, "libraries");
|
||||||
|
userLibrariesPath = userLibrariesFolder.getAbsolutePath();
|
||||||
|
|
||||||
openMenu = new JMenu("Sketchbook");
|
openMenu = new JMenu("Sketchbook");
|
||||||
popupMenu = new JMenu("Sketchbook");
|
popupMenu = new JMenu("Sketchbook");
|
||||||
importMenu = new JMenu("Import Library");
|
importMenu = new JMenu("Import Library");
|
||||||
@ -386,6 +392,7 @@ public class Sketchbook {
|
|||||||
if (addLibraries(importMenu, examplesFolder)) {
|
if (addLibraries(importMenu, examplesFolder)) {
|
||||||
importMenu.addSeparator();
|
importMenu.addSeparator();
|
||||||
}
|
}
|
||||||
|
addLibraries(importMenu, userLibrariesFolder);
|
||||||
addLibraries(importMenu, librariesFolder);
|
addLibraries(importMenu, librariesFolder);
|
||||||
//System.out.println("libraries cp is now " + librariesClassPath);
|
//System.out.println("libraries cp is now " + librariesClassPath);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user