Only deactivate the RootView once during shutdown

Previously window.shutdown() was called multiple times
if window.close() was called since the shutdown handler
was also fired in the native window controller.

This prevented proper serialization of the RootView
from occurring when then window was closed via meta-w or
meta-W since it was called a second time when already
empty of packages and editors.
This commit is contained in:
Kevin Sawicki 2013-01-07 14:26:53 -08:00
parent 1f1e0aac78
commit b43c756820
2 changed files with 15 additions and 2 deletions

View File

@ -2,8 +2,11 @@ $ = require 'jquery'
fs = require 'fs'
describe "Window", ->
[rootView] = []
beforeEach ->
window.attachRootView(require.resolve('fixtures'))
rootView = window.rootView
afterEach ->
window.shutdown()
@ -68,7 +71,7 @@ describe "Window", ->
expect(atom.getRootViewStateForPath(window.rootView.project.getPath())).toBeUndefined()
expectedState = JSON.parse(JSON.stringify(window.rootView.serialize())) # JSON.stringify removes keys with undefined values
$(window).trigger 'beforeunload'
expect(atom.getRootViewStateForPath(window.rootView.project.getPath())).toEqual expectedState
expect(atom.getRootViewStateForPath(rootView.project.getPath())).toEqual expectedState
it "unsubscribes from all buffers", ->
rootView.open('sample.js')
@ -79,3 +82,12 @@ describe "Window", ->
$(window).trigger 'beforeunload'
expect(editor1.getBuffer().subscriptionCount()).toBe 0
describe ".shutdown()", ->
it "only deactivates the RootView the first time it is called", ->
deactivateSpy = spyOn(rootView, "deactivate").andCallThrough()
window.shutdown()
expect(rootView.deactivate).toHaveBeenCalled()
deactivateSpy.reset()
window.shutdown()
expect(rootView.deactivate).not.toHaveBeenCalled()

View File

@ -47,7 +47,8 @@ windowAdditions =
false
shutdown: ->
@rootView.deactivate()
@rootView?.deactivate()
@rootView = null
$(window).unbind('focus')
$(window).unbind('blur')
$(window).off('before')