RootView.toggleFileFinder scans urls asynchronously.

This commit is contained in:
Nathan Sobo
2012-01-03 16:39:09 -07:00
parent 07b40cdbeb
commit 6dddb1aa26
3 changed files with 45 additions and 38 deletions

View File

@@ -4,28 +4,23 @@ RootView = require 'root-view'
describe "RootView", ->
rootView = null
beforeEach -> rootView = RootView.build()
url = null
beforeEach ->
url = require.resolve 'fixtures/dir/a'
rootView = RootView.build {url}
describe "initialize", ->
describe "when called with a url", ->
describe "when the url references a file", ->
url = null
beforeEach ->
url = require.resolve 'fixtures/sample.txt'
rootView = RootView.build {url}
it "creates a project for the file's parent directory", ->
it "creates a project for the file's parent directory and opens it in the editor", ->
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", ->
url = null
rootView = RootView.build {url}
expect(rootView.editor.buffer.url).toBeNull()
rootView = RootView.build()
expect(rootView.editor.buffer.url).toBeUndefined()
describe ".addPane(view)", ->
it "adds the given view to the rootView (at the bottom by default)", ->
@@ -33,34 +28,41 @@ describe "RootView", ->
rootView.addPane $('<div id="foo">')
expect(rootView.vertical.children().length).toBe 2
describe "toggleFileFinder", ->
describe "when the editor has a url", ->
baseUrl = require.resolve('fixtures/dir/a')
beforeEach ->
rootView.editor.open baseUrl
describe ".toggleFileFinder()", ->
describe "when there is a project", ->
it "shows the FileFinder when it is not on screen and hides it when it is", ->
expect(rootView.find('.file-finder')).not.toExist()
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).toExist()
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()
runs ->
expect(rootView.find('.file-finder')).not.toExist()
waitsForPromise ->
rootView.toggleFileFinder()
runs ->
expect(rootView.find('.file-finder')).toExist()
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()
it "shows all urls for the current project", ->
rootView.toggleFileFinder()
expect(rootView.fileFinder.urlList.children('li').length).toBe 3
waitsForPromise ->
rootView.toggleFileFinder()
runs ->
expect(rootView.fileFinder.urlList.children('li').length).toBe 3
it "remove common path prefix from files", ->
rootView.toggleFileFinder()
commonPathPattern = new RegExp("^" + fs.directory(baseUrl))
expect(rootView.fileFinder.urlList.children('li:first').text()).not.toMatch commonPathPattern
it "removes common path prefix from files", ->
waitsForPromise ->
rootView.toggleFileFinder()
runs ->
commonPathPattern = new RegExp("^" + fs.directory(url))
expect(rootView.fileFinder.urlList.children('li:first').text()).not.toMatch commonPathPattern
describe "when there is no project", ->
beforeEach ->
rootView = RootView.build()
describe "when the editor has no url", ->
it "does not open the FileFinder", ->
expect(rootView.editor.buffer.url).toBeUndefined()
expect(rootView.find('.file-finder')).not.toExist()
rootView.toggleFileFinder()
expect(rootView.find('.file-finder')).not.toExist()

View File

@@ -15,3 +15,7 @@ window.keydown = (pattern) ->
window.createKeyEvent = (pattern) ->
$.Event "keydown", atom.keyBinder.parseKeyPattern(pattern)
window.waitsForPromise = (fn) ->
window.waitsFor (moveOn) ->
fn().done(moveOn)

View File

@@ -37,9 +37,10 @@ class RootView extends Template
@fileFinder = null
else
directory = fs.directory @editor.buffer.url
urls = (url for url in fs.list(directory, true) when fs.isFile url)
urls = (url.replace(directory, "") for url in urls)
@fileFinder = FileFinder.build({urls})
@addPane(@fileFinder)
@fileFinder.input.focus()
return fs.async.list(directory, true).done (urls) =>
urls = (url for url in urls when fs.isFile url)
urls = (url.replace(directory, "") for url in urls)
@fileFinder = FileFinder.build({urls})
@addPane(@fileFinder)
@fileFinder.input.focus()