Add show next / previous item.

This commit is contained in:
Nathan Sobo
2013-02-18 11:44:51 -07:00
committed by probablycorey
parent 372393d9ca
commit ef0c62f532
2 changed files with 42 additions and 2 deletions

View File

@@ -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()