RootView handles opening directories

This commit is contained in:
Corey Johnson & Nathan Sobo 2012-01-04 10:51:41 -08:00
parent 9fde405ebe
commit 236ea5e906
3 changed files with 42 additions and 15 deletions

View File

@ -11,14 +11,28 @@ describe "App", ->
window.close() for window in app.windows()
describe "open", ->
it "loads a buffer based on the given path and displays it in a new window", ->
filePath = require.resolve 'fixtures/sample.txt'
expect(app.windows().length).toBe 0
describe "when opening a filePath", ->
it "loads a buffer with filePath contents and displays it in a new window", ->
filePath = require.resolve 'fixtures/sample.txt'
expect(app.windows().length).toBe 0
app.open filePath
app.open filePath
expect(app.windows().length).toBe 1
newWindow = app.windows()[0]
expect(app.windows().length).toBe 1
newWindow = app.windows()[0]
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)
expect(newWindow.rootView.editor.buffer.url).toEqual filePath
expect(newWindow.rootView.editor.buffer.getText()).toEqual fs.read(filePath)
describe "when opening a dirPath", ->
it "loads an empty buffer", ->
dirPath = require.resolve 'fixtures'
expect(app.windows().length).toBe 0
app.open dirPath
expect(app.windows().length).toBe 1
newWindow = app.windows()[0]
expect(newWindow.rootView.editor.buffer.url).toBeUndefined
expect(newWindow.rootView.editor.buffer.getText()).toBe ""

View File

@ -11,11 +11,18 @@ describe "RootView", ->
rootView = RootView.build {url}
describe "initialize", ->
describe "when called with a url", ->
describe "when the url references a file", ->
it "creates a project for the file's parent directory and opens it in the editor", ->
expect(rootView.project.url).toBe fs.directory(url)
expect(rootView.editor.buffer.url).toBe url
describe "when called with a url that references a file", ->
it "creates a project for the file's parent directory and opens it in the editor", ->
expect(rootView.project.url).toBe fs.directory(url)
expect(rootView.editor.buffer.url).toBe url
describe "when called with a url that references a directory", ->
it "creates a project for the directory and opens and empty buffer", ->
url = require.resolve 'fixtures/dir'
rootView = RootView.build {url}
expect(rootView.project.url).toBe url
expect(rootView.editor.buffer.url).toBeUndefined()
describe "when not called with a url", ->
it "opens an empty buffer", ->

View File

@ -21,8 +21,14 @@ class RootView extends Template
@bindKey 'meta+w', => window.close()
@bindKey 'meta+t', => @toggleFileFinder()
@project = new Project(fs.directory(url)) if url
@editor.open url
if not url
# not sure what to do
else if fs.isDirectory url
@project = new Project url
@editor.open()
else
@project = new Project(fs.directory(url))
@editor.open url
addPane: (view) ->
pane = $('<div class="pane">')