Prompt split editors to save on close

Previously an editor that was split into multiple panes would not
prompt to save correctly when the window was unloading.

This adds a new `windowCloseRequested` option passed through from the
beforeunload handler to the editor so that it can specially handle this
case.

Closes #5257
This commit is contained in:
Kevin Sawicki
2015-02-04 17:14:46 -08:00
parent c5b6b90c88
commit fd1d872840
6 changed files with 34 additions and 9 deletions

View File

@@ -152,12 +152,12 @@ class PaneContainer extends Model
saveAll: ->
pane.saveItems() for pane in @getPanes()
confirmClose: ->
confirmClose: (options) ->
allSaved = true
for pane in @getPanes()
for item in pane.getItems()
unless pane.promptToSaveItem(item)
unless pane.promptToSaveItem(item, options)
allSaved = false
break

View File

@@ -437,8 +437,8 @@ class Pane extends Model
destroyInactiveItems: ->
@destroyItem(item) for item in @getItems() when item isnt @activeItem
promptToSaveItem: (item) ->
return true unless item.shouldPromptToSave?()
promptToSaveItem: (item, options={}) ->
return true unless item.shouldPromptToSave?(options)
if typeof item.getURI is 'function'
uri = item.getURI()

View File

@@ -641,7 +641,11 @@ class TextEditor extends Model
# Determine whether the user should be prompted to save before closing
# this editor.
shouldPromptToSave: -> @isModified() and not @buffer.hasMultipleEditors()
shouldPromptToSave: ({windowCloseRequested}={})->
if windowCloseRequested
@isModified()
else
@isModified() and not @buffer.hasMultipleEditors()
###
Section: Reading Text

View File

@@ -52,7 +52,7 @@ class WindowEventHandler
@subscribe $(window), 'blur', -> document.body.classList.add('is-blurred')
@subscribe $(window), 'beforeunload', =>
confirmed = atom.workspace?.confirmClose()
confirmed = atom.workspace?.confirmClose(windowCloseRequested: true)
atom.hide() if confirmed and not @reloadRequested and atom.getCurrentWindow().isWebViewFocused()
@reloadRequested = false

View File

@@ -599,8 +599,8 @@ class Workspace extends Model
saveAll: ->
@paneContainer.saveAll()
confirmClose: ->
@paneContainer.confirmClose()
confirmClose: (options) ->
@paneContainer.confirmClose(options)
# Save the active pane item.
#