Skip to content

[gnc-optiondb] allow any report option to have a "changed" callback #2099

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: stable
Choose a base branch
from

Conversation

christopherlam
Copy link
Contributor

@christopherlam christopherlam commented Jun 4, 2025

Thus options other than boolean and multichoice can have callbacks. e.g. we can attach a callback to the account-sel option to set other options.

Adding another option type callback is as easy as:

modified   gnucash/gnome-utils/gnc-option-gtk-ui.cpp
@@ -215,6 +215,11 @@ public:
         auto widget{GTK_ENTRY(get_widget())};
         option.set_value(std::string{gtk_entry_get_text(widget)});
     }
+    SCM get_widget_scm_value(const GncOption& option) const override
+    {
+        auto widget{GTK_ENTRY(get_widget())};
+        return scm_from_utf8_string (gtk_entry_get_text (widget));
+    }
 };
 
 template<> void
modified   gnucash/report/trep-engine.scm
@@ -595,6 +595,11 @@ Expenses:Car and Expenses:Flights. Use a period (.) to match a single character
 '20../.' will match 'Travel 2017/1 London'. ")
     #f)
 
+  (gnc-option-set-changed-callback
+   options pagename-filter optname-account-matcher
+   (lambda (txt) (gnc:pk "new account matcher: " txt)))
+
   (gnc-register-simple-boolean-option options
     pagename-filter optname-account-matcher-exclude "a7"
     (G_ "If this option is selected, accounts matching filter are excluded.")

TODO: after updating other options, need to find a way to refresh ui.

@jralls
Copy link
Member

jralls commented Jun 4, 2025

Thus options other than boolean and multichoice can have callbacks. e.g. we can attach a callback to the account-sel option to set other options.

That's a terrible idea. It makes it impossible to reason about the code. I consider it a very serious bug that I couldn't remove the callbacks from the two types that have it without breaking the reports that abuse it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants