[gnome-calculator] Minor refactoring for variable and function popovers
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator] Minor refactoring for variable and function popovers
- Date: Mon, 1 Aug 2022 06:32:54 +0000 (UTC)
commit 95e4c21f1501f31329fe23ede530507909dec70f
Author: Robert Roth <robert roth off gmail com>
Date: Mon Aug 1 09:28:23 2022 +0300
Minor refactoring for variable and function popovers
fix.function-crash.patch | 46 -----------------------------------------
src/math-function-popover.vala | 34 +++++++++---------------------
src/math-popover.vala | 15 ++++++++++++++
src/math-variable-popover.vala | 21 +++++++++----------
src/ui/math-function-popover.ui | 1 -
5 files changed, 35 insertions(+), 82 deletions(-)
---
diff --git a/src/math-function-popover.vala b/src/math-function-popover.vala
index b1b950b2..6d812113 100644
--- a/src/math-function-popover.vala
+++ b/src/math-function-popover.vala
@@ -23,7 +23,6 @@ public class MathFunctionPopover : MathPopover<MathFunction>
[GtkChild]
private unowned Gtk.Entry function_name_entry;
- private bool function_name_entry_placeholder_reseted = false;
[GtkChild]
private unowned Gtk.Button add_function_button;
@@ -41,6 +40,16 @@ public class MathFunctionPopover : MathPopover<MathFunction>
item_edited.connect (function_edited_cb);
item_deleted.connect (function_deleted_cb);
}
+
+ protected abstract Gtk.Entry name_entry ()
+ {
+ return function_name_entry;
+ }
+
+ protected abstract Gtk.Button add_button ()
+ {
+ return add_function_button;
+ }
private void function_edited_cb (MathFunction function)
{
@@ -71,29 +80,6 @@ public class MathFunctionPopover : MathPopover<MathFunction>
equation.place_cursor (end);
}
- /*
- [GtkCallback]
- private bool function_name_focus_cb (Gtk.Widget widget, Gtk.DirectionType direction)
- {
- if (!this.function_name_entry_placeholder_reseted)
- {
- this.function_name_entry_placeholder_reseted = true;
- this.function_name_entry.text = "";
- }
-
- return false;
- }
- */
-
- [GtkCallback]
- private void function_name_entry_changed_cb (Gtk.Editable editable)
- {
- this.function_name_entry_placeholder_reseted = true;
- var entry = editable as Gtk.Entry;
- entry.text = entry.text.replace (" ", "_");
- add_function_button.sensitive = entry.text != "";
- }
-
[GtkCallback]
private void add_function_cb (Gtk.Widget widget)
{
diff --git a/src/math-popover.vala b/src/math-popover.vala
index dd69672f..2906782e 100644
--- a/src/math-popover.vala
+++ b/src/math-popover.vala
@@ -16,11 +16,26 @@ public abstract class MathPopover<T> : Gtk.Popover
private CompareDataFunc<T> compare_func;
+ private ulong changed_handler;
+
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);
+ this.changed_handler = function_name_entry.changed.connect (name_entry_changed_cb);
+ }
+
+ protected abstract Gtk.Entry name_entry ();
+ protected abstract Gtk.Button add_button ();
+
+ private void name_entry_changed_cb (Gtk.Editable editable)
+ {
+ var entry = editable as Gtk.Entry;
+ SignalHandler.block (entry, changed_handler);
+ entry.text = entry.text.replace (" ", "_");
+ SignalHandler.unblock (entry, changed_handler);
+ add_button ().sensitive = entry.text != "";
}
public void item_added_cb (T item)
diff --git a/src/math-variable-popover.vala b/src/math-variable-popover.vala
index 76b17eea..48dce2ca 100644
--- a/src/math-variable-popover.vala
+++ b/src/math-variable-popover.vala
@@ -42,8 +42,6 @@ public class MathVariablePopover : MathPopover<MathVariable>
[GtkChild]
private unowned Gtk.Button store_variable_button;
- private ulong changed_handler;
-
public MathVariablePopover (MathEquation equation, ListStore model, CompareDataFunc compare_func)
{
base(equation, model, (a,b) => MathVariable.name_compare_func(a as MathVariable,b as MathVariable));
@@ -54,6 +52,16 @@ public class MathVariablePopover : MathPopover<MathVariable>
item_deleted.connect (delete_variable_cb);
}
+ protected abstract Gtk.Entry name_entry ()
+ {
+ return variable_name_entry;
+ }
+
+ protected abstract Gtk.Button add_button ()
+ {
+ return store_variable_button;
+ }
+
protected override int get_item_index (MathVariable item)
{
uint position;
@@ -75,15 +83,6 @@ public class MathVariablePopover : MathPopover<MathVariable>
equation.insert (variable.name);
}
- private void variable_name_changed_cb (Gtk.Editable editable)
- {
- var entry = editable as Gtk.Entry;
- SignalHandler.block (entry, changed_handler);
- entry.text = entry.text.replace (" ", "_");
- SignalHandler.unblock (entry, changed_handler);
- store_variable_button.sensitive = (entry.text != "");
- }
-
[GtkCallback]
private void store_variable_cb (Gtk.Widget widget)
{
diff --git a/src/ui/math-function-popover.ui b/src/ui/math-function-popover.ui
index bd6f167e..42a656d0 100644
--- a/src/ui/math-function-popover.ui
+++ b/src/ui/math-function-popover.ui
@@ -26,7 +26,6 @@
<object class="GtkEntry" id="function_name_entry">
<property name="placeholder_text" translatable="yes">New function</property>
<!--<signal name="focus" handler="function_name_focus_cb" swapped="no"/>-->
- <signal name="changed" handler="function_name_entry_changed_cb" swapped="no"/>
<signal name="activate" handler="add_function_cb" swapped="no"/>
</object>
</child>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]