Populate fuzzy-finder asynchronously

This commit is contained in:
Corey Johnson & Kevin Sawicki
2012-12-12 12:26:39 -08:00
parent 70796da309
commit 404f637101
8 changed files with 119 additions and 51 deletions

View File

@@ -24,13 +24,10 @@ class Project
@setPath(path)
@editSessions = []
@buffers = []
@ignoredFolderNames = [
@ignoredNames = [
'.git'
]
@ignoredFileNames = [
'.DS_Store'
]
@ignoredPathRegexes = []
@repo = new Git(path)
destroy: ->
@@ -55,52 +52,27 @@ class Project
@rootDirectory
getFilePaths: ->
filePaths = []
deferred = $.Deferred()
fs.getAllPathsAsync @getPath(), (paths) =>
paths = paths.filter (path) => not @isPathIgnored(path)
deferred.resolve(paths)
deferred.promise()
onFile = (path) =>
filePaths.push(path) unless @ignoreFile(path)
onDirectory = (path) =>
return not @ignoreDirectory(path)
fs.traverseTree @getPath(), onFile, onDirectory
filePaths
ignoreDirectory: (path) ->
isPathIgnored: (path) ->
lastSlash = path.lastIndexOf('/')
if lastSlash isnt -1
name = path.substring(lastSlash + 1)
else
name = path
for ignored in @ignoredFolderNames
for ignored in @ignoredNames
return true if name is ignored
for regex in @ignoredPathRegexes
return true if path.match(regex)
@ignoreRepositoryPath(path)
ignoreFile: (path) ->
lastSlash = path.lastIndexOf('/')
if lastSlash isnt -1
name = path.substring(lastSlash + 1)
else
name = path
for ignored in @ignoredFileNames
return true if name is ignored
for regex in @ignoredPathRegexes
return true if path.match(regex)
@ignoreRepositoryPath(path)
ignoreRepositoryPath: (path) ->
@hideIgnoredFiles and @repo.isPathIgnored(fs.join(@getPath(), path))
ignorePathRegex: ->
@ignoredPathRegexes.map((regex) -> "(#{regex.source})").join("|")
resolve: (filePath) ->
filePath = fs.join(@getPath(), filePath) unless filePath[0] == '/'
fs.absolute filePath

View File

@@ -9,6 +9,7 @@ class SelectList extends View
@div class: @viewClass(), =>
@subview 'miniEditor', new Editor(mini: true)
@div class: 'error', outlet: 'error'
@div class: 'loading', outlet: 'loading'
@ol outlet: 'list'
@viewClass: -> 'select-list'
@@ -38,6 +39,7 @@ class SelectList extends View
setArray: (@array) ->
@populateList()
@selectItem(@list.find('li:first'))
@setLoading()
setError: (message) ->
if not message or message.length == ""
@@ -49,6 +51,13 @@ class SelectList extends View
@error.show()
@addClass("error")
setLoading: (message) ->
if not message or message.length == ""
@loading.text("").hide()
else
@setError()
@loading.text(message).show()
populateList: ->
filterQuery = @miniEditor.getText()
if filterQuery.length