diff --git a/spec/app/root-view-spec.coffee b/spec/app/root-view-spec.coffee index d6e948d41..0f6bdd1a8 100644 --- a/spec/app/root-view-spec.coffee +++ b/spec/app/root-view-spec.coffee @@ -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' diff --git a/spec/app/status-bar-spec.coffee b/spec/app/status-bar-spec.coffee index 4d0bc3120..310cda50a 100644 --- a/spec/app/status-bar-spec.coffee +++ b/spec/app/status-bar-spec.coffee @@ -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() diff --git a/spec/extensions/command-panel-spec.coffee b/spec/extensions/command-panel-spec.coffee index d89accfe4..bf02c1293 100644 --- a/spec/extensions/command-panel-spec.coffee +++ b/spec/extensions/command-panel-spec.coffee @@ -5,6 +5,7 @@ describe "CommandPanel", -> beforeEach -> rootView = new RootView + rootView.open() rootView.enableKeymap() commandPanel = rootView.commandPanel diff --git a/spec/extensions/strip-trailing-whitespace-spec.coffee b/spec/extensions/strip-trailing-whitespace-spec.coffee index e94c3475e..b7a993511 100644 --- a/spec/extensions/strip-trailing-whitespace-spec.coffee +++ b/spec/extensions/strip-trailing-whitespace-spec.coffee @@ -7,6 +7,8 @@ describe "StripTrailingWhitespace", -> beforeEach -> rootView = new RootView + rootView.open() + StripTrailingWhitespace.activate(rootView) rootView.focus() editor = rootView.activeEditor() diff --git a/src/app/root-view.coffee b/src/app/root-view.coffee index 98c07dcc3..2929595f6 100644 --- a/src/app/root-view.coffee +++ b/src/app/root-view.coffee @@ -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) diff --git a/src/app/window.coffee b/src/app/window.coffee index dd2b85fc7..21824a395 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -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: ->