Emit {will,did}SavePath on ipcMain before/after a buffer is saved

This commit is contained in:
Antonio Scandurra
2016-05-23 18:37:26 +02:00
parent 720ad9c0b4
commit ef3ab03d28
5 changed files with 33 additions and 3 deletions

View File

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

View File

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

View File

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

View File

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

View File

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