Destroy inactive editor sessions that are dirty

A confirm dialog is now displayed whenever a session
with a dirty buffer is closed so dirty sessions can now
be processed when 'editor:close-other-tabs' is fired.
This commit is contained in:
Kevin Sawicki
2013-01-07 16:47:32 -08:00
parent 0adae3c634
commit ebe7ff7090
2 changed files with 22 additions and 16 deletions

View File

@@ -2050,14 +2050,12 @@ describe "Editor", ->
expect(editor.getEditSessions().length).toBe 2
spyOn(atom, "confirm")
editor.destroyEditSessionIndex(0)
expect(atom.confirm).toHaveBeenCalled
expect(atom.confirm).toHaveBeenCalled()
expect(editor.getEditSessions().length).toBe 2
expect(editor.getEditSessions()[0].buffer.isModified()).toBeTruthy()
describe ".destroyInactiveEditSessions()", ->
it "destroys all non-active, non-modified edit sessions", ->
editor.setText("I'm dirty")
dirtySession = editor.activeEditSession
it "destroys every edit session except the active one", ->
rootView.open('sample.txt')
cssSession = rootView.open('css.css')
rootView.open('coffee.coffee')
@@ -2065,7 +2063,17 @@ describe "Editor", ->
expect(editor.getEditSessions().length).toBe 5
editor.setActiveEditSessionIndex(2)
editor.destroyInactiveEditSessions()
expect(editor.getActiveEditSessionIndex()).toBe 1
expect(editor.getActiveEditSessionIndex()).toBe 0
expect(editor.getEditSessions().length).toBe 1
expect(editor.getEditSessions()[0]).toBe cssSession
it "prompts to save dirty buffers before destroying", ->
editor.setText("I'm dirty")
dirtySession = editor.activeEditSession
rootView.open('sample.txt')
expect(editor.getEditSessions().length).toBe 2
expect(editor.getEditSessions()[0]).toBe dirtySession
expect(editor.getEditSessions()[1]).toBe cssSession
spyOn(atom, "confirm")
editor.destroyInactiveEditSessions()
expect(atom.confirm).toHaveBeenCalled()
expect(editor.getEditSessions().length).toBe 2
expect(editor.getEditSessions()[0].buffer.isModified()).toBeTruthy()

View File

@@ -447,17 +447,18 @@ class Editor extends View
destroyActiveEditSession: ->
@destroyEditSessionIndex(@getActiveEditSessionIndex())
destroyEditSessionIndex: (index) ->
destroyEditSessionIndex: (index, callback) ->
return if @mini
editSession = @editSessions[index]
destroySession = =>
if index is @getActiveEditSessionIndex()
if index is @getActiveEditSessionIndex() and @editSessions.length > 1
@loadPreviousEditSession()
_.remove(@editSessions, editSession)
editSession.destroy()
@trigger 'editor:edit-session-removed', [editSession, index]
@remove() if @editSessions.length is 0
callback(index) if callback
if editSession.buffer.isModified()
@promptToSaveDirtySession(editSession, destroySession)
@@ -465,13 +466,10 @@ class Editor extends View
destroySession(editSession)
destroyInactiveEditSessions: ->
index = 0
while session = @editSessions[index]
if @activeEditSession is session or session.buffer.isModified()
index++
else
@destroyEditSessionIndex(index)
destroyIndex = (index) =>
index++ if @activeEditSession is @editSessions[index]
@destroyEditSessionIndex(index, destroyIndex) if @editSessions[index]
destroyIndex(0)
loadNextEditSession: ->
nextIndex = (@getActiveEditSessionIndex() + 1) % @editSessions.length
@setActiveEditSessionIndex(nextIndex)