scan of library only at startup

This commit is contained in:
hneemann 2017-07-18 20:48:27 +02:00
parent d1b5eccc51
commit da3f2311e5
2 changed files with 21 additions and 40 deletions

View File

@ -67,7 +67,6 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
private final LibraryNode root;
private ShapeFactory shapeFactory;
private ElementLibraryFolder custom;
private ElementLibraryFolder library;
private File rootLibraryPath;
/**
@ -161,7 +160,10 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
populateNodeMap();
custom = new ElementLibraryFolder(root, Lang.get("menu_custom"));
library = new ElementLibraryFolder(root, Lang.get("menu_library"));
File libPath = Settings.getInstance().get(Keys.SETTINGS_LIBRARY_PATH);
if (libPath != null && libPath.exists())
new ElementLibraryFolder(root, Lang.get("menu_library")).scanFolder(libPath);
isProgrammable.clear();
root.traverse(libraryNode -> {
@ -296,22 +298,12 @@ public class ElementLibrary implements Iterable<ElementLibrary.ElementContainer>
private void rescanFolder() throws IOException {
LOGGER.debug("rescan folder");
File libPath = Settings.getInstance().get(Keys.SETTINGS_LIBRARY_PATH);
if (libPath != null && !libPath.exists()) libPath = null;
LibraryNode cn1 = library.scanFolder(libPath);
LibraryNode cn2 = custom.scanFolder(rootLibraryPath);
LibraryNode cn = custom.scanFolder(rootLibraryPath);
populateNodeMap();
if (cn1 == root || cn2 == root) {
fireLibraryChanged(root);
} else {
if (cn1 != null)
fireLibraryChanged(cn1);
if (cn2 != null)
fireLibraryChanged(cn2);
}
if (cn != null)
fireLibraryChanged(cn);
}
/**

View File

@ -37,15 +37,6 @@ public class ElementLibraryFolder {
return node;
}
private boolean hasChanged(File path) {
File lp = lastPath;
lastPath = path;
if (lp == path) return false;
return lp == null || !lp.equals(path);
}
/**
* scans the given folder
*
@ -54,7 +45,6 @@ public class ElementLibraryFolder {
*/
public LibraryNode scanFolder(File path) {
LibraryNode changedNode = null;
if (hasChanged(path)) {
if (path != null) {
if (node == null) {
node = new LibraryNode(menuTitle);
@ -71,7 +61,6 @@ public class ElementLibraryFolder {
node = null;
changedNode = root;
}
}
return changedNode;
}