Phobos: Using open and save dialogs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
kmo
Reply | Threaded
Open this post in threaded view
|

Phobos: Using open and save dialogs

kmo
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.
kmo
Reply | Threaded
Open this post in threaded view
|

Re: Phobos: Using open and save dialogs

kmo
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.
Reply | Threaded
Open this post in threaded view
|

Re: Phobos: Using open and save dialogs

Pavel Krivanek-3
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 <[hidden email]>:

> 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.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>

kmo
Reply | Threaded
Open this post in threaded view
|

Re: Phobos: Using open and save dialogs

kmo
Thanks, that's great. (I'm only thinking of running with client and server on the same machine at the moment).