gnucash stable: Adding custom report to a custom sub-menu
Robert Fewell
bobit at code.gnucash.org
Fri Mar 13 10:18:44 EDT 2026
Updated via https://github.com/Gnucash/gnucash/commit/672bb3c1 (commit)
from https://github.com/Gnucash/gnucash/commit/62af7f0d (commit)
commit 672bb3c11d20e6b21fa510a019260594619603a5
Author: Robert Fewell <14uBobIT at gmail.com>
Date: Fri Mar 13 13:52:57 2026 +0000
Adding custom report to a custom sub-menu
If the custom sub-menu does not have an accelerator key defined then
one is added if possible which changes the action label. This new label
creates a new full path which is used in the build_menu_hash table to
reference the created GMenuItem.
When adding the menu entry, the full path used still comprises of the
original label and hence the GMenuItem can not be found in the
build_menu_hash table and so gets added as a top level menu entry.
To fix this, a second entry is added to the build_menu_hash table using
the original menu label so the required GMenuItem can be found.
diff --git a/gnucash/gnome-utils/gnc-menu-extensions.c b/gnucash/gnome-utils/gnc-menu-extensions.c
index 36666feffe..65fa54ba72 100644
--- a/gnucash/gnome-utils/gnc-menu-extensions.c
+++ b/gnucash/gnome-utils/gnc-menu-extensions.c
@@ -275,6 +275,7 @@ gnc_create_extension_info (SCM extension)
name = gnc_extension_name (extension);
guid = gnc_extension_guid (extension);
ext_info->action_label = g_strdup (gettext (name));
+ ext_info->action_label_original = NULL;
ext_info->action_name = gnc_ext_gen_action_name (guid);
ext_info->action_tooltip = gnc_extension_documentation (extension);
g_free (name);
@@ -324,6 +325,7 @@ cleanup_extension_info (gpointer extension_info, gpointer not_used)
g_free (ext_info->sort_key);
g_free ((gchar *)ext_info->action_name);
g_free ((gchar *)ext_info->action_label);
+ g_free ((gchar *)ext_info->action_label_original);
g_free ((gchar *)ext_info->action_tooltip);
g_free (ext_info->path);
g_free (ext_info);
diff --git a/gnucash/gnome-utils/gnc-menu-extensions.h b/gnucash/gnome-utils/gnc-menu-extensions.h
index 060ab1e3f9..6e9559a5a3 100644
--- a/gnucash/gnome-utils/gnc-menu-extensions.h
+++ b/gnucash/gnome-utils/gnc-menu-extensions.h
@@ -37,6 +37,7 @@ typedef struct _ExtensionInfo
SCM extension;
gchar *action_label;
+ gchar *action_label_original;
gchar *action_name;
gchar *action_tooltip;
diff --git a/gnucash/gnome-utils/gnc-plugin-menu-additions.c b/gnucash/gnome-utils/gnc-plugin-menu-additions.c
index 483912b4b1..a01032af47 100644
--- a/gnucash/gnome-utils/gnc-plugin-menu-additions.c
+++ b/gnucash/gnome-utils/gnc-plugin-menu-additions.c
@@ -359,6 +359,11 @@ gnc_menu_additions_assign_accel (ExtensionInfo *info, GHashTable *table)
new_label = g_strconcat(start, "_", ptr, (gchar *)NULL);
g_free(start);
DEBUG("label '%s' -> '%s'", info->action_label, new_label);
+
+ /* Save the original action_label before adding accelerator */
+ if (info->type == GNC_SUB_MENU_ITEM)
+ info->action_label_original = g_strdup (info->action_label);
+
g_free((gchar *)info->action_label);
info->action_label = new_label;
@@ -446,6 +451,15 @@ gnc_menu_additions_menu_setup_one (ExtensionInfo *ext_info,
}
g_hash_table_insert (per_window->build_menu_hash, g_strdup (full_path), gmenu_item);
+ /* if the action_label has been changed, we need to add another entry to the table
+ with the original action_label so the gmenu_item can be found */
+ if (ext_info->action_label_original)
+ {
+ gchar *full_path_original = g_strconcat (ext_info->path, "/", ext_info->action_label_original, NULL);
+ g_hash_table_insert (per_window->build_menu_hash, g_strdup (full_path_original), gmenu_item);
+ g_object_ref (gmenu_item);
+ g_free (full_path_original);
+ }
g_free (full_path);
}
Summary of changes:
gnucash/gnome-utils/gnc-menu-extensions.c | 2 ++
gnucash/gnome-utils/gnc-menu-extensions.h | 1 +
gnucash/gnome-utils/gnc-plugin-menu-additions.c | 14 ++++++++++++++
3 files changed, 17 insertions(+)
More information about the gnucash-changes
mailing list