diff --git a/spec/pane-container-spec.coffee b/spec/pane-container-spec.coffee index 1701e3f03..c28436c6b 100644 --- a/spec/pane-container-spec.coffee +++ b/spec/pane-container-spec.coffee @@ -115,3 +115,29 @@ describe "PaneContainer", -> pane3.addItems([new Object, new Object]) expect(observed).toEqual container.getPaneItems() + + describe "::confirmClose()", -> + [container, pane1, pane2] = [] + + beforeEach -> + class TestItem + shouldPromptToSave: -> true + getUri: -> 'test' + + container = new PaneContainer + container.getRoot().splitRight() + [pane1, pane2] = container.getPanes() + pane1.addItem(new TestItem) + pane2.addItem(new TestItem) + + it "returns true if all the user saves all modified files when prompted", -> + spyOn(atom, "confirm").andReturn(0) + saved = container.confirmClose() + expect(saved).toBeTruthy() + expect(atom.confirm).toHaveBeenCalled() + + it "returns false if the user cancels saving", -> + spyOn(atom, "confirm").andReturn(1) + saved = container.confirmClose() + expect(saved).toBeFalsy() + expect(atom.confirm).toHaveBeenCalled() diff --git a/spec/pane-container-view-spec.coffee b/spec/pane-container-view-spec.coffee index 2c2a359dc..b5cbb4372 100644 --- a/spec/pane-container-view-spec.coffee +++ b/spec/pane-container-view-spec.coffee @@ -71,29 +71,6 @@ describe "PaneContainerView", -> for item in pane.getItems() expect(item.saved).toBeTruthy() - describe ".confirmClose()", -> - it "returns true after modified files are saved", -> - pane1.itemAtIndex(0).shouldPromptToSave = -> true - pane2.itemAtIndex(0).shouldPromptToSave = -> true - spyOn(atom, "confirm").andReturn(0) - - saved = container.confirmClose() - - runs -> - expect(saved).toBeTruthy() - expect(atom.confirm).toHaveBeenCalled() - - it "returns false if the user cancels saving", -> - pane1.itemAtIndex(0).shouldPromptToSave = -> true - pane2.itemAtIndex(0).shouldPromptToSave = -> true - spyOn(atom, "confirm").andReturn(1) - - saved = container.confirmClose() - - runs -> - expect(saved).toBeFalsy() - expect(atom.confirm).toHaveBeenCalled() - describe "serialization", -> it "can be serialized and deserialized, and correctly adjusts dimensions of deserialized panes after attach", -> newContainer = atom.workspace.getView(container.model.testSerialization()).__spacePenView diff --git a/spec/window-spec.coffee b/spec/window-spec.coffee index 6c588ec2d..ace60ebe8 100644 --- a/spec/window-spec.coffee +++ b/spec/window-spec.coffee @@ -63,9 +63,9 @@ describe "Window", -> beforeUnloadEvent = $.Event(new Event('beforeunload')) describe "when pane items are are modified", -> - it "prompts user to save and and calls workspaceView.confirmClose", -> + it "prompts user to save and and calls atom.workspace.confirmClose", -> editor = null - spyOn(atom.workspaceView, 'confirmClose').andCallThrough() + spyOn(atom.workspace, 'confirmClose').andCallThrough() spyOn(atom, "confirm").andReturn(2) waitsForPromise -> @@ -74,7 +74,7 @@ describe "Window", -> runs -> editor.insertText("I look different, I feel different.") $(window).trigger(beforeUnloadEvent) - expect(atom.workspaceView.confirmClose).toHaveBeenCalled() + expect(atom.workspace.confirmClose).toHaveBeenCalled() expect(atom.confirm).toHaveBeenCalled() it "prompts user to save and handler returns true if don't save", -> diff --git a/src/pane-container-view.coffee b/src/pane-container-view.coffee index 6f59f6fd2..bd04f38e2 100644 --- a/src/pane-container-view.coffee +++ b/src/pane-container-view.coffee @@ -30,13 +30,7 @@ class PaneContainerView extends View @trigger 'pane-container:active-pane-item-changed', [activeItem] confirmClose: -> - saved = true - for paneView in @getPaneViews() - for item in paneView.getItems() - if not paneView.promptToSaveItem(item) - saved = false - break - saved + @model.confirmClose() getPaneViews: -> @find('.pane').views() diff --git a/src/pane-container.coffee b/src/pane-container.coffee index 07c86c8a8..aa9f17d97 100644 --- a/src/pane-container.coffee +++ b/src/pane-container.coffee @@ -144,6 +144,17 @@ class PaneContainer extends Model saveAll: -> pane.saveItems() for pane in @getPanes() + confirmClose: -> + allSaved = true + + for pane in @getPanes() + for item in pane.getItems() + unless pane.promptToSaveItem(item) + allSaved = false + break + + allSaved + activateNextPane: -> panes = @getPanes() if panes.length > 1 diff --git a/src/pane.coffee b/src/pane.coffee index e88588875..b188473b3 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -413,11 +413,10 @@ class Pane extends Model @destroyItem(item) for item in @getItems() when item isnt @activeItem promptToSaveItem: (item) -> - return true unless item.shouldPromptToSave?() + return true unless typeof item.getUri is 'function' and item.shouldPromptToSave?() - uri = item.getUri() chosen = atom.confirm - message: "'#{item.getTitle?() ? item.getUri()}' has changes, do you want to save them?" + message: "'#{item.getTitle?() ? item.getUri?()}' has changes, do you want to save them?" detailedMessage: "Your changes will be lost if you close this item without saving." buttons: ["Save", "Cancel", "Don't Save"] diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 5fe4a9ec6..31ce35ec5 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -37,7 +37,7 @@ class WindowEventHandler atom.workspace?.open(pathToOpen, {initialLine, initialColumn}) @subscribe $(window), 'beforeunload', => - confirmed = atom.workspaceView?.confirmClose() + confirmed = atom.workspace?.confirmClose() atom.hide() if confirmed and not @reloadRequested and atom.getCurrentWindow().isWebViewFocused() @reloadRequested = false diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index 12947db59..b838acc51 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -348,7 +348,7 @@ class WorkspaceView extends View # Prompts to save all unsaved items confirmClose: -> - @panes.confirmClose() + @model.confirmClose() # Updates the application's title and proxy icon based on whichever file is # open. diff --git a/src/workspace.coffee b/src/workspace.coffee index 33b5bbd3f..999ee0b01 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -433,6 +433,9 @@ class Workspace extends Model saveAll: -> @paneContainer.saveAll() + confirmClose: -> + @paneContainer.confirmClose() + # Save the active pane item. # # If the active pane item currently has a URI according to the item's