[gnome-calculator/convert-categories: 17/21] Added dummy unit category selector combo




commit baf4faac5ddfaa6456297919ec6cde56953e0f48
Author: Robert Roth <robert roth off gmail com>
Date:   Thu Nov 11 15:00:10 2021 +0200

    Added dummy unit category selector combo

 src/math-converter.vala  | 30 ++++++++++++++++++++++++++++++
 src/ui/math-converter.ui | 14 ++++++++++++++
 2 files changed, 44 insertions(+)
---
diff --git a/src/math-converter.vala b/src/math-converter.vala
index e43d71fa..65b0e341 100644
--- a/src/math-converter.vala
+++ b/src/math-converter.vala
@@ -18,6 +18,8 @@ public class MathConverter : Gtk.Grid
     [GtkChild]
     private unowned Gtk.CellRendererText from_renderer;
 
+    [GtkChild]
+    private unowned Gtk.ComboBox category_combo;
     [GtkChild]
     private unowned Gtk.ComboBox from_combo;
     [GtkChild]
@@ -45,6 +47,7 @@ public class MathConverter : Gtk.Grid
             update_result_label ();
         });
 
+        build_category_model ();
         update_visibility ();
         update_from_model ();
     }
@@ -60,6 +63,18 @@ public class MathConverter : Gtk.Grid
         equation.notify["display"].connect ((pspec) => { update_result_label (); });
     }
 
+    private void build_category_model () {
+        var category_model = new Gtk.TreeStore (2, typeof (string), typeof (UnitCategory));
+        var categories = UnitManager.get_default ().get_categories ();
+        foreach (var category in categories)
+        {
+            Gtk.TreeIter parent;
+            category_model.append (out parent, null);
+            category_model.set (parent, 0, category.display_name, 1, category, -1);
+        }
+        category_combo.model = category_model;
+    }
+
     public void set_category (string? category)
     {
         if (this.category == category)
@@ -200,6 +215,21 @@ public class MathConverter : Gtk.Grid
         return false;
     }
 
+    [GtkCallback]
+    private void category_combobox_changed_cb ()
+    {
+        UnitCategory? category = null;
+        Gtk.TreeIter iter;
+
+        var model = category_combo.get_model ();
+
+        if (!category_combo.get_active_iter (out iter))
+            return;
+
+        model.get (iter, 1, out category, -1);
+
+    }
+
     [GtkCallback]
     private void from_combobox_changed_cb ()
     {
diff --git a/src/ui/math-converter.ui b/src/ui/math-converter.ui
index 9daf5823..73be0e00 100644
--- a/src/ui/math-converter.ui
+++ b/src/ui/math-converter.ui
@@ -12,6 +12,20 @@
         <property name="valign">center</property>
         <property name="hexpand">True</property>
         <property name="vexpand">False</property>
+        <child>
+          <object class="GtkComboBox" id="category_combo">
+            <property name="hexpand">False</property>
+            <signal name="changed" handler="category_combobox_changed_cb" swapped="no"/>
+            <child>
+              <object class="GtkCellRendererText" id="category_renderer">
+                <property name="ellipsize">end</property>
+              </object>
+              <attributes>
+                <attribute name="text">0</attribute>
+              </attributes>
+            </child>
+          </object>
+        </child>
         <child>
           <object class="GtkComboBox" id="from_combo">
             <property name="hexpand">True</property>


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