mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Consolidate pane item destruction
This commit is contained in:
@@ -167,8 +167,8 @@ describe "PaneContainer", ->
|
||||
|
||||
describe ".confirmClose()", ->
|
||||
it "returns true after modified files are saved", ->
|
||||
pane1.itemAtIndex(0).isModified = -> true
|
||||
pane2.itemAtIndex(0).isModified = -> true
|
||||
pane1.itemAtIndex(0).shouldPromptToSave = -> true
|
||||
pane2.itemAtIndex(0).shouldPromptToSave = -> true
|
||||
spyOn(atom, "confirmSync").andReturn(0)
|
||||
|
||||
saved = container.confirmClose()
|
||||
@@ -178,8 +178,8 @@ describe "PaneContainer", ->
|
||||
expect(atom.confirmSync).toHaveBeenCalled()
|
||||
|
||||
it "returns false if the user cancels saving", ->
|
||||
pane1.itemAtIndex(0).isModified = -> true
|
||||
pane2.itemAtIndex(0).isModified = -> true
|
||||
pane1.itemAtIndex(0).shouldPromptToSave = -> true
|
||||
pane2.itemAtIndex(0).shouldPromptToSave = -> true
|
||||
spyOn(atom, "confirmSync").andReturn(1)
|
||||
|
||||
saved = container.confirmClose()
|
||||
|
||||
@@ -128,8 +128,8 @@ class PaneContainer extends View
|
||||
confirmClose: ->
|
||||
saved = true
|
||||
for pane in @getPanes()
|
||||
for item in pane.getItems() when item.isModified?()
|
||||
if not @paneAtIndex(0).promptToSaveItem item
|
||||
for item in pane.getItems()
|
||||
if not pane.destroyItem(item)
|
||||
saved = false
|
||||
break
|
||||
saved
|
||||
|
||||
@@ -196,15 +196,14 @@ class Pane extends View
|
||||
destroyItem: (item) ->
|
||||
@trigger 'pane:before-item-destroyed', [item]
|
||||
container = @getContainer()
|
||||
reallyDestroyItem = =>
|
||||
|
||||
if @promptToSaveItem(item)
|
||||
@removeItem(item)
|
||||
container.itemDestroyed(item)
|
||||
item.destroy?()
|
||||
|
||||
if item.shouldPromptToSave?()
|
||||
reallyDestroyItem() if @promptToSaveItem(item)
|
||||
true
|
||||
else
|
||||
reallyDestroyItem()
|
||||
false
|
||||
|
||||
# Public: Remove and delete all items.
|
||||
destroyItems: ->
|
||||
@@ -216,6 +215,8 @@ class Pane extends View
|
||||
|
||||
# Public: Prompt the user to save the given item.
|
||||
promptToSaveItem: (item) ->
|
||||
return true unless item.shouldPromptToSave?()
|
||||
|
||||
uri = item.getUri()
|
||||
chosen = atom.confirmSync(
|
||||
"'#{item.getTitle?() ? item.getUri()}' has changes, do you want to save them?"
|
||||
|
||||
Reference in New Issue
Block a user