From bb951fe783cc038714fcb07f8f76b80cdd1b811e Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Sun, 8 Dec 2013 15:38:43 +0100 Subject: [PATCH] print dialog: Use headerbar Make the print dialog use a headerbar when desired. https://bugzilla.gnome.org/show_bug.cgi?id=720059 --- gtk/gtkprintunixdialog.c | 47 ++++++++++++++++++++++---- gtk/gtkprintunixdialog.ui | 67 ++----------------------------------- gtk/gtkprintunixdialog.ui.h | 3 -- 3 files changed, 44 insertions(+), 73 deletions(-) diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c index 1bc7617268..acbfc3c1c0 100644 --- a/gtk/gtkprintunixdialog.c +++ b/gtk/gtkprintunixdialog.c @@ -55,6 +55,7 @@ #include "gtkintl.h" #include "gtkprivate.h" #include "gtktypebuiltins.h" +#include "gtkdialogprivate.h" /** @@ -132,6 +133,9 @@ #define RULER_RADIUS 2 +static GObject *gtk_print_unix_dialog_constructor (GType type, + guint n_params, + GObjectConstructParam *params); static void gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog); static void gtk_print_unix_dialog_finalize (GObject *object); static void gtk_print_unix_dialog_set_property (GObject *object, @@ -307,7 +311,6 @@ struct GtkPrintUnixDialogPrivate GtkWidget *print_at_radio; GtkWidget *print_at_entry; GtkWidget *print_hold_radio; - GtkWidget *preview_button; GtkWidget *paper_size_combo; GtkWidget *paper_size_combo_label; GtkCellRenderer *paper_size_renderer; @@ -401,6 +404,7 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class) object_class = (GObjectClass *) class; widget_class = (GtkWidgetClass *) class; + object_class->constructor = gtk_print_unix_dialog_constructor; object_class->finalize = gtk_print_unix_dialog_finalize; object_class->set_property = gtk_print_unix_dialog_set_property; object_class->get_property = gtk_print_unix_dialog_get_property; @@ -514,7 +518,6 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class) gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, print_at_radio); gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, print_at_entry); gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, print_hold_radio); - gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, preview_button); gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, paper_size_combo); gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, paper_size_combo_label); gtk_widget_class_bind_template_child_private (widget_class, GtkPrintUnixDialog, paper_size_renderer); @@ -743,6 +746,13 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog) priv->has_selection = FALSE; gtk_widget_init_template (GTK_WIDGET (dialog)); + gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog)); + gtk_dialog_add_buttons (GTK_DIALOG (dialog), + _("Pre_view"), GTK_RESPONSE_APPLY, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Print"), GTK_RESPONSE_OK, + NULL); + gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); /* Treeview auxilary functions need to be setup here */ gtk_tree_model_filter_set_visible_func (priv->printer_list_filter, @@ -794,6 +804,32 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog) _gtk_print_load_custom_papers (priv->custom_paper_list); } +static GObject * +gtk_print_unix_dialog_constructor (GType type, + guint n_params, + GObjectConstructParam *params) +{ + GObject *object; + gboolean use_header; + + object = G_OBJECT_CLASS (gtk_print_unix_dialog_parent_class)->constructor (type, n_params, params); + + g_object_get (object, "use-header-bar", &use_header, NULL); + if (use_header) + { + /* Reorder the preview button */ + GtkWidget *button, *parent; + button = gtk_dialog_get_widget_for_response (GTK_DIALOG (object), GTK_RESPONSE_APPLY); + g_object_ref (button); + parent = gtk_widget_get_parent (button); + gtk_container_remove (GTK_CONTAINER (parent), button); + gtk_header_bar_pack_end (GTK_HEADER_BAR (parent), button); + g_object_unref (button); + } + + return object; +} + static void gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog) { @@ -1612,6 +1648,7 @@ update_dialog_from_capabilities (GtkPrintUnixDialog *dialog) GtkPrintUnixDialogPrivate *priv = dialog->priv; gboolean can_collate; const gchar *copies; + GtkWidget *button; copies = gtk_entry_get_text (GTK_ENTRY (priv->copies_spin)); can_collate = (*copies != '\0' && atoi (copies) > 1); @@ -1632,10 +1669,8 @@ update_dialog_from_capabilities (GtkPrintUnixDialog *dialog) gtk_widget_set_sensitive (GTK_WIDGET (priv->pages_per_sheet), caps & GTK_PRINT_CAPABILITY_NUMBER_UP); - if (caps & GTK_PRINT_CAPABILITY_PREVIEW) - gtk_widget_show (priv->preview_button); - else - gtk_widget_hide (priv->preview_button); + button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_APPLY); + gtk_widget_set_visible (button, (caps & GTK_PRINT_CAPABILITY_PREVIEW) != 0); update_collate_icon (NULL, dialog); diff --git a/gtk/gtkprintunixdialog.ui b/gtk/gtkprintunixdialog.ui index 0a0530ab96..3d2aec7d39 100644 --- a/gtk/gtkprintunixdialog.ui +++ b/gtk/gtkprintunixdialog.ui @@ -58,68 +58,12 @@ False vertical 2 - - - False - end - - - Pre_view - True - True - True - True - - - False - True - 0 - - - - - _Cancel - True - True - True - True - - - False - True - 1 - - - - - _Print - True - False - True - True - True - True - True - - - False - True - 2 - - - - - False - True - end - 0 - - + 0 True False - 5 + 0 vertical 6 @@ -1719,15 +1663,10 @@ True True - 1 + 0 - - preview_button - cancel_button - print_button - diff --git a/gtk/gtkprintunixdialog.ui.h b/gtk/gtkprintunixdialog.ui.h index a70fba7d4e..7630dbe3d4 100644 --- a/gtk/gtkprintunixdialog.ui.h +++ b/gtk/gtkprintunixdialog.ui.h @@ -1,6 +1,3 @@ -N_("Pre_view"); -N_("_Cancel"); -N_("_Print"); N_("Printer"); /* this is the header for the location column in the print dialog */