[gedit: 4/5] spell-checker-dialog: use a template widget



commit cad0d3b22d9c9dc8ce04572cfcb2ff408344c6d0
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sat Jul 25 12:31:41 2015 +0200

    spell-checker-dialog: use a template widget

 plugins/spell/gedit-spell-checker-dialog.c  |   53 +++++++----------------
 plugins/spell/resources/ui/spell-checker.ui |   61 ++++++++++++++++-----------
 2 files changed, 53 insertions(+), 61 deletions(-)
---
diff --git a/plugins/spell/gedit-spell-checker-dialog.c b/plugins/spell/gedit-spell-checker-dialog.c
index 0a798b3..11bcf19 100644
--- a/plugins/spell/gedit-spell-checker-dialog.c
+++ b/plugins/spell/gedit-spell-checker-dialog.c
@@ -156,6 +156,7 @@ static void
 gedit_spell_checker_dialog_class_init (GeditSpellCheckerDialogClass *klass)
 {
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
        GtkBindingSet *binding_set;
 
        object_class->get_property = gedit_spell_checker_dialog_get_property;
@@ -238,6 +239,20 @@ gedit_spell_checker_dialog_class_init (GeditSpellCheckerDialogClass *klass)
                              NULL, NULL, NULL,
                              G_TYPE_NONE,
                              0);
+
+       /* Bind class to template */
+       gtk_widget_class_set_template_from_resource (widget_class,
+                                                    "/org/gnome/gedit/plugins/spell/ui/spell-checker.ui");
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, header_bar);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, misspelled_word_label);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, word_entry);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, check_word_button);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, ignore_button);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, ignore_all_button);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, change_button);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, change_all_button);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, add_word_button);
+       gtk_widget_class_bind_template_child (widget_class, GeditSpellCheckerDialog, suggestions_view);
 }
 
 static void
@@ -482,46 +497,12 @@ change_all_button_clicked_handler (GtkButton               *button,
 static void
 gedit_spell_checker_dialog_init (GeditSpellCheckerDialog *dialog)
 {
-       GtkBuilder *builder;
-       GtkWidget *content;
        GtkListStore *store;
        GtkTreeViewColumn *column;
        GtkCellRenderer *cell;
        GtkTreeSelection *selection;
-       gchar *root_objects[] = {
-               "header_bar",
-               "content",
-               "check_word_image",
-               "add_word_image",
-               "ignore_image",
-               "change_image",
-               "ignore_all_image",
-               "change_all_image",
-               NULL
-       };
-
-       builder = gtk_builder_new ();
-       gtk_builder_add_objects_from_resource (builder, "/org/gnome/gedit/plugins/spell/ui/spell-checker.ui",
-                                              root_objects, NULL);
-       content = GTK_WIDGET (gtk_builder_get_object (builder, "content"));
-       dialog->header_bar = GTK_HEADER_BAR (gtk_builder_get_object (builder, "header_bar"));
-       dialog->misspelled_word_label = GTK_LABEL (gtk_builder_get_object (builder, "misspelled_word_label"));
-       dialog->word_entry = GTK_ENTRY (gtk_builder_get_object (builder, "word_entry"));
-       dialog->check_word_button = GTK_WIDGET (gtk_builder_get_object (builder, "check_word_button"));
-       dialog->ignore_button = GTK_WIDGET (gtk_builder_get_object (builder, "ignore_button"));
-       dialog->ignore_all_button = GTK_WIDGET (gtk_builder_get_object (builder, "ignore_all_button"));
-       dialog->change_button = GTK_WIDGET (gtk_builder_get_object (builder, "change_button"));
-       dialog->change_all_button = GTK_WIDGET (gtk_builder_get_object (builder, "change_all_button"));
-       dialog->add_word_button = GTK_WIDGET (gtk_builder_get_object (builder, "add_word_button"));
-       dialog->suggestions_view = GTK_TREE_VIEW (gtk_builder_get_object (builder, "suggestions_view"));
-
-       gtk_window_set_titlebar (GTK_WINDOW (dialog),
-                                GTK_WIDGET (dialog->header_bar));
-
-       gtk_header_bar_set_subtitle (dialog->header_bar, NULL);
-
-       gtk_container_add (GTK_CONTAINER (dialog), content);
-       g_object_unref (builder);
+
+       gtk_widget_init_template (GTK_WIDGET (dialog));
 
        gtk_label_set_label (dialog->misspelled_word_label, "");
        gtk_widget_set_sensitive (GTK_WIDGET (dialog->word_entry), FALSE);
diff --git a/plugins/spell/resources/ui/spell-checker.ui b/plugins/spell/resources/ui/spell-checker.ui
index 0a1fa26..281610a 100644
--- a/plugins/spell/resources/ui/spell-checker.ui
+++ b/plugins/spell/resources/ui/spell-checker.ui
@@ -1,19 +1,13 @@
 <?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.19.0 -->
 <interface>
-  <!-- interface-requires gtk+ 3.0 -->
-  <object class="GtkWindow" id="check_spelling_window">
+  <requires lib="gtk+" version="3.16"/>
+  <template class="GeditSpellCheckerDialog" parent="GtkWindow">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Check spelling</property>
     <property name="resizable">False</property>
     <property name="type_hint">dialog</property>
-    <child type="titlebar">
-      <object class="GtkHeaderBar" id="header_bar">
-        <property name="visible">True</property>
-        <property name="title" translatable="yes">Check spelling</property>
-        <property name="show_close_button">True</property>
-      </object>
-    </child>
     <child>
       <object class="GtkBox" id="content">
         <property name="visible">True</property>
@@ -33,23 +27,23 @@
               <object class="GtkLabel" id="label1">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="xalign">0</property>
                 <property name="label" translatable="yes">Misspelled word:</property>
                 <property name="justify">center</property>
+                <property name="xalign">0</property>
               </object>
               <packing>
                 <property name="x_options">GTK_FILL</property>
-                <property name="y_options"></property>
+                <property name="y_options"/>
               </packing>
             </child>
             <child>
               <object class="GtkLabel" id="misspelled_word_label">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="xalign">0</property>
                 <property name="label" translatable="yes">word</property>
                 <property name="use_markup">True</property>
                 <property name="justify">center</property>
+                <property name="xalign">0</property>
                 <attributes>
                   <attribute name="weight" value="bold"/>
                 </attributes>
@@ -58,24 +52,24 @@
                 <property name="left_attach">1</property>
                 <property name="right_attach">2</property>
                 <property name="x_options">GTK_FILL</property>
-                <property name="y_options"></property>
+                <property name="y_options"/>
               </packing>
             </child>
             <child>
               <object class="GtkLabel" id="label3">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="xalign">0</property>
                 <property name="label" translatable="yes">Change _to:</property>
                 <property name="use_underline">True</property>
                 <property name="justify">center</property>
                 <property name="mnemonic_widget">word_entry</property>
+                <property name="xalign">0</property>
               </object>
               <packing>
                 <property name="top_attach">1</property>
                 <property name="bottom_attach">2</property>
                 <property name="x_options">GTK_FILL</property>
-                <property name="y_options"></property>
+                <property name="y_options"/>
               </packing>
             </child>
             <child>
@@ -97,10 +91,10 @@
                 <child>
                   <object class="GtkButton" id="check_word_button">
                     <property name="label" translatable="yes">Check _Word</property>
+                    <property name="use_action_appearance">False</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">False</property>
-                    <property name="use_action_appearance">False</property>
                     <property name="use_underline">True</property>
                   </object>
                   <packing>
@@ -134,18 +128,24 @@
             <property name="column_spacing">12</property>
             <property name="row_spacing">6</property>
             <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
               <object class="GtkLabel" id="label4">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="xalign">0</property>
                 <property name="label" translatable="yes">_Suggestions:</property>
                 <property name="use_underline">True</property>
                 <property name="justify">center</property>
                 <property name="mnemonic_widget">suggestions_view</property>
+                <property name="xalign">0</property>
               </object>
               <packing>
                 <property name="x_options">GTK_FILL</property>
-                <property name="y_options"></property>
+                <property name="y_options"/>
               </packing>
             </child>
             <child>
@@ -189,10 +189,10 @@
                     <child>
                       <object class="GtkButton" id="ignore_button">
                         <property name="label" translatable="yes">_Ignore</property>
+                        <property name="use_action_appearance">False</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="use_underline">True</property>
                       </object>
                       <packing>
@@ -202,10 +202,10 @@
                     <child>
                       <object class="GtkButton" id="change_button">
                         <property name="label" translatable="yes">Cha_nge</property>
+                        <property name="use_action_appearance">False</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="use_underline">True</property>
                       </object>
                       <packing>
@@ -217,10 +217,10 @@
                     <child>
                       <object class="GtkButton" id="ignore_all_button">
                         <property name="label" translatable="yes">Ignore _All</property>
+                        <property name="use_action_appearance">False</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="use_underline">True</property>
                       </object>
                       <packing>
@@ -232,10 +232,10 @@
                     <child>
                       <object class="GtkButton" id="change_all_button">
                         <property name="label" translatable="yes">Change A_ll</property>
+                        <property name="use_action_appearance">False</property>
                         <property name="visible">True</property>
                         <property name="can_focus">True</property>
                         <property name="receives_default">False</property>
-                        <property name="use_action_appearance">False</property>
                         <property name="use_underline">True</property>
                       </object>
                       <packing>
@@ -263,9 +263,9 @@
                       <object class="GtkLabel" id="label6">
                         <property name="visible">True</property>
                         <property name="can_focus">False</property>
-                        <property name="xalign">7.4505801528346183e-09</property>
                         <property name="label" translatable="yes">User dictionary:</property>
                         <property name="use_markup">True</property>
+                        <property name="xalign">7.4505801528346183e-09</property>
                       </object>
                       <packing>
                         <property name="expand">False</property>
@@ -282,10 +282,10 @@
                         <child>
                           <object class="GtkButton" id="add_word_button">
                             <property name="label" translatable="yes">Add w_ord</property>
+                            <property name="use_action_appearance">False</property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="receives_default">False</property>
-                            <property name="use_action_appearance">False</property>
                             <property name="use_underline">True</property>
                           </object>
                           <packing>
@@ -316,6 +316,9 @@
                 <property name="bottom_attach">2</property>
               </packing>
             </child>
+            <child>
+              <placeholder/>
+            </child>
           </object>
           <packing>
             <property name="expand">True</property>
@@ -325,5 +328,13 @@
         </child>
       </object>
     </child>
-  </object>
+    <child type="titlebar">
+      <object class="GtkHeaderBar" id="header_bar">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="title">Check spelling</property>
+        <property name="show_close_button">True</property>
+      </object>
+    </child>
+  </template>
 </interface>


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