How to create a File dialog?


#1

How to open a native File dialog from a package?

It seems that require "dialog" does not work.


#2

I would also like to open a File dialog. My goal is to to save as the contents of a view when a user attempts to save.

My Package: https://github.com/Glavin001/atom-preview
Issue: https://github.com/Glavin001/atom-preview/issues/20


#3

@leedohm hey, is there a way to do it?


#4

I cannot be sure, but I think you could potentially use the following:

atom.open()

Note though that the above will present the File/Folder Dialog and open the selection in a New Window.

To get a Save As dialog, I believe it should be possible to use:

atom.showSaveDialogSync()

I haven’t tried the above out myself, but from the source these seem to be the most probable candidates for what you want.

If none of the above work, then you might have to dig deeper in to the “remote”, “ipc”, & “dialog” modules.

Hope that helps!


#5

Thanks a lot! :thumbsup:

atom.open() or atom.showSaveDialogSync() does not return the path.

After I dig in a little more, here is what I come up:

remote = require "remote"
dialog = remote.require "dialog"

dialog.showOpenDialog({properties:['openFile']})

APIs: dialog and remote


#6

Sorry @zhuochun, I don’t know of a way … but I also haven’t looked into it. It sounds like the other suggestions here are good, though :grinning: