How to give the user a file name?

Search call FileDialog

I would like to ask the user to specify a file name in Pharo 4.0

Through the registrar, I found a class

FileDialogWindow 

using method

  answerFileName 

Looking for senders #answerFileName I get a class

  UITheme 

where is it called in the method

  chooseFileNameIn: aThemedMorph title: title extensions: exts path: path preview: preview 

And from there I come to class

  TEasilyThemed 

using method

  chooseFileName: title extensions: exts path: path preview: preview 

From there, finally, I will move on to the class

  WidgetExamples class >> exampleDialogs 

And then I have a call

 WidgetExamples exampleBuilder chooseFileName: 'Pick a file name' extensions: nil path: nil preview: nil. 

However, a print it this expression does not return the file name.

Question

What is the usual way to invoke a file dialog box?

Additional question after answers

Two classes providing this service are indicated.

  • UIManager
  • Uitheme

Comment by UIManager

UIManager is the dispatcher for various user interface requests.

Comment by UITheme

General superclass for user interface themes. Provides methods for creating new morphs in a standard way, various "services", such as a dialog with files, message dialogs, etc., as well as methods for configuring aspects of the appearance of various morphs. Although conceptually abstract, no code is "missing." Therefore, subclasses must redefine the aspects they want to change.

What is the difference between these two approaches?

+5
source share
2 answers

The easiest way is to use:

 UIManager default chooseFileMatching: nil 

You can specify patterns as:

 UIManager default chooseFileMatching: #('*.jpg' '*.png') 

You can also specify a label for the dialog:

 UIManager default chooseFileMatching: #('*.jpg' '*.png') label: 'Please select and image to process' 
+6
source

What I use in one of my demo applications,

 MindmapNode class>>open |fileName| fileName := UITheme current chooseFileIn: World title: 'Choose file' extensions: nil path: nil preview:nil. fileName ifNotNil: [ (FLMaterializer materializationFromFileNamed: fileName) root openInWorld attachAllSubnodes detachAllSubnodes ] MindmapNode>>saveMap |fileName| fileName := UITheme current fileSaveIn: World title: 'Choose file' extensions: nil path: nil. fileName ifNotNil: [ FLSerializer serialize: self toFileNamed: fileName]. 

UIManager takes care of being able to run headless from the command line. Then you want to be able to specify the file name either in the parameter or in the input file. In the default UIManager image situation, the default is MorphicUIManager, which delegates the current theme.

So using UIManager is likely to be better

+2
source

All Articles