X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=gtk%2Fgtkfilechooserdialog.c;h=6ed41b68f31928d982878e43b9cc3438f878890d;hb=feb64f40b0f50735104da0a7fdafbe480763c180;hp=bcc8c3bc6953688e35828c8fcf5f59050c6114f4;hpb=b140884fec56d0ac5f15fe3937879a7a1dd6f0c1;p=~andy%2Fgtk
diff --git a/gtk/gtkfilechooserdialog.c b/gtk/gtkfilechooserdialog.c
index bcc8c3bc6..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"
@@ -27,7 +25,6 @@
#include "gtkfilechooserwidget.h"
#include "gtkfilechooserutils.h"
#include "gtkfilechooserembed.h"
-#include "gtkfilechoosersettings.h"
#include "gtkfilesystem.h"
#include "gtksizerequest.h"
#include "gtktypebuiltins.h"
@@ -35,6 +32,167 @@
#include
+
+/**
+ * SECTION:gtkfilechooserdialog
+ * @Short_description: A file chooser dialog, suitable for "File/Open" or "File/Save" commands
+ * @Title: GtkFileChooserDialog
+ * @See_also: #GtkFileChooser, #GtkDialog
+ *
+ * #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 #GtkFileChooser interface, so you can use all of the
+ * #GtkFileChooser functions on the file chooser dialog as well as
+ * those for #GtkDialog.
+ *
+ * Note that #GtkFileChooserDialog does not have any methods of its
+ * own. Instead, you should use the functions that work on a
+ * #GtkFileChooser.
+ *
+ *
+ * Typical usage
+ * In the simplest of cases, you can the following code to use
+ * #GtkFileChooserDialog to select a file for opening:
+ *
+ *
+ * GtkWidget *dialog;
+ *
+ * dialog = gtk_file_chooser_dialog_new ("Open File",
+ * parent_window,
+ * GTK_FILE_CHOOSER_ACTION_OPEN,
+ * GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ * GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ * NULL);
+ *
+ * if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ * {
+ * char *filename;
+ *
+ * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ * open_file (filename);
+ * g_free (filename);
+ * }
+ *
+ * gtk_widget_destroy (dialog);
+ *
+ *
+ * To use a dialog for saving, you can use this:
+ *
+ *
+ * GtkWidget *dialog;
+ *
+ * dialog = gtk_file_chooser_dialog_new ("Save File",
+ * parent_window,
+ * GTK_FILE_CHOOSER_ACTION_SAVE,
+ * GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ * GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ * NULL);
+ * gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+ *
+ * if (user_edited_a_new_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);
+ *
+ * if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
+ * {
+ * char *filename;
+ *
+ * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+ * save_to_file (filename);
+ * g_free (filename);
+ * }
+ *
+ * gtk_widget_destroy (dialog);
+ *
+ *
+ *
+ *
+ * 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
+ * go in its action area have response codes such as
+ * #GTK_RESPONSE_ACCEPT and #GTK_RESPONSE_CANCEL. For example, you
+ * could call gtk_file_chooser_dialog_new() as follows:
+ *
+ *
+ * GtkWidget *dialog;
+ *
+ * dialog = gtk_file_chooser_dialog_new ("Open File",
+ * parent_window,
+ * GTK_FILE_CHOOSER_ACTION_OPEN,
+ * GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ * GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ * NULL);
+ *
+ *
+ * This will create buttons for "Cancel" and "Open" that use stock
+ * response identifiers from #GtkResponseType. For most dialog
+ * boxes you can use your own custom response codes rather than the
+ * ones in #GtkResponseType, but #GtkFileChooserDialog assumes that
+ * its "accept"-type action, e.g. an "Open" or "Save" button,
+ * will have one of the following response
+ * codes:
+ *
+ *
+ * #GTK_RESPONSE_ACCEPT
+ * #GTK_RESPONSE_OK
+ * #GTK_RESPONSE_YES
+ * #GTK_RESPONSE_APPLY
+ *
+ *
+ * This is because #GtkFileChooserDialog must intercept responses
+ * and switch to folders if appropriate, rather than letting the
+ * dialog terminate — the implementation uses these known
+ * response codes to know which responses can be blocked if
+ * appropriate.
+ *
+ *
+ * To summarize, make sure you use a
+ * stock response code
+ * when you use #GtkFileChooserDialog to ensure proper operation.
+ *
+ *
+ *
+ */
+
+
#define GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE(o) (GTK_FILE_CHOOSER_DIALOG (o)->priv)
static void gtk_file_chooser_dialog_finalize (GObject *object);
@@ -75,6 +233,8 @@ gtk_file_chooser_dialog_class_init (GtkFileChooserDialogClass *class)
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);
g_type_class_add_private (class, sizeof (GtkFileChooserDialogPrivate));
@@ -99,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
@@ -199,10 +361,10 @@ file_chooser_widget_default_size_changed (GtkWidget *widget,
{
/* Force a size request of everything before we start. This will make sure
* that widget->requisition is meaningful. */
- gtk_size_request_get_size (GTK_SIZE_REQUEST (dialog),
- &req, NULL);
- gtk_size_request_get_size (GTK_SIZE_REQUEST (widget),
- &widget_req, NULL);
+ gtk_widget_get_preferred_size (GTK_WIDGET (dialog),
+ &req, NULL);
+ gtk_widget_get_preferred_size (widget,
+ &widget_req, NULL);
}
_gtk_file_chooser_embed_get_default_size (GTK_FILE_CHOOSER_EMBED (priv->widget),
@@ -372,30 +534,38 @@ gtk_file_chooser_dialog_map (GtkWidget *widget)
ensure_default_response (dialog);
- if (!gtk_widget_get_mapped (priv->widget))
- gtk_widget_map (priv->widget);
-
_gtk_file_chooser_embed_initial_focus (GTK_FILE_CHOOSER_EMBED (priv->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);
- GtkFileChooserDialogPrivate *priv = GTK_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
- GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->unmap (widget);
+ save_dialog_geometry (dialog);
- /* See bug #145470. We unmap the GtkFileChooserWidget so that if the dialog
- * is remapped, the widget will be remapped as well. Implementations should
- * refresh their contents when this happens, as some applications keep a
- * single file chooser alive and map/unmap it as needed, rather than creating
- * a new file chooser every time they need one.
- */
- gtk_widget_unmap (priv->widget);
+ GTK_WIDGET_CLASS (gtk_file_chooser_dialog_parent_class)->unmap (widget);
}
/* GtkDialog::response handler */
@@ -453,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().