mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -599,8 +599,8 @@ class Workspace extends Model
|
||||
saveAll: ->
|
||||
@paneContainer.saveAll()
|
||||
|
||||
confirmClose: ->
|
||||
@paneContainer.confirmClose()
|
||||
confirmClose: (options) ->
|
||||
@paneContainer.confirmClose(options)
|
||||
|
||||
# Save the active pane item.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user