Don't use error class in select list

Use a subtler error message that displays in the same place as the
loading message but does not change the entire background of the
view.

Also, extending classes can now customize the message displayed
when there are no items and also no filtered items to allow for
different messages for these two cases.
This commit is contained in:
Kevin Sawicki 2013-06-13 11:31:09 -07:00
parent 77172800a8
commit ff7c639b64
9 changed files with 62 additions and 52 deletions

View File

@ -42,7 +42,6 @@ describe "SelectList", ->
expect(list.find('li:contains(Delta)')).toExist()
expect(list.find('li:first')).toHaveClass 'selected'
expect(selectList.error).not.toBeVisible()
expect(selectList).not.toHaveClass("error")
it "displays an error if there are no matches, removes error when there are matches", ->
miniEditor.insertText('nothing will match this')
@ -50,14 +49,12 @@ describe "SelectList", ->
expect(list.find('li').length).toBe 0
expect(selectList.error).not.toBeHidden()
expect(selectList).toHaveClass("error")
miniEditor.setText('la')
window.advanceClock(selectList.inputThrottle)
expect(list.find('li').length).toBe 2
expect(selectList.error).not.toBeVisible()
expect(selectList).not.toHaveClass("error")
it "displays no elements until the array has been set on the list", ->
selectList.array = null
@ -66,7 +63,7 @@ describe "SelectList", ->
window.advanceClock(selectList.inputThrottle)
expect(list.find('li').length).toBe 0
expect(selectList).not.toHaveClass("error")
expect(selectList.error).toBeHidden()
selectList.setArray(array)
expect(list.find('li').length).toBe 2

View File

@ -11,7 +11,7 @@ class SelectList extends View
@content: ->
@div class: @viewClass(), =>
@subview 'miniEditor', new Editor(mini: true)
@div class: 'error', outlet: 'error'
@div class: 'error-message', outlet: 'error'
@div class: 'loading', outlet: 'loadingArea', =>
@span class: 'loading-message', outlet: 'loading'
@span class: 'badge', outlet: 'loadingBadge'
@ -62,12 +62,10 @@ class SelectList extends View
setError: (message='') ->
if message.length is 0
@error.text("").hide()
@removeClass("error")
@error.text('').hide()
else
@setLoading()
@error.text(message).show()
@addClass("error")
setLoading: (message='') ->
if message.length is 0
@ -103,7 +101,9 @@ class SelectList extends View
@selectItem(@list.find('li:first'))
else
@setError("No matches found")
@setError(@getEmptyMessage(@array.length, filteredArray.length))
getEmptyMessage: (itemCount, filteredItemCount) -> 'No matches found'
selectPreviousItem: ->
item = @getSelectedItem().prev()

View File

@ -1,20 +1,26 @@
.select-list.autocomplete {
box-sizing: content-box;
margin-left: 0;
}
.autocomplete {
&.select-list {
box-sizing: content-box;
margin-left: 0;
.autocomplete ol {
box-sizing: content-box;
position: relative;
overflow-y: scroll;
max-height: 200px;
}
ol li {
padding: 5px 0 5px 0;
}
}
.select-list.autocomplete ol li {
padding: 5px 0 5px 0;
}
ol {
box-sizing: content-box;
position: relative;
overflow-y: scroll;
max-height: 200px;
}
.autocomplete span {
padding-left: 5px;
padding-right: 5px;
span {
padding-left: 5px;
padding-right: 5px;
}
.error-message {
margin: 2px;
}
}

View File

@ -11,6 +11,7 @@ Point = require 'point'
module.exports =
class FuzzyFinderView extends SelectList
filenameRegex: /[\w\.\-\/\\]+/
finderMode: null
@viewClass: ->
[super, 'fuzzy-finder', 'overlay', 'from-top'].join(' ')
@ -104,6 +105,7 @@ class FuzzyFinderView extends SelectList
setTimeout((=> @setError()), 2000)
toggleFileFinder: ->
@finderMode = 'file'
if @hasParent()
@cancel()
else
@ -113,6 +115,7 @@ class FuzzyFinderView extends SelectList
@attach()
toggleBufferFinder: ->
@finderMode = 'buffer'
if @hasParent()
@cancel()
else
@ -121,6 +124,7 @@ class FuzzyFinderView extends SelectList
@attach() if @paths?.length
toggleGitFinder: ->
@finderMode = 'git'
if @hasParent()
@cancel()
else
@ -129,6 +133,20 @@ class FuzzyFinderView extends SelectList
@populateGitStatusPaths()
@attach()
getEmptyMessage: (itemCount) ->
if itemCount is 0
switch @finderMode
when 'git'
'Nothing to commit, working directory clean'
when 'buffer'
'No open editors'
when 'file'
'Project is empty'
else
super
else
super
findUnderCursor: ->
if @hasParent()
@cancel()

View File

@ -116,9 +116,9 @@ describe 'FuzzyFinder', ->
finderView.confirmed({filePath: 'dir/this/is/not/a/file.txt'})
expect(finderView.hasParent()).toBeTruthy()
expect(rootView.getActiveView().getPath()).toBe editorPath
expect(finderView.find('.error').text().length).toBeGreaterThan 0
expect(finderView.error.text().length).toBeGreaterThan 0
advanceClock(2000)
expect(finderView.find('.error').text().length).toBe 0
expect(finderView.error.text().length).toBe 0
describe "buffer-finder behavior", ->
describe "toggling", ->
@ -429,7 +429,7 @@ describe 'FuzzyFinder', ->
finderView.is(':visible')
runs ->
expect(finderView.find('.error').text().length).toBeGreaterThan 0
expect(finderView.error.text().length).toBeGreaterThan 0
it "displays error when there is no word under the cursor", ->
editor.setText("&&&&&&&&&&&&&&& sample")
@ -441,7 +441,7 @@ describe 'FuzzyFinder', ->
finderView.is(':visible')
runs ->
expect(finderView.find('.error').text().length).toBeGreaterThan 0
expect(finderView.error.text().length).toBeGreaterThan 0
describe "opening a path into a split", ->
it "opens the path by splitting the active editor left", ->

View File

@ -9,7 +9,6 @@ $ = require 'jquery'
module.exports =
class SymbolsView extends SelectList
@activate: ->
new SymbolsView
@ -34,6 +33,12 @@ class SymbolsView extends SelectList
text = path.basename(file)
@div text, class: 'secondary-line'
getEmptyMessage: (itemCount) ->
if itemCount is 0
'No symbols found'
else
super
toggleFileSymbols: ->
if @hasParent()
@cancel()
@ -46,11 +51,8 @@ class SymbolsView extends SelectList
@list.empty()
@setLoading("Generating symbols...")
new TagGenerator(filePath).generate().done (tags) =>
if tags.length > 0
@maxItem = Infinity
@setArray(tags)
else
@setError("No symbols found")
@maxItem = Infinity
@setArray(tags)
toggleProjectSymbols: ->
if @hasParent()
@ -63,13 +65,8 @@ class SymbolsView extends SelectList
@list.empty()
@setLoading("Loading symbols...")
TagReader.getAllTags(project).done (tags) =>
if tags.length > 0
@miniEditor.show()
@maxItems = 10
@setArray(tags)
else
@miniEditor.hide()
@setError("No symbols found")
@maxItems = 10
@setArray(tags)
confirmed : (tag) ->
if tag.file and not fsUtils.isFileSync(project.resolve(tag.file))

View File

@ -34,7 +34,6 @@ describe "SymbolsView", ->
expect(symbolsView.list.children('li:first').find('.secondary-line')).toHaveText 'Line 1'
expect(symbolsView.list.children('li:last').find('.primary-line')).toHaveText 'quicksort.sort'
expect(symbolsView.list.children('li:last').find('.secondary-line')).toHaveText 'Line 2'
expect(symbolsView).not.toHaveClass "error"
expect(symbolsView.error).not.toBeVisible()
it "displays error when no tags match text in mini-editor", ->
@ -53,14 +52,12 @@ describe "SymbolsView", ->
expect(symbolsView.list.children('li').length).toBe 0
expect(symbolsView.error).toBeVisible()
expect(symbolsView.error.text().length).toBeGreaterThan 0
expect(symbolsView).toHaveClass "error"
# Should remove error
symbolsView.miniEditor.setText("")
window.advanceClock(symbolsView.inputThrottle)
expect(symbolsView.list.children('li').length).toBe 2
expect(symbolsView).not.toHaveClass "error"
expect(symbolsView.error).not.toBeVisible()
describe "when tags can't be generated for a file", ->
@ -78,7 +75,6 @@ describe "SymbolsView", ->
expect(symbolsView.list.children('li').length).toBe 0
expect(symbolsView.error).toBeVisible()
expect(symbolsView.error.text().length).toBeGreaterThan 0
expect(symbolsView).toHaveClass "error"
expect(symbolsView.loadingArea).not.toBeVisible()
it "moves the cursor to the selected function", ->
@ -196,7 +192,6 @@ describe "SymbolsView", ->
expect(symbolsView.list.children('li:first').find('.secondary-line')).toHaveText 'tagged.js'
expect(symbolsView.list.children('li:last').find('.primary-line')).toHaveText 'thisIsCrazy'
expect(symbolsView.list.children('li:last').find('.secondary-line')).toHaveText 'tagged.js'
expect(symbolsView).not.toHaveClass "error"
expect(symbolsView.error).not.toBeVisible()
describe "when selecting a tag", ->
@ -223,4 +218,3 @@ describe "SymbolsView", ->
symbolsView.list.children('li:first').mousedown().mouseup()
expect(rootView.open).not.toHaveBeenCalled()
expect(symbolsView.error.text().length).toBeGreaterThan 0
expect(symbolsView).toHaveClass "error"

View File

@ -1,10 +1,6 @@
@import "octicon-mixins.less";
.select-list {
.error {
font-weight: bold;
}
.loading {
.loading-message:before {
font-family: 'Octicons Regular';

View File

@ -1,4 +1,6 @@
.select-list {
background: #202123;
.error {
color: white;
text-shadow: 0 1px 0 #4E0000;