[gnome-calculator/convert-categories: 2/5] Migrated category combo to category dropdown
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator/convert-categories: 2/5] Migrated category combo to category dropdown
- Date: Fri, 12 Nov 2021 12:29:15 +0000 (UTC)
commit 619d752a06caad733c267efcd89dd7eb147093b9
Author: Robert Roth <robert roth off gmail com>
Date: Thu Nov 11 16:09:13 2021 +0200
Migrated category combo to category dropdown
src/math-converter.vala | 24 +++++++++++-------------
src/ui/math-converter.ui | 13 ++-----------
2 files changed, 13 insertions(+), 24 deletions(-)
---
diff --git a/src/math-converter.vala b/src/math-converter.vala
index 65b0e341..23dfc3c4 100644
--- a/src/math-converter.vala
+++ b/src/math-converter.vala
@@ -19,7 +19,7 @@ public class MathConverter : Gtk.Grid
private unowned Gtk.CellRendererText from_renderer;
[GtkChild]
- private unowned Gtk.ComboBox category_combo;
+ private unowned Gtk.DropDown category_combo;
[GtkChild]
private unowned Gtk.ComboBox from_combo;
[GtkChild]
@@ -64,15 +64,18 @@ public class MathConverter : Gtk.Grid
}
private void build_category_model () {
- var category_model = new Gtk.TreeStore (2, typeof (string), typeof (UnitCategory));
+ var category_model = new ListStore (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_model.append (category);
}
category_combo.model = category_model;
+
+ var expression = new Gtk.PropertyExpression (typeof (UnitCategory),
+ null,
+ "display_name");
+ category_combo.expression = expression;
}
public void set_category (string? category)
@@ -218,15 +221,10 @@ public class MathConverter : Gtk.Grid
[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);
+ UnitCategory? category = category_combo.selected_item as UnitCategory;
+ print ("%s\n", category.name);
+ // set_category (category.name);
}
diff --git a/src/ui/math-converter.ui b/src/ui/math-converter.ui
index 73be0e00..21006d6a 100644
--- a/src/ui/math-converter.ui
+++ b/src/ui/math-converter.ui
@@ -13,17 +13,8 @@
<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 class="GtkDropDown" id="category_combo">
+ <signal name="notify::selected" handler="category_combobox_changed_cb" swapped="no"/>
</object>
</child>
<child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]