mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Make RootView.initialize unaware of deserialization.
When RootView is created without a pathToOpen, no editor is created.
This commit is contained in:
@@ -16,7 +16,7 @@ describe "RootView", ->
|
||||
rootView.focus()
|
||||
project = rootView.project
|
||||
|
||||
describe "initialize(viewState)", ->
|
||||
describe "initialize(pathToOpen)", ->
|
||||
describe "when called with a pathToOpen", ->
|
||||
describe "when pathToOpen references a file", ->
|
||||
it "creates a project for the file's parent directory, then sets the document.title and opens the file in an editor", ->
|
||||
@@ -45,13 +45,15 @@ describe "RootView", ->
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
editor1 = rootView.activeEditor()
|
||||
buffer = editor1.buffer
|
||||
editor1.splitRight()
|
||||
viewState = rootView.serialize()
|
||||
|
||||
it "constructs the view with the same panes", ->
|
||||
rootView = new RootView(viewState)
|
||||
console.log 'spec'
|
||||
rootView = RootView.deserialize(viewState)
|
||||
expect(rootView.project.path).toBeNull()
|
||||
expect(rootView.editors().length).toBe 2
|
||||
expect(rootView.activeEditor().buffer.getText()).toBe buffer.getText()
|
||||
@@ -74,7 +76,7 @@ describe "RootView", ->
|
||||
rootView.remove()
|
||||
|
||||
it "constructs the view with the same project and panes", ->
|
||||
rootView = new RootView(viewState)
|
||||
rootView = RootView.deserialize(viewState)
|
||||
rootView.attachToDom()
|
||||
|
||||
expect(rootView.editors().length).toBe 4
|
||||
@@ -104,11 +106,10 @@ describe "RootView", ->
|
||||
|
||||
expect(document.title).toBe editor2.buffer.path
|
||||
|
||||
describe "when called with no state data", ->
|
||||
it "opens an empty buffer and sets the document.title to untitled", ->
|
||||
describe "when called with no pathToOpen", ->
|
||||
it "opens no buffer", ->
|
||||
rootView = new RootView
|
||||
expect(rootView.editors().length).toBe 1
|
||||
expect(rootView.activeEditor().buffer.path).toBeUndefined()
|
||||
expect(rootView.editors().length).toBe 0
|
||||
expect(document.title).toBe 'untitled'
|
||||
|
||||
describe "focus", ->
|
||||
@@ -377,7 +378,7 @@ describe "RootView", ->
|
||||
rootView = new RootView
|
||||
|
||||
it "does not open the FileFinder", ->
|
||||
expect(rootView.activeEditor().buffer.path).toBeUndefined()
|
||||
expect(rootView.activeEditor()).toBeUndefined()
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
rootView.trigger 'toggle-file-finder'
|
||||
expect(rootView.find('.file-finder')).not.toExist()
|
||||
@@ -437,6 +438,7 @@ describe "RootView", ->
|
||||
|
||||
it "creates a project if there isn't one yet and the buffer was previously unsaved", ->
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
expect(rootView.project.path).toBeNull()
|
||||
rootView.activeEditor().buffer.saveAs('/tmp/ignore-me')
|
||||
expect(rootView.project.path).toBe '/tmp'
|
||||
|
||||
@@ -28,6 +28,7 @@ describe "StatusBar", ->
|
||||
describe "when associated with an unsaved buffer", ->
|
||||
it "displays 'untitled' instead of the buffer's path, but still displays the buffer position", ->
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
rootView.simulateDomAttachment()
|
||||
StatusBar.activate(rootView)
|
||||
statusBar = rootView.find('.status-bar').view()
|
||||
|
||||
@@ -5,6 +5,7 @@ describe "CommandPanel", ->
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
rootView.enableKeymap()
|
||||
commandPanel = rootView.commandPanel
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ describe "StripTrailingWhitespace", ->
|
||||
|
||||
beforeEach ->
|
||||
rootView = new RootView
|
||||
rootView.open()
|
||||
|
||||
StripTrailingWhitespace.activate(rootView)
|
||||
rootView.focus()
|
||||
editor = rootView.activeEditor()
|
||||
|
||||
@@ -22,13 +22,33 @@ class RootView extends View
|
||||
@div id: 'horizontal', outlet: 'horizontal', =>
|
||||
@div id: 'panes', outlet: 'panes'
|
||||
|
||||
@deserialize: (viewState) ->
|
||||
new RootView(viewState)
|
||||
@deserialize: ({ projectPath, panesViewState, extensionStates }) ->
|
||||
rootView = new RootView(pathToOpen: projectPath)
|
||||
rootView.setRootPane(rootView.deserializeView(panesViewState)) if panesViewState
|
||||
rootView.extensionStates = extensionStates if extensionStates
|
||||
rootView
|
||||
|
||||
extensions: null
|
||||
extensionStates: null
|
||||
|
||||
initialize: ({ pathToOpen, projectPath, panesViewState, @extensionStates }) ->
|
||||
initialize: ({ pathToOpen }) ->
|
||||
@handleEvents()
|
||||
|
||||
@extensions = {}
|
||||
@extensionStates = {}
|
||||
@commandPanel = new CommandPanel({rootView: this})
|
||||
|
||||
@setTitle()
|
||||
@project = new Project(pathToOpen)
|
||||
if pathToOpen? and fs.isFile(pathToOpen)
|
||||
@open(pathToOpen)
|
||||
|
||||
serialize: ->
|
||||
projectPath: @project?.path
|
||||
panesViewState: @panes.children().view()?.serialize()
|
||||
extensionStates: @serializeExtensions()
|
||||
|
||||
handleEvents: ->
|
||||
@on 'toggle-file-finder', => @toggleFileFinder()
|
||||
@on 'show-console', => window.showConsole()
|
||||
@on 'focus', (e) =>
|
||||
@@ -42,35 +62,9 @@ class RootView extends View
|
||||
@project.setPath(path) unless @project.getPath()
|
||||
@setTitle(path)
|
||||
|
||||
@commandPanel = new CommandPanel({rootView: this})
|
||||
|
||||
if pathToOpen?
|
||||
@project = new Project(pathToOpen)
|
||||
@open(pathToOpen) if fs.isFile(pathToOpen)
|
||||
else
|
||||
@project = new Project(projectPath)
|
||||
@open() unless panesViewState?
|
||||
|
||||
@deserializePanes(panesViewState) if panesViewState
|
||||
|
||||
@extensionStates ?= {}
|
||||
@extensions = {}
|
||||
|
||||
afterAttach: (onDom) ->
|
||||
@focus() if onDom
|
||||
|
||||
serialize: ->
|
||||
projectPath: @project?.path
|
||||
panesViewState: @serializePanes()
|
||||
extensionStates: @serializeExtensions()
|
||||
|
||||
serializePanes: ->
|
||||
@panes.children().view()?.serialize()
|
||||
|
||||
deserializePanes: (panesViewState) ->
|
||||
@panes.append @deserializeView(panesViewState)
|
||||
@adjustPaneDimensions()
|
||||
|
||||
serializeExtensions: ->
|
||||
extensionStates = {}
|
||||
for name, extension of @extensions
|
||||
@@ -134,6 +128,11 @@ class RootView extends View
|
||||
else
|
||||
@panes.find('.editor:first').view()
|
||||
|
||||
setRootPane: (pane) ->
|
||||
@panes.empty()
|
||||
@panes.append(pane)
|
||||
@adjustPaneDimensions()
|
||||
|
||||
adjustPaneDimensions: ->
|
||||
rootPane = @panes.children().first().view()
|
||||
rootPane?.css(width: '100%', height: '100%', top: 0, left: 0)
|
||||
|
||||
@@ -23,6 +23,7 @@ windowAdditions =
|
||||
startup: (path) ->
|
||||
@attachRootView(path)
|
||||
@loadUserConfiguration()
|
||||
rootView.activateExtension(require 'tree-view')
|
||||
$(window).on 'close', => @close()
|
||||
$(window).on 'beforeunload', =>
|
||||
@shutdown()
|
||||
@@ -39,10 +40,12 @@ windowAdditions =
|
||||
|
||||
attachRootView: (pathToOpen) ->
|
||||
rootViewState = atom.rootViewStates[$windowNumber]
|
||||
@rootView = if rootViewState
|
||||
RootView.deserialize(rootViewState)
|
||||
if rootViewState
|
||||
@rootView = RootView.deserialize(rootViewState)
|
||||
else
|
||||
new RootView {pathToOpen}
|
||||
@rootView = new RootView(pathToOpen: pathToOpen)
|
||||
@rootView.open() unless pathToOpen
|
||||
|
||||
$(@rootViewParentSelector).append @rootView
|
||||
|
||||
loadUserConfiguration: ->
|
||||
|
||||
Reference in New Issue
Block a user