Avoid spurious deprecation warnings when editor URIs are undefined

Signed-off-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Nathan Sobo
2015-01-14 11:21:02 -07:00
parent 76b7a8cec9
commit 56da4f49d4
2 changed files with 19 additions and 8 deletions

View File

@@ -427,13 +427,18 @@ class Pane extends Model
@destroyItem(item) for item in @getItems() when item isnt @activeItem
promptToSaveItem: (item) ->
if typeof item.getUri is 'function' and typeof item.getURI isnt 'function'
Grim.deprecate("Implement `::getURI` on pane items instead of `::getUri`")
return true unless item.shouldPromptToSave?()
return true unless (typeof item.getURI is 'function' or typeof item.getUri is 'function') and item.shouldPromptToSave?()
if typeof item.getURI is 'function'
uri = item.getURI()
else if typeof item.getUri is 'function'
deprecate("Pane items should implement `::getURI` instead of `::getUri`.")
uri = item.getUri()
else
return true
chosen = atom.confirm
message: "'#{item.getTitle?() ? item.getURI?() ? item.getUri?()}' has changes, do you want to save them?"
message: "'#{item.getTitle?() ? uri}' has changes, do you want to save them?"
detailedMessage: "Your changes will be lost if you close this item without saving."
buttons: ["Save", "Cancel", "Don't Save"]

View File

@@ -655,18 +655,24 @@ class Workspace extends Model
# Removes the item's uri from the list of potential items to reopen.
itemOpened: (item) ->
if typeof item.getUri is 'function' and not typeof item.getURI is 'function'
if typeof item.getURI is 'function'
uri = item.getURI()
else if typeof item.getUri is 'function'
deprecate("Pane items should implement `::getURI` instead of `::getUri`.")
uri = item.getUri()
if uri = item.getURI?() ? item.getUri?()
if uri?
_.remove(@destroyedItemURIs, uri)
# Adds the destroyed item's uri to the list of items to reopen.
didDestroyPaneItem: ({item}) =>
if typeof item.getUri is 'function' and not typeof item.getURI is 'function'
if typeof item.getURI is 'function'
uri = item.getURI()
else if typeof item.getUri is 'function'
deprecate("Pane items should implement `::getURI` instead of `::getUri`.")
uri = item.getUri()
if uri = item.getURI?() ? item.getUri?()
if uri?
@destroyedItemURIs.push(uri)
# Called by Model superclass when destroyed