X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkfilechooserdialog.c;h=6ed41b68f31928d982878e43b9cc3438f878890d;hb=feb64f40b0f50735104da0a7fdafbe480763c180;hp=ea19777c7be7b045d8a1e6557603bdf656f46373;hpb=fe65ec5b87569f8bd4ec5171b60bd7c9326163cc;p=~andy%2Fgtk diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c index ea19777c7..6ed41b68f 100644 --- a/gtk/gtkfilechooserdialog.c +++ b/gtk/gtkfilechooserdialog.c @@ -14,9 +14,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * License along with this library. If not, see . */ #include "config.h" @@ -44,7 +42,7 @@ * #GtkFileChooserDialog is a dialog box suitable for use with * "File/Open" or "File/Save as" commands. This widget works by * putting a #GtkFileChooserWidget inside a #GtkDialog. It exposes - * the #GtkFileChooserIface interface, so you can use all of the + * the #GtkFileChooser interface, so you can use all of the * #GtkFileChooser functions on the file chooser dialog as well as * those for #GtkDialog. * @@ -93,10 +91,7 @@ * gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE); * * if (user_edited_a_new_document) - * { - * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), default_folder_for_saving); - * gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document"); - * } + * gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document"); * else * gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document); * @@ -113,6 +108,42 @@ * * * + *
+ * Setting up a file chooser dialog + * There are various cases in which you may need to use a #GtkFileChooserDialog: + * To select a file for opening, as for a + * File/Open command. Use + * #GTK_FILE_CHOOSER_ACTION_OPEN. + * + * To save a file for the first time, as for a + * File/Save command. Use + * #GTK_FILE_CHOOSER_ACTION_SAVE, and suggest a name such as + * "Untitled" with gtk_file_chooser_set_current_name(). + * + * To save a file under a different name, as for a + * File/Save As command. Use + * #GTK_FILE_CHOOSER_ACTION_SAVE, and set the existing filename + * with gtk_file_chooser_set_filename(). + * + * To choose a folder instead of a file. Use + * #GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER. + * + * + * + * Old versions of the file chooser's documentation suggested + * using gtk_file_chooser_set_current_folder() in various + * situations, with the intention of letting the application + * suggest a reasonable default folder. This is no longer + * considered to be a good policy, as now the file chooser is + * able to make good suggestions on its own. In general, you + * should only cause the file chooser to show a specific folder + * when it is appropriate to use gtk_file_chooser_set_filename(), + * i.e. when you are doing a File/Save + * As command and you already + * have a file saved somewhere. + * + * + *
*
* Response Codes * #GtkFileChooserDialog inherits from #GtkDialog, so buttons that @@ -179,6 +210,7 @@ static void gtk_file_chooser_dialog_get_property (GObject *obj GParamSpec *pspec); static void gtk_file_chooser_dialog_map (GtkWidget *widget); +static void gtk_file_chooser_dialog_unmap (GtkWidget *widget); static void response_cb (GtkDialog *dialog, gint response_id); @@ -199,6 +231,9 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class) gobject_class->finalize = gtk_file_chooser_dialog_finalize; widget_class->map = gtk_file_chooser_dialog_map; + widget_class->unmap = gtk_file_chooser_dialog_unmap; + + gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_FILE_CHOOSER); _gtk_file_chooser_install_properties (gobject_class); @@ -224,6 +259,8 @@ gtk_file_chooser_dialog_init (GtkFileChooserDialog *dialog) gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */ gtk_container_set_border_width (GTK_CONTAINER (action_area), 5); + gtk_window_set_role (GTK_WINDOW (dialog), "GtkFileChooserDialog"); + /* We do a signal connection here rather than overriding the method in * class_init because GtkDialog::response is a RUN_LAST signal. We want *our* * handler to be run *first*, regardless of whether the user installs response @@ -502,6 +539,35 @@ gtk_file_chooser_dialog_map (GtkWidget *widget) GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->map (widget); } +static void +save_dialog_geometry (GtkFileChooserDialog *dialog) +{ + GtkWindow *window; + GSettings *settings; + int x, y, width, height; + + settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (dialog)); + + window = GTK_WINDOW (dialog); + + gtk_window_get_position (window, &x, &y); + gtk_window_get_size (window, &width, &height); + + g_settings_set (settings, SETTINGS_KEY_WINDOW_POSITION, "(ii)", x, y); + g_settings_set (settings, SETTINGS_KEY_WINDOW_SIZE, "(ii)", width, height); +} + +/* GtkWidget::unmap handler */ +static void +gtk_file_chooser_dialog_unmap (GtkWidget *widget) +{ + GtkFileChooserDialog *dialog = GTK_FILE_CHOOSER_DIALOG (widget); + + save_dialog_geometry (dialog); + + GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->unmap (widget); +} + /* GtkDialog::response handler */ static void response_cb (GtkDialog *dialog, @@ -557,7 +623,7 @@ gtk_file_chooser_dialog_new_valist (const gchar *title, * @parent: (allow-none): Transient parent of the dialog, or %NULL * @action: Open or save mode for the dialog * @first_button_text: (allow-none): stock ID or text to go in the first button, or %NULL - * @Varargs: response ID for the first button, then additional (button, id) pairs, ending with %NULL + * @...: response ID for the first button, then additional (button, id) pairs, ending with %NULL * * Creates a new #GtkFileChooserDialog. This function is analogous to * gtk_dialog_new_with_buttons().