mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-10-26 08:00:05 -05:00
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.
This commit is contained in:
1 parent
62af7f0d6d
commit
672bb3c11d
3 files changed
+17
No files matched your search
@@ -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);
|
||||
|
||||
@@ -37,6 +37,7 @@ typedef struct _ExtensionInfo
|
||||
SCM extension;
|
||||
|
||||
gchar *action_label;
|
||||
gchar *action_label_original;
|
||||
gchar *action_name;
|
||||
gchar *action_tooltip;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user