diff --git a/spec/project-spec.coffee b/spec/project-spec.coffee index 17fea7360..89a629c1e 100644 --- a/spec/project-spec.coffee +++ b/spec/project-spec.coffee @@ -112,6 +112,28 @@ describe "Project", -> editor.saveAs(tempFile) expect(atom.project.getPaths()[0]).toBe path.dirname(tempFile) + describe "before and after saving a buffer", -> + [buffer] = [] + beforeEach -> + waitsForPromise -> + atom.project.bufferForPath(path.join(__dirname, 'fixtures', 'sample.js')).then (o) -> + buffer = o + buffer.retain() + + afterEach -> + buffer.release() + + it "emits save events on the main process", -> + spyOn(atom.project.applicationDelegate, 'emitDidSavePath') + spyOn(atom.project.applicationDelegate, 'emitWillSavePath') + + buffer.save() + + expect(atom.project.applicationDelegate.emitDidSavePath.calls.length).toBe(1) + expect(atom.project.applicationDelegate.emitDidSavePath).toHaveBeenCalledWith(buffer.getPath()) + expect(atom.project.applicationDelegate.emitWillSavePath.calls.length).toBe(1) + expect(atom.project.applicationDelegate.emitWillSavePath).toHaveBeenCalledWith(buffer.getPath()) + describe "when a watch error is thrown from the TextBuffer", -> editor = null beforeEach -> diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index aee02ee8e..efe2af28e 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -266,3 +266,9 @@ class ApplicationDelegate getAutoUpdateManagerErrorMessage: -> ipcRenderer.sendSync('get-auto-update-manager-error') + + emitWillSavePath: (path) -> + ipcRenderer.send('will-save-path', path) + + emitDidSavePath: (path) -> + ipcRenderer.send('did-save-path', path) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 7b3edee0a..5247ceb97 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -185,7 +185,7 @@ class AtomEnvironment extends Model @clipboard = new Clipboard() - @project = new Project({notificationManager: @notifications, packageManager: @packages, @config}) + @project = new Project({notificationManager: @notifications, packageManager: @packages, @config, @applicationDelegate}) @commandInstaller = new CommandInstaller(@getVersion(), @applicationDelegate) diff --git a/src/project.coffee b/src/project.coffee index bf64753cf..f0ce265ed 100644 --- a/src/project.coffee +++ b/src/project.coffee @@ -21,7 +21,7 @@ class Project extends Model Section: Construction and Destruction ### - constructor: ({@notificationManager, packageManager, config}) -> + constructor: ({@notificationManager, packageManager, config, @applicationDelegate}) -> @emitter = new Emitter @buffers = [] @paths = [] @@ -390,6 +390,8 @@ class Project extends Model @on 'buffer-created', (buffer) -> callback(buffer) subscribeToBuffer: (buffer) -> + buffer.onWillSave ({path}) => @applicationDelegate.emitWillSavePath(path) + buffer.onDidSave ({path}) => @applicationDelegate.emitDidSavePath(path) buffer.onDidDestroy => @removeBuffer(buffer) buffer.onDidChangePath => unless @getPaths().length > 0 diff --git a/src/text-editor.coffee b/src/text-editor.coffee index fa52eae6d..e054a3e33 100644 --- a/src/text-editor.coffee +++ b/src/text-editor.coffee @@ -124,7 +124,7 @@ class TextEditor extends Model @softTabs, @firstVisibleScreenRow, @firstVisibleScreenColumn, initialLine, initialColumn, @tabLength, @softWrapped, @decorationManager, @selectionsMarkerLayer, @buffer, suppressCursorCreation, @mini, @placeholderText, lineNumberGutterVisible, @largeFileMode, @config, @clipboard, @grammarRegistry, - @assert, @applicationDelegate, grammar, @showInvisibles, @autoHeight, @scrollPastEnd, @editorWidthInChars, + @assert, grammar, @showInvisibles, @autoHeight, @scrollPastEnd, @editorWidthInChars, @tokenizedBuffer, @ignoreInvisibles, @displayLayer } = params