diff --git a/js/project/file.js b/js/project/file.js index 9e89f12..d5ec6f6 100644 --- a/js/project/file.js +++ b/js/project/file.js @@ -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); }); \ No newline at end of file diff --git a/js/project/node.js b/js/project/node.js index 5bf1c61..cdaf273 100644 --- a/js/project/node.js +++ b/js/project/node.js @@ -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; diff --git a/js/project/tree.js b/js/project/tree.js index 3de093e..cc78653 100644 --- a/js/project/tree.js +++ b/js/project/tree.js @@ -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 } }); \ No newline at end of file diff --git a/templates/projectFile.html b/templates/projectFile.html index 1c8f1e2..5326f2d 100644 --- a/templates/projectFile.html +++ b/templates/projectFile.html @@ -1,7 +1,5 @@