mirror of
https://github.com/atom/atom.git
synced 2026-02-15 09:05:58 -05:00
[Gutter] Create event subscription methods for gutter changes
This commit is contained in:
@@ -46,6 +46,7 @@ class GutterContainer
|
||||
break
|
||||
if !inserted
|
||||
@gutters.push newGutter
|
||||
@emitter.emit 'did-add-gutter', newGutter
|
||||
return newGutter
|
||||
|
||||
getGutters: ->
|
||||
@@ -60,7 +61,16 @@ class GutterContainer
|
||||
Section: Event Subscription
|
||||
###
|
||||
|
||||
# @param callback: function( nameOfRemovedGutter )
|
||||
# See {TextEditor::observeGutters} for details.
|
||||
observeGutters: (callback) ->
|
||||
callback(gutter) for gutter in @getGutters()
|
||||
@onDidAddGutter callback
|
||||
|
||||
# See {TextEditor::onDidAddGutter} for details.
|
||||
onDidAddGutter: (callback) ->
|
||||
@emitter.on 'did-add-gutter', callback
|
||||
|
||||
# See {TextEditor::onDidRemoveGutter} for details.
|
||||
onDidRemoveGutter: (callback) ->
|
||||
@emitter.on 'did-remove-gutter', callback
|
||||
|
||||
|
||||
@@ -524,6 +524,34 @@ class TextEditor extends Model
|
||||
gutterWithName: (name) ->
|
||||
@gutterContainer.gutterWithName name
|
||||
|
||||
# Calls your `callback` when a {Gutter} is added to the editor.
|
||||
# Immediately calls your callback for each existing gutter.
|
||||
#
|
||||
# * `callback` {Function}
|
||||
# * `gutter` {Gutter} that currently exists/was added.
|
||||
#
|
||||
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
|
||||
observeGutters: (callback) ->
|
||||
@gutterContainer.observeGutters callback
|
||||
|
||||
# Calls your `callback` when a {Gutter} is added to the editor.
|
||||
#
|
||||
# * `callback` {Function}
|
||||
# * `gutter` {Gutter} that was added.
|
||||
#
|
||||
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
|
||||
onDidAddGutter: (callback) ->
|
||||
@gutterContainer.onDidAddGutter callback
|
||||
|
||||
# Calls your `callback` when a {Gutter} is removed from the editor.
|
||||
#
|
||||
# * `callback` {Function}
|
||||
# * `name` The name of the {Gutter} that was removed.
|
||||
#
|
||||
# Returns a {Disposable} on which `.dispose()` can be called to unsubscribe.
|
||||
onDidRemoveGutter: (callback) ->
|
||||
@gutterContainer.onDidRemoveGutter callback
|
||||
|
||||
# Set the number of characters that can be displayed horizontally in the
|
||||
# editor.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user