aboutsummaryrefslogtreecommitdiff
path: root/src/idoswitchmenuitem.c
diff options
context:
space:
mode:
authorRobert Tari <robert@tari.in>2024-07-09 16:07:52 +0200
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2024-07-10 13:30:12 +0200
commit255c93f5c070077cc54aed3f7360cb165fc97000 (patch)
tree6e5d3078e2f3529de99e5fbd255283a7091fcf36 /src/idoswitchmenuitem.c
parent2bb2f321c64b903b6e4b5c581d79602632c851c5 (diff)
downloadayatana-ido-255c93f5c070077cc54aed3f7360cb165fc97000.tar.gz
ayatana-ido-255c93f5c070077cc54aed3f7360cb165fc97000.tar.bz2
ayatana-ido-255c93f5c070077cc54aed3f7360cb165fc97000.zip
src/idoswitchmenuitem.c: Allow the switch to display an accelerator.
This enables the IDO switch menu item to process GMenuItem's standard 'accel' property and display it in a user readable format.
Diffstat (limited to 'src/idoswitchmenuitem.c')
-rw-r--r--src/idoswitchmenuitem.c46
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)
{