From fbcd8e43a083f80cd27c0e0e0fcbfb5a7570f510 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 26 Apr 2012 16:26:49 -0700 Subject: [PATCH 1/2] Add fs.makeDirectory --- Atom/src/native_handler.mm | 14 +++++++++++++- src/stdlib/fs.coffee | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Atom/src/native_handler.mm b/Atom/src/native_handler.mm index 7f5a8562a..92b75940a 100644 --- a/Atom/src/native_handler.mm +++ b/Atom/src/native_handler.mm @@ -13,7 +13,7 @@ NSString *stringFromCefV8Value(const CefRefPtr& value) { NativeHandler::NativeHandler() : CefV8Handler() { m_object = CefV8Value::CreateObject(NULL); - const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath"}; + const char *functionNames[] = {"exists", "read", "write", "absolute", "list", "isFile", "isDirectory", "remove", "asyncList", "open", "openDialog", "quit", "writeToPasteboard", "readFromPasteboard", "showDevTools", "newWindow", "saveDialog", "exit", "watchPath", "unwatchPath", "makeDirectory"}; NSUInteger arrayLength = sizeof(functionNames) / sizeof(const char *); for (NSUInteger i = 0; i < arrayLength; i++) { const char *functionName = functionNames[i]; @@ -308,6 +308,18 @@ bool NativeHandler::Execute(const CefString& name, return true; } + else if (name == "makeDirectory") { + NSString *path = stringFromCefV8Value(arguments[0]); + NSFileManager *fm = [NSFileManager defaultManager]; + NSError *error = nil; + [fm createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:&error]; + + if (error) { + exception = [[error localizedDescription] UTF8String]; + } + + return true; + } return false; }; \ No newline at end of file diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index b72b774f9..fff77aec1 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -66,6 +66,9 @@ module.exports = write: (path, content) -> $native.write(path, content) + makeDirectory: (path) -> + $native.makeDirectory(path) + async: list: (path) -> deferred = $.Deferred() From 0a39ca25a9a51dcf42e0022952a429a6847dd39f Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 26 Apr 2012 17:12:56 -0700 Subject: [PATCH 2/2] Pressing 'm' in tree view brings up a move dialog --- spec/extensions/tree-view-spec.coffee | 45 +++++++++++++++++++++++++++ src/app/keymaps/tree-view.coffee | 1 + src/extensions/tree-view.coffee | 27 ++++++++++++++++ static/tree-view.css | 9 ++++++ 4 files changed, 82 insertions(+) diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index c144ec6f2..2edba773b 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -276,6 +276,51 @@ describe "TreeView", -> rootDirectoryView.trigger 'tree-view:open-selected-entry' expect(rootView.activeEditor()).toBeUndefined() + describe "file modification", -> + [fileElement, rootDirPath, dirPath, filePath] = [] + + beforeEach -> + treeView.deactivate() + + rootDirPath = "/tmp/atom-tests" + dirPath = fs.join(rootDirPath, "test-dir") + filePath = fs.join(dirPath, "test-file.txt") + fs.makeDirectory(rootDirPath) + fs.makeDirectory(dirPath) + fs.write(filePath, "doesn't matter") + + rootView = new RootView(pathToOpen: rootDirPath) + project = rootView.project + treeView = new TreeView(rootView) + dirView = treeView.root.entries.find('.directory:contains(test-dir)').view() + dirView.expand() + fileElement = treeView.find('.file:contains(test-file.txt)') + + afterEach -> + fs.remove(rootDirPath) + + describe "tree-view:move", -> + describe "when a file is selected", -> + moveDialog = null + + beforeEach -> + fileElement.click() + treeView.trigger "tree-view:move" + moveDialog = treeView.find(".move-dialog").view() + + it "opens a move dialog with the file's current path populated", -> + expect(moveDialog).toExist() + expect(moveDialog.editor.getText()).toBe(project.relativize(filePath)) + expect(moveDialog.editor.getSelectedText()).toBe fs.base(filePath) + expect(moveDialog.editor.isFocused).toBeTruthy() + + describe "when the move dialog's editor loses focus", -> + it "removes the dialog", -> + treeView.attachToDom() + treeView.focus() + expect(moveDialog.parent()).not.toExist() + + describe "file system events", -> temporaryFilePath = null diff --git a/src/app/keymaps/tree-view.coffee b/src/app/keymaps/tree-view.coffee index a68092bb6..afeab4e8f 100644 --- a/src/app/keymaps/tree-view.coffee +++ b/src/app/keymaps/tree-view.coffee @@ -2,4 +2,5 @@ window.keymap.bindKeys '.tree-view' 'right': 'tree-view:expand-directory' 'left': 'tree-view:collapse-directory' 'enter': 'tree-view:open-selected-entry' + 'm': 'tree-view:move' diff --git a/src/extensions/tree-view.coffee b/src/extensions/tree-view.coffee index f33abc1a4..96d83317b 100644 --- a/src/extensions/tree-view.coffee +++ b/src/extensions/tree-view.coffee @@ -25,6 +25,7 @@ class TreeView extends View @on 'tree-view:expand-directory', => @expandDirectory() @on 'tree-view:collapse-directory', => @collapseDirectory() @on 'tree-view:open-selected-entry', => @openSelectedEntry() + @on 'tree-view:move', => @move() @rootView.on 'active-editor-path-change', => @selectActiveFile() deactivate: -> @@ -70,6 +71,15 @@ class TreeView extends View else if selectedEntry.is('.file') @rootView.open(selectedEntry.attr('path')) + move: -> + entry = @selectedEntry() + dialog = new MoveDialog(@rootView.project, entry.attr('path')) + @append dialog + + dialog.css + top: entry.position().top + entry.outerHeight() + @scrollTop() + left: 0 + selectedEntry: -> @find('.selected') @@ -144,3 +154,20 @@ class DirectoryView extends View view = $(this).view() view.entryStates = childEntryStates view.expand() + +Editor = require 'editor' +fs = require 'fs' +class MoveDialog extends View + @content: -> + @div class: 'move-dialog', => + @subview 'editor', new Editor(mini: true) + + initialize: (@project, path) -> + @editor.focus() + @editor.on 'focusout', => @remove() + + relativePath = @project.relativize(path) + @editor.setText(relativePath) + baseName = fs.base(path) + range = [[0, relativePath.length - baseName.length], [0, relativePath.length]] + @editor.setSelectionBufferRange(range) \ No newline at end of file diff --git a/static/tree-view.css b/static/tree-view.css index fd542c8a0..5f7f0bff0 100644 --- a/static/tree-view.css +++ b/static/tree-view.css @@ -1,4 +1,5 @@ .tree-view { + position: relative; height: 100%; background: black; color: white; @@ -34,3 +35,11 @@ color: black; } +.move-dialog { + position: absolute; + width: 100%; + + background-color: #444; + border: 2px solid #222; + -webkit-box-shadow: 0 0 3px 3px rgba(0, 0, 0, .5); +} \ No newline at end of file