Display a “Save As” dialog?


#1

For a build package of mine, I’m saving the file prior to when the user triggers the build command. I would like to show a “Save As” dialog, when the buffer hasn’t been saved before. The TextEditor class has a saveAs() method, but that requires a path to be passed. The decision where a file gets saved to, should be the user’s decision. So I was wondering what alternative there is? IMHO, the saveAs() method should pop up a dialog, when there’s no path specified.


#2

What does the save() method do if the file hasn’t been saved before?


#3

Judging from the error message, I assume that save() ultimately calls saveAs() and passes getPath() as file-path:

Error: Can't save buffer with no file path
    at TextBuffer.module.exports.TextBuffer.saveAs (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:1089:15)
    at TextBuffer.module.exports.TextBuffer.save (/Applications/Atom.app/Contents/Resources/app.asar/node_modules/text-buffer/lib/text-buffer.js:1083:19)
    at TextEditor.module.exports.TextEditor.save (/Applications/Atom.app/Contents/Resources/app.asar/src/text-editor.js:660:26)

#4

That’s not what the TextEditor.saveAs function is for. We have other methods for displaying an OS-provided save dialog, specifically:

http://electron.atom.io/docs/api/dialog/#dialogshowsavedialogbrowserwindow-options-callback

Once you get the path from the user, however you decide to do that, you can pass the path to the TextEditor.saveAs function.