beginner question - how to get a fully qualified filename from a dialog
Posted by amaloney on May 12, 2015; 4:00pm
URL: https://forum.world.st/beginner-question-how-to-get-a-fully-qualified-filename-from-a-dialog-tp4826037.html
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