FileChooser och FileDialog
FileChooser är ett gränssnitt som kan implementeras av komponenter som visar en lista med filer. gtkmm tillhandahåller tre inbyggda implementationer för att välja senaste filer eller andra filer: FileChooserWidget, FileChooserDialog och FileChooserNative.
FileChooserWidget is a simple widget for displaying a list of recently used files or other files. FileChooserWidget is the basic building block for FileChooserDialog, but you can embed it into your user interface if you want to.
FileChooser och klasserna som implementerar den är föråldrade sedan gtkmm 4.10. De har ersatts av FileDialog, vilken finns tillgänglig sedan gtkmm 4.10.
Enkelt FileDialog-exempel
Shown below is a simple example of how to use the FileDialog class in a program. This simple program has a menubar with a menu item. When you select this menu item, a dialog pops up showing a list of files. If you select in the sidebar, the list of recently used files is shown.
If this is the first time you're using a program that uses the Recent Files framework, the dialog may be empty at first. Otherwise it should show the list of recently used documents registered by other applications.
After selecting the
menu item and the sidebar item, you should see something similar to the following window.
Konstruktorn för ExampleWindow skapar menyn och verktygsfältet med Builder (se Menyer och verktygsfält for mer information). Den lägger sedan till menyn och verktygsfältet till fönstret.
Filtrera filer
For any of the FileChooser classes, if you don't wish to display all of the items in the list of files, you can filter the list to show only those that you want. You can filter the list with the help of the FileFilter class. This class allows you to filter files by their name (add_pattern()), or their mime type (add_mime_type()).
After you've created and set up the filter to match only the items you want, you can apply a filter to a chooser widget with the FileChooser::add_filter() function.