diff --git a/spec/app/config-view-spec.coffee b/spec/app/config-view-spec.coffee index 5defd234a..0952fe3d9 100644 --- a/spec/app/config-view-spec.coffee +++ b/spec/app/config-view-spec.coffee @@ -7,6 +7,23 @@ describe "ConfigView", -> beforeEach -> configView = new ConfigView + describe "serialization", -> + it "remembers which panel was visible", -> + configView.showPanel('Editor') + newConfigView = deserialize(configView.serialize()) + configView.remove() + newConfigView.attachToDom() + expect(newConfigView.activePanelName).toBe 'Editor' + + it "shows the previously active panel if it is added after deserialization", -> + configView.addPanel('Panel 1', $$ -> @div id: 'panel-1') + configView.showPanel('Panel 1') + newConfigView = deserialize(configView.serialize()) + configView.remove() + newConfigView.attachToDom() + newConfigView.addPanel('Panel 1', $$ -> @div id: 'panel-1') + expect(newConfigView.activePanelName).toBe 'Panel 1' + describe ".addPanel(name, view)", -> it "adds a menu entry to the left and a panel that can be activated by clicking it", -> configView.addPanel('Panel 1', $$ -> @div id: 'panel-1') diff --git a/spec/app/window-spec.coffee b/spec/app/window-spec.coffee index 108b5ed3f..a173689c7 100644 --- a/spec/app/window-spec.coffee +++ b/spec/app/window-spec.coffee @@ -12,7 +12,7 @@ describe "Window", -> projectPath = project.getPath() afterEach -> - window.shutdown() + window.unloadEditorWindow() $(window).off 'beforeunload' describe "when the window is loaded", -> @@ -120,7 +120,7 @@ describe "Window", -> removeStylesheet(cssPath) expect($(document.body).css('font-weight')).not.toBe("bold") - describe ".shutdown()", -> + describe ".unloadEditorWindow()", -> it "saves the serialized state of the window so it can be deserialized after reload", -> projectPath = project.getPath() expect(atom.getWindowState()).toEqual {} @@ -130,7 +130,7 @@ describe "Window", -> projectState = JSON.parse(JSON.stringify(project.serialize())) syntaxState = JSON.parse(JSON.stringify(syntax.serialize())) - window.shutdown() + window.unloadEditorWindow() windowState = atom.getWindowState() expect(windowState.rootView).toEqual rootViewState @@ -145,14 +145,14 @@ describe "Window", -> rootView.getActivePane().splitRight() expect(window.rootView.find('.editor').length).toBe 2 - window.shutdown() + window.unloadEditorWindow() expect(buffer.subscriptionCount()).toBe 0 it "only serializes window state the first time it is called", -> - window.shutdown() - window.shutdown() + window.unloadEditorWindow() + window.unloadEditorWindow() expect(atom.saveWindowState.callCount).toBe 1 describe ".installAtomCommand(commandPath)", -> diff --git a/src/app/atom.coffee b/src/app/atom.coffee index b73a58ff7..caa871506 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -251,12 +251,16 @@ _.extend atom, null getSavedWindowState: -> - if pathToOpen = window.location.params.pathToOpen - localStorage[pathToOpen] + storageKey = switch @windowMode + when 'editor' then window.location.params.pathToOpen + when 'config' then 'config' + localStorage[storageKey] if storageKey saveWindowState: -> - if pathToOpen = @getPathToOpen() - localStorage[pathToOpen] = JSON.stringify(@getWindowState()) + storageKey = switch @windowMode + when 'editor' then @getPathToOpen() + when 'config' then 'config' + localStorage[storageKey] = JSON.stringify(@getWindowState()) update: -> @sendMessageToBrowserProcess('update') diff --git a/src/app/config-view.coffee b/src/app/config-view.coffee index ac51ca99a..db557cee0 100644 --- a/src/app/config-view.coffee +++ b/src/app/config-view.coffee @@ -5,6 +5,13 @@ EditorConfigPanel = require 'editor-config-panel' module.exports = class ConfigView extends View + registerDeserializer(this) + + @deserialize: ({activePanelName}) -> + view = new ConfigView() + view.showPanel(activePanelName) + view + @content: -> @div id: 'config-view', => @ol id: 'panel-menu', outlet: 'panelMenu' @@ -25,10 +32,22 @@ class ConfigView extends View panel.hide() @panelsByName[name] = panel @panels.append(panel) - @showPanel(name) if _.values(@panelsByName).length == 1 + @showPanel(name) if @getPanelCount() is 1 or @panelToShow is name + + getPanelCount: -> + _.values(@panelsByName).length showPanel: (name) -> - @panels.children().hide() - @panelMenu.children('.active').removeClass('active') - @panelsByName[name].show() - @panelMenu.children("[name='#{name}']").addClass('active') + if @panelsByName[name] + @panels.children().hide() + @panelMenu.children('.active').removeClass('active') + @panelsByName[name].show() + @panelMenu.children("[name='#{name}']").addClass('active') + @activePanelName = name + @panelToShow = null + else + @panelToShow = name + + serialize: -> + deserializer: @constructor.name + activePanelName: @activePanelName diff --git a/src/app/window.coffee b/src/app/window.coffee index 5438fa6d4..4f382b040 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -43,6 +43,7 @@ window.startEditorWindow = -> else console.warn "Failed to install `atom` binary" + atom.windowMode = 'editor' handleWindowEvents() handleDragDrop() config.load() @@ -53,10 +54,11 @@ window.startEditorWindow = -> atom.activatePackages() keymap.loadUserKeymaps() atom.requireUserInitScript() - $(window).on 'beforeunload', -> shutdown(); false + $(window).on 'beforeunload', -> unloadEditorWindow(); false $(window).focus() window.startConfigWindow = -> + atom.windowMode = 'config' handleWindowEvents() config.load() keymap.loadBundledKeymaps() @@ -65,8 +67,10 @@ window.startConfigWindow = -> deserializeConfigWindow() atom.activatePackageConfigs() keymap.loadUserKeymaps() + $(window).on 'beforeunload', -> unloadConfigWindow(); false + $(window).focus() -window.shutdown = -> +window.unloadEditorWindow = -> return if not project and not rootView atom.setWindowState('pathToOpen', project.getPath()) atom.setWindowState('project', project.serialize()) @@ -99,6 +103,14 @@ window.installAtomCommand = (commandPath, done) -> else fs.chmod(commandPath, 0o755, commandPath) +window.unloadConfigWindow = -> + return if not configView + atom.setWindowState('configView', configView.serialize()) + atom.saveWindowState() + configView.remove() + window.configView = null + $(window).off('focus blur before') + window.handleWindowEvents = -> $(window).command 'window:toggle-full-screen', => atom.toggleFullScreen() $(window).on 'focus', -> $("body").removeClass('is-blurred') @@ -143,7 +155,8 @@ window.deserializeEditorWindow = -> window.deserializeConfigWindow = -> ConfigView = require 'config-view' - window.configView = new ConfigView() + windowState = atom.getWindowState() + window.configView = deserialize(windowState.configView) ? new ConfigView() $(rootViewParentSelector).append(configView) window.stylesheetElementForId = (id) ->