Hook up most commands. Fixes double-open from project tree.

This commit is contained in:
Thomas Wilburn 2015-03-22 16:54:47 -07:00
parent 1fe74fa2fc
commit 36d875c251
4 changed files with 30 additions and 24 deletions

View file

@ -112,12 +112,9 @@ define([
if (!keepRetained) chrome.storage.local.remove("retainedProject");
};
/*
commands to handle:
project:generate
project:open
project:edit
project:clear
*/
command.on("project:generate", generateProject);
command.on("project:open", openProjectFile);
command.on("project:edit", editProjectFile);
command.on("project:clear", clearProject);
});

View file

@ -8,8 +8,8 @@ define([
"util/dom2"
], function(M, elementData, sessions, File, inflate, context) {
//TODO: create a promise for when the directory is ready
//TODO: move rendering out into a separate NodeView
//TODO: implement a polling-based watch for directories
//TODO: pull the blacklist and use it during readdir()
var noop = function() {};
var guid = 0;

View file

@ -52,6 +52,14 @@ define([
setVisible();
};
var removeAll = function() {
tree.innerHTML = "";
directories = [];
pathmap = {};
setVisible();
};
//toggle directories, or open files directly
tree.on("click", function(e) {
var li = e.target.findUp("li");
var node = elementData.get(li);
@ -63,18 +71,26 @@ define([
}
});
/* commands to handle:
project:refresh-dir
project:add-dir
project:remove-all
project:open-file (for the palette)
*/
command.on("project:refresh-dir", function() {
pathMap = {};
directories.forEach(function(dir) {
M.chain(
dir.readdir.bind(dir),
dir.render.bind(dir),
function() {
dir.walk(function(node) {
pathMap[node.entry.fullPath] = node;
});
}
);
});
});
command.on("project:add-dir", addDirectory);
command.on("project:open-file", function(path) {
var node = pathMap[path];
if (node) node.openFile();
});
command.on("project:remove-all", removeAll);
context.register(
i18n.get("projectRemoveDirectory"),
@ -89,12 +105,7 @@ define([
getPaths: function() { return Object.keys(pathMap) },
getDirectories: function() { return directories },
insertDirectory: addDirectory,
clear: function() {
tree.innerHTML = "";
directories = [];
pathmap = {};
setVisible();
}
clear: removeAll
}
});

View file

@ -1,7 +1,5 @@
<a
argument="{{path}}"
class="file label"
command="project:open-file"
href="{{contextMenu}}"
tabindex="-1"
>