From a92ff3fa5f76dd279bd2cd90ece0184edf19a6ca Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Mon, 3 Nov 2003 00:50:33 +0000 Subject: [PATCH] Do not set a border width for the toplevel container. (toolbar_create): 2003-11-02 Federico Mena Quintero * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_init): Do not set a border width for the toplevel container. (toolbar_create): New function; create a simple toolbar for the file chooser. (gtk_file_chooser_default_constructor): Use a spacing of 12 for the table, as per the HIG. (gtk_file_chooser_default_init): Likewise, for the default implementation's vbox. * gtk/gtkfilesystem.c (gtk_file_system_get_parent): Added docs to note that NULL is a valid return value for the parent path. --- ChangeLog | 14 ++++++ ChangeLog.pre-2-10 | 14 ++++++ ChangeLog.pre-2-4 | 14 ++++++ ChangeLog.pre-2-6 | 14 ++++++ ChangeLog.pre-2-8 | 14 ++++++ gtk/gtkfilechooserdefault.c | 86 ++++++++++++++++++++++++++++++++++++- gtk/gtkfilesystem.c | 14 ++++++ 7 files changed, 168 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8a39f9fdb7..7a98b02e83 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2003-11-02 Federico Mena Quintero + + * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_init): Do + not set a border width for the toplevel container. + (toolbar_create): New function; create a simple toolbar for the + file chooser. + (gtk_file_chooser_default_constructor): Use a spacing of 12 for + the table, as per the HIG. + (gtk_file_chooser_default_init): Likewise, for the default + implementation's vbox. + + * gtk/gtkfilesystem.c (gtk_file_system_get_parent): Added docs to + note that NULL is a valid return value for the parent path. + Sat Nov 1 14:59:27 2003 Owen Taylor * gtk/gtkfilechooserdefault.c (shortcuts_row_activated): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 8a39f9fdb7..7a98b02e83 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,17 @@ +2003-11-02 Federico Mena Quintero + + * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_init): Do + not set a border width for the toplevel container. + (toolbar_create): New function; create a simple toolbar for the + file chooser. + (gtk_file_chooser_default_constructor): Use a spacing of 12 for + the table, as per the HIG. + (gtk_file_chooser_default_init): Likewise, for the default + implementation's vbox. + + * gtk/gtkfilesystem.c (gtk_file_system_get_parent): Added docs to + note that NULL is a valid return value for the parent path. + Sat Nov 1 14:59:27 2003 Owen Taylor * gtk/gtkfilechooserdefault.c (shortcuts_row_activated): diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 8a39f9fdb7..7a98b02e83 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,17 @@ +2003-11-02 Federico Mena Quintero + + * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_init): Do + not set a border width for the toplevel container. + (toolbar_create): New function; create a simple toolbar for the + file chooser. + (gtk_file_chooser_default_constructor): Use a spacing of 12 for + the table, as per the HIG. + (gtk_file_chooser_default_init): Likewise, for the default + implementation's vbox. + + * gtk/gtkfilesystem.c (gtk_file_system_get_parent): Added docs to + note that NULL is a valid return value for the parent path. + Sat Nov 1 14:59:27 2003 Owen Taylor * gtk/gtkfilechooserdefault.c (shortcuts_row_activated): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 8a39f9fdb7..7a98b02e83 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,17 @@ +2003-11-02 Federico Mena Quintero + + * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_init): Do + not set a border width for the toplevel container. + (toolbar_create): New function; create a simple toolbar for the + file chooser. + (gtk_file_chooser_default_constructor): Use a spacing of 12 for + the table, as per the HIG. + (gtk_file_chooser_default_init): Likewise, for the default + implementation's vbox. + + * gtk/gtkfilesystem.c (gtk_file_system_get_parent): Added docs to + note that NULL is a valid return value for the parent path. + Sat Nov 1 14:59:27 2003 Owen Taylor * gtk/gtkfilechooserdefault.c (shortcuts_row_activated): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 8a39f9fdb7..7a98b02e83 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,17 @@ +2003-11-02 Federico Mena Quintero + + * gtk/gtkfilechooserdefault.c (gtk_file_chooser_default_init): Do + not set a border width for the toplevel container. + (toolbar_create): New function; create a simple toolbar for the + file chooser. + (gtk_file_chooser_default_constructor): Use a spacing of 12 for + the table, as per the HIG. + (gtk_file_chooser_default_init): Likewise, for the default + implementation's vbox. + + * gtk/gtkfilesystem.c (gtk_file_system_get_parent): Added docs to + note that NULL is a valid return value for the parent path. + Sat Nov 1 14:59:27 2003 Owen Taylor * gtk/gtkfilechooserdefault.c (shortcuts_row_activated): diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 846f11f277..2c0aac01ef 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -37,10 +37,13 @@ #include "gtkimage.h" #include "gtklabel.h" #include "gtkmenuitem.h" +#include "gtkmessagedialog.h" #include "gtkprivate.h" #include "gtkscrolledwindow.h" #include "gtkstock.h" #include "gtktable.h" +#include "gtktoolbar.h" +#include "gtktoolbutton.h" #include "gtktreeview.h" #include "gtktreemodelsort.h" #include "gtktreeselection.h" @@ -91,6 +94,7 @@ struct _GtkFileChooserDefault GtkWidget *preview_frame; + GtkWidget *toolbar; GtkWidget *filter_alignment; GtkWidget *filter_combo; GtkWidget *tree_scrollwin; @@ -322,7 +326,7 @@ gtk_file_chooser_default_init (GtkFileChooserDefault *impl) impl->select_multiple = FALSE; impl->show_hidden = FALSE; - gtk_container_set_border_width (GTK_CONTAINER (impl), 5); + gtk_box_set_spacing (GTK_BOX (impl), 12); } static void @@ -337,6 +341,27 @@ gtk_file_chooser_default_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } +/* Shows a simple error dialog */ +static void +error_dialog (GtkFileChooserDefault *impl, + const char *msg, + GError *error) +{ + GtkWidget *toplevel; + GtkWidget *dialog; + + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (impl)); + + dialog = gtk_message_dialog_new (toplevel ? GTK_WINDOW (toplevel) : NULL, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + msg, + error->message); + gtk_dialog_run (GTK_DIALOG (dialog)); + gtk_widget_destroy (dialog); +} + static void update_preview_widget_visibility (GtkFileChooserDefault *impl) { @@ -618,6 +643,56 @@ create_shortcuts_model (GtkFileChooserDefault *impl) gtk_tree_view_set_model (GTK_TREE_VIEW (impl->shortcuts_tree), GTK_TREE_MODEL (impl->shortcuts_model)); } +/* Callback used when the "Up" toolbar button is clicked */ +static void +toolbar_up_cb (GtkToolButton *button, + GtkFileChooserDefault *impl) +{ + GtkFilePath *parent_path; + GError *error; + + error = NULL; + if (gtk_file_system_get_parent (impl->file_system, impl->current_folder, &parent_path, &error)) + { + if (parent_path) /* If we were on a root, parent_path will be NULL */ + { + _gtk_file_chooser_set_current_folder_path (GTK_FILE_CHOOSER (impl), parent_path); + gtk_file_path_free (parent_path); + } + } + else + { + error_dialog (impl, + "Could not go to the parent folder:\n%s", + error); + g_error_free (error); + } +} + +/* Appends an item to the toolbar */ +static void +toolbar_add_item (GtkFileChooserDefault *impl, + const char *stock_id, + GCallback callback) +{ + GtkToolItem *item; + + item = gtk_tool_button_new_from_stock (stock_id); + g_signal_connect (item, "clicked", callback, impl); + gtk_toolbar_insert (GTK_TOOLBAR (impl->toolbar), item, -1); + gtk_widget_show (GTK_WIDGET (item)); +} + +/* Creates the toolbar widget */ +static GtkWidget * +toolbar_create (GtkFileChooserDefault *impl) +{ + impl->toolbar = gtk_toolbar_new (); + toolbar_add_item (impl, GTK_STOCK_GO_UP, G_CALLBACK (toolbar_up_cb)); + + return impl->toolbar; +} + /* Creates the widgets for the filter combo box */ static GtkWidget * create_filter (GtkFileChooserDefault *impl) @@ -816,6 +891,7 @@ create_shortcuts_tree (GtkFileChooserDefault *impl) gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (impl->shortcuts_tree), FALSE); selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (impl->shortcuts_tree)); + gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); gtk_tree_selection_set_select_function (selection, shortcuts_select_func, impl, NULL); @@ -1005,10 +1081,16 @@ gtk_file_chooser_default_constructor (GType type, gtk_widget_push_composite_child (); + /* Toolbar */ + widget = toolbar_create (impl); + gtk_box_pack_start (GTK_BOX (impl), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + /* Basic table */ table = gtk_table_new (3, 2, FALSE); - gtk_table_set_col_spacings (GTK_TABLE (table), 6); + gtk_table_set_col_spacings (GTK_TABLE (table), 12); + gtk_table_set_row_spacings (GTK_TABLE (table), 12); gtk_box_pack_start (GTK_BOX (impl), table, TRUE, TRUE, 0); gtk_widget_show (table); diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c index ea7c4fee74..200a3185c2 100644 --- a/gtk/gtkfilesystem.c +++ b/gtk/gtkfilesystem.c @@ -508,6 +508,20 @@ gtk_file_system_create_folder(GtkFileSystem *file_system, return GTK_FILE_SYSTEM_GET_IFACE (file_system)->create_folder (file_system, path, error); } +/** + * gtk_file_system_get_parent: + * @file_system: a #GtkFileSystem + * @path: base path name + * @parent: location to store parent path name + * @error: location to store error, or %NULL + * + * Gets the name of the parent folder of a file. + * + * Return value: TRUE if the operation was successful; note that in this case @parent + * can be returned as %NULL if the base @path has no parent folder (i.e. if it is + * already a file system root). If the operation fails, this function returns FALSE + * and sets the @error value if it is specified. + **/ gboolean gtk_file_system_get_parent (GtkFileSystem *file_system, const GtkFilePath *path,