mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
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:
committed by
probablycorey
parent
ad62f896bc
commit
4a6f05ae4e
@@ -27,6 +27,27 @@ describe "Pane", ->
|
||||
expect(view2.css('display')).toBe ''
|
||||
expect(pane.currentItem).toBe view2
|
||||
|
||||
it "triggers 'pane:active-item-changed' if the pane is active and the item isn't already the currentItem", ->
|
||||
pane.makeActive()
|
||||
itemChangedHandler = jasmine.createSpy("itemChangedHandler")
|
||||
container.on 'pane:active-item-changed', itemChangedHandler
|
||||
|
||||
expect(pane.currentItem).toBe view1
|
||||
pane.showItem(view2)
|
||||
pane.showItem(view2)
|
||||
expect(itemChangedHandler.callCount).toBe 1
|
||||
expect(itemChangedHandler.argsForCall[0][1]).toBe view2
|
||||
itemChangedHandler.reset()
|
||||
|
||||
pane.showItem(editSession1)
|
||||
expect(itemChangedHandler).toHaveBeenCalled()
|
||||
expect(itemChangedHandler.argsForCall[0][1]).toBe editSession1
|
||||
itemChangedHandler.reset()
|
||||
|
||||
pane.makeInactive()
|
||||
pane.showItem(editSession2)
|
||||
expect(itemChangedHandler).not.toHaveBeenCalled()
|
||||
|
||||
describe "when the given item isn't yet in the items list on the pane", ->
|
||||
it "adds it to the items list after the current item", ->
|
||||
view3 = $$ -> @div id: 'view-3', "View 3"
|
||||
@@ -130,6 +151,18 @@ describe "Pane", ->
|
||||
pane.focus()
|
||||
expect(focusHandler).toHaveBeenCalled()
|
||||
|
||||
it "triggers 'pane:active-item-changed' if it was not previously active", ->
|
||||
itemChangedHandler = jasmine.createSpy("itemChangedHandler")
|
||||
container.on 'pane:active-item-changed', itemChangedHandler
|
||||
|
||||
expect(pane.isActive()).toBeFalsy()
|
||||
pane.focusin()
|
||||
expect(pane.isActive()).toBeTruthy()
|
||||
pane.focusin()
|
||||
|
||||
expect(itemChangedHandler.callCount).toBe 1
|
||||
expect(itemChangedHandler.argsForCall[0][1]).toBe pane.currentItem
|
||||
|
||||
describe "split methods", ->
|
||||
[pane1, view3, view4] = []
|
||||
beforeEach ->
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user