From 99b8e159bdcbef5cab0a8d9ddcaed1986a4307fc Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 1 Oct 2014 10:46:30 -0600 Subject: [PATCH] Add Project::onDidChangePaths event --- src/atom.coffee | 2 +- src/project.coffee | 18 +++++++++++++++++- src/workspace-view.coffee | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 1dc2fedea..a18cafe4d 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -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) -> diff --git a/src/project.coffee b/src/project.coffee index 9f0f3dbfe..7493f684a 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -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]) diff --git a/src/workspace-view.coffee b/src/workspace-view.coffee index 52898a0d4..b4a395bca 100644 --- a/src/workspace-view.coffee +++ b/src/workspace-view.coffee @@ -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()