A simple replacement for Pharo's native file/folder selection dialog.
- list of most common places (home, root, image directory, temp)
- custom bookmarks by dragging folders from file-pane to bookmark-pane
- toggle hidden files (right-click on file listing)
- preset file name
- filtering files by extensions or patterns and toggling between filters
- synchronous and asynchronous mode
(catalog soon)
Metacello new
baseline: 'FileDialog';
repository: 'github://peteruhnak/file-dialog/repository';
load.
If you feel brave, you can replace the native dialogs everywhere in the system be running
FDMorphicUIManager new beDefault
Of course you can switch back anytime you want.
MorphicUIManager new beDefault
If you chose using the extended UIManager, then you can use that
UIManager default chooseFileMatching: #('*.ston')
You can also use the classes directly — there are just minor differences in the behavior, such as DirectoryDialog
will not show files, etc.
FDSaveFileDialog
- saving a fileFDOpenFileDialog
- selecting a fileFDOpenDirectoryDialog
- selecting a directory
The user-facing API is in the public
protocol of FDFileDialog
defaultFolder: aPath
— where should the dialog open, the default is the imageDirectorydefaultName: aString
— prefill the file name inputextensionFilters: aCollection
— a collection oflabel -> extensions
filtersfileFilters: aCollection
— a collection oflabel -> pattern
filterswhenSelected: aBlock
— a one arg block executed when a file was selectedopenModal
— when you open the dialog as modal, you will get the selected value as a return instead of using the block
extensionFilters:
is just a convenience for fileFilters:
automatically adding labels & stuff, so the following is equivalent
extensionFilters: { 'STON files' -> #(ston json) }
fileFilters: { 'STON files (*.ston, *.json)' -> #('*.ston' '*.json') }
asynchronous — execute behavior on selection from a block
FDSaveFileDialog new
whenSelected: [ :file | file inspect ];
filteredExtensions: {
'All images' -> #(jpg png gif svg).
'All files' -> #()
};
defaultFolder: FileLocator imageDirectory asFileReference;
defaultName: 'hello.png';
open
synchronous — return the selected file as a value
file := FDOpenFileDialog new
openModal