1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-01 12:24:14 +01:00

Separator between user and IDE libraries also in examples menu

This commit is contained in:
Cristian Maglie 2012-07-03 17:26:15 +02:00
parent 00f8cdb931
commit 01bd432af3
2 changed files with 49 additions and 25 deletions

View File

@ -935,24 +935,30 @@ public class Base {
}
}
public Map<String, File> getIDELibs() {
Map<String, File> ideLibs = new HashMap<String, File>(libraries);
for (String lib : libraries.keySet()) {
if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
ideLibs.remove(lib);
}
return ideLibs;
}
public Map<String, File> getUserLibs() {
Map<String, File> userLibs = new HashMap<String, File>(libraries);
for (String lib : libraries.keySet()) {
if (!FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib)))
userLibs.remove(lib);
}
return userLibs;
}
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);
}
}
Map<String, File> ideLibs = getIDELibs();
Map<String, File> userLibs = getUserLibs();
try {
// Find the current target. Get the platform, and then select the
// correct name and core path.
@ -962,10 +968,14 @@ public class Base {
JMenuItem platformItem = new JMenuItem(targetname);
platformItem.setEnabled(false);
importMenu.add(platformItem);
importMenu.addSeparator();
addLibraries(importMenu, ideLibs);
importMenu.addSeparator();
addLibraries(importMenu, userLibs);
if (ideLibs.size()>0) {
importMenu.addSeparator();
addLibraries(importMenu, ideLibs);
}
if (userLibs.size()>0) {
importMenu.addSeparator();
addLibraries(importMenu, userLibs);
}
} catch (IOException e) {
e.printStackTrace();
}
@ -980,12 +990,24 @@ public class Base {
if (found) menu.addSeparator();
// Add examples from libraries
List<String> names = new ArrayList<String>(libraries.keySet());
Map<String, File> ideLibs = getIDELibs();
List<String> names = new ArrayList<String>(ideLibs.keySet());
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
for (String name : names) {
File folder = libraries.get(name);
File folder = ideLibs.get(name);
addSketchesSubmenu(menu, name, folder, false);
}
Map<String, File> userLibs = getUserLibs();
if (userLibs.size()>0) {
menu.addSeparator();
names = new ArrayList<String>(userLibs.keySet());
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
for (String name : names) {
File folder = userLibs.get(name);
addSketchesSubmenu(menu, name, folder, false);
}
}
} catch (IOException e) {
e.printStackTrace();
}

View File

@ -14,12 +14,14 @@ public class FileUtils {
* @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();
public static boolean isSubDirectory(File base, File child) {
try {
base = base.getCanonicalFile();
child = child.getCanonicalFile();
} catch (IOException e) {
return false;
}
File parentFile = child;
while (parentFile != null) {