mirror of
https://github.com/atom/atom.git
synced 2026-02-06 12:44:59 -05:00
Serialize the state of the config window on refresh
This commit is contained in:
committed by
Corey Johnson & Kevin Sawicki
parent
c32c894d23
commit
f0cddf9f32
@@ -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')
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) ->
|
||||
|
||||
Reference in New Issue
Block a user