Phobos: Using open and save dialogs
Does anyone know how you use the XULRunner /open/ and/ save/ dialogs from Phobos? I need to get a filename back from the user interface into the pharo/phobos image. -- View this message in context: http://forum.world.st/Phobos-Using-open-and-save-dialogs-tp4774528.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
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. -- View this message in context: http://forum.world.st/Phobos-Using-open-and-save-dialogs-tp4774528p4774537.h... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Hi, I will look at it and add the methods to the Phobos code. You have to take into account that Phobos uses client-server architecture where server can be on a different computer. Then Pharo will not have direct access to the file provided by XULRunner client. Cheers, -- Pavel 2014-08-25 11:10 GMT+02:00 kmo <voxkmp@gmail.com>:
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.
-- View this message in context: http://forum.world.st/Phobos-Using-open-and-save-dialogs-tp4774528p4774537.h... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Thanks, that's great. (I'm only thinking of running with client and server on the same machine at the moment). -- View this message in context: http://forum.world.st/Phobos-Using-open-and-save-dialogs-tp4774528p4774580.h... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
participants (2)
-
kmo -
Pavel Krivanek