automatically expand single child directory chains

pull/282/head
nightwing 2016-03-28 03:24:30 +04:00
rodzic aa2eaf0ff4
commit 19e5f7a8aa
3 zmienionych plików z 30 dodań i 15 usunięć

Wyświetl plik

@ -49,7 +49,7 @@ var DataProvider = function(root) {
}; };
this.open = this.open =
this.expand = function(node, deep, silent, justLoaded) { this.expand = function(node, deep, silent) {
if (typeof deep != "number") if (typeof deep != "number")
deep = deep ? 100 : 0; deep = deep ? 100 : 0;
if (!node) if (!node)
@ -69,7 +69,7 @@ var DataProvider = function(root) {
this.collapse(node, null, true); this.collapse(node, null, true);
node.status = "loaded"; node.status = "loaded";
if (!err) if (!err)
this.expand(node, null, false, true); this.expand(node, null, false);
}.bind(this)); }.bind(this));
this.setOpen(node, true); this.setOpen(node, true);
return; return;
@ -95,9 +95,6 @@ var DataProvider = function(root) {
} }
} }
if (justLoaded)
node.justLoaded = true;
this.rows = items.length; this.rows = items.length;
silent || this._signal("expand", node); silent || this._signal("expand", node);
}; };

Wyświetl plik

@ -95,6 +95,7 @@ define(function(require, exports, module) {
orphans[e.path] = node; orphans[e.path] = node;
orphan = true; orphan = true;
} }
node.$lastReadT = Date.now();
// Indicate this directory has been fully read // Indicate this directory has been fully read
model.setAttribute(node, "status", "loaded"); model.setAttribute(node, "status", "loaded");

Wyświetl plik

@ -405,15 +405,10 @@ define(function(require, exports, module) {
emit("expand", { path: id }); emit("expand", { path: id });
if (node.justLoaded) {
delete node.justLoaded;
return;
}
// Only save if we are not loading the tree // Only save if we are not loading the tree
if (!refreshing || loadedSettings != -1) { if (!refreshing || loadedSettings != -1) {
if (!node.isRoot) { if (!node.isRoot) {
var refresh = !refreshing && node.status == "loaded"; var refresh = !refreshing && node.status == "loaded" && Date.now() - node.$lastReadT > 500;
watcher.watch(id, refresh); watcher.watch(id, refresh);
// watch children // watch children
@ -425,8 +420,10 @@ define(function(require, exports, module) {
}); });
} }
changed = true; if (!updateSingleDirectoryChain(true, node)) {
settings.save(); changed = true;
settings.save();
}
} }
}, plugin); }, plugin);
@ -452,10 +449,30 @@ define(function(require, exports, module) {
}); });
} }
changed = true; if (!updateSingleDirectoryChain(false, node)) {
settings.save(); changed = true;
settings.save();
}
}, plugin); }, plugin);
function updateSingleDirectoryChain(isExpand, node) {
if (!node.children || node.children.length !== 1)
return;
var child = node.children[0];
if (!child || !child.isFolder || child.$depth > 0xff)
return;
if (isExpand && !child.isOpen) {
expandNode(child);
return true;
}
else if (!isExpand && child.isOpen) {
updateSingleDirectoryChain(false, child);
delete expandedList[child.path];
return true;
}
}
// Rename // Rename
tree.on("beforeRename", function(e) { tree.on("beforeRename", function(e) {
if (emit("beforeRename", e) === false) if (emit("beforeRename", e) === false)