From 3848da4488c5a5a00eb679fb49a3faa5bdcefeea Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 25 Feb 2016 17:21:01 -0800 Subject: [PATCH] :lipstick: and :memo: for pending API --- src/pane.coffee | 45 ++++++++++---------------------------------- src/workspace.coffee | 5 ++++- 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/src/pane.coffee b/src/pane.coffee index 16c2f79b2..5952352d1 100644 --- a/src/pane.coffee +++ b/src/pane.coffee @@ -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 diff --git a/src/workspace.coffee b/src/workspace.coffee index 39ec2c599..636ebfd69 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -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