[gnome-calculator/wip-gtk4-port] Use MathPopover as base for MathFunctionPopover



commit 861ccb3487fbc3b06426eed47de3b47bd500144b
Author: Robert Roth <robert roth off gmail com>
Date:   Fri Oct 1 12:11:50 2021 +0300

    Use MathPopover as base for MathFunctionPopover

 src/math-popover.vala | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/meson.build       |  1 +
 2 files changed, 49 insertions(+)
---
diff --git a/src/math-popover.vala b/src/math-popover.vala
new file mode 100644
index 00000000..11f9b44b
--- /dev/null
+++ b/src/math-popover.vala
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2021 Robert Roth
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
+ * license.
+ */
+
+public abstract class MathPopover<T> : Gtk.Popover
+{
+    protected MathEquation equation;
+
+    protected ListStore model;
+
+    private CompareDataFunc<T> compare_func;
+
+    protected MathPopover (MathEquation equation, ListStore model, CompareDataFunc<T> compare_func)
+    {
+        this.equation = equation;
+        this.model = model;
+        this.compare_func = (a,b) => compare_func(a,b);
+    }
+
+    public void item_added_cb (T item)
+    {
+        model.insert_sorted (item as Object, (a,b) => compare_func(a, b));
+    }
+
+    public void item_edited_cb (T item)
+    {
+        item_deleted_cb (item);
+        item_added_cb (item);
+    }
+
+    public void item_deleted_cb (T item)
+    {
+        uint position = get_item_index (item);
+        if (position >= 0)
+            model.remove (position);
+    }
+
+    public abstract int get_item_index (T item);
+
+    protected abstract Gtk.Widget make_item_row (MathFunction function);
+
+}
diff --git a/src/meson.build b/src/meson.build
index d4ee5ffc..5c8fa032 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -5,6 +5,7 @@ gnome_calculator_vala_sources = [
   'math-converter.vala',
   'math-display.vala',
   'math-preferences.vala',
+  'math-popover.vala',
   'math-function-popover.vala',
   'math-variable-popover.vala',
   'math-window.vala',


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