mirror of
https://github.com/atom/atom.git
synced 2026-01-23 22:08:08 -05:00
Emit {will,did}SavePath on ipcMain before/after a buffer is saved
This commit is contained in:
@@ -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 ->
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user