Re: Phobos: Using open and save dialogs
Posted by
kmo on
Aug 25, 2014; 9:10am
URL: https://forum.world.st/Phobos-Using-open-and-save-dialogs-tp4774528p4774537.html
It's Ok I think I've got it.
You can add a method like this to your main.js:
function doFileOpen() {
/* See:
http://developer.mozilla.org/en/docs/XUL_Tutorial:Open_and_Save_Dialogs */
var nsIFilePicker = Components.interfaces.nsIFilePicker;
var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
fp.init(window, "Open File", nsIFilePicker.modeOpen);
fp.appendFilters(nsIFilePicker.filterText | nsIFilePicker.filterAll);
var res = fp.show();
if (res == nsIFilePicker.returnOK) {
var thefile = fp.file;
return(thefile.leafName);
// --- do something with the file here ---
}
}
Then call it from pharo with an evaluateJS method - if you return the filename from the javascript method pharo can pick it up:
MyPhobosComponent>>getFilename
|res|
res:= self evaluateJS:'doFileOpen();'.
Of course, you could build the entire javascript method as a string in pharo and call it using evaluteJS but it's simpler to put it into main.js as deaing with embedded quotes is fiddly.