diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2024-07-10 13:31:01 +0200 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2024-07-10 13:31:01 +0200 |
commit | bd25ec74138ca20849bd1fe1ae12b584c7d583e4 (patch) | |
tree | 6e5d3078e2f3529de99e5fbd255283a7091fcf36 | |
parent | 2bb2f321c64b903b6e4b5c581d79602632c851c5 (diff) | |
parent | 255c93f5c070077cc54aed3f7360cb165fc97000 (diff) | |
download | ayatana-ido-bd25ec74138ca20849bd1fe1ae12b584c7d583e4.tar.gz ayatana-ido-bd25ec74138ca20849bd1fe1ae12b584c7d583e4.tar.bz2 ayatana-ido-bd25ec74138ca20849bd1fe1ae12b584c7d583e4.zip |
Merge branch 'tari01-pr/switch-accelerator'
Attributes GH PR #70: https://github.com/AyatanaIndicators/ayatana-ido/pull/70
-rw-r--r-- | src/idoswitchmenuitem.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/src/idoswitchmenuitem.c b/src/idoswitchmenuitem.c index 9bc9ef9..af90d7b 100644 --- a/src/idoswitchmenuitem.c +++ b/src/idoswitchmenuitem.c @@ -33,6 +33,7 @@ typedef struct GtkWidget * label; GtkWidget * image; GtkWidget * switch_w; + GtkWidget * accelerator; } IdoSwitchMenuItemPrivate; /*** @@ -168,13 +169,47 @@ ido_switch_menu_item_set_label (IdoSwitchMenuItem *item, priv->label = gtk_label_new (NULL); gtk_widget_set_halign (priv->label, GTK_ALIGN_START); gtk_widget_show (priv->label); - gtk_box_pack_end (GTK_BOX (priv->content_area), priv->label, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (priv->content_area), priv->label, TRUE, TRUE, 0); } gtk_label_set_text (GTK_LABEL (priv->label), label); } /** + * ido_switch_menu_item_set_accelerator: + * @item: a #IdoSwitchMenuItem. + * @accelerator: a string to set as the accelerator of @item + * + * Set the accelerator of @item to @accelerator. + **/ + +void ido_switch_menu_item_set_accelerator (IdoSwitchMenuItem *item, const gchar *accelerator) +{ + IdoSwitchMenuItemPrivate *priv; + + g_return_if_fail (IDO_IS_SWITCH_MENU_ITEM (item)); + g_return_if_fail (accelerator != NULL); + + priv = ido_switch_menu_item_get_instance_private (item); + + if (priv->accelerator == NULL) + { + priv->accelerator = gtk_label_new (NULL); + gtk_widget_set_halign (priv->accelerator, GTK_ALIGN_END); + GtkStyleContext *pContext = gtk_widget_get_style_context (priv->accelerator); + gtk_style_context_add_class (pContext, "accelerator"); + gtk_widget_show (priv->accelerator); + gtk_box_pack_end (GTK_BOX (priv->content_area), priv->accelerator, FALSE, FALSE, 6); + } + + guint nKey; + GdkModifierType cType; + gtk_accelerator_parse (accelerator, &nKey, &cType); + gchar *sText = gtk_accelerator_get_label (nKey, cType); + gtk_label_set_text (GTK_LABEL (priv->accelerator), sText); +} + +/** * ido_switch_menu_item_set_icon: * @item: a #IdoSwitchMenuItem. * @icon: (allow-none): a #GIcon @@ -248,6 +283,15 @@ ido_switch_menu_item_new_from_menu_model (GMenuItem *menuitem, g_free (label); } + gchar *sAccelerator; + gboolean bAccelerator = g_menu_item_get_attribute (menuitem, "accel", "s", &sAccelerator); + + if (bAccelerator) + { + ido_switch_menu_item_set_accelerator (IDO_SWITCH_MENU_ITEM (item), sAccelerator); + g_free (sAccelerator); + } + serialized_icon = g_menu_item_get_attribute_value (menuitem, "icon", NULL); if (serialized_icon) { |