Login  Register

Re: Streams and FileDialog in Pharo 6 and 7

Posted by Peter Uhnak on Sep 06, 2018; 8:42pm
URL: https://forum.world.st/Streams-and-FileDialog-in-Pharo-6-and-7-tp5084352p5084360.html

>  It should return a FileReference, not an open stream. I believe there are methods that do that.

There are different APIs for that.

fileOpen*, as the name implies, _opens the file_ and returns the stream. (I think this should be the case for fileSave*)

If you want file reference, then you can use e.g.

UIManager default chooseFileMatching: #() label: nil

or `chooseFileMatching:label:`, `chooseFileName:extensions:path:preview:`, `chooseFullFileName:extensions:path:preview:`, `chooseFullFileNameMatching:label:`.
Also some methods for selecting directories (`chooseDirectory:path:`, chooseDirectory:from:`, ...)

iirc some of them actually return String (file path) instead of FileReference. ( https://gist.github.com/peteruhnak/8ac6667b8eb11daee71517d0172b7355#file-ui-manager-md )

So it can be confusing, but the API is already available.

Also iirc UIManager should be preferred over UITheme builder.

Peter

On Thu, Sep 6, 2018 at 9:57 PM Sven Van Caekenberghe <[hidden email]> wrote:


> On 6 Sep 2018, at 21:37, Torsten Bergmann <[hidden email]> wrote:
>
> Hi,
>
> A question to those who worked on the new streams for Pharo 7:
>
>
> In PHARO 6 I used the following expression to open a file dialog and let the user choose
> a binary file:
>
>    s := UITheme builder fileOpen: 'Choose a file' extensions: #('exe').
>
> This returned
> - either nil (when file dialog was canceled)
> - a "MultiByteFileStream" instance when a file was selected
>
> The MultiByteFileStream instance already had the name of the file (= full path) and I was
> able to query it for further use:
>
> s := UITheme builder fileOpen: 'Choose a file' extensions: #('exe').
> s name inspect
>
> (for instance to display which file is processed in a window by showing the full path)
>
>
>
> Now in PHARO 7 same expression returns an instance of ZnCharacterReadStream (as MultiByteFileStream
> is deprecated):
>
> s := UITheme builder fileOpen: 'Choose a file' extensions: #('exe').
>
> and  ZnCharacterReadStream  does not understand #name - and in fact the info about the name is
> totally lost/not available. To me this looks missing/broken.
>
> So what is the recommended way in Pharo 7 to open a file dialog, let the use choose a file
> and get a file stream but also the name? IMHO this is either broken or missing...
>
> Thanks
> T.

It should return a FileReference, not an open stream. I believe there are methods that do that.

But that is an incompatible API change (same selector, different return type). So hard to decide.