mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-20 21:01:25 +03:00
Separator between user and IDE libraries also in examples menu
This commit is contained in:
@ -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) {
|
public void rebuildImportMenu(JMenu importMenu) {
|
||||||
importMenu.removeAll();
|
importMenu.removeAll();
|
||||||
|
|
||||||
// Split between user supplied libraries and IDE libraries
|
// Split between user supplied libraries and IDE libraries
|
||||||
Map<String, File> ideLibs = new HashMap<String, File>(libraries);
|
Map<String, File> ideLibs = getIDELibs();
|
||||||
Map<String, File> userLibs = new HashMap<String, File>(libraries);
|
Map<String, File> userLibs = getUserLibs();
|
||||||
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 {
|
try {
|
||||||
// Find the current target. Get the platform, and then select the
|
// Find the current target. Get the platform, and then select the
|
||||||
// correct name and core path.
|
// correct name and core path.
|
||||||
@ -962,10 +968,14 @@ public class Base {
|
|||||||
JMenuItem platformItem = new JMenuItem(targetname);
|
JMenuItem platformItem = new JMenuItem(targetname);
|
||||||
platformItem.setEnabled(false);
|
platformItem.setEnabled(false);
|
||||||
importMenu.add(platformItem);
|
importMenu.add(platformItem);
|
||||||
|
if (ideLibs.size()>0) {
|
||||||
importMenu.addSeparator();
|
importMenu.addSeparator();
|
||||||
addLibraries(importMenu, ideLibs);
|
addLibraries(importMenu, ideLibs);
|
||||||
|
}
|
||||||
|
if (userLibs.size()>0) {
|
||||||
importMenu.addSeparator();
|
importMenu.addSeparator();
|
||||||
addLibraries(importMenu, userLibs);
|
addLibraries(importMenu, userLibs);
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -980,12 +990,24 @@ public class Base {
|
|||||||
if (found) menu.addSeparator();
|
if (found) menu.addSeparator();
|
||||||
|
|
||||||
// Add examples from libraries
|
// 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);
|
Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
|
||||||
for (String name : names) {
|
for (String name : names) {
|
||||||
File folder = libraries.get(name);
|
File folder = ideLibs.get(name);
|
||||||
addSketchesSubmenu(menu, name, folder, false);
|
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) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,14 @@ public class FileUtils {
|
|||||||
* @param child
|
* @param child
|
||||||
* the suspected child directory.
|
* the suspected child directory.
|
||||||
* @return true, if the child is a subdirectory of the base 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 {
|
public static boolean isSubDirectory(File base, File child) {
|
||||||
|
try {
|
||||||
base = base.getCanonicalFile();
|
base = base.getCanonicalFile();
|
||||||
child = child.getCanonicalFile();
|
child = child.getCanonicalFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
File parentFile = child;
|
File parentFile = child;
|
||||||
while (parentFile != null) {
|
while (parentFile != null) {
|
||||||
|
Reference in New Issue
Block a user