Trigger 'pane:active-item-changed' on Pane

This event is triggered when the item changes on the active pane, or
when a different pane becomes active.

Also: Pane now sets itself as the active pane, rather than letting
PaneContainer handle the focusin event.
This commit is contained in:
Kevin Sawicki & Nathan Sobo
2013-02-21 16:22:19 -07:00
committed by probablycorey
parent ad62f896bc
commit 4a6f05ae4e
3 changed files with 50 additions and 11 deletions

View File

@@ -13,11 +13,6 @@ class PaneContainer extends View
@content: ->
@div id: 'panes'
initialize: ->
@on 'focusin', (e) =>
focusedPane = $(e.target).closest('.pane').view()
@setActivePane(focusedPane)
serialize: ->
deserializer: 'PaneContainer'
root: @getRoot()?.serialize()
@@ -40,9 +35,6 @@ class PaneContainer extends View
getActivePane: ->
@find('.pane.active').view() ? @find('.pane:first').view()
setActivePane: (pane) ->
@find('.pane').removeClass('active')
pane.addClass('active')
adjustPaneDimensions: ->
if root = @getRoot()

View File

@@ -27,9 +27,21 @@ class Pane extends View
@command 'pane:split-right', => @splitRight()
@command 'pane:split-up', => @splitUp()
@command 'pane:split-down', => @splitDown()
@on 'focus', =>
@viewForCurrentItem().focus()
false
@on 'focus', => @currentView.focus(); false
@on 'focusin', => @makeActive()
makeActive: ->
for pane in @getContainer().getPanes() when pane isnt this
pane.makeInactive()
wasActive = @isActive()
@addClass('active')
@trigger 'pane:active-item-changed', [@currentItem] unless wasActive
makeInactive: ->
@removeClass('active')
isActive: ->
@hasClass('active')
getItems: ->
new Array(@items...)
@@ -55,6 +67,7 @@ class Pane extends View
@showItem(@items[index])
showItem: (item) ->
return if item is @currentItem
@addItem(item)
@itemViews.children().hide()
view = @viewForItem(item)
@@ -62,6 +75,7 @@ class Pane extends View
@currentItem = item
@currentView = view
@currentView.show()
@trigger 'pane:active-item-changed', [item] if @isActive()
addItem: (item) ->
return if _.include(@items, item)