From 3843185df1e71e14e4f2e5d34aca34724090b496 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sat, 30 Aug 2008 04:42:02 +0000 Subject: Preferences window awesomeness. svn path=/branches/kill-bonobo/; revision=36215 --- widgets/misc/e-preferences-window.c | 143 ++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 64 deletions(-) (limited to 'widgets/misc/e-preferences-window.c') diff --git a/widgets/misc/e-preferences-window.c b/widgets/misc/e-preferences-window.c index 988d065d76..c18d975c1d 100644 --- a/widgets/misc/e-preferences-window.c +++ b/widgets/misc/e-preferences-window.c @@ -20,6 +20,7 @@ #include "e-preferences-window.h" +#include #include #define SWITCH_PAGE_INTERVAL 250 @@ -79,7 +80,13 @@ preferences_window_load_pixbuf (const gchar *icon_name) } static void -preferences_window_selection_changed_cb (EPreferencesWindow *dialog) +preferences_window_help_clicked_cb (GtkWindow *window) +{ + e_display_help (window, "config-prefs"); +} + +static void +preferences_window_selection_changed_cb (EPreferencesWindow *window) { GtkIconView *icon_view; GtkNotebook *notebook; @@ -88,7 +95,7 @@ preferences_window_selection_changed_cb (EPreferencesWindow *dialog) GList *list; gint page; - icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); + icon_view = GTK_ICON_VIEW (window->priv->icon_view); list = gtk_icon_view_get_selected_items (icon_view); if (list == NULL) return; @@ -97,7 +104,7 @@ preferences_window_selection_changed_cb (EPreferencesWindow *dialog) gtk_tree_model_get_iter (model, &iter, list->data); gtk_tree_model_get (model, &iter, COLUMN_PAGE, &page, -1); - notebook = GTK_NOTEBOOK (dialog->priv->notebook); + notebook = GTK_NOTEBOOK (window->priv->notebook); gtk_notebook_set_current_page (notebook, page); g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL); @@ -143,35 +150,16 @@ preferences_window_finalize (GObject *object) } static void -preferences_window_map (GtkWidget *widget) +preferences_window_show (GtkWidget *widget) { - GtkDialog *dialog; + EPreferencesWindowPrivate *priv; - /* Chain up to parent's map() method. */ - GTK_WIDGET_CLASS (parent_class)->map (widget); + priv = E_PREFERENCES_WINDOW_GET_PRIVATE (widget); - /* Override those stubborn style properties. */ - dialog = GTK_DIALOG (widget); - gtk_box_set_spacing (GTK_BOX (dialog->vbox), 12); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - gtk_container_set_border_width (GTK_CONTAINER (dialog->vbox), 0); - gtk_container_set_border_width (GTK_CONTAINER (dialog->action_area), 0); -} + gtk_widget_grab_focus (priv->icon_view); -static void -preferences_window_response (GtkDialog *dialog, - gint response_id) -{ - switch (response_id) { - case GTK_RESPONSE_HELP: - e_display_help (GTK_WINDOW (dialog), "config-prefs"); - break; - - case GTK_RESPONSE_CLOSE: - default: - gtk_widget_destroy (GTK_WIDGET (dialog)); - break; - } + /* Chain up to parent's show() method. */ + GTK_WIDGET_CLASS (parent_class)->show (widget); } static void @@ -179,7 +167,6 @@ preferences_window_class_init (EPreferencesWindowClass *class) { GObjectClass *object_class; GtkWidgetClass *widget_class; - GtkDialogClass *dialog_class; parent_class = g_type_class_peek_parent (class); g_type_class_add_private (class, sizeof (EPreferencesWindowPrivate)); @@ -189,42 +176,53 @@ preferences_window_class_init (EPreferencesWindowClass *class) object_class->finalize = preferences_window_finalize; widget_class = GTK_WIDGET_CLASS (class); - widget_class->map = preferences_window_map; - - dialog_class = GTK_DIALOG_CLASS (class); - dialog_class->response = preferences_window_response; + widget_class->show = preferences_window_show; } static void -preferences_window_init (EPreferencesWindow *dialog) +preferences_window_init (EPreferencesWindow *window) { GtkListStore *store; GtkWidget *container; GtkWidget *hbox; + GtkWidget *vbox; GtkWidget *widget; GHashTable *index; + const gchar *title; index = g_hash_table_new_full ( g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) gtk_tree_row_reference_free); - dialog->priv = E_PREFERENCES_WINDOW_GET_PRIVATE (dialog); - dialog->priv->index = index; + window->priv = E_PREFERENCES_WINDOW_GET_PRIVATE (window); + window->priv->index = index; store = gtk_list_store_new ( 4, G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_INT, G_TYPE_INT); gtk_tree_sortable_set_sort_column_id ( GTK_TREE_SORTABLE (store), COLUMN_SORT, GTK_SORT_ASCENDING); - gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE); - gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); + title = _("Evolution Preferences"); + gtk_window_set_title (GTK_WINDOW (window), title); + gtk_window_set_resizable (GTK_WINDOW (window), TRUE); + gtk_container_set_border_width (GTK_CONTAINER (window), 12); + + g_signal_connect ( + window, "delete-event", + G_CALLBACK (gtk_widget_hide_on_delete), NULL); - container = GTK_DIALOG (dialog)->vbox; + widget = gtk_vbox_new (FALSE, 12); + gtk_container_add (GTK_CONTAINER (window), widget); + gtk_widget_show (widget); - hbox = gtk_hbox_new (FALSE, 12); - gtk_container_add (GTK_CONTAINER (container), hbox); - gtk_widget_show (hbox); + vbox = widget; + + widget = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (vbox), widget, TRUE, TRUE, 0); + gtk_widget_show (widget); + + hbox = widget; widget = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy ( @@ -243,9 +241,9 @@ preferences_window_init (EPreferencesWindow *dialog) gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (widget), COLUMN_PIXBUF); g_signal_connect_swapped ( widget, "selection-changed", - G_CALLBACK (preferences_window_selection_changed_cb), dialog); + G_CALLBACK (preferences_window_selection_changed_cb), window); gtk_container_add (GTK_CONTAINER (container), widget); - dialog->priv->icon_view = g_object_ref (widget); + window->priv->icon_view = g_object_ref (widget); gtk_widget_show (widget); g_object_unref (store); @@ -253,17 +251,34 @@ preferences_window_init (EPreferencesWindow *dialog) gtk_notebook_set_show_tabs (GTK_NOTEBOOK (widget), FALSE); gtk_notebook_set_show_border (GTK_NOTEBOOK (widget), FALSE); gtk_box_pack_start (GTK_BOX (hbox), widget, TRUE, TRUE, 0); - dialog->priv->notebook = g_object_ref (widget); + window->priv->notebook = g_object_ref (widget); gtk_widget_show (widget); - gtk_dialog_add_buttons ( - GTK_DIALOG (dialog), - GTK_STOCK_HELP, GTK_RESPONSE_HELP, - GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, - NULL); + widget = gtk_hbutton_box_new (); + gtk_button_box_set_layout ( + GTK_BUTTON_BOX (widget), GTK_BUTTONBOX_END); + gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); + gtk_widget_show (widget); + + container = widget; - gtk_dialog_set_default_response ( - GTK_DIALOG (dialog), GTK_RESPONSE_CLOSE); + widget = gtk_button_new_from_stock (GTK_STOCK_HELP); + g_signal_connect_swapped ( + widget, "clicked", + G_CALLBACK (preferences_window_help_clicked_cb), window); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + gtk_button_box_set_child_secondary ( + GTK_BUTTON_BOX (container), widget, TRUE); + gtk_widget_show (widget); + + widget = gtk_button_new_from_stock (GTK_STOCK_CLOSE); + g_signal_connect_swapped ( + widget, "clicked", + G_CALLBACK (gtk_widget_hide), window); + GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_DEFAULT); + gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0); + gtk_widget_grab_default (widget); + gtk_widget_show (widget); } GType @@ -286,7 +301,7 @@ e_preferences_window_get_type (void) }; type = g_type_register_static ( - GTK_TYPE_DIALOG, "EPreferencesWindow", &type_info, 0); + GTK_TYPE_WINDOW, "EPreferencesWindow", &type_info, 0); } return type; @@ -299,7 +314,7 @@ e_preferences_window_new (void) } void -e_preferences_window_add_page (EPreferencesWindow *dialog, +e_preferences_window_add_page (EPreferencesWindow *window, const gchar *page_name, const gchar *icon_name, const gchar *caption, @@ -316,14 +331,14 @@ e_preferences_window_add_page (EPreferencesWindow *dialog, GtkTreeIter iter; gint page; - g_return_if_fail (E_IS_MULTI_CONFIG_DIALOG (dialog)); + g_return_if_fail (E_IS_PREFERENCES_WINDOW (window)); g_return_if_fail (page_name != NULL); g_return_if_fail (icon_name != NULL); g_return_if_fail (caption != NULL); g_return_if_fail (GTK_IS_WIDGET (widget)); - icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); - notebook = GTK_NOTEBOOK (dialog->priv->notebook); + icon_view = GTK_ICON_VIEW (window->priv->icon_view); + notebook = GTK_NOTEBOOK (window->priv->notebook); page = gtk_notebook_get_n_pages (notebook); model = gtk_icon_view_get_model (icon_view); @@ -336,7 +351,7 @@ e_preferences_window_add_page (EPreferencesWindow *dialog, COLUMN_TEXT, caption, COLUMN_PIXBUF, pixbuf, COLUMN_PAGE, page, COLUMN_SORT, sort_order, -1); - index = dialog->priv->index; + index = window->priv->index; path = gtk_tree_model_get_path (model, &iter); reference = gtk_tree_row_reference_new (model, path); g_hash_table_insert (index, g_strdup (page_name), reference); @@ -345,24 +360,24 @@ e_preferences_window_add_page (EPreferencesWindow *dialog, gtk_notebook_append_page (notebook, widget, NULL); if (page == 0) - e_preferences_window_show_page (dialog, page_name); + e_preferences_window_show_page (window, page_name); - gtk_widget_queue_resize (GTK_WIDGET (dialog)); + gtk_widget_queue_resize (GTK_WIDGET (window)); } void -e_preferences_window_show_page (EPreferencesWindow *dialog, +e_preferences_window_show_page (EPreferencesWindow *window, const gchar *page_name) { GtkTreeRowReference *reference; GtkIconView *icon_view; GtkTreePath *path; - g_return_if_fail (E_IS_MULTI_CONFIG_DIALOG (dialog)); + g_return_if_fail (E_IS_PREFERENCES_WINDOW (window)); g_return_if_fail (page_name != NULL); - icon_view = GTK_ICON_VIEW (dialog->priv->icon_view); - reference = g_hash_table_lookup (dialog->priv->index, page_name); + icon_view = GTK_ICON_VIEW (window->priv->icon_view); + reference = g_hash_table_lookup (window->priv->index, page_name); g_return_if_fail (reference != NULL); path = gtk_tree_row_reference_get_path (reference); -- cgit