mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Rename Pane.currentItem/View to activeItem/View
This commit is contained in:
committed by
probablycorey
parent
15d8a6cada
commit
a40d05f6ee
@@ -27,13 +27,13 @@ describe "PaneContainer", ->
|
||||
it "focuses the pane following the focused pane or the first pane if no pane has focus", ->
|
||||
container.attachToDom()
|
||||
container.focusNextPane()
|
||||
expect(pane1.currentItem).toMatchSelector ':focus'
|
||||
expect(pane1.activeItem).toMatchSelector ':focus'
|
||||
container.focusNextPane()
|
||||
expect(pane2.currentItem).toMatchSelector ':focus'
|
||||
expect(pane2.activeItem).toMatchSelector ':focus'
|
||||
container.focusNextPane()
|
||||
expect(pane3.currentItem).toMatchSelector ':focus'
|
||||
expect(pane3.activeItem).toMatchSelector ':focus'
|
||||
container.focusNextPane()
|
||||
expect(pane1.currentItem).toMatchSelector ':focus'
|
||||
expect(pane1.activeItem).toMatchSelector ':focus'
|
||||
|
||||
describe ".getActivePane()", ->
|
||||
it "returns the most-recently focused pane", ->
|
||||
|
||||
@@ -20,19 +20,19 @@ describe "Pane", ->
|
||||
expect(pane.itemViews.find('#view-1')).toExist()
|
||||
|
||||
describe ".showItem(item)", ->
|
||||
it "hides all item views except the one being shown and sets the currentItem", ->
|
||||
expect(pane.currentItem).toBe view1
|
||||
it "hides all item views except the one being shown and sets the activeItem", ->
|
||||
expect(pane.activeItem).toBe view1
|
||||
pane.showItem(view2)
|
||||
expect(view1.css('display')).toBe 'none'
|
||||
expect(view2.css('display')).toBe ''
|
||||
expect(pane.currentItem).toBe view2
|
||||
expect(pane.activeItem).toBe view2
|
||||
|
||||
it "triggers 'pane:active-item-changed' if the item isn't already the currentItem", ->
|
||||
it "triggers 'pane:active-item-changed' if the item isn't already the activeItem", ->
|
||||
pane.makeActive()
|
||||
itemChangedHandler = jasmine.createSpy("itemChangedHandler")
|
||||
container.on 'pane:active-item-changed', itemChangedHandler
|
||||
|
||||
expect(pane.currentItem).toBe view1
|
||||
expect(pane.activeItem).toBe view1
|
||||
pane.showItem(view2)
|
||||
pane.showItem(view2)
|
||||
expect(itemChangedHandler.callCount).toBe 1
|
||||
@@ -45,20 +45,20 @@ describe "Pane", ->
|
||||
itemChangedHandler.reset()
|
||||
|
||||
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", ->
|
||||
it "adds it to the items list after the active item", ->
|
||||
view3 = $$ -> @div id: 'view-3', "View 3"
|
||||
pane.showItem(editSession1)
|
||||
expect(pane.getCurrentItemIndex()).toBe 1
|
||||
expect(pane.getActiveItemIndex()).toBe 1
|
||||
pane.showItem(view3)
|
||||
expect(pane.getItems()).toEqual [view1, editSession1, view3, view2, editSession2]
|
||||
expect(pane.currentItem).toBe view3
|
||||
expect(pane.getCurrentItemIndex()).toBe 2
|
||||
expect(pane.activeItem).toBe view3
|
||||
expect(pane.getActiveItemIndex()).toBe 2
|
||||
|
||||
describe "when showing a model item", ->
|
||||
describe "when no view has yet been appended for that item", ->
|
||||
it "appends and shows a view to display the item based on its `.getViewClass` method", ->
|
||||
pane.showItem(editSession1)
|
||||
editor = pane.currentView
|
||||
editor = pane.activeView
|
||||
expect(editor.css('display')).toBe ''
|
||||
expect(editor.activeEditSession).toBe editSession1
|
||||
|
||||
@@ -67,7 +67,7 @@ describe "Pane", ->
|
||||
pane.showItem(editSession1)
|
||||
pane.showItem(editSession2)
|
||||
expect(pane.itemViews.find('.editor').length).toBe 1
|
||||
editor = pane.currentView
|
||||
editor = pane.activeView
|
||||
expect(editor.css('display')).toBe ''
|
||||
expect(editor.activeEditSession).toBe editSession2
|
||||
|
||||
@@ -76,18 +76,18 @@ describe "Pane", ->
|
||||
expect(pane.itemViews.find('#view-2')).not.toExist()
|
||||
pane.showItem(view2)
|
||||
expect(pane.itemViews.find('#view-2')).toExist()
|
||||
expect(pane.currentView).toBe view2
|
||||
expect(pane.activeView).toBe view2
|
||||
|
||||
describe ".removeItem(item)", ->
|
||||
it "removes the item from the items list and shows the next item if it was showing", ->
|
||||
pane.removeItem(view1)
|
||||
expect(pane.getItems()).toEqual [editSession1, view2, editSession2]
|
||||
expect(pane.currentItem).toBe editSession1
|
||||
expect(pane.activeItem).toBe editSession1
|
||||
|
||||
pane.showItem(editSession2)
|
||||
pane.removeItem(editSession2)
|
||||
expect(pane.getItems()).toEqual [editSession1, view2]
|
||||
expect(pane.currentItem).toBe editSession1
|
||||
expect(pane.activeItem).toBe editSession1
|
||||
|
||||
it "removes the pane when its last item is removed", ->
|
||||
pane.removeItem(item) for item in pane.getItems()
|
||||
@@ -112,7 +112,7 @@ describe "Pane", ->
|
||||
expect(editSession2.destroyed).toBeTruthy()
|
||||
|
||||
describe "core:close", ->
|
||||
it "removes the current item and does not bubble the event", ->
|
||||
it "removes the active item and does not bubble the event", ->
|
||||
containerCloseHandler = jasmine.createSpy("containerCloseHandler")
|
||||
container.on 'core:close', containerCloseHandler
|
||||
|
||||
@@ -124,15 +124,15 @@ describe "Pane", ->
|
||||
|
||||
describe "pane:show-next-item and pane:show-previous-item", ->
|
||||
it "advances forward/backward through the pane's items, looping around at either end", ->
|
||||
expect(pane.currentItem).toBe view1
|
||||
expect(pane.activeItem).toBe view1
|
||||
pane.trigger 'pane:show-previous-item'
|
||||
expect(pane.currentItem).toBe editSession2
|
||||
expect(pane.activeItem).toBe editSession2
|
||||
pane.trigger 'pane:show-previous-item'
|
||||
expect(pane.currentItem).toBe view2
|
||||
expect(pane.activeItem).toBe view2
|
||||
pane.trigger 'pane:show-next-item'
|
||||
expect(pane.currentItem).toBe editSession2
|
||||
expect(pane.activeItem).toBe editSession2
|
||||
pane.trigger 'pane:show-next-item'
|
||||
expect(pane.currentItem).toBe view1
|
||||
expect(pane.activeItem).toBe view1
|
||||
|
||||
describe ".remove()", ->
|
||||
it "destroys all the pane's items", ->
|
||||
@@ -204,9 +204,9 @@ describe "Pane", ->
|
||||
expect(rootView.focus).not.toHaveBeenCalled()
|
||||
|
||||
describe "when the pane is focused", ->
|
||||
it "focuses the current item view", ->
|
||||
it "focuses the active item view", ->
|
||||
focusHandler = jasmine.createSpy("focusHandler")
|
||||
pane.currentItem.on 'focus', focusHandler
|
||||
pane.activeItem.on 'focus', focusHandler
|
||||
pane.focus()
|
||||
expect(focusHandler).toHaveBeenCalled()
|
||||
|
||||
@@ -231,11 +231,11 @@ describe "Pane", ->
|
||||
|
||||
describe "splitRight(items...)", ->
|
||||
it "builds a row if needed, then appends a new pane after itself", ->
|
||||
# creates the new pane with a copy of the current item if none are given
|
||||
# creates the new pane with a copy of the active item if none are given
|
||||
pane2 = pane1.splitRight()
|
||||
expect(container.find('.row .pane').toArray()).toEqual [pane1[0], pane2[0]]
|
||||
expect(pane2.items).toEqual [editSession1]
|
||||
expect(pane2.currentItem).not.toBe editSession1 # it's a copy
|
||||
expect(pane2.activeItem).not.toBe editSession1 # it's a copy
|
||||
|
||||
pane3 = pane2.splitRight(view3, view4)
|
||||
expect(pane3.getItems()).toEqual [view3, view4]
|
||||
@@ -243,11 +243,11 @@ describe "Pane", ->
|
||||
|
||||
describe "splitRight(items...)", ->
|
||||
it "builds a row if needed, then appends a new pane before itself", ->
|
||||
# creates the new pane with a copy of the current item if none are given
|
||||
# creates the new pane with a copy of the active item if none are given
|
||||
pane2 = pane.splitLeft()
|
||||
expect(container.find('.row .pane').toArray()).toEqual [pane2[0], pane[0]]
|
||||
expect(pane2.items).toEqual [editSession1]
|
||||
expect(pane2.currentItem).not.toBe editSession1 # it's a copy
|
||||
expect(pane2.activeItem).not.toBe editSession1 # it's a copy
|
||||
|
||||
pane3 = pane2.splitLeft(view3, view4)
|
||||
expect(pane3.getItems()).toEqual [view3, view4]
|
||||
@@ -255,11 +255,11 @@ describe "Pane", ->
|
||||
|
||||
describe "splitDown(items...)", ->
|
||||
it "builds a column if needed, then appends a new pane after itself", ->
|
||||
# creates the new pane with a copy of the current item if none are given
|
||||
# creates the new pane with a copy of the active item if none are given
|
||||
pane2 = pane.splitDown()
|
||||
expect(container.find('.column .pane').toArray()).toEqual [pane[0], pane2[0]]
|
||||
expect(pane2.items).toEqual [editSession1]
|
||||
expect(pane2.currentItem).not.toBe editSession1 # it's a copy
|
||||
expect(pane2.activeItem).not.toBe editSession1 # it's a copy
|
||||
|
||||
pane3 = pane2.splitDown(view3, view4)
|
||||
expect(pane3.getItems()).toEqual [view3, view4]
|
||||
@@ -267,11 +267,11 @@ describe "Pane", ->
|
||||
|
||||
describe "splitUp(items...)", ->
|
||||
it "builds a column if needed, then appends a new pane before itself", ->
|
||||
# creates the new pane with a copy of the current item if none are given
|
||||
# creates the new pane with a copy of the active item if none are given
|
||||
pane2 = pane.splitUp()
|
||||
expect(container.find('.column .pane').toArray()).toEqual [pane2[0], pane[0]]
|
||||
expect(pane2.items).toEqual [editSession1]
|
||||
expect(pane2.currentItem).not.toBe editSession1 # it's a copy
|
||||
expect(pane2.activeItem).not.toBe editSession1 # it's a copy
|
||||
|
||||
pane3 = pane2.splitUp(view3, view4)
|
||||
expect(pane3.getItems()).toEqual [view3, view4]
|
||||
|
||||
@@ -13,21 +13,21 @@ class Pane extends View
|
||||
@deserialize: ({items}) ->
|
||||
new Pane(items.map((item) -> deserialize(item))...)
|
||||
|
||||
currentItem: null
|
||||
activeItem: null
|
||||
items: null
|
||||
|
||||
initialize: (@items...) ->
|
||||
@viewsByClassName = {}
|
||||
@showItem(@items[0])
|
||||
|
||||
@command 'core:close', @removeCurrentItem
|
||||
@command 'core:close', @removeActiveItem
|
||||
@command 'pane:show-next-item', @showNextItem
|
||||
@command 'pane:show-previous-item', @showPreviousItem
|
||||
@command 'pane:split-left', => @splitLeft()
|
||||
@command 'pane:split-right', => @splitRight()
|
||||
@command 'pane:split-up', => @splitUp()
|
||||
@command 'pane:split-down', => @splitDown()
|
||||
@on 'focus', => @currentView.focus(); false
|
||||
@on 'focus', => @activeView.focus(); false
|
||||
@on 'focusin', => @makeActive()
|
||||
|
||||
afterAttach: ->
|
||||
@@ -52,47 +52,47 @@ class Pane extends View
|
||||
new Array(@items...)
|
||||
|
||||
showNextItem: =>
|
||||
index = @getCurrentItemIndex()
|
||||
index = @getActiveItemIndex()
|
||||
if index < @items.length - 1
|
||||
@showItemAtIndex(index + 1)
|
||||
else
|
||||
@showItemAtIndex(0)
|
||||
|
||||
showPreviousItem: =>
|
||||
index = @getCurrentItemIndex()
|
||||
index = @getActiveItemIndex()
|
||||
if index > 0
|
||||
@showItemAtIndex(index - 1)
|
||||
else
|
||||
@showItemAtIndex(@items.length - 1)
|
||||
|
||||
getCurrentItemIndex: ->
|
||||
@items.indexOf(@currentItem)
|
||||
getActiveItemIndex: ->
|
||||
@items.indexOf(@activeItem)
|
||||
|
||||
showItemAtIndex: (index) ->
|
||||
@showItem(@items[index])
|
||||
|
||||
showItem: (item) ->
|
||||
return if item is @currentItem
|
||||
return if item is @activeItem
|
||||
@addItem(item)
|
||||
@itemViews.children().hide()
|
||||
view = @viewForItem(item)
|
||||
@itemViews.append(view) unless view.parent().is(@itemViews)
|
||||
@currentItem = item
|
||||
@currentView = view
|
||||
@currentView.show()
|
||||
@activeItem = item
|
||||
@activeView = view
|
||||
@activeView.show()
|
||||
@trigger 'pane:active-item-changed', [item]
|
||||
|
||||
addItem: (item) ->
|
||||
return if _.include(@items, item)
|
||||
@items.splice(@getCurrentItemIndex() + 1, 0, item)
|
||||
@items.splice(@getActiveItemIndex() + 1, 0, item)
|
||||
item
|
||||
|
||||
removeCurrentItem: =>
|
||||
@removeItem(@currentItem)
|
||||
removeActiveItem: =>
|
||||
@removeItem(@activeItem)
|
||||
false
|
||||
|
||||
removeItem: (item) ->
|
||||
@showNextItem() if item is @currentItem and @items.length > 1
|
||||
@showNextItem() if item is @activeItem and @items.length > 1
|
||||
_.remove(@items, item)
|
||||
item.destroy?()
|
||||
@cleanupItemView(item)
|
||||
@@ -122,8 +122,8 @@ class Pane extends View
|
||||
view = @viewsByClassName[viewClass.name] = new viewClass(item)
|
||||
view
|
||||
|
||||
viewForCurrentItem: ->
|
||||
@viewForItem(@currentItem)
|
||||
viewForActiveItem: ->
|
||||
@viewForItem(@activeItem)
|
||||
|
||||
serialize: ->
|
||||
deserializer: "Pane"
|
||||
@@ -153,7 +153,7 @@ class Pane extends View
|
||||
.insertBefore(this)
|
||||
.append(@detach())
|
||||
|
||||
items = [@copyCurrentItem()] unless items.length
|
||||
items = [@copyActiveItem()] unless items.length
|
||||
pane = new Pane(items...)
|
||||
this[side](pane)
|
||||
@getContainer().adjustPaneDimensions()
|
||||
@@ -168,8 +168,8 @@ class Pane extends View
|
||||
getContainer: ->
|
||||
@closest('#panes').view()
|
||||
|
||||
copyCurrentItem: ->
|
||||
deserialize(@currentItem.serialize())
|
||||
copyActiveItem: ->
|
||||
deserialize(@activeItem.serialize())
|
||||
|
||||
remove: (selector, keepData) ->
|
||||
return super if keepData
|
||||
|
||||
Reference in New Issue
Block a user