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

Wyświetl plik

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

Wyświetl plik

@ -405,15 +405,10 @@ define(function(require, exports, module) {
emit("expand", { path: id });
if (node.justLoaded) {
delete node.justLoaded;
return;
}
// Only save if we are not loading the tree
if (!refreshing || loadedSettings != -1) {
if (!node.isRoot) {
var refresh = !refreshing && node.status == "loaded";
var refresh = !refreshing && node.status == "loaded" && Date.now() - node.$lastReadT > 500;
watcher.watch(id, refresh);
// watch children
@ -425,8 +420,10 @@ define(function(require, exports, module) {
});
}
changed = true;
settings.save();
if (!updateSingleDirectoryChain(true, node)) {
changed = true;
settings.save();
}
}
}, plugin);
@ -452,10 +449,30 @@ define(function(require, exports, module) {
});
}
changed = true;
settings.save();
if (!updateSingleDirectoryChain(false, node)) {
changed = true;
settings.save();
}
}, 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
tree.on("beforeRename", function(e) {
if (emit("beforeRename", e) === false)