1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-20 14:54:31 +01:00

Added separator between user supplied libraries and IDE libraries

This commit is contained in:
Cristian Maglie 2012-06-25 17:29:16 +02:00
parent 6640bc9bd2
commit ddc8fa98c9
2 changed files with 54 additions and 7 deletions

View File

@ -32,6 +32,7 @@ import javax.swing.*;
import processing.app.debug.TargetPackage;
import processing.app.debug.TargetPlatform;
import processing.app.helpers.FileUtils;
import processing.app.helpers.PreferencesMap;
import processing.app.helpers.filefilters.OnlyDirs;
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
@ -937,6 +938,21 @@ public class Base {
public void rebuildImportMenu(JMenu importMenu) {
importMenu.removeAll();
// Split between user supplied libraries and IDE libraries
Map<String, File> ideLibs = new HashMap<String, File>(libraries);
Map<String, File> userLibs = new HashMap<String, File>(libraries);
for (String lib : libraries.keySet()) {
try {
if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
ideLibs.remove(lib);
else
userLibs.remove(lib);
} catch (IOException e) {
ideLibs.remove(lib);
userLibs.remove(lib);
}
}
try {
// Find the current target. Get the platform, and then select the
// correct name and core path.
@ -947,7 +963,9 @@ public class Base {
platformItem.setEnabled(false);
importMenu.add(platformItem);
importMenu.addSeparator();
addLibraries(importMenu, libraries);
addLibraries(importMenu, ideLibs);
importMenu.addSeparator();
addLibraries(importMenu, userLibs);
} catch (IOException e) {
e.printStackTrace();
}
@ -1017,7 +1035,7 @@ public class Base {
// Scan for libraries in each library folder.
// Libraries located in the latest folders on the list can override
// other libraries with the same.
// other libraries with the same name.
libraries = scanLibraries(librariesFolders);
// Populate importToLibraryTable
@ -1209,7 +1227,7 @@ public class Base {
return found;
}
protected boolean addLibraries(JMenu menu, Map<String, File> libs) throws IOException {
protected void addLibraries(JMenu menu, Map<String, File> libs) throws IOException {
List<String> list = new ArrayList<String>(libs.keySet());
Collections.sort(list, String.CASE_INSENSITIVE_ORDER);
@ -1220,8 +1238,6 @@ public class Base {
}
};
boolean found = false;
for (String name : list) {
File folder = libs.get(name);
@ -1230,11 +1246,9 @@ public class Base {
item.addActionListener(listener);
item.setActionCommand(folder.getAbsolutePath());
menu.add(item);
found = true;
// XXX: DAM: should recurse here so that library folders can be nested
}
return found;
}
/**

View File

@ -0,0 +1,33 @@
package processing.app.helpers;
import java.io.File;
import java.io.IOException;
public class FileUtils {
/**
* Checks, whether the child directory is a subdirectory of the base
* directory.
*
* @param base
* the base directory.
* @param child
* the suspected child directory.
* @return true, if the child is a subdirectory of the base directory.
* @throws IOException
* if an IOError occured during the test.
*/
public static boolean isSubDirectory(File base, File child) throws IOException {
base = base.getCanonicalFile();
child = child.getCanonicalFile();
File parentFile = child;
while (parentFile != null) {
if (base.equals(parentFile)) {
return true;
}
parentFile = parentFile.getParentFile();
}
return false;
}
}