[gedit] Use the an headerbar with a close button if possible



commit 4068c557a09d9b3010d2c0956418793fffff30b6
Author: Paolo Borelli <pborelli gnome org>
Date:   Sun Jan 18 17:54:36 2015 +0100

    Use the an headerbar with a close button if possible
    
    This is a bit of a hack, since we do not want to move Find, Replace
    and Replace All buttons, so we cannot use the automatic stuff of
    GtkDialog. We check the settings ourselves and create the header
    bar manually, otherwise we show the classic Close button.

 gedit/gedit-replace-dialog.c               |   29 ++++++++++++++++++++++++++++
 gedit/resources/ui/gedit-replace-dialog.ui |    4 +-
 2 files changed, 31 insertions(+), 2 deletions(-)
---
diff --git a/gedit/gedit-replace-dialog.c b/gedit/gedit-replace-dialog.c
index efd437a..d547502 100644
--- a/gedit/gedit-replace-dialog.c
+++ b/gedit/gedit-replace-dialog.c
@@ -48,6 +48,7 @@ struct _GeditReplaceDialogPrivate
        GtkWidget *regex_checkbutton;
        GtkWidget *backwards_checkbutton;
        GtkWidget *wrap_around_checkbutton;
+       GtkWidget *close_button;
 
        GeditDocument *active_document;
 
@@ -539,6 +540,7 @@ gedit_replace_dialog_class_init (GeditReplaceDialogClass *klass)
        gtk_widget_class_bind_template_child_private (widget_class, GeditReplaceDialog, regex_checkbutton);
        gtk_widget_class_bind_template_child_private (widget_class, GeditReplaceDialog, 
backwards_checkbutton);
        gtk_widget_class_bind_template_child_private (widget_class, GeditReplaceDialog, 
wrap_around_checkbutton);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditReplaceDialog, close_button);
 }
 
 static void
@@ -746,14 +748,41 @@ GtkWidget *
 gedit_replace_dialog_new (GeditWindow *window)
 {
        GeditReplaceDialog *dialog;
+       gboolean use_header;
 
        g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
 
        dialog = g_object_new (GEDIT_TYPE_REPLACE_DIALOG,
                               "transient-for", window,
                               "destroy-with-parent", TRUE,
+                              "use-header-bar", FALSE,
                               NULL);
 
+       /* We force the Find/Replace buttons at the bottom, so we
+        * turn off the automatic header bar, but we check the
+        * setting and if an header bar showld be used we
+        * create it and use it for the close button.
+        */
+       g_object_get (gtk_settings_get_default (),
+                     "gtk-dialogs-use-header", &use_header,
+                     NULL);
+
+       if (use_header)
+       {
+               GtkWidget *header_bar;
+
+               header_bar = gtk_header_bar_new ();
+               gtk_header_bar_set_title (GTK_HEADER_BAR (header_bar), _("Find and Replace"));
+               gtk_header_bar_set_show_close_button (GTK_HEADER_BAR (header_bar), TRUE);
+               gtk_widget_show (header_bar);
+               gtk_window_set_titlebar (GTK_WINDOW (dialog), header_bar);
+       }
+       else
+       {
+               gtk_widget_set_no_show_all (dialog->priv->close_button, FALSE);
+               gtk_widget_show (dialog->priv->close_button);
+       }
+
        return GTK_WIDGET (dialog);
 }
 
diff --git a/gedit/resources/ui/gedit-replace-dialog.ui b/gedit/resources/ui/gedit-replace-dialog.ui
index c725e43..5895633 100644
--- a/gedit/resources/ui/gedit-replace-dialog.ui
+++ b/gedit/resources/ui/gedit-replace-dialog.ui
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
+  <requires lib="gtk+" version="3.0"/>
   <template class="GeditReplaceDialog" parent="GtkDialog">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
@@ -22,10 +22,10 @@
               <object class="GtkButton" id="close_button">
                 <property name="label" translatable="yes">_Close</property>
                 <property name="use_action_appearance">False</property>
-                <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="can_default">True</property>
                 <property name="receives_default">False</property>
+                <property name="no_show_all">True</property>
                 <property name="use_underline">True</property>
               </object>
               <packing>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]