Synopsis
#include <gtk/gtk.h>
GtkFileSelection;
GtkWidget* gtk_file_selection_new (const gchar *title);
void gtk_file_selection_set_filename (GtkFileSelection *filesel,
const gchar *filename);
const gchar* gtk_file_selection_get_filename (GtkFileSelection *filesel);
void gtk_file_selection_complete (GtkFileSelection *filesel,
const gchar *pattern);
void gtk_file_selection_show_fileop_buttons
(GtkFileSelection *filesel);
void gtk_file_selection_hide_fileop_buttons
(GtkFileSelection *filesel);
gchar** gtk_file_selection_get_selections (GtkFileSelection *filesel);
void gtk_file_selection_set_select_multiple
(GtkFileSelection *filesel,
gboolean select_multiple);
gboolean gtk_file_selection_get_select_multiple
(GtkFileSelection *filesel);
Object Hierarchy
GObject
+----GInitiallyUnowned
+----GtkObject
+----GtkWidget
+----GtkContainer
+----GtkBin
+----GtkWindow
+----GtkDialog
+----GtkFileSelection
Properties"filename" gchar* : Read / Write "select-multiple" gboolean : Read / Write "show-fileops" gboolean : Read / Write DescriptionGtkFileSelection has been superseded by the newer GtkFileChooser family of widgets. GtkFileSelection should be used to retrieve file or directory names from the user. It will create a new dialog window containing a directory list, and a file list corresponding to the current working directory. The filesystem can be navigated using the directory list or the drop-down history menu. Alternatively, the TAB key can be used to navigate using filename completion - common in text based editors such as emacs and jed.
File selection dialogs are created with a call to
The default filename can be set using
Use
Simple file operations; create directory, delete file, and rename file, are available from buttons at the top of the dialog. These can be hidden using
Example 56. Getting a filename from the user.
/* The file selection widget and the string to store the chosen filename */
void store_filename (GtkWidget *widget, gpointer user_data) {
GtkWidget *file_selector = GTK_WIDGET (user_data);
const gchar *selected_filename;
selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector));
g_print ("Selected filename: %s\n", selected_filename);
}
void create_file_selection (void) {
GtkWidget *file_selector;
/* Create the selector */
file_selector = gtk_file_selection_new ("Please select a file for editing.");
g_signal_connect (GTK_FILE_SELECTION (file_selector)->ok_button,
"clicked",
G_CALLBACK (store_filename),
file_selector);
/* Ensure that the dialog box is destroyed when the user clicks a button. */
g_signal_connect_swapped (GTK_FILE_SELECTION (file_selector)->ok_button,
"clicked",
G_CALLBACK (gtk_widget_destroy),
file_selector);
g_signal_connect_swapped (GTK_FILE_SELECTION (file_selector)->cancel_button,
"clicked",
G_CALLBACK (gtk_widget_destroy),
file_selector);
/* Display that dialog */
gtk_widget_show (file_selector);
}
DetailsGtkFileSelectiontypedef struct {
GtkWidget *dir_list;
GtkWidget *file_list;
GtkWidget *selection_entry;
GtkWidget *selection_text;
GtkWidget *main_vbox;
GtkWidget *ok_button;
GtkWidget *cancel_button;
GtkWidget *help_button;
GtkWidget *history_pulldown;
GtkWidget *history_menu;
GList *history_list;
GtkWidget *fileop_dialog;
GtkWidget *fileop_entry;
gchar *fileop_file;
gpointer cmpl_state;
GtkWidget *fileop_c_dir;
GtkWidget *fileop_del_file;
GtkWidget *fileop_ren_file;
GtkWidget *button_area;
GtkWidget *action_area;
} GtkFileSelection;
Warning
The GtkFileSelection struct contains the following GtkWidget fields:
gtk_file_selection_new ()GtkWidget* gtk_file_selection_new (const gchar *title); Warning
Creates a new file selection dialog box. By default it will contain a GtkTreeView of the application's current working directory, and a file listing. Operation buttons that allow the user to create a directory, delete files and rename files, are also present.
gtk_file_selection_set_filename ()void gtk_file_selection_set_filename (GtkFileSelection *filesel, const gchar *filename); Warning
Sets a default path for the file requestor. If
This has the consequence that in order to open the requestor with a
working directory and an empty filename,
The encoding of
gtk_file_selection_get_filename ()const gchar* gtk_file_selection_get_filename (GtkFileSelection *filesel); Warning
This function returns the selected filename in the GLib file name
encoding. To convert to UTF-8, call If no file is selected then the selected directory path is returned.
gtk_file_selection_complete ()void gtk_file_selection_complete (GtkFileSelection *filesel, const gchar *pattern); Warning
Will attempt to match
gtk_file_selection_show_fileop_buttons ()void gtk_file_selection_show_fileop_buttons
(GtkFileSelection *filesel);
Warning
Shows the file operation buttons, if they have previously been hidden. The rest of the widgets in the dialog will be resized accordingly.
gtk_file_selection_hide_fileop_buttons ()void gtk_file_selection_hide_fileop_buttons
(GtkFileSelection *filesel);
Warning
Hides the file operation buttons that normally appear at the top of the dialog. Useful if you wish to create a custom file selector, based on GtkFileSelection.
gtk_file_selection_get_selections ()gchar** gtk_file_selection_get_selections (GtkFileSelection *filesel); Warning
Retrieves the list of file selections the user has made in the dialog box. This function is intended for use when the user can select multiple files in the file list.
The filenames are in the GLib file name encoding. To convert to
UTF-8, call
gtk_file_selection_set_select_multiple ()void gtk_file_selection_set_select_multiple
(GtkFileSelection *filesel,
gboolean select_multiple);
Warning
Sets whether the user is allowed to select multiple files in the file list.
Use
gtk_file_selection_get_select_multiple ()gboolean gtk_file_selection_get_select_multiple
(GtkFileSelection *filesel);
Warning
Determines whether or not the user is allowed to select multiple files in
the file list. See
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||