mirror of
https://github.com/atom/atom.git
synced 2026-02-13 08:04:56 -05:00
Conditionally include deprecations in Workspace
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{deprecate} = require 'grim'
|
||||
{includeDeprecations, deprecate} = require 'grim'
|
||||
_ = require 'underscore-plus'
|
||||
path = require 'path'
|
||||
{join} = path
|
||||
@@ -33,16 +33,6 @@ class Workspace extends Model
|
||||
atom.deserializers.add(this)
|
||||
Serializable.includeInto(this)
|
||||
|
||||
Object.defineProperty @::, 'activePaneItem',
|
||||
get: ->
|
||||
Grim.deprecate "Use ::getActivePaneItem() instead of the ::activePaneItem property"
|
||||
@getActivePaneItem()
|
||||
|
||||
Object.defineProperty @::, 'activePane',
|
||||
get: ->
|
||||
Grim.deprecate "Use ::getActivePane() instead of the ::activePane property"
|
||||
@getActivePane()
|
||||
|
||||
@properties
|
||||
paneContainer: null
|
||||
fullScreen: false
|
||||
@@ -342,32 +332,6 @@ class Workspace extends Model
|
||||
@onDidAddPaneItem ({item, pane, index}) ->
|
||||
callback({textEditor: item, pane, index}) if item instanceof TextEditor
|
||||
|
||||
eachEditor: (callback) ->
|
||||
deprecate("Use Workspace::observeTextEditors instead")
|
||||
|
||||
callback(editor) for editor in @getEditors()
|
||||
@subscribe this, 'editor-created', (editor) -> callback(editor)
|
||||
|
||||
getEditors: ->
|
||||
deprecate("Use Workspace::getTextEditors instead")
|
||||
|
||||
editors = []
|
||||
for pane in @paneContainer.getPanes()
|
||||
editors.push(item) for item in pane.getItems() when item instanceof TextEditor
|
||||
|
||||
editors
|
||||
|
||||
on: (eventName) ->
|
||||
switch eventName
|
||||
when 'editor-created'
|
||||
deprecate("Use Workspace::onDidAddTextEditor or Workspace::observeTextEditors instead.")
|
||||
when 'uri-opened'
|
||||
deprecate("Use Workspace::onDidOpen or Workspace::onDidAddPaneItem instead. https://atom.io/docs/api/latest/Workspace#instance-onDidOpen")
|
||||
else
|
||||
deprecate("Subscribing via ::on is deprecated. Use documented event subscription methods instead.")
|
||||
|
||||
super
|
||||
|
||||
###
|
||||
Section: Opening
|
||||
###
|
||||
@@ -425,7 +389,7 @@ class Workspace extends Model
|
||||
# the containing pane. Defaults to `true`.
|
||||
openSync: (uri='', options={}) ->
|
||||
# TODO: Remove deprecated changeFocus option
|
||||
if options.changeFocus?
|
||||
if includeDeprecations and options.changeFocus?
|
||||
deprecate("The `changeFocus` option has been renamed to `activatePane`")
|
||||
options.activatePane = options.changeFocus
|
||||
delete options.changeFocus
|
||||
@@ -446,7 +410,7 @@ class Workspace extends Model
|
||||
|
||||
openURIInPane: (uri, pane, options={}) ->
|
||||
# TODO: Remove deprecated changeFocus option
|
||||
if options.changeFocus?
|
||||
if includeDeprecations and options.changeFocus?
|
||||
deprecate("The `changeFocus` option has been renamed to `activatePane`")
|
||||
options.activatePane = options.changeFocus
|
||||
delete options.changeFocus
|
||||
@@ -496,12 +460,6 @@ class Workspace extends Model
|
||||
else
|
||||
Q()
|
||||
|
||||
# Deprecated
|
||||
reopenItemSync: ->
|
||||
deprecate("Use Workspace::reopenItem instead")
|
||||
if uri = @destroyedItemURIs.pop()
|
||||
@openSync(uri)
|
||||
|
||||
# Public: Register an opener for a uri.
|
||||
#
|
||||
# An {TextEditor} will be used if no openers return a value.
|
||||
@@ -519,24 +477,20 @@ class Workspace extends Model
|
||||
# Returns a {Disposable} on which `.dispose()` can be called to remove the
|
||||
# opener.
|
||||
addOpener: (opener) ->
|
||||
packageName = @getCallingPackageName()
|
||||
if includeDeprecations
|
||||
packageName = @getCallingPackageName()
|
||||
|
||||
wrappedOpener = (uri, options) ->
|
||||
item = opener(uri, options)
|
||||
if item? and typeof item.getUri is 'function' and typeof item.getURI isnt 'function'
|
||||
Grim.deprecate("Pane item with class `#{item.constructor.name}` should implement `::getURI` instead of `::getUri`.", {packageName})
|
||||
item
|
||||
wrappedOpener = (uri, options) ->
|
||||
item = opener(uri, options)
|
||||
if item? and typeof item.getUri is 'function' and typeof item.getURI isnt 'function'
|
||||
Grim.deprecate("Pane item with class `#{item.constructor.name}` should implement `::getURI` instead of `::getUri`.", {packageName})
|
||||
item
|
||||
|
||||
@openers.push(wrappedOpener)
|
||||
new Disposable => _.remove(@openers, wrappedOpener)
|
||||
|
||||
registerOpener: (opener) ->
|
||||
Grim.deprecate("Call Workspace::addOpener instead")
|
||||
@addOpener(opener)
|
||||
|
||||
unregisterOpener: (opener) ->
|
||||
Grim.deprecate("Call .dispose() on the Disposable returned from ::addOpener instead")
|
||||
_.remove(@openers, opener)
|
||||
@openers.push(wrappedOpener)
|
||||
new Disposable => _.remove(@openers, wrappedOpener)
|
||||
else
|
||||
@openers.push(opener)
|
||||
new Disposable => _.remove(@openers, opener)
|
||||
|
||||
getOpeners: ->
|
||||
@openers
|
||||
@@ -599,11 +553,6 @@ class Workspace extends Model
|
||||
activeItem = @getActivePaneItem()
|
||||
activeItem if activeItem instanceof TextEditor
|
||||
|
||||
# Deprecated
|
||||
getActiveEditor: ->
|
||||
Grim.deprecate "Call ::getActiveTextEditor instead"
|
||||
@getActivePane()?.getActiveEditor()
|
||||
|
||||
# Save all pane items.
|
||||
saveAll: ->
|
||||
@paneContainer.saveAll()
|
||||
@@ -667,10 +616,6 @@ class Workspace extends Model
|
||||
paneForURI: (uri) ->
|
||||
@paneContainer.paneForURI(uri)
|
||||
|
||||
paneForUri: (uri) ->
|
||||
deprecate("Use ::paneForURI instead.")
|
||||
@paneForURI(uri)
|
||||
|
||||
# Extended: Get the {Pane} containing the given item.
|
||||
#
|
||||
# * `item` Item the returned pane contains.
|
||||
@@ -945,3 +890,61 @@ class Workspace extends Model
|
||||
checkFinished()
|
||||
|
||||
deferred.promise
|
||||
|
||||
if includeDeprecations
|
||||
Object.defineProperty Workspace::, 'activePaneItem',
|
||||
get: ->
|
||||
Grim.deprecate "Use ::getActivePaneItem() instead of the ::activePaneItem property"
|
||||
@getActivePaneItem()
|
||||
|
||||
Object.defineProperty Workspace::, 'activePane',
|
||||
get: ->
|
||||
Grim.deprecate "Use ::getActivePane() instead of the ::activePane property"
|
||||
@getActivePane()
|
||||
|
||||
Workspace::eachEditor = (callback) ->
|
||||
deprecate("Use Workspace::observeTextEditors instead")
|
||||
|
||||
callback(editor) for editor in @getEditors()
|
||||
@subscribe this, 'editor-created', (editor) -> callback(editor)
|
||||
|
||||
Workspace::getEditors = ->
|
||||
deprecate("Use Workspace::getTextEditors instead")
|
||||
|
||||
editors = []
|
||||
for pane in @paneContainer.getPanes()
|
||||
editors.push(item) for item in pane.getItems() when item instanceof TextEditor
|
||||
|
||||
editors
|
||||
|
||||
Workspace::on = (eventName) ->
|
||||
switch eventName
|
||||
when 'editor-created'
|
||||
deprecate("Use Workspace::onDidAddTextEditor or Workspace::observeTextEditors instead.")
|
||||
when 'uri-opened'
|
||||
deprecate("Use Workspace::onDidOpen or Workspace::onDidAddPaneItem instead. https://atom.io/docs/api/latest/Workspace#instance-onDidOpen")
|
||||
else
|
||||
deprecate("Subscribing via ::on is deprecated. Use documented event subscription methods instead.")
|
||||
|
||||
super
|
||||
|
||||
Workspace::reopenItemSync = ->
|
||||
deprecate("Use Workspace::reopenItem instead")
|
||||
if uri = @destroyedItemURIs.pop()
|
||||
@openSync(uri)
|
||||
|
||||
Workspace::registerOpener = (opener) ->
|
||||
Grim.deprecate("Call Workspace::addOpener instead")
|
||||
@addOpener(opener)
|
||||
|
||||
Workspace::unregisterOpener = (opener) ->
|
||||
Grim.deprecate("Call .dispose() on the Disposable returned from ::addOpener instead")
|
||||
_.remove(@openers, opener)
|
||||
|
||||
Workspace::getActiveEditor = ->
|
||||
Grim.deprecate "Call ::getActiveTextEditor instead"
|
||||
@getActivePane()?.getActiveEditor()
|
||||
|
||||
Workspace::paneForUri = (uri) ->
|
||||
deprecate("Use ::paneForURI instead.")
|
||||
@paneForURI(uri)
|
||||
|
||||
Reference in New Issue
Block a user