[gedit] Use a template for the replace dialog



commit 62d067adc3949d947fed644bfe0513c43bb64b4c
Author: Paolo Borelli <pborelli gnome org>
Date:   Sat Apr 27 14:41:17 2013 +0200

    Use a template for the replace dialog

 gedit/gedit-replace-dialog.c  |  121 ++++++++++-------------------------------
 gedit/gedit-replace-dialog.ui |   23 +++++---
 po/POTFILES.in                |    1 +
 3 files changed, 44 insertions(+), 101 deletions(-)
---
diff --git a/gedit/gedit-replace-dialog.c b/gedit/gedit-replace-dialog.c
index 9b2d1a3..0dec808 100644
--- a/gedit/gedit-replace-dialog.c
+++ b/gedit/gedit-replace-dialog.c
@@ -20,14 +20,6 @@
  * Boston, MA 02111-1307, USA.
  */
 
-/*
- * Modified by the gedit Team, 2005. See the AUTHORS file for a
- * list of people on the gedit Team.
- * See the ChangeLog files for a list of changes.
- *
- * $Id$
- */
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -42,10 +34,6 @@
 #include "gedit-marshal.h"
 #include "gedit-dirs.h"
 
-#define GEDIT_REPLACE_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
-                                               GEDIT_TYPE_REPLACE_DIALOG,              \
-                                               GeditReplaceDialogPrivate))
-
 struct _GeditReplaceDialogPrivate
 {
        GtkWidget *grid;
@@ -131,11 +119,25 @@ static void
 gedit_replace_dialog_class_init (GeditReplaceDialogClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
-       GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass);
-       GtkDialogClass *gtkdialog_class = GTK_DIALOG_CLASS (klass);
-
-       gtkwidget_class->delete_event = gedit_replace_dialog_delete_event;
-       gtkdialog_class->response = gedit_replace_dialog_response;
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+       GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
+
+       widget_class->delete_event = gedit_replace_dialog_delete_event;
+       dialog_class->response = gedit_replace_dialog_response;
+
+       /* Bind class to template */
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    "/org/gnome/gedit/ui/gedit-replace-dialog.ui");
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, grid);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, search_label);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, replace_label);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, match_case_checkbutton);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, entire_word_checkbutton);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, backwards_checkbutton);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, wrap_around_checkbutton);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, find_button);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, replace_button);
+       gtk_widget_class_bind_child (widget_class, GeditReplaceDialogPrivate, replace_all_button);
 
        g_type_class_add_private (object_class, sizeof (GeditReplaceDialogPrivate));
 }
@@ -206,54 +208,16 @@ search_text_entry_changed (GtkEditable        *editable,
 static void
 gedit_replace_dialog_init (GeditReplaceDialog *dlg)
 {
-       GtkWidget *content;
-       GtkBuilder *builder;
-       gchar *root_objects[] = {
-               "replace_dialog_content",
-               NULL
-       };
-
-       dlg->priv = GEDIT_REPLACE_DIALOG_GET_PRIVATE (dlg);
-
-       gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
-       gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE);
-       gtk_window_set_title (GTK_WINDOW (dlg), _("Replace"));
-
-       gtk_dialog_add_buttons (GTK_DIALOG (dlg),
-                               GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
-                               NULL);
-
-       /* HIG defaults */
-       gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
-       gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
-                            2); /* 2 * 5 + 2 = 12 */
-       gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))),
-                                       5);
-       gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))),
-                            6);
-
-       builder = gtk_builder_new ();
-       gtk_builder_add_objects_from_resource (builder, "/org/gnome/gedit/ui/gedit-replace-dialog.ui",
-                                              root_objects, NULL);
-       content = GTK_WIDGET (gtk_builder_get_object (builder, "replace_dialog_content"));
-       g_object_ref (content);
-       dlg->priv->grid = GTK_WIDGET (gtk_builder_get_object (builder, "grid"));
-       dlg->priv->search_label = GTK_WIDGET (gtk_builder_get_object (builder, "search_label"));
-       dlg->priv->replace_label = GTK_WIDGET (gtk_builder_get_object (builder, "replace_with_label"));
-       dlg->priv->match_case_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, 
"match_case_checkbutton"));
-       dlg->priv->entire_word_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, 
"entire_word_checkbutton"));
-       dlg->priv->backwards_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, 
"search_backwards_checkbutton"));
-       dlg->priv->wrap_around_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, 
"wrap_around_checkbutton"));
-       g_object_unref (builder);
+       dlg->priv = G_TYPE_INSTANCE_GET_PRIVATE (dlg, GEDIT_TYPE_REPLACE_DIALOG, GeditReplaceDialogPrivate);
+
+       gtk_widget_init_template (GTK_WIDGET (dlg));
 
        dlg->priv->search_entry = gedit_history_entry_new ("search-for-entry", TRUE);
        gtk_widget_set_size_request (dlg->priv->search_entry, 300, -1);
-       gedit_history_entry_set_escape_func
-                       (GEDIT_HISTORY_ENTRY (dlg->priv->search_entry),
-                        (GeditHistoryEntryEscapeFunc) gedit_utils_escape_search_text);
+       gedit_history_entry_set_escape_func (GEDIT_HISTORY_ENTRY (dlg->priv->search_entry),
+                                            (GeditHistoryEntryEscapeFunc) gedit_utils_escape_search_text);
        gtk_widget_set_hexpand (GTK_WIDGET (dlg->priv->search_entry), TRUE);
-       dlg->priv->search_text_entry = gedit_history_entry_get_entry
-                       (GEDIT_HISTORY_ENTRY (dlg->priv->search_entry));
+       dlg->priv->search_text_entry = gedit_history_entry_get_entry (GEDIT_HISTORY_ENTRY 
(dlg->priv->search_entry));
        gtk_entry_set_activates_default (GTK_ENTRY (dlg->priv->search_text_entry), TRUE);
        gtk_grid_attach_next_to (GTK_GRID (dlg->priv->grid),
                                 dlg->priv->search_entry,
@@ -261,12 +225,10 @@ gedit_replace_dialog_init (GeditReplaceDialog *dlg)
                                 GTK_POS_RIGHT, 1, 1);
 
        dlg->priv->replace_entry = gedit_history_entry_new ("replace-with-entry", TRUE);
-       gedit_history_entry_set_escape_func
-                       (GEDIT_HISTORY_ENTRY (dlg->priv->replace_entry),
-                        (GeditHistoryEntryEscapeFunc) gedit_utils_escape_search_text);
+       gedit_history_entry_set_escape_func (GEDIT_HISTORY_ENTRY (dlg->priv->replace_entry),
+                                            (GeditHistoryEntryEscapeFunc) gedit_utils_escape_search_text);
        gtk_widget_set_hexpand (GTK_WIDGET (dlg->priv->replace_entry), TRUE);
-       dlg->priv->replace_text_entry = gedit_history_entry_get_entry
-                       (GEDIT_HISTORY_ENTRY (dlg->priv->replace_entry));
+       dlg->priv->replace_text_entry = gedit_history_entry_get_entry (GEDIT_HISTORY_ENTRY 
(dlg->priv->replace_entry));
        gtk_entry_set_activates_default (GTK_ENTRY (dlg->priv->replace_text_entry), TRUE);
        gtk_grid_attach_next_to (GTK_GRID (dlg->priv->grid),
                                 dlg->priv->replace_entry,
@@ -278,24 +240,6 @@ gedit_replace_dialog_init (GeditReplaceDialog *dlg)
        gtk_label_set_mnemonic_widget (GTK_LABEL (dlg->priv->replace_label),
                                       dlg->priv->replace_entry);
 
-       dlg->priv->find_button = gtk_button_new_from_stock (GTK_STOCK_FIND);
-       dlg->priv->replace_all_button = gtk_button_new_with_mnemonic (_("Replace _All"));
-       dlg->priv->replace_button = gedit_gtk_button_new_with_stock_icon (_("_Replace"),
-                                                                         GTK_STOCK_FIND_AND_REPLACE);
-
-       gtk_dialog_add_action_widget (GTK_DIALOG (dlg),
-                                     dlg->priv->replace_all_button,
-                                     GEDIT_REPLACE_DIALOG_REPLACE_ALL_RESPONSE);
-       gtk_dialog_add_action_widget (GTK_DIALOG (dlg),
-                                     dlg->priv->replace_button,
-                                     GEDIT_REPLACE_DIALOG_REPLACE_RESPONSE);
-       gtk_dialog_add_action_widget (GTK_DIALOG (dlg),
-                                     dlg->priv->find_button,
-                                     GEDIT_REPLACE_DIALOG_FIND_RESPONSE);
-       g_object_set (G_OBJECT (dlg->priv->find_button),
-                     "can-default", TRUE,
-                     NULL);
-
        gtk_dialog_set_default_response (GTK_DIALOG (dlg),
                                         GEDIT_REPLACE_DIALOG_FIND_RESPONSE);
 
@@ -310,11 +254,6 @@ gedit_replace_dialog_init (GeditReplaceDialog *dlg)
                                           GEDIT_REPLACE_DIALOG_REPLACE_ALL_RESPONSE,
                                           FALSE);
 
-       gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
-                           content, FALSE, FALSE, 0);
-       g_object_unref (content);
-       gtk_container_set_border_width (GTK_CONTAINER (content), 5);
-
        g_signal_connect (dlg->priv->search_text_entry,
                          "insert_text",
                          G_CALLBACK (insert_text_handler),
@@ -370,9 +309,7 @@ gedit_replace_dialog_set_search_text (GeditReplaceDialog *dialog,
                                           (text != '\0'));
 }
 
-/*
- * The text must be unescaped before searching.
- */
+/* The text must be unescaped before searching */
 const gchar *
 gedit_replace_dialog_get_search_text (GeditReplaceDialog *dialog)
 {
diff --git a/gedit/gedit-replace-dialog.ui b/gedit/gedit-replace-dialog.ui
index 11c8b4c..3ce06c0 100644
--- a/gedit/gedit-replace-dialog.ui
+++ b/gedit/gedit-replace-dialog.ui
@@ -1,21 +1,25 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkDialog" id="dialog">
+  <template class="GeditReplaceDialog" parent="GtkDialog">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Replace</property>
     <property name="resizable">False</property>
+    <property name="destroy_with_parent">True</property>
     <property name="type_hint">dialog</property>
+    <property name="border_width">5</property>
     <child internal-child="vbox">
       <object class="GtkBox" id="dialog-vbox1">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="orientation">vertical</property>
-        <property name="spacing">8</property>
+        <property name="spacing">2</property>
         <child internal-child="action_area">
           <object class="GtkButtonBox" id="dialog-action_area1">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
+            <property name="border_width">5</property>
+            <property name="spacing">6</property>
             <child>
               <object class="GtkButton" id="close_button">
                 <property name="label">gtk-close</property>
@@ -35,7 +39,7 @@
             </child>
             <child>
               <object class="GtkButton" id="replace_all_button">
-                <property name="label" translatable="yes">Replace All</property>
+                <property name="label" translatable="yes">Replace _All</property>
                 <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -52,7 +56,7 @@
             </child>
             <child>
               <object class="GtkButton" id="replace_button">
-                <property name="label" translatable="yes">Replace</property>
+                <property name="label" translatable="yes">_Replace</property>
                 <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -68,7 +72,7 @@
               </packing>
             </child>
             <child>
-              <object class="GtkButton" id="find_next_button">
+              <object class="GtkButton" id="find_button">
                 <property name="label">gtk-find</property>
                 <property name="use_action_appearance">False</property>
                 <property name="visible">True</property>
@@ -105,6 +109,7 @@
                 <property name="can_focus">False</property>
                 <property name="row_spacing">12</property>
                 <property name="column_spacing">12</property>
+                <property name="border_width">5</property>
                 <child>
                   <object class="GtkLabel" id="search_label">
                     <property name="visible">True</property>
@@ -121,7 +126,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="replace_with_label">
+                  <object class="GtkLabel" id="replace_label">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0</property>
@@ -191,7 +196,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkCheckButton" id="search_backwards_checkbutton">
+                  <object class="GtkCheckButton" id="backwards_checkbutton">
                     <property name="label" translatable="yes">Search _backwards</property>
                     <property name="use_action_appearance">False</property>
                     <property name="visible">True</property>
@@ -247,7 +252,7 @@
       <action-widget response="0">close_button</action-widget>
       <action-widget response="0">replace_all_button</action-widget>
       <action-widget response="0">replace_button</action-widget>
-      <action-widget response="0">find_next_button</action-widget>
+      <action-widget response="0">find_button</action-widget>
     </action-widgets>
-  </object>
+  </template>
 </interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 18215d9..6c799bd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -31,6 +31,7 @@ gedit/gedit-preferences-dialog.c
 gedit/gedit-print-job.c
 [type: gettext/glade]gedit/gedit-print-preferences.ui
 gedit/gedit-print-preview.c
+[type: gettext/glade]gedit/gedit-print-preview.ui
 gedit/gedit-replace-dialog.c
 [type: gettext/glade]gedit/gedit-replace-dialog.ui
 gedit/gedit-statusbar.c


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