From 6f99b61dd34dbd900052b87fbe5f311d80fbddc4 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 29 Aug 2012 10:59:45 -0700 Subject: [PATCH] Now storing a window's state based on its rootDirectory (instead of on windowNumber) --- benchmark/benchmark-suite.coffee | 2 +- native/atom_window_controller.mm | 9 ++++----- spec/app/window-spec.coffee | 10 +++++----- src/app/atom.coffee | 19 +++++++++++++++++-- src/app/root-view.coffee | 2 +- src/app/window.coffee | 6 ++---- static/index.html | 1 - 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/benchmark/benchmark-suite.coffee b/benchmark/benchmark-suite.coffee index 3a68627b0..8abf33f10 100644 --- a/benchmark/benchmark-suite.coffee +++ b/benchmark/benchmark-suite.coffee @@ -16,7 +16,7 @@ describe "editor.", -> afterEach -> $(window).off 'beforeunload' window.shutdown() - delete atom.rootViewStates[$windowNumber] + atom.setRootViewStateForPath(rootView.project.getPath(), null) describe "opening-buffers.", -> benchmark "300-line-file.", -> diff --git a/native/atom_window_controller.mm b/native/atom_window_controller.mm index dcc2409f1..22107170c 100644 --- a/native/atom_window_controller.mm +++ b/native/atom_window_controller.mm @@ -21,7 +21,7 @@ if (!background) { [self showWindow:self]; } - + return self; } @@ -59,9 +59,8 @@ NSURL *url = [[NSBundle mainBundle] resourceURL]; NSMutableString *urlString = [NSMutableString string]; [urlString appendString:[[url URLByAppendingPathComponent:@"static/index.html"] absoluteString] ]; - - [urlString appendFormat:@"?windowNumber=%d", [self.window windowNumber]]; - [urlString appendFormat:@"&bootstrapScript=%@", [_bootstrapScript stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; + + [urlString appendFormat:@"?bootstrapScript=%@", [_bootstrapScript stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; if (_pathToOpen) [urlString appendFormat:@"&pathToOpen=%@", [_pathToOpen stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; CefBrowserHost::CreateBrowser(window_info, _cefClient.get(), [urlString UTF8String], settings); @@ -127,4 +126,4 @@ settings.fullscreen_enabled = true; } -@end \ No newline at end of file +@end diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index baa14f409..5ccd0edf8 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -3,11 +3,11 @@ fs = require 'fs' describe "Window", -> beforeEach -> - window.startup() + window.startup(require.resolve('fixtures')) afterEach -> window.shutdown() - delete atom.rootViewStates[$windowNumber] + atom.setRootViewStateForPath(rootView.project.getPath(), null) $(window).off 'beforeunload' describe ".close()", -> @@ -49,10 +49,10 @@ describe "Window", -> describe "before the window is unloaded", -> it "saves the serialized state of the root view to the atom object so it can be rehydrated after reload", -> - expect(atom.rootViewStates[$windowNumber]).toBeUndefined() - expectedState = window.rootView.serialize() + 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.rootViewStates[$windowNumber]).toEqual JSON.stringify(expectedState) + expect(atom.getRootViewStateForPath(window.rootView.project.getPath())).toEqual expectedState it "unsubscribes from all buffers", -> editor1 = rootView.getActiveEditor() diff --git a/src/app/atom.coffee b/src/app/atom.coffee index fc88a057c..255069f19 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -2,5 +2,20 @@ fs = require('fs') atom.configDirPath = fs.absolute("~/.atom") atom.configFilePath = fs.join(atom.configDirPath, "atom.coffee") -atom.open = (args...) -> @sendMessageToBrowserProcess('open', args) -atom.newWindow = (args...) -> @sendMessageToBrowserProcess('newWindow', args) + +atom.open = (args...) -> + @sendMessageToBrowserProcess('open', args) + +atom.newWindow = (args...) -> + @sendMessageToBrowserProcess('newWindow', args) + +atom.getRootViewStateForPath = (path) -> + if json = localStorage[path] + JSON.parse(json) + +atom.setRootViewStateForPath = (path, state) -> + return unless path + if state? + localStorage[path] = JSON.stringify(state) + else + delete localStorage[path] diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index d09abbd5b..4b57d0e8b 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -94,7 +94,7 @@ class RootView extends View delete @extensions[extension.name] deactivate: -> - # atom.rootViewStates[$windowNumber] = JSON.stringify(@serialize()) # TODO: Reinstate + atom.setRootViewStateForPath(@project.getPath(), @serialize()) @deactivateExtension(extension) for name, extension of @extensions @remove() diff --git a/src/app/window.coffee b/src/app/window.coffee index ed30c3b0b..69308ece0 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -25,14 +25,12 @@ windowAdditions = @shutdown() false $(window).focus() - # atom.windowOpened this # TODO: Reinstate this! shutdown: -> @rootView.deactivate() $(window).unbind('focus') $(window).unbind('blur') $(window).off('before') - # atom.windowClosed this # TODO: Reinstate this! setUpKeymap: -> Keymap = require 'keymap' @@ -47,8 +45,8 @@ windowAdditions = # Note: RootView assigns itself on window on initialization so that # window.rootView is available when loading user configuration attachRootView: (pathToOpen) -> - if rootViewState = atom.rootViewStates?[$windowNumber] - RootView.deserialize(JSON.parse(rootViewState)) + if rootViewState = atom.getRootViewStateForPath(pathToOpen) + RootView.deserialize(rootViewState) else new RootView(pathToOpen) @rootView.open() unless pathToOpen diff --git a/static/index.html b/static/index.html index d068f713b..02b3f6914 100644 --- a/static/index.html +++ b/static/index.html @@ -11,7 +11,6 @@ var pair = param.split("=") window.location.params[pair[0]] = pair[1]; }); - window.$windowNumber = window.location.params.windowNumber var bootstrapScript = window.location.params.bootstrapScript; if (bootstrapScript) require(bootstrapScript); }