Add Project::onDidChangePaths event

This commit is contained in:
Nathan Sobo
2014-10-01 10:46:30 -06:00
parent 33c1ce863e
commit 99b8e159bd
3 changed files with 19 additions and 3 deletions

View File

@@ -620,7 +620,7 @@ class Atom extends Model
watchProjectPath: ->
onProjectPathChanged = =>
ipc.send('window-command', 'project-path-changed', @project.getPaths()[0])
@subscribe @project, 'path-changed', onProjectPathChanged
@subscribe @project.onDidChangePaths(onProjectPathChanged)
onProjectPathChanged()
exit: (status) ->

View File

@@ -6,7 +6,8 @@ fs = require 'fs-plus'
Q = require 'q'
{deprecate} = require 'grim'
{Model} = require 'theorist'
{Emitter, Subscriber} = require 'emissary'
{Subscriber} = require 'emissary'
{Emitter} = require 'event-kit'
Serializable = require 'serializable'
TextBuffer = require 'text-buffer'
{Directory} = require 'pathwatcher'
@@ -35,6 +36,7 @@ class Project extends Model
###
constructor: ({path, paths, @buffers}={}) ->
@emitter = new Emitter
@buffers ?= []
for buffer in @buffers
@@ -69,6 +71,19 @@ class Project extends Model
params.buffers = params.buffers.map (bufferState) -> atom.deserializers.deserialize(bufferState)
params
###
Section: Event Subscription
###
onDidChangePaths: (callback) ->
@emitter.on 'did-change-paths', callback
on: (eventName) ->
if eventName is 'path-changed'
Grim.deprecate("Use Project::onDidChangePaths instead")
super
###
Section: Accessing the git repository
###
@@ -112,6 +127,7 @@ class Project extends Model
@rootDirectory = null
@emit "path-changed"
@emitter.emit 'did-change-paths', projectPaths
setPath: (path) ->
Grim.deprecate("Use ::setPaths instead")
@setPaths([path])

View File

@@ -102,7 +102,7 @@ class WorkspaceView extends View
@subscribe $(window), 'focus', (e) =>
@handleFocus(e) if document.activeElement is document.body
atom.project.on 'path-changed', => @updateTitle()
atom.project.onDidChangePaths => @updateTitle()
@on 'pane-container:active-pane-item-changed', => @updateTitle()
@on 'pane:active-item-title-changed', '.active.pane', => @updateTitle()
@on 'pane:active-item-modified-status-changed', '.active.pane', => @updateDocumentEdited()