Use PaneContainer to keep the state of open editors

This commit is contained in:
Corey Johnson
2014-04-11 11:10:00 -07:00
parent fe0d714710
commit e56fa3ec4f
3 changed files with 10 additions and 15 deletions

View File

@@ -182,7 +182,7 @@ class Editor extends Model
@subscribe @$scrollTop, (scrollTop) => @emit 'scroll-top-changed', scrollTop
@subscribe @$scrollLeft, (scrollLeft) => @emit 'scroll-left-changed', scrollLeft
atom.workspace.addEditor(this) if registerEditor
atom.workspace.editorAdded(this) if registerEditor
serializeParams: ->
id: @id
@@ -225,19 +225,17 @@ class Editor extends Model
@buffer.release()
@displayBuffer.destroy()
@languageMode.destroy()
atom.workspace?.removeEditor(this)
# Create an {Editor} with its initial state based on this object
copy: ->
tabLength = @getTabLength()
displayBuffer = @displayBuffer.copy()
softTabs = @getSoftTabs()
newEditor = new Editor({@buffer, displayBuffer, tabLength, softTabs, suppressCursorCreation: true})
newEditor = new Editor({@buffer, displayBuffer, tabLength, softTabs, suppressCursorCreation: true, registerEditor: true})
newEditor.setScrollTop(@getScrollTop())
newEditor.setScrollLeft(@getScrollLeft())
for marker in @findMarkers(editorId: @id)
marker.copy(editorId: newEditor.id, preserveFolds: true)
atom.workspace.addEditor(newEditor)
newEditor
# Public: Get the title the editor's title for display in other parts of the

View File

@@ -292,8 +292,7 @@ class Project extends Model
deferred.promise
buildEditorForBuffer: (buffer, editorOptions) ->
editor = new Editor(_.extend({buffer}, editorOptions))
atom.workspace.addEditor(editor)
editor = new Editor(_.extend({buffer, registerEditor: true}, editorOptions))
editor
eachBuffer: (args...) ->

View File

@@ -5,6 +5,7 @@ _ = require 'underscore-plus'
Q = require 'q'
Serializable = require 'serializable'
Delegator = require 'delegato'
Editor = require './editor'
PaneContainer = require './pane-container'
Pane = require './pane'
@@ -30,7 +31,6 @@ class Workspace extends Model
super
@openers = []
@editors = []
@subscribe @paneContainer, 'item-destroyed', @onPaneItemDestroyed
@registerOpener (filePath) =>
@@ -54,13 +54,8 @@ class Workspace extends Model
paneContainer: @paneContainer.serialize()
fullScreen: atom.isFullScreen()
addEditor: (editor) ->
@editors.push editor
editorAdded: (editor) ->
@emit 'editor-created', editor
editor
removeEditor: (editor) ->
_.remove(@editors, editor)
# Public: Register a function to be called for every current and future
# {Editor} in the workspace.
@@ -77,7 +72,11 @@ class Workspace extends Model
#
# Returns an {Array} of {Editor}s.
getEditors: ->
_.clone(@editors)
editors = []
for pane in @paneContainer.getPanes()
editors.push(item) for item in pane.getItems() when item instanceof Editor
editors
# Public: Open a given a URI in Atom asynchronously.
#
@@ -284,5 +283,4 @@ class Workspace extends Model
# Called by Model superclass when destroyed
destroyed: ->
editor.destroy() for editor in @getEditors()
@paneContainer.destroy()