mirror of
https://github.com/atom/atom.git
synced 2026-01-23 05:48:10 -05:00
Use PaneContainer to keep the state of open editors
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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...) ->
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user