From ea1205f094041359fd5de5c145559e24e616a10f Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 14 Apr 2023 18:54:16 +0200 Subject: [PATCH] Issue #9349: removing 2 duplicate "*-short" actions. "edit-paste-as-new-image-short" and "vectors-selection-to-vectors-short" were just duplicate of the action named the same, except for the "-short" suffix, and the only point was to have different labels. Not though that this time, it was not enough to conclude that the action in a menu shoud have the short variant. These were both used differently depending on the menu. Instead I added the concept of "label-variant" attribute in .ui menu files. When the "long" variant is set, then we simply use the longer label. There is still one more "-short" action: "tools-by-color-select-short", but I am a still unsure how to handle this one. --- app/actions/edit-actions.c | 10 +++------- app/actions/vectors-actions.c | 10 ++-------- app/widgets/gimpmenu.c | 28 ++++++++++++++++++++++++---- app/widgets/gimpmenumodel.c | 26 ++++++++++++++++++++++++-- menus/image-menu.ui.in.in | 4 ++-- menus/selection-menu.ui | 2 +- menus/vectors-menu.ui | 2 +- 7 files changed, 57 insertions(+), 25 deletions(-) diff --git a/app/actions/edit-actions.c b/app/actions/edit-actions.c index fc8f56d469..d0fff8ac55 100644 --- a/app/actions/edit-actions.c +++ b/app/actions/edit-actions.c @@ -120,13 +120,9 @@ static const GimpActionEntry edit_actions[] = GIMP_HELP_EDIT_COPY_VISIBLE }, { "edit-paste-as-new-image", GIMP_ICON_EDIT_PASTE_AS_NEW, - NC_("edit-action", "From _Clipboard"), NULL, { "V", "Paste", NULL }, - NC_("edit-action", "Create a new image from the content of the clipboard"), - edit_paste_as_new_image_cmd_callback, - GIMP_HELP_EDIT_PASTE_AS_NEW_IMAGE }, - - { "edit-paste-as-new-image-short", GIMP_ICON_EDIT_PASTE_AS_NEW, - NC_("edit-action", "Paste as _New Image"), NULL, { NULL }, + NC_("edit-action", "Paste as _New Image"), + NC_("edit-action", "From _Clipboard"), + { "V", "Paste", NULL }, NC_("edit-action", "Create a new image from the content of the clipboard"), edit_paste_as_new_image_cmd_callback, GIMP_HELP_EDIT_PASTE_AS_NEW_IMAGE }, diff --git a/app/actions/vectors-actions.c b/app/actions/vectors-actions.c index 60b63467d1..8b06a8dfe6 100644 --- a/app/actions/vectors-actions.c +++ b/app/actions/vectors-actions.c @@ -274,13 +274,8 @@ static const GimpEnumActionEntry vectors_to_selection_actions[] = static const GimpEnumActionEntry vectors_selection_to_vectors_actions[] = { { "vectors-selection-to-vectors", GIMP_ICON_SELECTION_TO_PATH, - NC_("vectors-action", "Selecti_on to Path"), NULL, { NULL }, - NC_("vectors-action", "Selection to path"), - FALSE, FALSE, - GIMP_HELP_SELECTION_TO_PATH }, - - { "vectors-selection-to-vectors-short", GIMP_ICON_SELECTION_TO_PATH, - NC_("vectors-action", "To _Path"), NULL, { NULL }, + NC_("vectors-action", "Selecti_on to Path"), + NC_("vectors-action", "To _Path"), { NULL }, NC_("vectors-action", "Selection to path"), FALSE, FALSE, GIMP_HELP_SELECTION_TO_PATH }, @@ -439,7 +434,6 @@ vectors_actions_update (GimpActionGroup *group, SET_SENSITIVE ("vectors-import", image); SET_SENSITIVE ("vectors-selection-to-vectors", image && !mask_empty); - SET_SENSITIVE ("vectors-selection-to-vectors-short", image && !mask_empty); SET_SENSITIVE ("vectors-selection-to-vectors-advanced", image && !mask_empty); SET_SENSITIVE ("vectors-fill", n_selected_vectors > 0 && dr_writable && diff --git a/app/widgets/gimpmenu.c b/app/widgets/gimpmenu.c index b78d65d771..f98333132b 100644 --- a/app/widgets/gimpmenu.c +++ b/app/widgets/gimpmenu.c @@ -88,6 +88,7 @@ static void gimp_menu_add_placeholder (GimpMenu *menu const gchar *label); static void gimp_menu_add_action (GimpMenu *menu, const gchar *action_name, + gboolean long_label, GtkWidget *sibling, gboolean top, GtkRadioMenuItem **group); @@ -264,7 +265,17 @@ gimp_menu_append (GimpMenuShell *shell, } else { - gimp_menu_add_action (menu, action_name, NULL, FALSE, &group); + gchar *label_variant = NULL; + + g_menu_model_get_item_attribute (G_MENU_MODEL (model), i, "label-variant", "s", &label_variant); + gimp_menu_add_action (menu, action_name, + /* By default, we use the short label in menus, + * unless "label-variant" attribute is set to + * "long". + */ + g_strcmp0 (label_variant, "long") == 0, + NULL, FALSE, &group); + g_free (label_variant); } g_free (label); @@ -295,7 +306,7 @@ gimp_menu_add_ui (GimpMenuShell *shell, if (! placeholder) g_warning ("%s: no placeholder item '%s'.", G_STRFUNC, placeholder_key); - gimp_menu_add_action (menu, action_name, placeholder, top, NULL); + gimp_menu_add_action (menu, action_name, FALSE, placeholder, top, NULL); } else { @@ -419,6 +430,7 @@ gimp_menu_add_placeholder (GimpMenu *menu, static void gimp_menu_add_action (GimpMenu *menu, const gchar *action_name, + gboolean long_label, GtkWidget *sibling, gboolean top, GtkRadioMenuItem **group) @@ -436,7 +448,10 @@ gimp_menu_add_action (GimpMenu *menu, g_return_if_fail (GIMP_IS_ACTION (action)); - action_label = gimp_action_get_short_label (action); + if (long_label) + action_label = gimp_action_get_label (action); + else + action_label = gimp_action_get_short_label (action); g_return_if_fail (action_label != NULL); if (GIMP_IS_TOGGLE_ACTION (action)) @@ -657,16 +672,21 @@ gimp_menu_section_items_changed (GMenuModel *model, while (added > 0) { - gchar *action_name = NULL; + gchar *action_name = NULL; + gchar *label_variant = NULL; g_menu_model_get_item_attribute (G_MENU_MODEL (model), position, G_MENU_ATTRIBUTE_ACTION, "s", &action_name); + g_menu_model_get_item_attribute (G_MENU_MODEL (model), position, + "label-variant", "s", &label_variant); g_return_if_fail (action_name != NULL); gimp_menu_add_action (menu, action_name, + g_strcmp0 (label_variant, "long") == 0, iter ? iter->data : NULL, iter ? TRUE : FALSE, NULL); g_free (action_name); + g_free (label_variant); added--; position++; diff --git a/app/widgets/gimpmenumodel.c b/app/widgets/gimpmenumodel.c index a7878715b1..e24b7990c0 100644 --- a/app/widgets/gimpmenumodel.c +++ b/app/widgets/gimpmenumodel.c @@ -654,6 +654,7 @@ gimp_menu_model_initialize (GimpMenuModel *model, if (action_name) { GimpAction *action; + gchar *label_variant = NULL; action = gimp_ui_manager_find_action (model->priv->manager, NULL, action_name); @@ -668,11 +669,21 @@ gimp_menu_model_initialize (GimpMenuModel *model, G_CALLBACK (gimp_menu_model_action_notify_visible), model, 0); - g_menu_item_set_label (item, gimp_action_get_short_label (action)); + g_menu_item_get_attribute (item, "label-variant", "s", &label_variant); + if (g_strcmp0 (label_variant, "long") == 0) + g_menu_item_set_label (item, gimp_action_get_label (action)); + else + g_menu_item_set_label (item, gimp_action_get_short_label (action)); + g_signal_connect_object (action, "notify::short-label", G_CALLBACK (gimp_menu_model_action_notify_label), item, 0); + g_signal_connect_object (action, + "notify::label", + G_CALLBACK (gimp_menu_model_action_notify_label), + item, 0); + g_free (label_variant); } /* else we instal a placeholder (no-action and always invisible) item. */ } @@ -824,10 +835,17 @@ gimp_menu_model_action_notify_label (GimpAction *action, GParamSpec *pspec, GMenuItem *item) { + gchar *label_variant = NULL; + g_return_if_fail (GIMP_IS_ACTION (action)); g_return_if_fail (G_IS_MENU_ITEM (item)); - g_menu_item_set_label (item, gimp_action_get_short_label (action)); + g_menu_item_get_attribute (item, "label-variant", "s", &label_variant); + if (g_strcmp0 (label_variant, "long") == 0) + g_menu_item_set_label (item, gimp_action_get_label (action)); + else + g_menu_item_set_label (item, gimp_action_get_short_label (action)); + g_free (label_variant); } static gboolean @@ -935,6 +953,10 @@ gimp_menu_model_ui_added (GimpUIManager *manager, "notify::short-label", G_CALLBACK (gimp_menu_model_action_notify_label), item, 0); + g_signal_connect_object (action, + "notify::label", + G_CALLBACK (gimp_menu_model_action_notify_label), + item, 0); g_menu_model_items_changed (G_MENU_MODEL (model), position, 0, 1); } else diff --git a/menus/image-menu.ui.in.in b/menus/image-menu.ui.in.in index ec96eb5345..055a2a5c30 100644 --- a/menus/image-menu.ui.in.in +++ b/menus/image-menu.ui.in.in @@ -85,7 +85,7 @@ app.edit-paste-merged-in-place app.edit-paste-into app.edit-paste-into-in-place - app.edit-paste-as-new-image-short + app.edit-paste-as-new-imagelong _Buffer @@ -138,7 +138,7 @@
app.quick-mask-toggle app.select-save - app.vectors-selection-to-vectors-short + app.vectors-selection-to-vectors
diff --git a/menus/selection-menu.ui b/menus/selection-menu.ui index 671cc9ea2c..23337119ca 100644 --- a/menus/selection-menu.ui +++ b/menus/selection-menu.ui @@ -21,7 +21,7 @@
app.select-save - app.vectors-selection-to-vectors-short + app.vectors-selection-to-vectors
app.select-fill app.select-stroke diff --git a/menus/vectors-menu.ui b/menus/vectors-menu.ui index b6aef16cf4..e3bf35a469 100644 --- a/menus/vectors-menu.ui +++ b/menus/vectors-menu.ui @@ -33,7 +33,7 @@ app.vectors-selection-add app.vectors-selection-subtract app.vectors-selection-intersect - app.vectors-selection-to-vectors + app.vectors-selection-to-vectorslong
app.vectors-fill