mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
79 lines
2.3 KiB
CoffeeScript
79 lines
2.3 KiB
CoffeeScript
{Emitter} = require 'event-kit'
|
|
|
|
# Extended: A container representing a panel on the edges of the editor window.
|
|
# You should not create a `Panel` directly, instead use {Workspace::addTopPanel}
|
|
# and friends to add panels.
|
|
#
|
|
# Examples: [tree-view](https://github.com/atom/tree-view),
|
|
# [status-bar](https://github.com/atom/status-bar),
|
|
# and [find-and-replace](https://github.com/atom/find-and-replace) all use
|
|
# panels.
|
|
module.exports =
|
|
class Panel
|
|
###
|
|
Section: Construction and Destruction
|
|
###
|
|
|
|
constructor: ({@viewRegistry, @item, @visible, @priority}) ->
|
|
@emitter = new Emitter
|
|
@visible ?= true
|
|
@priority ?= 100
|
|
|
|
# Public: Destroy and remove this panel from the UI.
|
|
destroy: ->
|
|
@emitter.emit 'did-destroy', this
|
|
|
|
###
|
|
Section: Event Subscription
|
|
###
|
|
|
|
# Public: Invoke the given callback when the pane hidden or shown.
|
|
#
|
|
# * `callback` {Function} to be called when the pane is destroyed.
|
|
# * `visible` {Boolean} true when the panel has been shown
|
|
#
|
|
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
|
|
onDidChangeVisible: (callback) ->
|
|
@emitter.on 'did-change-visible', callback
|
|
|
|
# Public: Invoke the given callback when the pane is destroyed.
|
|
#
|
|
# * `callback` {Function} to be called when the pane is destroyed.
|
|
# * `panel` {Panel} this panel
|
|
#
|
|
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
|
|
onDidDestroy: (callback) ->
|
|
@emitter.on 'did-destroy', callback
|
|
|
|
###
|
|
Section: Panel Details
|
|
###
|
|
|
|
# Public: Gets this panel model's view DOM node.
|
|
#
|
|
# Returns an `<atom-panel>` {Element}
|
|
getView: -> @viewRegistry.getView(this)
|
|
|
|
# Public: Gets your panel contents view.
|
|
#
|
|
# Returns an {Element} or jQuery element, depeneding on how you created the panel.
|
|
getItemView: -> @viewRegistry.getView(@item)
|
|
|
|
# Public: Returns a {Number} indicating this panel's priority.
|
|
getPriority: -> @priority
|
|
|
|
# Public: Returns a {Boolean} true when the panel is visible.
|
|
isVisible: -> @visible
|
|
|
|
# Public: Hide this panel
|
|
hide: ->
|
|
wasVisible = @visible
|
|
@visible = false
|
|
@emitter.emit 'did-change-visible', @visible if wasVisible
|
|
|
|
# Public: Show this panel
|
|
show: ->
|
|
wasVisible = @visible
|
|
@visible = true
|
|
@emitter.emit 'did-change-visible', @visible unless wasVisible
|