From b43c756820a0cdb9dc145c92aae28b90841318fa Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 7 Jan 2013 14:26:53 -0800 Subject: [PATCH] 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. --- spec/app/window-spec.coffee | 14 +++++++++++++- src/app/window.coffee | 3 ++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index 316f480c8..2471d6cc3 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -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() diff --git a/src/app/window.coffee b/src/app/window.coffee index 23e4dbb36..85077e84a 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -47,7 +47,8 @@ windowAdditions = false shutdown: -> - @rootView.deactivate() + @rootView?.deactivate() + @rootView = null $(window).unbind('focus') $(window).unbind('blur') $(window).off('before')