Keep existing PaneView SpacePen API working as before

We will eventually deprecate all access to views via
`atom.workspaceView`, which is the only way to get a reference to
instances of PaneView. Draining the swamp!
This commit is contained in:
Nathan Sobo
2014-09-17 16:30:02 -06:00
parent 4ba3162f3e
commit de29ca6906
4 changed files with 19 additions and 77 deletions

View File

@@ -55,7 +55,7 @@
"season": "^1.0.2",
"semver": "1.1.4",
"serializable": "^1",
"space-pen": "3.4.7",
"space-pen": "3.5.0",
"temp": "0.7.0",
"text-buffer": "^3.2.6",
"theorist": "^1.0.2",

View File

@@ -1,18 +1,19 @@
{CompositeDisposable} = require 'event-kit'
{$} = require './space-pen-extensions'
PaneView = require './pane-view'
class PaneElement extends HTMLElement
createdCallback: ->
@subscriptions = new CompositeDisposable
@initializeContent()
@subscribeToDOMEvents()
@createSpacePenShim()
attachedCallback: ->
@focus() if @model.isFocused()
detachedCallback: ->
@subscriptions.dispose()
@model.destroy() unless @model.isDestroyed()
initializeContent: ->
@setAttribute 'class', 'pane'
@@ -25,6 +26,9 @@ class PaneElement extends HTMLElement
@addEventListener 'focusout', => @model.blur()
@addEventListener 'focus', => @getActiveView()?.focus()
createSpacePenShim: ->
@__spacePenView = new PaneView(this)
getModel: -> @model
setModel: (@model) ->
@@ -32,6 +36,7 @@ class PaneElement extends HTMLElement
@subscriptions.add @model.observeActive(@activeStatusChanged.bind(this))
@subscriptions.add @model.observeActiveItem(@activeItemChanged.bind(this))
@subscriptions.add @model.onDidRemoveItem(@itemRemoved.bind(this))
@__spacePenView.setModel(@model)
activated: ->
@focus() unless @hasFocus()

View File

@@ -17,12 +17,6 @@ class PaneView extends View
Delegator.includeInto(this)
PropertyAccessors.includeInto(this)
@version: 1
@content: (wrappedView) ->
@div class: 'pane', tabindex: -1, =>
@div class: 'item-views', outlet: 'itemViews'
@delegatesProperties 'items', 'activeItem', toProperty: 'model'
@delegatesMethods 'getItems', 'activateNextItem', 'activatePreviousItem', 'getActiveItemIndex',
'activateItemAtIndex', 'activateItem', 'addItem', 'itemAtIndex', 'moveItem', 'moveItemToPane',
@@ -33,48 +27,26 @@ class PaneView extends View
previousActiveItem: null
initialize: (@model) ->
@subscriptions = new CompositeDisposable
@onItemAdded(item) for item in @items
@handleEvents()
constructor: (@element) ->
@itemViews = $(element.itemViews)
super
handleEvents: ->
setModel: (@model) ->
@subscriptions = new CompositeDisposable
@subscriptions.add @model.observeActiveItem(@onActiveItemChanged)
@subscriptions.add @model.onDidAddItem(@onItemAdded)
@subscriptions.add @model.observeItems(@onItemAdded)
@subscriptions.add @model.onDidRemoveItem(@onItemRemoved)
@subscriptions.add @model.onDidMoveItem(@onItemMoved)
@subscriptions.add @model.onWillDestroyItem(@onBeforeItemDestroyed)
@subscriptions.add @model.onDidActivate(@onActivated)
@subscriptions.add @model.observeActive(@onActiveStatusChanged)
@subscribe this, 'focusin', => @model.focus()
@subscribe this, 'focusout', => @model.blur()
@subscribe this, 'focus', =>
@activeView?.focus()
false
afterAttach: ->
@container ?= @closest('.panes').view()
@trigger 'pane:attached', [this]
@command 'pane:save-items', => @saveItems()
@command 'pane:show-next-item', => @activateNextItem()
@command 'pane:show-previous-item', => @activatePreviousItem()
@command 'pane:show-item-1', => @activateItemAtIndex(0)
@command 'pane:show-item-2', => @activateItemAtIndex(1)
@command 'pane:show-item-3', => @activateItemAtIndex(2)
@command 'pane:show-item-4', => @activateItemAtIndex(3)
@command 'pane:show-item-5', => @activateItemAtIndex(4)
@command 'pane:show-item-6', => @activateItemAtIndex(5)
@command 'pane:show-item-7', => @activateItemAtIndex(6)
@command 'pane:show-item-8', => @activateItemAtIndex(7)
@command 'pane:show-item-9', => @activateItemAtIndex(8)
@command 'pane:split-left', => @model.splitLeft(copyActiveItem: true)
@command 'pane:split-right', => @model.splitRight(copyActiveItem: true)
@command 'pane:split-up', => @model.splitUp(copyActiveItem: true)
@command 'pane:split-down', => @model.splitDown(copyActiveItem: true)
@command 'pane:close', =>
@model.destroyItems()
@model.destroy()
@command 'pane:close-other-items', => @destroyInactiveItems()
beforeRemove: ->
@subscriptions.dispose()
@model.destroy() unless @model.isDestroyed()
# Essential: Returns the {Pane} model underlying this pane view
getModel: -> @model
@@ -109,23 +81,10 @@ class PaneView extends View
deprecate("Use PaneView::activatePreviousItem instead")
@activatePreviousItem()
afterAttach: (onDom) ->
@focus() if @model.focused and onDom
return if @attached
@container = @closest('.panes').view()
@attached = true
@trigger 'pane:attached', [this]
onActivated: =>
@focus() unless @hasFocus()
onActiveStatusChanged: (active) =>
if active
@addClass('active')
@trigger 'pane:became-active'
else
@removeClass('active')
@trigger 'pane:became-inactive'
# Public: Returns the next pane, ordered by creation.
@@ -179,17 +138,6 @@ class PaneView extends View
@trigger 'pane:item-added', [item, index]
onItemRemoved: ({item, index, destroyed}) =>
if item instanceof $
viewToRemove = item
else
viewToRemove = @model.getView(item).__spacePenView
if viewToRemove?
if destroyed
viewToRemove.remove()
else
viewToRemove.detach()
@trigger 'pane:item-removed', [item, index]
onItemMoved: ({item, newIndex}) =>
@@ -220,12 +168,3 @@ class PaneView extends View
# Returns a {View}.
getContainer: ->
@closest('.panes').view()
beforeRemove: ->
@subscriptions.dispose()
@model.destroy() unless @model.isDestroyed()
remove: (selector, keepData) ->
return super if keepData
@unsubscribe()
super

View File

@@ -69,6 +69,4 @@ jQuery(document.body).on 'show.bs.tooltip', ({target}) ->
jQuery.fn.setTooltip.getKeystroke = getKeystroke
jQuery.fn.setTooltip.humanizeKeystrokes = humanizeKeystrokes
Object.defineProperty jQuery.fn, 'element', get: -> @[0]
module.exports = spacePen