beginner question - how to get a fully qualified filename from a dialog

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

beginner question - how to get a fully qualified filename from a dialog

amaloney
I have a method:
openSimulationFile
        inFile := (StandardFileStream fileNamed: '/Users/amaloney/Squeak/30shoes.txt') ascii
I want to replace the hard coded fully qualified filename with the result of a file browser dialog.

I've done some Googling and poked around in the system browser and I find that if I enter (in a playground)
UIManager default chooseDirectory and inspect-it I get: a FileReference (/Users/amaloney/Squeak)
and if I try UIManager default chooseFileMatching: #( '*.txt' ) I get: a ByteString ('Readme.txt').

It seems that UIManager chooseDirectory is the method I should start exploring (since it returns a FileReference object) but the method is:
chooseDirectory
        "Let the user choose a directory"
        ^self chooseDirectoryFrom: FileSystem workingDirectory

and when I look at chooseDirectoryFrom: I get
chooseDirectoryFrom: dir
        "Let the user choose a directory"
        ^self chooseDirectory: nil from: dir
so I look at chooseDirectory: from:
and I get:
chooseDirectory: label from: dir
        "Let the user choose a directory"
        ^self subclassResponsibility
Which doesn't help so I dig around in the docs some more and find out that the green down arrow is clickable.
When I click it and choose MorphicUlManager>>#chooseDirectory:from:
the method definition is:
chooseDirectory: label from: dir
        "Answer the user choice of a directory."
       
        | modalMorph realLabel |
        realLabel := label ifNil: ['Choose Directory' translated].
        (ProvideAnswerNotification signal: realLabel) ifNotNil: [:answer |
                ^answer ].
        modalMorph := self modalMorph.
        ^modalMorph theme  
                chooseDirectoryIn: modalMorph
                title: realLabel
                path: (dir ifNotNil: [dir fullName])

The problem is that I cannot find a chooseDirectoryIn:title:path: method.

I wrote this all out hoping someone can tell me where I chose the wrong rabbit hole and can point me to instructions on how to choose the correct rabbit hole. ;-) (Also, if there is a short answer i.e. use this object>>method, I'd appreciate that as well.)

Thanks,

Mike





Reply | Threaded
Open this post in threaded view
|

Re: beginner question - how to get a fully qualified filename from a dialog

CyrilFerlicot
Hi,
maybe instead of UIManager you could look on UITheme.
For example the following code:

Smalltalk ui theme
                chooseFullFileNameIn: World
                title: 'Select file to open'
                extensions: nil
                path:
                    (myActualFilePath isNil
                        ifTrue: [ myActualFilePath ]
                        ifFalse: [ FileSystem workingDirectory ])
                preview: nil

This will open a dialog with "Select file to open" in title, it will
accept file of every extension and the path will begin at
myActualFilePath or into the working directory if the actual file path
is nil.



On 12 May 2015 at 18:00, amaloney <[hidden email]> wrote:

> I have a method:
> openSimulationFile
>         inFile := (StandardFileStream fileNamed:
> '/Users/amaloney/Squeak/30shoes.txt') ascii
> I want to replace the hard coded fully qualified filename with the result of
> a file browser dialog.
>
> I've done some Googling and poked around in the system browser and I find
> that if I enter (in a playground)
> UIManager default chooseDirectory and inspect-it I get: a FileReference
> (/Users/amaloney/Squeak)
> and if I try UIManager default chooseFileMatching: #( '*.txt' ) I get: a
> ByteString ('Readme.txt').
>
> It seems that UIManager chooseDirectory is the method I should start
> exploring (since it returns a FileReference object) but the method is:
> chooseDirectory
>         "Let the user choose a directory"
>         ^self chooseDirectoryFrom: FileSystem workingDirectory
>
> and when I look at chooseDirectoryFrom: I get
> chooseDirectoryFrom: dir
>         "Let the user choose a directory"
>         ^self chooseDirectory: nil from: dir
> so I look at chooseDirectory: from:
> and I get:
> chooseDirectory: label from: dir
>         "Let the user choose a directory"
>         ^self subclassResponsibility
> Which doesn't help so I dig around in the docs some more and find out that
> the green down arrow is clickable.
> When I click it and choose MorphicUlManager>>#chooseDirectory:from:
> the method definition is:
> chooseDirectory: label from: dir
>         "Answer the user choice of a directory."
>
>         | modalMorph realLabel |
>         realLabel := label ifNil: ['Choose Directory' translated].
>         (ProvideAnswerNotification signal: realLabel) ifNotNil: [:answer |
>                 ^answer ].
>         modalMorph := self modalMorph.
>         ^modalMorph theme
>                 chooseDirectoryIn: modalMorph
>                 title: realLabel
>                 path: (dir ifNotNil: [dir fullName])
>
> The problem is that I cannot find a chooseDirectoryIn:title:path: method.
>
> I wrote this all out hoping someone can tell me where I chose the wrong
> rabbit hole and can point me to instructions on how to choose the correct
> rabbit hole. ;-) (Also, if there is a short answer i.e. use this
> object>>method, I'd appreciate that as well.)
>
> Thanks,
>
> Mike
>
>
>
>
>
>
>
>
>
> --
> View this message in context: http://forum.world.st/beginner-question-how-to-get-a-fully-qualified-filename-from-a-dialog-tp4826037.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>



--
Cheers
Cyril Ferlicot

Reply | Threaded
Open this post in threaded view
|

Re: beginner question - how to get a fully qualified filename from a dialog

amaloney
Thank you for that Cyril; it's just what I need.

Cheers!