Add ability to search for menu actions with a specific target

This commit is contained in:
Robert Fewell 2023-04-02 11:22:58 +01:00
parent 96d28f2f02
commit 98c11d620a
5 changed files with 32 additions and 1 deletions

View File

@ -633,6 +633,8 @@ extract_items_from_model (GMenuModel *model,
const gchar *action = NULL;
const gchar *label = NULL;
const gchar *tooltip = NULL;
const gchar *target_char = NULL;
gint target_int = -1;
iter = g_menu_model_iterate_item_attributes (model, item);
while (g_menu_attribute_iter_get_next (iter, &key, &value))
@ -646,10 +648,32 @@ extract_items_from_model (GMenuModel *model,
else if (g_str_equal (key, G_MENU_ATTRIBUTE_ACTION) &&
g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
action = g_variant_get_string (value, NULL);
else if (g_str_equal (key, G_MENU_ATTRIBUTE_TARGET) &&
g_variant_is_of_type (value, G_VARIANT_TYPE_STRING))
target_char = g_variant_get_string (value, NULL);
else if (g_str_equal (key, G_MENU_ATTRIBUTE_TARGET) &&
g_variant_is_of_type (value, G_VARIANT_TYPE_INT32))
target_int = g_variant_get_int32 (value);
g_variant_unref (value);
}
if (gsm->search_action_target)
{
gboolean target_test = FALSE;
if (target_int != -1 && target_int == atoi (gsm->search_action_target))
target_test = TRUE;
if (target_char && g_strcmp0 (target_char, gsm->search_action_target) == 0)
target_test = TRUE;
if (!target_test)
{
g_object_unref (iter);
return;
}
}
if (action && gsm->search_action_name)
{
if (g_str_has_suffix (action, gsm->search_action_name))
@ -759,6 +783,7 @@ gnc_menubar_model_find_menu_item (GMenuModel *menu_model, GtkWidget *menu, const
gsm->search_action_label = NULL;
gsm->search_action_name = action_name;
gsm->search_action_target = NULL;
if (gnc_menubar_model_find_item (menu_model, gsm))
menu_item = gnc_find_menu_item_by_action_label (menu, gsm->search_action_label);

View File

@ -83,6 +83,7 @@ struct _GncMenuModelSearch
{
const gchar *search_action_name;
const gchar *search_action_label;
const gchar *search_action_target;
const gchar *tooltip;
GMenuModel *model;
gint index;

View File

@ -1813,6 +1813,7 @@ gnc_main_window_update_one_menu_action (GncMainWindow *window,
gsm->search_action_label = nullptr;
gsm->search_action_name = "WindowsPlaceholder1"; // placeholder
gsm->search_action_target = nullptr;
if (!gnc_menubar_model_find_item (priv->menubar_model, gsm))
{
@ -3457,6 +3458,7 @@ update_menu_model (GncMainWindow *window, const gchar *ui_filename,
gsm->search_action_label = nullptr;
gsm->search_action_name = ui_updates[i];
gsm->search_action_target = nullptr;
if (gnc_menubar_model_find_item (priv->menubar_model, gsm))
g_menu_insert_section (G_MENU(gsm->model), gsm->index, NULL, G_MENU_MODEL(menu_model_part));
@ -3820,6 +3822,7 @@ gnc_main_window_update_menu_and_toolbar (GncMainWindow *window,
gsm->search_action_label = nullptr;
gsm->search_action_name = ui_updates[i];
gsm->search_action_target = nullptr;
if (gnc_menubar_model_find_item (priv->menubar_model, gsm))
g_menu_insert_section (G_MENU(gsm->model), gsm->index,

View File

@ -520,6 +520,7 @@ gnc_plugin_menu_additions_add_to_window (GncPlugin *plugin,
// add the report menu to the window
gsm->search_action_label = NULL;
gsm->search_action_name = "ReportsPlaceholder0";
gsm->search_action_target = NULL;
if (gnc_menubar_model_find_item (menubar_model, gsm))
{

View File

@ -1047,6 +1047,7 @@ gnc_plugin_page_register_ui_update (gpointer various,
gsm->search_action_label = NULL;
gsm->search_action_name = *iter;
gsm->search_action_target = NULL;
found = gnc_menubar_model_find_item (gnc_window_get_menubar_model (gnc_window), gsm);