mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Unify root view state with window state
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
#import <iostream>
|
||||
|
||||
static std::string windowState = "{}";
|
||||
static std::string windowState = "";
|
||||
static NSLock *windowStateLock = [[NSLock alloc] init];
|
||||
|
||||
namespace v8_extensions {
|
||||
|
||||
@@ -8,12 +8,11 @@ describe "Window", ->
|
||||
beforeEach ->
|
||||
spyOn(atom, 'getPathToOpen').andReturn(project.getPath())
|
||||
window.handleWindowEvents()
|
||||
window.buildProjectAndRootView()
|
||||
window.deserializeWindowState()
|
||||
projectPath = project.getPath()
|
||||
|
||||
afterEach ->
|
||||
window.shutdown()
|
||||
atom.setRootViewStateForPath(projectPath, null)
|
||||
$(window).off 'beforeunload'
|
||||
|
||||
describe "when the window is loaded", ->
|
||||
@@ -129,18 +128,20 @@ describe "Window", ->
|
||||
expect($(document.body).css('font-weight')).not.toBe("bold")
|
||||
|
||||
describe ".shutdown()", ->
|
||||
it "saves the serialized state of the project and root view to the atom object so it can be rehydrated after reload", ->
|
||||
it "saves the serialized state of the window so it can be deserialized after reload", ->
|
||||
projectPath = project.getPath()
|
||||
expect(atom.getRootViewStateForPath(projectPath)).toBeUndefined()
|
||||
expect(atom.getWindowState()).toEqual {}
|
||||
|
||||
# JSON.stringify removes keys with undefined values
|
||||
rootViewState = JSON.parse(JSON.stringify(rootView.serialize()))
|
||||
projectState = JSON.parse(JSON.stringify(project.serialize()))
|
||||
|
||||
window.shutdown()
|
||||
|
||||
expect(atom.getRootViewStateForPath(projectPath)).toEqual
|
||||
project: projectState
|
||||
rootView: rootViewState
|
||||
expect(atom.getWindowState().rootView).toEqual rootViewState
|
||||
expect(atom.getWindowState().project).toEqual projectState
|
||||
|
||||
expect(atom.saveWindowState).toHaveBeenCalled()
|
||||
|
||||
it "unsubscribes from all buffers", ->
|
||||
rootView.open('sample.js')
|
||||
@@ -153,10 +154,10 @@ describe "Window", ->
|
||||
expect(buffer.subscriptionCount()).toBe 0
|
||||
|
||||
it "only serializes window state the first time it is called", ->
|
||||
deactivateSpy = spyOn(atom, "setRootViewStateForPath").andCallThrough()
|
||||
|
||||
window.shutdown()
|
||||
window.shutdown()
|
||||
expect(atom.setRootViewStateForPath.callCount).toBe 1
|
||||
expect(atom.saveWindowState.callCount).toBe 1
|
||||
|
||||
describe ".installAtomCommand(commandPath)", ->
|
||||
commandPath = '/tmp/installed-atom-command/atom'
|
||||
|
||||
@@ -38,6 +38,8 @@ beforeEach ->
|
||||
window.resetTimeouts()
|
||||
atom.atomPackageStates = {}
|
||||
atom.loadedPackages = []
|
||||
spyOn(atom, 'saveWindowState')
|
||||
$native.setWindowState('')
|
||||
|
||||
# used to reset keymap after each spec
|
||||
bindingSetsToRestore = _.clone(keymap.bindingSets)
|
||||
|
||||
@@ -179,17 +179,6 @@ _.extend atom,
|
||||
toggleFullScreen: ->
|
||||
@sendMessageToBrowserProcess('toggleFullScreen')
|
||||
|
||||
getRootViewStateForPath: (path) ->
|
||||
if json = localStorage[path]
|
||||
JSON.parse(json)
|
||||
|
||||
setRootViewStateForPath: (path, state) ->
|
||||
return unless path
|
||||
if state?
|
||||
localStorage[path] = JSON.stringify(state)
|
||||
else
|
||||
delete localStorage[path]
|
||||
|
||||
sendMessageToBrowserProcess: (name, data=[], callbacks) ->
|
||||
messageId = messageIdCounter++
|
||||
data.unshift(messageId)
|
||||
@@ -209,12 +198,17 @@ _.extend atom,
|
||||
windowState
|
||||
|
||||
getWindowState: (keyPath) ->
|
||||
windowState = JSON.parse($native.getWindowState())
|
||||
inMemoryState = $native.getWindowState()
|
||||
inMemoryState = null unless inMemoryState.length > 0
|
||||
windowState = JSON.parse(inMemoryState ? localStorage[window.location.params.pathToOpen] ? '{}')
|
||||
if keyPath
|
||||
_.valueForKeyPath(windowState, keyPath)
|
||||
else
|
||||
windowState
|
||||
|
||||
saveWindowState: ->
|
||||
localStorage[@getPathToOpen()] = JSON.stringify(@getWindowState())
|
||||
|
||||
update: ->
|
||||
@sendMessageToBrowserProcess('update')
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ window.startup = ->
|
||||
keymap.loadBundledKeymaps()
|
||||
atom.loadThemes()
|
||||
atom.loadPackages()
|
||||
buildProjectAndRootView()
|
||||
deserializeWindowState()
|
||||
atom.activatePackages()
|
||||
keymap.loadUserKeymaps()
|
||||
atom.requireUserInitScript()
|
||||
@@ -66,9 +66,9 @@ window.startup = ->
|
||||
window.shutdown = ->
|
||||
return if not project and not rootView
|
||||
atom.setWindowState('pathToOpen', project.getPath())
|
||||
atom.setRootViewStateForPath project.getPath(),
|
||||
project: project.serialize()
|
||||
rootView: rootView.serialize()
|
||||
atom.setWindowState('project', project.serialize())
|
||||
atom.setWindowState('rootView', rootView.serialize())
|
||||
atom.saveWindowState()
|
||||
rootView.deactivate()
|
||||
project.destroy()
|
||||
git?.destroy()
|
||||
@@ -91,13 +91,15 @@ window.handleWindowEvents = ->
|
||||
$(window).on 'blur', -> $("body").addClass('is-blurred')
|
||||
$(window).command 'window:close', => confirmClose()
|
||||
|
||||
window.buildProjectAndRootView = ->
|
||||
window.deserializeWindowState = ->
|
||||
RootView = require 'root-view'
|
||||
Project = require 'project'
|
||||
Git = require 'git'
|
||||
|
||||
pathToOpen = atom.getPathToOpen()
|
||||
windowState = atom.getRootViewStateForPath(pathToOpen) ? {}
|
||||
|
||||
windowState = atom.getWindowState()
|
||||
|
||||
window.project = deserialize(windowState.project) ? new Project(pathToOpen)
|
||||
window.rootView = deserialize(windowState.rootView) ? new RootView
|
||||
|
||||
|
||||
Reference in New Issue
Block a user