From 545671a64145c0164317160bf300d4e16e86d9b3 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 8 May 2012 10:18:17 -0700 Subject: [PATCH 1/4] fs.isFile(path) returns false if given path does not exist --- Atom/src/native_handler.mm | 9 +++++++++ spec/stdlib/fs-spec.coffee | 14 ++++++++++++++ src/stdlib/fs.coffee | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Atom/src/native_handler.mm b/Atom/src/native_handler.mm index e3e8b3fb6..31038e8ee 100644 --- a/Atom/src/native_handler.mm +++ b/Atom/src/native_handler.mm @@ -127,6 +127,15 @@ bool NativeHandler::Execute(const CefString& name, return true; } + else if (name == "isFile") { + NSString *path = stringFromCefV8Value(arguments[0]); + + BOOL isDir = false; + BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDir]; + retval = CefV8Value::CreateBool(exists && !isDir); + + return true; + } else if (name == "remove") { NSString *path = stringFromCefV8Value(arguments[0]); diff --git a/spec/stdlib/fs-spec.coffee b/spec/stdlib/fs-spec.coffee index 11ef89c83..dd48935c8 100644 --- a/spec/stdlib/fs-spec.coffee +++ b/spec/stdlib/fs-spec.coffee @@ -1,6 +1,20 @@ fs = require 'fs' describe "fs", -> + describe ".isFile(path)", -> + fixturesDir = require.resolve('fixtures') + beforeEach -> + + it "returns true with a file path", -> + expect(fs.isFile(fs.join(fixturesDir, 'sample.js'))).toBe true + + it "returns false with a directory path", -> + expect(fs.isFile(fixturesDir)).toBe false + + it "returns false with a non-existent path", -> + expect(fs.isFile(fs.join(fixturesDir, 'non-existent'))).toBe false + expect(fs.isFile(null)).toBe false + describe ".directory(path)", -> describe "when called with a file path", -> it "returns the path to the directory", -> diff --git a/src/stdlib/fs.coffee b/src/stdlib/fs.coffee index e7f9e1b8d..9cb912311 100644 --- a/src/stdlib/fs.coffee +++ b/src/stdlib/fs.coffee @@ -51,7 +51,7 @@ module.exports = # Returns true if the file specified by path exists and is a # regular file. isFile: (path) -> - not $native.isDirectory path + $native.isFile path # Returns an array with all the names of files contained # in the directory path. From cb45675f1454738ae191d7bb0cc669e9e6b9d562 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 8 May 2012 11:00:27 -0700 Subject: [PATCH 2/4] Remove @path var from project --- spec/app/project-spec.coffee | 4 ++-- spec/app/root-view-spec.coffee | 12 ++++++------ spec/extensions/file-finder-spec.coffee | 2 +- spec/extensions/tree-view-spec.coffee | 2 +- src/app/project.coffee | 17 +++++++---------- src/app/root-view.coffee | 7 +++---- src/extensions/file-finder.coffee | 2 +- 7 files changed, 21 insertions(+), 25 deletions(-) diff --git a/spec/app/project-spec.coffee b/spec/app/project-spec.coffee index 5627c81ab..144b697e8 100644 --- a/spec/app/project-spec.coffee +++ b/spec/app/project-spec.coffee @@ -69,5 +69,5 @@ describe "Project", -> describe "when path is null", -> it "sets its path and root directory to null", -> project.setPath(null) - expect(project.getPath()).toBeNull() - expect(project.getRootDirectory()).toBeNull() + expect(project.getPath()?).toBeFalsy() + expect(project.getRootDirectory()?).toBeFalsy() diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index 759b76efd..f3e082d98 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -20,7 +20,7 @@ describe "RootView", -> describe "when called with a pathToOpen", -> describe "when pathToOpen references a file", -> it "creates a project for the file's parent directory, then sets the document.title and opens the file in an editor", -> - expect(rootView.project.path).toBe fs.directory(path) + expect(rootView.project.getPath()).toBe fs.directory(path) expect(rootView.editors().length).toBe 1 expect(rootView.editors()[0]).toHaveClass 'active' expect(rootView.activeEditor().buffer.getPath()).toBe path @@ -33,7 +33,7 @@ describe "RootView", -> rootView = new RootView(pathToOpen: path) rootView.focus() - expect(rootView.project.path).toBe path + expect(rootView.project.getPath()).toBe path expect(rootView.editors().length).toBe 0 expect(document.title).toBe path @@ -53,7 +53,7 @@ describe "RootView", -> it "constructs the view with the same panes", -> rootView = RootView.deserialize(viewState) - expect(rootView.project.path).toBeNull() + expect(rootView.project.getPath()?).toBeFalsy() expect(rootView.editors().length).toBe 2 expect(rootView.activeEditor().buffer.getText()).toBe buffer.getText() expect(document.title).toBe 'untitled' @@ -377,9 +377,9 @@ describe "RootView", -> it "creates a project if there isn't one yet and the buffer was previously unsaved", -> rootView = new RootView rootView.open() - expect(rootView.project.path).toBeNull() + expect(rootView.project.getPath()?).toBeFalsy() rootView.activeEditor().buffer.saveAs('/tmp/ignore-me') - expect(rootView.project.path).toBe '/tmp' + expect(rootView.project.getPath()).toBe '/tmp' describe "when editors are focused", -> it "triggers 'active-editor-path-change' events if the path of the active editor actually changes", -> @@ -407,5 +407,5 @@ describe "RootView", -> describe "when the last editor is removed", -> it "updates the title to the project path", -> rootView.editors()[0].remove() - expect(document.title).toBe rootView.project.path + expect(document.title).toBe rootView.project.getPath() diff --git a/spec/extensions/file-finder-spec.coffee b/spec/extensions/file-finder-spec.coffee index de2a44ba4..aed9fd7db 100644 --- a/spec/extensions/file-finder-spec.coffee +++ b/spec/extensions/file-finder-spec.coffee @@ -43,7 +43,7 @@ describe 'FileFinder', -> describe "when root view's project has no path", -> beforeEach -> - rootView.project.path = undefined + rootView.project.setPath(null) it "does not open the FileFinder", -> expect(rootView.find('.file-finder')).not.toExist() diff --git a/spec/extensions/tree-view-spec.coffee b/spec/extensions/tree-view-spec.coffee index fc9595ab8..9dc33a35f 100644 --- a/spec/extensions/tree-view-spec.coffee +++ b/spec/extensions/tree-view-spec.coffee @@ -43,7 +43,7 @@ describe "TreeView", -> expect(rootEntries.find('> .file:contains(sample.js)')).toExist() expect(rootEntries.find('> .file:contains(sample.txt)')).toExist() - describe "when the project has not path", -> + describe "when the project has no path", -> beforeEach -> treeView.deactivate() diff --git a/src/app/project.coffee b/src/app/project.coffee index e4aa71866..0ada35dd4 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -6,7 +6,6 @@ Directory = require 'directory' module.exports = class Project - path: null rootDirectory: null buffers: null @@ -15,16 +14,15 @@ class Project @buffers = [] getPath: -> - @path + @rootDirectory?.path setPath: (path) -> - @rootDirectory.off() if @rootDirectory + @rootDirectory?.off() if path? - @path = if fs.isDirectory(path) then path else fs.directory(path) - @rootDirectory = new Directory(@path) + directory = if fs.isDirectory(path) then path else fs.directory(path) + @rootDirectory = new Directory(directory) else - @path = null @rootDirectory = null @trigger "path-change" @@ -33,8 +31,7 @@ class Project @rootDirectory getFilePaths: -> - projectPath = @path - fs.async.listTree(@path).pipe (paths) => + fs.async.listTree(@getPath()).pipe (paths) => @relativize(path) for path in paths when fs.isFile(path) open: (filePath) -> @@ -51,11 +48,11 @@ class Project buffer resolve: (filePath) -> - filePath = fs.join(@path, filePath) unless filePath[0] == '/' + filePath = fs.join(@getPath(), filePath) unless filePath[0] == '/' fs.absolute filePath relativize: (fullPath) -> - fullPath.replace(@path, "").replace(/^\//, '') + fullPath.replace(@getPath(), "").replace(/^\//, '') bufferWithId: (id) -> return buffer for buffer in @buffers when buffer.id == id diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index a2a596cb5..f151cda22 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -39,11 +39,10 @@ class RootView extends View @setTitle() @project = new Project(pathToOpen) - if pathToOpen? and fs.isFile(pathToOpen) - @open(pathToOpen) + @open(pathToOpen) if fs.isFile(pathToOpen) serialize: -> - projectPath: @project?.path + projectPath: @project?.getPath() panesViewState: @panes.children().view()?.serialize() extensionStates: @serializeExtensions() @@ -57,7 +56,7 @@ class RootView extends View @setTitle(@project?.getPath()) @on 'active-editor-path-change', (e, path) => - @project.setPath(path) unless @project.getPath() + @project.setPath(path) unless @project.getRootDirectory() @setTitle(path) afterAttach: (onDom) -> diff --git a/src/extensions/file-finder.coffee b/src/extensions/file-finder.coffee index 664879256..00e7c758c 100644 --- a/src/extensions/file-finder.coffee +++ b/src/extensions/file-finder.coffee @@ -33,7 +33,7 @@ class FileFinder extends View if @hasParent() @detach() else - @attach() if @rootView.project.path? + @attach() if @rootView.project.getPath()? attach: -> @rootView.project.getFilePaths().done (@paths) => @populatePathList() From 935ae3323ea97a6e86ec5f9ad3fd8dafb0e1e01d Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 8 May 2012 13:17:25 -0700 Subject: [PATCH 3/4] Rename class var @treeView to @instance --- src/extensions/tree-view/tree-view.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/extensions/tree-view/tree-view.coffee b/src/extensions/tree-view/tree-view.coffee index 772a8113a..0931db668 100644 --- a/src/extensions/tree-view/tree-view.coffee +++ b/src/extensions/tree-view/tree-view.coffee @@ -14,14 +14,14 @@ class TreeView extends View requireStylesheet 'tree-view.css' if state - @treeView = TreeView.deserialize(state, rootView) + @instance = TreeView.deserialize(state, rootView) else - @treeView = new TreeView(rootView) + @instance = new TreeView(rootView) - rootView.horizontal.prepend(@treeView) + rootView.horizontal.prepend(@instance) @serialize: -> - @treeView.serialize() + @instance.serialize() @content: (rootView) -> @div class: 'tree-view', tabindex: -1, => From 77baa7be099e7e16c51e88a36e3d91c74ebcbe71 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Tue, 8 May 2012 13:49:06 -0700 Subject: [PATCH 4/4] Extract command panel as an extension --- spec/extensions/command-panel-spec.coffee | 7 ++++--- src/app/root-view.coffee | 9 +++------ src/extensions/command-panel.coffee | 20 +++++++++++++++++--- static/command-panel.css | 12 ++++++------ 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/spec/extensions/command-panel-spec.coffee b/spec/extensions/command-panel-spec.coffee index bf02c1293..7524cd91e 100644 --- a/spec/extensions/command-panel-spec.coffee +++ b/spec/extensions/command-panel-spec.coffee @@ -1,4 +1,5 @@ RootView = require 'root-view' +CommandPanel = require 'command-panel' describe "CommandPanel", -> [rootView, commandPanel] = [] @@ -7,7 +8,7 @@ describe "CommandPanel", -> rootView = new RootView rootView.open() rootView.enableKeymap() - commandPanel = rootView.commandPanel + commandPanel = rootView.activateExtension(CommandPanel) describe "when toggle-command-panel is triggered on the root view", -> it "toggles the command panel", -> @@ -43,8 +44,8 @@ describe "CommandPanel", -> describe "when command-panel:find-in-file is triggered on an editor", -> it "pre-populates command panel's editor with /", -> rootView.activeEditor().trigger "command-panel:find-in-file" - expect(rootView.commandPanel.parent).not.toBeEmpty() - expect(rootView.commandPanel.editor.getText()).toBe "/" + expect(commandPanel.parent).not.toBeEmpty() + expect(commandPanel.editor.getText()).toBe "/" describe "when esc is pressed in the command panel", -> it "closes the command panel", -> diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index f151cda22..21d0c5088 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -8,7 +8,6 @@ Buffer = require 'buffer' Editor = require 'editor' Project = require 'project' VimMode = require 'vim-mode' -CommandPanel = require 'command-panel' Pane = require 'pane' PaneColumn = require 'pane-column' PaneRow = require 'pane-row' @@ -31,14 +30,12 @@ class RootView extends View extensionStates: null initialize: ({ pathToOpen }) -> - @handleEvents() - @extensions = {} @extensionStates = {} - @commandPanel = new CommandPanel({rootView: this}) - - @setTitle() @project = new Project(pathToOpen) + + @handleEvents() + @setTitle() @open(pathToOpen) if fs.isFile(pathToOpen) serialize: -> diff --git a/src/extensions/command-panel.coffee b/src/extensions/command-panel.coffee index f202440f9..051946df1 100644 --- a/src/extensions/command-panel.coffee +++ b/src/extensions/command-panel.coffee @@ -5,6 +5,22 @@ Editor = require 'editor' module.exports = class CommandPanel extends View + @activate: (rootView, state) -> + requireStylesheet 'command-panel.css' + if state? + @instance = CommandPanel.deserialize(state, rootView) + else + @instance = new CommandPanel(rootView) + + @serialize: -> + text: @instance.editor.getText() + visible: @instance.hasParent() + + @deserialize: (state, rootView) -> + commandPanel = new CommandPanel(rootView) + commandPanel.show(state.text) if state.visible + commandPanel + @content: -> @div class: 'command-panel', => @div ':', class: 'prompt', outlet: 'prompt' @@ -14,9 +30,7 @@ class CommandPanel extends View history: null historyIndex: 0 - initialize: ({@rootView})-> - requireStylesheet 'command-panel.css' - + initialize: (@rootView)-> @commandInterpreter = new CommandInterpreter() @history = [] diff --git a/static/command-panel.css b/static/command-panel.css index e87cd4a68..7d0e546d9 100644 --- a/static/command-panel.css +++ b/static/command-panel.css @@ -1,10 +1,12 @@ .command-panel { position: absolute; bottom: 0; + width: 100%; background: #515151; - display: -webkit-box; padding: 3px; -webkit-transition: background 200ms ease-out; + + display: -webkit-box; } .command-panel.error { @@ -13,8 +15,6 @@ .command-panel .prompt { color: white; -} - -.command-panel .editor { - -webkit-box-flex: 1 -} + font-weight: bold; + padding: .2em; +} \ No newline at end of file