💄 and 📝 for pending API

This commit is contained in:
Katrina Uychaco 2016-02-25 17:21:01 -08:00 committed by Michelle Tilley
parent 1c65d0e5e4
commit 3848da4488
2 changed files with 14 additions and 36 deletions

View File

@ -58,7 +58,7 @@ class Pane extends Model
items: compact(@items.map((item) -> item.serialize?()))
activeItemURI: activeItemURI
focused: @focused
flexScale: @flexScale # TODO: is it okay to not serialize pending state? does it need to be restored?
flexScale: @flexScale
getParent: -> @parent
@ -348,7 +348,9 @@ class Pane extends Model
# Public: Make the given item *active*, causing it to be displayed by
# the pane's view.
#
# * `pending` TODO
# * `pending` (optional) {Boolean} indicating that the item should be added
# in a pending state if it does not yet exist in the pane. Existing pending
# items in a pane are replaced with new pending items when they are opened.
activateItem: (item, pending=false) ->
if item?
if @isItemPending(@activeItem)
@ -364,7 +366,9 @@ class Pane extends Model
# view.
# * `index` (optional) {Number} indicating the index at which to add the item.
# If omitted, the item is added after the current active item.
# * `pending` TODO
# * `pending` (optional) {Boolean} indicating that the item should be
# added in a pending state. Existing pending items in a pane are replaced with
# new pending items when they are opened.
#
# Returns the added item.
addItem: (item, index=@getActiveItemIndex() + 1, moved=false, pending=false) ->
@ -391,44 +395,15 @@ class Pane extends Model
@setActiveItem(item) unless @getActiveItem()?
item
clearPendingItem: =>
@setPendingItem(null)
setPendingItem: (item) =>
# TODO: figure out events for changing/clearing pending item
@pendingItem = item
@emitter.emit 'did-change-pending-item', @pendingItem
@pendingItem = item if @pendingItem isnt item
@emitter.emit 'did-terminate-pending-state' if not item
# Public: Get the pending pane item in this pane, if any.
#
# Returns a pane item or `null`.
getPendingItem: =>
@pendingItem or null
isItemPending: (item) =>
@pendingItem is item
# Invoke the given callback when the value of {::getPendingItem} changes.
#
# * `callback` {Function} to be called with when the pending item changes.
# * `pendingItem` The current pending item, or `null`.
#
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
onDidChangePendingItem: (callback) =>
@emitter.on 'did-change-pending-item', callback
# Public: Invoke the given callback with the current and future values of
# {::getPendingItem}.
#
# * `callback` {Function} to be called with the current and future pending
# items.
# * `pendingItem` The current pending item.
#
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
observePendingItem: (callback) ->
callback(@getPendingItem())
@onDidChangePendingItem(callback)
clearPendingItem: =>
@setPendingItem(null)
onDidTerminatePendingState: (callback) =>
@emitter.on 'did-terminate-pending-state', callback

View File

@ -403,6 +403,9 @@ class Workspace extends Model
# containing pane. Defaults to `true`.
# * `activateItem` A {Boolean} indicating whether to call {Pane::activateItem}
# on containing pane. Defaults to `true`.
# * `pending` A {Boolean} indicating whether or not the item should be opened
# in a pending state. Existing pending items in a pane are replaced with
# new pending items when they are opened.
# * `searchAllPanes` A {Boolean}. If `true`, the workspace will attempt to
# activate an existing item for the given URI on any pane.
# If `false`, only the active pane will be searched for
@ -477,7 +480,7 @@ class Workspace extends Model
if uri?
if item = pane.itemForURI(uri)
pane.setPendingItem(null) if not options.pending
pane.clearPendingItem() if not options.pending and pane.getPendingItem() is item
item ?= opener(uri, options) for opener in @getOpeners() when not item
try