Move editor tracking to workspace

This commit is contained in:
probablycorey
2014-04-04 10:00:34 -07:00
parent 3aab0b7f51
commit 7685b27218
3 changed files with 20 additions and 17 deletions

View File

@@ -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()