[Gutter] Create event subscription methods for gutter changes

This commit is contained in:
Jess Lin
2015-03-12 15:48:25 -07:00
parent b361e1719c
commit ee7625249f
3 changed files with 113 additions and 1 deletions

View File

@@ -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

View File

@@ -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.
#