I am currently working with two packages. One of them intercepts all the
core:save events and performs some actions based on the target (so far, it works with
atom-text-editor as target), like this:
@subscriptions.add atom.commands.onDidDispatch (event) => if event.type is 'core:save' savedPath = if event.target.model.getPath then event.target.model.getPath() else null @doWhateverWithFileAt savedPath else if event.type is 'tree-view:remove' # do something else with removed files
The second package opens files into a mini text editor created with
atom-space-pen-views and allows the user to edit and save such files.
@content: (params) => @subview 'extraView', new TextEditorView(mini: true, placeholderText: '...') @div class: "btn-group", => @button outlet: 'openButton', click: 'openExtra', class: 'btn btn-sm btn-primary', 'Open in new tab' @button outlet: 'saveButton', click: 'saveExtra', class: 'btn btn-sm disabled', 'Save changes' ... saveExtra: -> # variable @extraFilePath contains the path of the open file return unless @extraFilePath toBeSaved = @extraView.getText() @extraFileCtnt = @extraView.getText() fs.writeFileSync @extraFilePath, toBeSaved @toggleSaveButton false
Point is, if I save the file with
fs, the core event is not fired and the first package cannot possibly catch it.
My question is, is there a way to dispatch a
core:save event so that it is properly caught? I tried with
atom.commands.dispatch @extraView, 'core:save' but it does not seem to work.
Thank you all!