RootView opens a project for the directory of the url passed to initialize.

Rename fixtures/file-finder-dir to fixtures/dir, because it's not really file-finder specific.
This commit is contained in:
Nathan Sobo
2012-01-03 16:01:37 -07:00
parent f8b04cd902
commit 07b40cdbeb
8 changed files with 42 additions and 8 deletions

View File

@@ -0,0 +1,15 @@
Project = require 'project'
fs = require 'fs'
describe "Project", ->
project = null
beforeEach ->
project = new Project(require.resolve('fixtures/dir'))
describe ".list()", ->
it "returns a promise which resolves to a list of all file urls in the project, recursively", ->
waitsFor (complete) ->
project.list().done (result) ->
expect(result).toEqual(fs.list(project.url, true))
complete()

View File

@@ -8,11 +8,17 @@ describe "RootView", ->
describe "initialize", ->
describe "when called with a url", ->
it "opens the given url in the editor", ->
url = require.resolve 'fixtures/sample.txt'
rootView = RootView.build {url}
describe "when the url references a file", ->
url = null
beforeEach ->
url = require.resolve 'fixtures/sample.txt'
rootView = RootView.build {url}
expect(rootView.editor.buffer.url).toBe url
it "creates a project for the file's parent directory", ->
expect(rootView.project.url).toBe fs.directory(url)
it "opens the file in the editor", ->
expect(rootView.editor.buffer.url).toBe url
describe "when not called with a url", ->
it "opens an empty buffer", ->
@@ -29,7 +35,7 @@ describe "RootView", ->
describe "toggleFileFinder", ->
describe "when the editor has a url", ->
baseUrl = require.resolve('fixtures/file-finder-dir/a')
baseUrl = require.resolve('fixtures/dir/a')
beforeEach ->
rootView.editor.open baseUrl
@@ -41,7 +47,7 @@ describe "RootView", ->
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()
it "shows urls for all files (not directories) by recursivley searching directory of editor.url", ->
it "shows all urls for the current project", ->
rootView.toggleFileFinder()
expect(rootView.fileFinder.urlList.children('li').length).toBe 3

View File

@@ -4,7 +4,7 @@ describe "fs", ->
describe ".async", ->
describe ".list(directoryPath, recursive)", ->
directoryPath = null
beforeEach -> directoryPath = require.resolve 'fixtures/file-finder-dir'
beforeEach -> directoryPath = require.resolve 'fixtures/dir'
describe "when recursive is true", ->
it "returns a promise that resolves to the recursive contents of that directory", ->

10
src/atom/project.coffee Normal file
View File

@@ -0,0 +1,10 @@
fs = require 'fs'
module.exports =
class Project
constructor: (@url) ->
list: ->
fs.async.list(@url, true)

View File

@@ -1,9 +1,10 @@
$ = require 'jquery'
fs = require 'fs'
Template = require 'template'
Editor = require 'editor'
FileFinder = require 'file-finder'
Template = require 'template'
Project = require 'project'
module.exports =
class RootView extends Template
@@ -20,6 +21,7 @@ class RootView extends Template
@bindKey 'meta+w', => window.close()
@bindKey 'meta+t', => @toggleFileFinder()
@project = new Project(fs.directory(url)) if url
@editor.open url
addPane: (view) ->
@@ -40,3 +42,4 @@ class RootView extends Template
@fileFinder = FileFinder.build({urls})
@addPane(@fileFinder)
@fileFinder.input.focus()