diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d57b594bc..3f8d1793e 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -935,24 +935,30 @@ public class Base { } } + public Map getIDELibs() { + Map ideLibs = new HashMap(libraries); + for (String lib : libraries.keySet()) { + if (FileUtils.isSubDirectory(getSketchbookFolder(), libraries.get(lib))) + ideLibs.remove(lib); + } + return ideLibs; + } + + public Map getUserLibs() { + Map userLibs = new HashMap(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 ideLibs = new HashMap(libraries); - Map userLibs = new HashMap(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 ideLibs = getIDELibs(); + Map 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 names = new ArrayList(libraries.keySet()); + Map ideLibs = getIDELibs(); + List names = new ArrayList(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 userLibs = getUserLibs(); + if (userLibs.size()>0) { + menu.addSeparator(); + names = new ArrayList(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(); } diff --git a/app/src/processing/app/helpers/FileUtils.java b/app/src/processing/app/helpers/FileUtils.java index 5952fe685..68c0c07a8 100644 --- a/app/src/processing/app/helpers/FileUtils.java +++ b/app/src/processing/app/helpers/FileUtils.java @@ -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) {