mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Move editor tracking to workspace
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.project.addEditor(this) if registerEditor
|
||||
atom.workspace.addEditor(this) if registerEditor
|
||||
|
||||
serializeParams: ->
|
||||
id: @id
|
||||
@@ -225,7 +225,7 @@ class Editor extends Model
|
||||
@buffer.release()
|
||||
@displayBuffer.destroy()
|
||||
@languageMode.destroy()
|
||||
atom.project?.removeEditor(this)
|
||||
atom.workspace?.removeEditor(this)
|
||||
|
||||
# Create an {Editor} with its initial state based on this object
|
||||
copy: ->
|
||||
@@ -237,7 +237,7 @@ class Editor extends Model
|
||||
newEditor.setScrollLeft(@getScrollLeft())
|
||||
for marker in @findMarkers(editorId: @id)
|
||||
marker.copy(editorId: newEditor.id, preserveFolds: true)
|
||||
atom.project.addEditor(newEditor)
|
||||
atom.workspace.addEditor(newEditor)
|
||||
newEditor
|
||||
|
||||
# Public: Get the title the editor's title for display in other parts of the
|
||||
|
||||
@@ -36,7 +36,6 @@ class Project extends Model
|
||||
do (buffer) =>
|
||||
buffer.once 'destroyed', => @removeBuffer(buffer)
|
||||
|
||||
@editors = []
|
||||
@setPath(path)
|
||||
|
||||
serializeParams: ->
|
||||
@@ -48,7 +47,6 @@ class Project extends Model
|
||||
params
|
||||
|
||||
destroyed: ->
|
||||
editor.destroy() for editor in @getEditors()
|
||||
buffer.destroy() for buffer in @getBuffers()
|
||||
@destroyRepo()
|
||||
|
||||
@@ -131,15 +129,6 @@ class Project extends Model
|
||||
filePath = @resolve(filePath)
|
||||
@buildEditorForBuffer(@bufferForPathSync(filePath), options)
|
||||
|
||||
# Add the given {Editor}.
|
||||
addEditor: (editor) ->
|
||||
@editors.push editor
|
||||
@emit 'editor-created', editor
|
||||
|
||||
# Return and removes the given {Editor}.
|
||||
removeEditor: (editor) ->
|
||||
_.remove(@editors, editor)
|
||||
|
||||
# Retrieves all the {TextBuffer}s in the project; that is, the
|
||||
# buffers for all open files.
|
||||
#
|
||||
@@ -304,7 +293,7 @@ class Project extends Model
|
||||
|
||||
buildEditorForBuffer: (buffer, editorOptions) ->
|
||||
editor = new Editor(_.extend({buffer}, editorOptions))
|
||||
@addEditor(editor)
|
||||
atom.workspace.addEditor(editor)
|
||||
editor
|
||||
|
||||
eachBuffer: (args...) ->
|
||||
@@ -335,4 +324,5 @@ class Project extends Model
|
||||
# Deprecated: delegate
|
||||
getEditors: ->
|
||||
deprecate("Use Workspace::getEditors instead")
|
||||
atom.getEditors()
|
||||
new Array(@editors...)
|
||||
|
||||
@@ -30,6 +30,8 @@ class Workspace extends Model
|
||||
super
|
||||
|
||||
@openers = []
|
||||
@editors = []
|
||||
|
||||
@subscribe @paneContainer, 'item-destroyed', @onPaneItemDestroyed
|
||||
@registerOpener (filePath) =>
|
||||
switch filePath
|
||||
@@ -52,6 +54,16 @@ class Workspace extends Model
|
||||
paneContainer: @paneContainer.serialize()
|
||||
fullScreen: atom.isFullScreen()
|
||||
|
||||
# Return and add the given {Editor}.
|
||||
addEditor: (editor) ->
|
||||
@editors.push editor
|
||||
@emit 'editor-created', editor
|
||||
editor
|
||||
|
||||
# Return and removes the given {Editor}.
|
||||
removeEditor: (editor) ->
|
||||
remove(@editors, editor)
|
||||
|
||||
# Public: Register a function to be called for every current and future
|
||||
# {Editor} in the workspace.
|
||||
#
|
||||
@@ -61,13 +73,13 @@ class Workspace extends Model
|
||||
# unregister the callback.
|
||||
eachEditor: (callback) ->
|
||||
callback(editor) for editor in @getEditors()
|
||||
@subscribe atom.project, 'editor-created', (editor) -> callback(editor)
|
||||
@subscribe this, 'editor-created', (editor) -> callback(editor)
|
||||
|
||||
# Public: Get all current editors in the workspace.
|
||||
#
|
||||
# Returns an {Array} of {Editor}s.
|
||||
getEditors: ->
|
||||
atom.project.getEditors()
|
||||
new Array(@editors...)
|
||||
|
||||
# Public: Open a given a URI in Atom asynchronously.
|
||||
#
|
||||
@@ -274,4 +286,5 @@ 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