mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-07 23:59:22 +03:00
Move Workspace and PaneContainer serialization to the model layer
The views are now stateless. You just construct them with a model to deserialize.
This commit is contained in:
parent
4a7b43f609
commit
c350285044
@ -121,7 +121,7 @@ describe "PaneContainerView", ->
|
||||
|
||||
describe "serialization", ->
|
||||
it "can be serialized and deserialized, and correctly adjusts dimensions of deserialized panes after attach", ->
|
||||
newContainer = atom.deserializers.deserialize(container.serialize())
|
||||
newContainer = new PaneContainerView(container.model.testSerialization())
|
||||
expect(newContainer.find('.pane-row > :contains(1)')).toExist()
|
||||
expect(newContainer.find('.pane-row > .pane-column > :contains(2)')).toExist()
|
||||
expect(newContainer.find('.pane-row > .pane-column > :contains(3)')).toExist()
|
||||
@ -133,7 +133,7 @@ describe "PaneContainerView", ->
|
||||
it "removes empty panes on deserialization", ->
|
||||
# only deserialize pane 1's view successfully
|
||||
TestView.deserialize = ({name}) -> new TestView(name) if name is '1'
|
||||
newContainer = atom.deserializers.deserialize(container.serialize())
|
||||
newContainer = new PaneContainerView(container.model.testSerialization())
|
||||
expect(newContainer.find('.pane-row, .pane-column')).not.toExist()
|
||||
expect(newContainer.find('> :contains(1)')).toExist()
|
||||
|
||||
|
@ -602,12 +602,12 @@ describe "PaneView", ->
|
||||
|
||||
describe "serialization", ->
|
||||
it "can serialize and deserialize the pane and all its items", ->
|
||||
newPane = pane.testSerialization()
|
||||
newPane = new PaneView(pane.model.testSerialization())
|
||||
expect(newPane.getItems()).toEqual [view1, editor1, view2, editor2]
|
||||
|
||||
it "restores the active item on deserialization", ->
|
||||
pane.activateItem(editor2)
|
||||
newPane = pane.testSerialization()
|
||||
newPane = new PaneView(pane.model.testSerialization())
|
||||
expect(newPane.activeItem).toEqual editor2
|
||||
|
||||
it "does not show items that cannot be deserialized", ->
|
||||
@ -618,7 +618,7 @@ describe "PaneView", ->
|
||||
|
||||
pane.activateItem(new Unserializable)
|
||||
|
||||
newPane = pane.testSerialization()
|
||||
newPane = new PaneView(pane.model.testSerialization())
|
||||
expect(newPane.activeItem).toEqual pane.items[0]
|
||||
expect(newPane.items.length).toBe pane.items.length - 1
|
||||
|
||||
@ -626,13 +626,13 @@ describe "PaneView", ->
|
||||
container.attachToDom()
|
||||
pane.focus()
|
||||
|
||||
container2 = container.testSerialization()
|
||||
container2 = new PaneContainerView(container.model.testSerialization())
|
||||
pane2 = container2.getRoot()
|
||||
container2.attachToDom()
|
||||
expect(pane2).toMatchSelector(':has(:focus)')
|
||||
|
||||
$(document.activeElement).blur()
|
||||
container3 = container.testSerialization()
|
||||
container3 = new PaneContainerView(container.model.testSerialization())
|
||||
pane3 = container3.getRoot()
|
||||
container3.attachToDom()
|
||||
expect(pane3).not.toMatchSelector(':has(:focus)')
|
||||
|
@ -88,12 +88,12 @@ describe "Window", ->
|
||||
|
||||
describe ".unloadEditorWindow()", ->
|
||||
it "saves the serialized state of the window so it can be deserialized after reload", ->
|
||||
workspaceViewState = atom.workspaceView.serialize()
|
||||
workspaceState = atom.workspace.serialize()
|
||||
syntaxState = atom.syntax.serialize()
|
||||
|
||||
atom.unloadEditorWindow()
|
||||
|
||||
expect(atom.state.workspaceView).toEqual workspaceViewState
|
||||
expect(atom.state.workspace).toEqual workspaceState
|
||||
expect(atom.state.syntax).toEqual syntaxState
|
||||
expect(atom.saveSync).toHaveBeenCalled()
|
||||
|
||||
|
@ -3,6 +3,7 @@ Q = require 'q'
|
||||
path = require 'path'
|
||||
temp = require 'temp'
|
||||
PaneView = require '../src/pane-view'
|
||||
Workspace = require '../src/workspace'
|
||||
|
||||
describe "WorkspaceView", ->
|
||||
pathToOpen = null
|
||||
@ -10,7 +11,8 @@ describe "WorkspaceView", ->
|
||||
beforeEach ->
|
||||
atom.project.setPath(atom.project.resolve('dir'))
|
||||
pathToOpen = atom.project.resolve('a')
|
||||
atom.workspaceView = new WorkspaceView
|
||||
atom.workspace = new Workspace
|
||||
atom.workspaceView = new WorkspaceView(atom.workspace)
|
||||
atom.workspaceView.enableKeymap()
|
||||
atom.workspaceView.openSync(pathToOpen)
|
||||
atom.workspaceView.focus()
|
||||
@ -19,11 +21,12 @@ describe "WorkspaceView", ->
|
||||
viewState = null
|
||||
|
||||
simulateReload = ->
|
||||
workspaceState = atom.workspaceView.serialize()
|
||||
workspaceState = atom.workspace.serialize()
|
||||
projectState = atom.project.serialize()
|
||||
atom.workspaceView.remove()
|
||||
atom.project = atom.deserializers.deserialize(projectState)
|
||||
atom.workspaceView = WorkspaceView.deserialize(workspaceState)
|
||||
atom.workspace = Workspace.deserialize(workspaceState)
|
||||
atom.workspaceView = new WorkspaceView(atom.workspace)
|
||||
atom.workspaceView.attachToDom()
|
||||
|
||||
describe "when the serialized WorkspaceView has an unsaved buffer", ->
|
||||
@ -187,7 +190,7 @@ describe "WorkspaceView", ->
|
||||
|
||||
describe "when the root view is deserialized", ->
|
||||
it "updates the title to contain the project's path", ->
|
||||
workspaceView2 = atom.deserializers.deserialize(atom.workspaceView.serialize())
|
||||
workspaceView2 = new WorkspaceView(atom.workspace.testSerialization())
|
||||
item = atom.workspaceView.getActivePaneItem()
|
||||
expect(workspaceView2.title).toBe "#{item.getTitle()} - #{atom.project.getPath()}"
|
||||
workspaceView2.remove()
|
||||
|
@ -230,8 +230,10 @@ class Atom extends Model
|
||||
|
||||
# Private:
|
||||
deserializeWorkspaceView: ->
|
||||
Workspace = require './workspace'
|
||||
WorkspaceView = require './workspace-view'
|
||||
@workspaceView = @deserializers.deserialize(@state.workspaceView) ? new WorkspaceView
|
||||
@workspace = Workspace.deserialize(@state.workspace) ? new Workspace
|
||||
@workspaceView = new WorkspaceView(@workspace)
|
||||
$(@workspaceViewParentSelector).append(@workspaceView)
|
||||
|
||||
# Private:
|
||||
@ -277,7 +279,7 @@ class Atom extends Model
|
||||
return if not @project and not @workspaceView
|
||||
|
||||
@state.syntax = @syntax.serialize()
|
||||
@state.workspaceView = @workspaceView.serialize()
|
||||
@state.workspace = @workspace.serialize()
|
||||
@packages.deactivatePackages()
|
||||
@state.packageStates = @packages.packageStates
|
||||
@saveSync()
|
||||
|
@ -1,4 +1,3 @@
|
||||
Serializable = require 'serializable'
|
||||
Delegator = require 'delegato'
|
||||
{$, View} = require './space-pen-extensions'
|
||||
PaneView = require './pane-view'
|
||||
@ -7,15 +6,10 @@ PaneContainer = require './pane-container'
|
||||
# Private: Manages the list of panes within a {WorkspaceView}
|
||||
module.exports =
|
||||
class PaneContainerView extends View
|
||||
atom.deserializers.add(this)
|
||||
Serializable.includeInto(this)
|
||||
Delegator.includeInto(this)
|
||||
|
||||
@delegatesMethod 'saveAll', toProperty: 'model'
|
||||
|
||||
@deserialize: (state) ->
|
||||
new this(PaneContainer.deserialize(state.model))
|
||||
|
||||
@content: ->
|
||||
@div class: 'panes'
|
||||
|
||||
@ -33,9 +27,6 @@ class PaneContainerView extends View
|
||||
viewClass = model.getViewClass()
|
||||
model._view ?= new viewClass(model)
|
||||
|
||||
serializeParams: ->
|
||||
model: @model.serialize()
|
||||
|
||||
### Public ###
|
||||
|
||||
getRoot: ->
|
||||
|
@ -1,5 +1,4 @@
|
||||
{$, View} = require './space-pen-extensions'
|
||||
Serializable = require 'serializable'
|
||||
Delegator = require 'delegato'
|
||||
PropertyAccessors = require 'property-accessors'
|
||||
|
||||
@ -13,15 +12,11 @@ Pane = require './pane'
|
||||
# building a package that deals with switching between panes or tiems.
|
||||
module.exports =
|
||||
class PaneView extends View
|
||||
Serializable.includeInto(this)
|
||||
Delegator.includeInto(this)
|
||||
PropertyAccessors.includeInto(this)
|
||||
|
||||
@version: 1
|
||||
|
||||
@deserialize: (state) ->
|
||||
new this(Pane.deserialize(state.model))
|
||||
|
||||
@content: (wrappedView) ->
|
||||
@div class: 'pane', tabindex: -1, =>
|
||||
@div class: 'item-views', outlet: 'itemViews'
|
||||
@ -86,13 +81,6 @@ class PaneView extends View
|
||||
@command 'pane:close', => @destroyItems()
|
||||
@command 'pane:close-other-items', => @destroyInactiveItems()
|
||||
|
||||
deserializeParams: (params) ->
|
||||
params.model = Pane.deserialize(params.model)
|
||||
params
|
||||
|
||||
serializeParams: ->
|
||||
model: @model.serialize()
|
||||
|
||||
# Deprecated: Use ::destroyItem
|
||||
removeItem: (item) -> @destroyItem(item)
|
||||
|
||||
|
@ -5,7 +5,6 @@ _ = require 'underscore-plus'
|
||||
Delegator = require 'delegato'
|
||||
{$, $$, View} = require './space-pen-extensions'
|
||||
fs = require 'fs-plus'
|
||||
Serializable = require 'serializable'
|
||||
Workspace = require './workspace'
|
||||
EditorView = require './editor-view'
|
||||
PaneView = require './pane-view'
|
||||
@ -40,8 +39,6 @@ Editor = require './editor'
|
||||
#
|
||||
module.exports =
|
||||
class WorkspaceView extends View
|
||||
atom.deserializers.add(this, PaneView, PaneRowView, PaneColumnView, EditorView)
|
||||
Serializable.includeInto(this)
|
||||
Delegator.includeInto(this)
|
||||
|
||||
@delegatesProperty 'fullScreen', 'destroyedItemUris', toProperty: 'model'
|
||||
@ -51,9 +48,6 @@ class WorkspaceView extends View
|
||||
|
||||
@version: 4
|
||||
|
||||
@deserialize: (state) ->
|
||||
new this(Workspace.deserialize(state.model))
|
||||
|
||||
@configDefaults:
|
||||
ignoredNames: [".git", ".svn", ".DS_Store"]
|
||||
excludeVcsIgnoredPaths: true
|
||||
@ -128,10 +122,6 @@ class WorkspaceView extends View
|
||||
@command 'core:save', => @saveActivePaneItem()
|
||||
@command 'core:save-as', => @saveActivePaneItemAs()
|
||||
|
||||
# Private:
|
||||
serializeParams: ->
|
||||
model: @model.serialize()
|
||||
|
||||
# Private:
|
||||
handleFocus: (e) ->
|
||||
if @getActivePane()
|
||||
|
Loading…
Reference in New Issue
Block a user