mirror of
https://github.com/atom/atom.git
synced 2026-01-24 22:38:20 -05:00
Add show next / previous item.
This commit is contained in:
committed by
probablycorey
parent
372393d9ca
commit
ef0c62f532
@@ -17,10 +17,12 @@ describe "Pane", ->
|
||||
expect(pane.itemViews.find('#view-1')).toExist()
|
||||
|
||||
describe ".showItem(item)", ->
|
||||
it "hides all item views except the one being shown", ->
|
||||
it "hides all item views except the one being shown and sets the currentItem", ->
|
||||
expect(pane.currentItem).toBe view1
|
||||
pane.showItem(view2)
|
||||
expect(view1.css('display')).toBe 'none'
|
||||
expect(view2.css('display')).toBe ''
|
||||
expect(pane.currentItem).toBe view2
|
||||
|
||||
describe "when showing a model item", ->
|
||||
describe "when no view has yet been appended for that item", ->
|
||||
@@ -42,3 +44,15 @@ describe "Pane", ->
|
||||
expect(pane.itemViews.find('#view-2')).not.toExist()
|
||||
pane.showItem(view2)
|
||||
expect(pane.itemViews.find('#view-2')).toExist()
|
||||
|
||||
describe "pane:show-next-item and pane:show-preview-item", ->
|
||||
it "advances forward/backward through the pane's items, looping around at either end", ->
|
||||
expect(pane.currentItem).toBe view1
|
||||
pane.trigger 'pane:show-previous-item'
|
||||
expect(pane.currentItem).toBe editSession2
|
||||
pane.trigger 'pane:show-previous-item'
|
||||
expect(pane.currentItem).toBe view2
|
||||
pane.trigger 'pane:show-next-item'
|
||||
expect(pane.currentItem).toBe editSession2
|
||||
pane.trigger 'pane:show-next-item'
|
||||
expect(pane.currentItem).toBe view1
|
||||
|
||||
@@ -12,15 +12,42 @@ class Pane extends View
|
||||
@deserialize: ({wrappedView}) ->
|
||||
new Pane(deserialize(wrappedView))
|
||||
|
||||
currentItem: null
|
||||
items: null
|
||||
|
||||
initialize: (@items...) ->
|
||||
@viewsByClassName = {}
|
||||
@showItem(@items[0])
|
||||
|
||||
@command 'pane:show-next-item', @showNextItem
|
||||
@command 'pane:show-previous-item', @showPreviousItem
|
||||
|
||||
showNextItem: =>
|
||||
index = @getCurrentItemIndex()
|
||||
if index < @items.length - 1
|
||||
@showItemAtIndex(index + 1)
|
||||
else
|
||||
@showItemAtIndex(0)
|
||||
|
||||
showPreviousItem: =>
|
||||
index = @getCurrentItemIndex()
|
||||
if index > 0
|
||||
@showItemAtIndex(index - 1)
|
||||
else
|
||||
@showItemAtIndex(@items.length - 1)
|
||||
|
||||
getCurrentItemIndex: ->
|
||||
@items.indexOf(@currentItem)
|
||||
|
||||
showItemAtIndex: (index) ->
|
||||
@showItem(@items[index])
|
||||
|
||||
showItem: (item) ->
|
||||
@itemViews.children().hide()
|
||||
view = @viewForItem(item)
|
||||
unless view.parent().is(@itemViews)
|
||||
@itemViews.append(view)
|
||||
@currentItem = item
|
||||
view.show()
|
||||
|
||||
viewForItem: (item) ->
|
||||
@@ -34,7 +61,6 @@ class Pane extends View
|
||||
else
|
||||
@viewsByClassName[viewClass.name] = new viewClass(item)
|
||||
|
||||
|
||||
serialize: ->
|
||||
deserializer: "Pane"
|
||||
wrappedView: @wrappedView?.serialize()
|
||||
|
||||
Reference in New Issue
Block a user