[seahorse] GenerateSelect: use GtkTemplate.



commit e627e866fd3bd31fe642c291c2da0d0669083c2e
Author: Niels De Graef <nielsdegraef gmail com>
Date:   Sat Aug 4 19:17:37 2018 +0200

    GenerateSelect: use GtkTemplate.
    
    I also added a translatable string for the window title. Apparently, we
    didn't even set one before, which looked really bad (especially with the
    buttons in the headerbar). I know this technically isn't allowed with
    the code freeze, but I think we can agree that an untranslated title is
    better than no title at all.

 src/generate-select.vala        |  32 ++---------
 src/seahorse-generate-select.ui | 119 +++++++++++++++++++++++-----------------
 2 files changed, 75 insertions(+), 76 deletions(-)
---
diff --git a/src/generate-select.vala b/src/generate-select.vala
index 20934779..3c77600d 100644
--- a/src/generate-select.vala
+++ b/src/generate-select.vala
@@ -18,8 +18,10 @@
  * <http://www.gnu.org/licenses/>.
  */
 
+[GtkTemplate (ui = "/org/gnome/Seahorse/seahorse-generate-select.ui")]
 public class Seahorse.GenerateSelect : Gtk.Dialog {
     private Gtk.ListStore store;
+    [GtkChild]
     private Gtk.TreeView view;
     private List<Gtk.ActionGroup>? action_groups;
 
@@ -61,49 +63,25 @@ public class Seahorse.GenerateSelect : Gtk.Dialog {
             }
         }
 
-        Gtk.Builder builder = new Gtk.Builder();
-        try {
-            string path = "/org/gnome/Seahorse/seahorse-generate-select.ui";
-            builder.add_from_resource(path);
-        } catch (GLib.Error err) {
-            critical("%s", err.message);
-        }
-
-        // Setup the dialog
-        set_default_size(-1, 410);
-        get_content_area().pack_start((Gtk.Widget) builder.get_object("generate-select"),
-                                        true, true, 0);
-        add_buttons(Gtk.Stock.CANCEL, Gtk.ResponseType.CANCEL,
-                    _("Continue"), Gtk.ResponseType.OK,
-                    null);
-
         // Hook it into the view
-        this.view = (Gtk.TreeView) builder.get_object("keytype-tree");
-
         Gtk.CellRendererPixbuf pixcell = new Gtk.CellRendererPixbuf();
         pixcell.stock_size = Gtk.IconSize.DND;
         this.view.insert_column_with_attributes(-1, "", pixcell, "gicon", Column.ICON, null);
         this.view.insert_column_with_attributes(-1, "", new Gtk.CellRendererText(), "markup", Column.TEXT, 
null);
         this.view.set_model(this.store);
 
-        // Setup selection, select first item
-        Gtk.TreeSelection selection = this.view.get_selection();
-        selection.set_mode(Gtk.SelectionMode.BROWSE);
-
+        // Select first item
         Gtk.TreeIter iter;
         this.store.get_iter_first(out iter);
-        selection.select_iter(iter);
+        this.view.get_selection().select_iter(iter);
 
         this.view.row_activated.connect(on_row_activated);
-        this.view.height_request = 410;
     }
 
     private Gtk.Action? get_selected_action() {
-        Gtk.TreeSelection selection = this.view.get_selection();
-
         Gtk.TreeIter iter;
         Gtk.TreeModel? model;
-        if (!selection.get_selected(out model, out iter))
+        if (!this.view.get_selection().get_selected(out model, out iter))
             return null;
 
         Gtk.Action? action;
diff --git a/src/seahorse-generate-select.ui b/src/seahorse-generate-select.ui
index 96351337..2c8d300e 100644
--- a/src/seahorse-generate-select.ui
+++ b/src/seahorse-generate-select.ui
@@ -1,61 +1,82 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <requires lib="gtk+" version="3.0"/>
-          <object class="GtkVBox" id="generate-select">
+  <requires lib="gtk+" version="3.22"/>
+  <template class="SeahorseGenerateSelect" parent="GtkDialog">
+    <property name="title" translatable="yes">New item</property>
+    <child internal-child="vbox">
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="height_request">300</property>
+        <property name="can_focus">False</property>
+        <property name="border_width">5</property>
+        <property name="margin">12</property>
+        <property name="spacing">6</property>
+        <child>
+          <object class="GtkLabel" id="label4">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="border_width">5</property>
-            <property name="spacing">12</property>
-            <child>
-              <object class="GtkLabel" id="label4">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="xalign">0</property>
-                <property name="yalign">0</property>
-                <property name="label" translatable="yes">_Select the type of item to create:</property>
-                <property name="use_underline">True</property>
-                <attributes>
-                 <attribute name="weight" value="bold"/>
-                </attributes>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
+            <property name="xalign">0</property>
+            <property name="yalign">0</property>
+            <property name="label" translatable="yes">_Select the type of item to create:</property>
+            <property name="use_underline">True</property>
+            <attributes>
+             <attribute name="weight" value="bold"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">never</property>
+            <property name="shadow_type">in</property>
             <child>
-              <object class="GtkAlignment" id="alignment3">
+              <object class="GtkTreeView" id="view">
+                <property name="height_request">210</property>
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="left_padding">12</property>
-                <child>
-                  <object class="GtkScrolledWindow" id="scrolledwindow1">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="hscrollbar_policy">never</property>
-                    <property name="shadow_type">in</property>
-                    <child>
-                      <object class="GtkTreeView" id="keytype-tree">
-                        <property name="height_request">210</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="has_focus">True</property>
-                        <property name="headers_visible">False</property>
-                        <property name="enable_search">False</property>
-                        <child internal-child="selection">
-                          <object class="GtkTreeSelection" id="treeview-selection1"/>
-                        </child>
-                      </object>
-                    </child>
+                <property name="can_focus">True</property>
+                <property name="has_focus">True</property>
+                <property name="headers_visible">False</property>
+                <property name="enable_search">False</property>
+                <child internal-child="selection">
+                  <object class="GtkTreeSelection" id="treeview-selection1">
+                    <property name="mode">browse</property>
                   </object>
                 </child>
               </object>
-              <packing>
-                <property name="expand">True</property>
-                <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
             </child>
           </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+
+    <child type="action">
+      <object class="GtkButton" id="button_cancel">
+        <property name="visible">True</property>
+        <property name="label" translatable="yes">Cancel</property>
+      </object>
+    </child>
+    <child type="action">
+      <object class="GtkButton" id="button_ok">
+        <property name="visible">True</property>
+        <property name="can-default">True</property>
+        <property name="label" translatable="yes">Continue</property>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="cancel">button_cancel</action-widget>
+      <action-widget response="ok" default="true">button_ok</action-widget>
+    </action-widgets>
+  </template>
 </interface>


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