mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-21 07:58:04 +03:00
Add Pane.destroyItem and rename removeActiveItem -> destroyActiveItem
Pane.removeItem removes an item, but no longer tries to call destroy on it. This will facilitate moving items between panes.
This commit is contained in:
parent
61fa393e03
commit
2e2ff3a1d0
@ -88,6 +88,12 @@ describe "Pane", ->
|
|||||||
expect(pane.itemViews.find('#view-2')).toExist()
|
expect(pane.itemViews.find('#view-2')).toExist()
|
||||||
expect(pane.activeView).toBe view2
|
expect(pane.activeView).toBe view2
|
||||||
|
|
||||||
|
describe ".destroyItem(item)", ->
|
||||||
|
it "removes the item and destroys it if it's a model", ->
|
||||||
|
pane.destroyItem(editSession2)
|
||||||
|
expect(pane.getItems().indexOf(editSession2)).toBe -1
|
||||||
|
expect(editSession2.destroyed).toBeTruthy()
|
||||||
|
|
||||||
describe ".removeItem(item)", ->
|
describe ".removeItem(item)", ->
|
||||||
it "removes the item from the items list and shows the next item if it was showing", ->
|
it "removes the item from the items list and shows the next item if it was showing", ->
|
||||||
pane.removeItem(view1)
|
pane.removeItem(view1)
|
||||||
@ -124,10 +130,6 @@ describe "Pane", ->
|
|||||||
pane.removeItem(editSession1)
|
pane.removeItem(editSession1)
|
||||||
expect(pane.itemViews.find('.editor')).not.toExist()
|
expect(pane.itemViews.find('.editor')).not.toExist()
|
||||||
|
|
||||||
it "calls destroy on the model", ->
|
|
||||||
pane.removeItem(editSession2)
|
|
||||||
expect(editSession2.destroyed).toBeTruthy()
|
|
||||||
|
|
||||||
describe ".moveItem(item, index)", ->
|
describe ".moveItem(item, index)", ->
|
||||||
it "moves the item to the given index and emits a 'pane:item-moved' event with the item and the new index", ->
|
it "moves the item to the given index and emits a 'pane:item-moved' event with the item and the new index", ->
|
||||||
itemMovedHandler = jasmine.createSpy("itemMovedHandler")
|
itemMovedHandler = jasmine.createSpy("itemMovedHandler")
|
||||||
@ -152,13 +154,15 @@ describe "Pane", ->
|
|||||||
itemMovedHandler.reset()
|
itemMovedHandler.reset()
|
||||||
|
|
||||||
describe "core:close", ->
|
describe "core:close", ->
|
||||||
it "removes the active item and does not bubble the event", ->
|
it "destroys the active item and does not bubble the event", ->
|
||||||
containerCloseHandler = jasmine.createSpy("containerCloseHandler")
|
containerCloseHandler = jasmine.createSpy("containerCloseHandler")
|
||||||
container.on 'core:close', containerCloseHandler
|
container.on 'core:close', containerCloseHandler
|
||||||
|
|
||||||
|
pane.showItem(editSession1)
|
||||||
initialItemCount = pane.getItems().length
|
initialItemCount = pane.getItems().length
|
||||||
pane.trigger 'core:close'
|
pane.trigger 'core:close'
|
||||||
expect(pane.getItems().length).toBe initialItemCount - 1
|
expect(pane.getItems().length).toBe initialItemCount - 1
|
||||||
|
expect(editSession1.destroyed).toBeTruthy()
|
||||||
|
|
||||||
expect(containerCloseHandler).not.toHaveBeenCalled()
|
expect(containerCloseHandler).not.toHaveBeenCalled()
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class Pane extends View
|
|||||||
@viewsByClassName = {}
|
@viewsByClassName = {}
|
||||||
@showItem(@items[0])
|
@showItem(@items[0])
|
||||||
|
|
||||||
@command 'core:close', @removeActiveItem
|
@command 'core:close', @destroyActiveItem
|
||||||
@command 'pane:show-next-item', @showNextItem
|
@command 'pane:show-next-item', @showNextItem
|
||||||
@command 'pane:show-previous-item', @showPreviousItem
|
@command 'pane:show-previous-item', @showPreviousItem
|
||||||
@command 'pane:split-left', => @splitLeft()
|
@command 'pane:split-left', => @splitLeft()
|
||||||
@ -89,17 +89,21 @@ class Pane extends View
|
|||||||
@trigger 'pane:item-added', [item, index]
|
@trigger 'pane:item-added', [item, index]
|
||||||
item
|
item
|
||||||
|
|
||||||
removeActiveItem: =>
|
destroyActiveItem: =>
|
||||||
@removeItem(@activeItem)
|
@destroyItem(@activeItem)
|
||||||
false
|
false
|
||||||
|
|
||||||
|
destroyItem: (item) ->
|
||||||
|
@removeItem(item)
|
||||||
|
item.destroy?()
|
||||||
|
|
||||||
removeItem: (item) ->
|
removeItem: (item) ->
|
||||||
index = @items.indexOf(item)
|
index = @items.indexOf(item)
|
||||||
return if index == -1
|
return if index == -1
|
||||||
|
|
||||||
@showNextItem() if item is @activeItem and @items.length > 1
|
@showNextItem() if item is @activeItem and @items.length > 1
|
||||||
_.remove(@items, item)
|
_.remove(@items, item)
|
||||||
item.destroy?()
|
|
||||||
@cleanupItemView(item)
|
@cleanupItemView(item)
|
||||||
@trigger 'pane:item-removed', [item, index]
|
@trigger 'pane:item-removed', [item, index]
|
||||||
@remove() unless @items.length
|
@remove() unless @items.length
|
||||||
|
Loading…
Reference in New Issue
Block a user