gpointer data);
static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
gpointer data);
+static gunichar parse_shortcut(const gchar *label, gchar **strippedlabel,
+ guint *position);
+
static void client_dest(ObClient *client, gpointer data)
{
return self;
}
+#define VALID_SHORTCUT(c) (((c) >= '0' && (c) <= '9') || \
+ ((c) >= 'A' && (c) <= 'Z') || \
+ ((c) >= 'a' && (c) <= 'z'))
+
+static gunichar parse_shortcut(const gchar *label, gchar **strippedlabel,
+ guint *position)
+{
+ gunichar shortcut = 0;
+
+ *position = 0;
+
+ g_assert(strippedlabel != NULL);
+
+ if (label == NULL) {
+ *strippedlabel = NULL;
+ } else {
+ gchar *i;
+
+ *strippedlabel = g_strdup(label);
+
+ i = strchr(*strippedlabel, '&');
+ if (i != NULL) {
+ /* there is an ampersand in the string */
+
+ /* you have to use a printable ascii character for shortcuts
+ don't allow space either, so you can have like "a & b"
+ */
+ if (VALID_SHORTCUT(*(i+1))) {
+ shortcut = g_unichar_tolower(g_utf8_get_char(i+1));
+ *position = i - *strippedlabel;
+
+ /* remove the & from the string */
+ for (; *i != '\0'; ++i)
+ *i = *(i+1);
+ }
+ } else {
+ /* there is no ampersand, so find the first valid character to use
+ instead */
+
+ for (i = *strippedlabel; *i != '\0'; ++i)
+ if (VALID_SHORTCUT(*i)) {
+ *position = i - *strippedlabel;
+ shortcut = g_unichar_tolower(g_utf8_get_char(i));
+ break;
+ }
+ }
+ }
+ return shortcut;
+}
+
static void parse_menu_item(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
gpointer data)
{
self = g_new0(ObMenu, 1);
self->name = g_strdup(name);
- self->title = g_strdup(title);
self->data = data;
+ self->shortcut = parse_shortcut(title, &self->title,
+ &self->shortcut_position);
+
g_hash_table_replace(menu_hash, self->name, self);
return self;
ObMenuEntryFrame *e = frame->entries->data;
if (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL &&
e->entry->data.normal.enabled)
- menu_frame_select(frame, e);
+ menu_frame_select(frame, e, FALSE);
}
}
ObMenuEntry *e;
e = menu_entry_new(self, OB_MENU_ENTRY_TYPE_NORMAL, id);
- e->data.normal.label = g_strdup(label);
e->data.normal.actions = actions;
+ menu_entry_set_label(e, label);
+
self->entries = g_list_append(self->entries, e);
return e;
}
ObMenuEntry *e;
e = menu_entry_new(self, OB_MENU_ENTRY_TYPE_SEPARATOR, id);
- e->data.separator.label = g_strdup(label);
+
+ menu_entry_set_label(e, label);
self->entries = g_list_append(self->entries, e);
return e;
e->data.submenu.submenu = menu_from_name(e->data.submenu.name);
}
}
+
+void menu_entry_set_label(ObMenuEntry *self, const gchar *label)
+{
+ switch (self->type) {
+ case OB_MENU_ENTRY_TYPE_SEPARATOR:
+ g_free(self->data.separator.label);
+ self->data.separator.label = g_strdup(label);
+ break;
+ case OB_MENU_ENTRY_TYPE_NORMAL:
+ g_free(self->data.normal.label);
+ self->data.normal.shortcut =
+ parse_shortcut(label, &self->data.normal.label,
+ &self->data.normal.shortcut_position);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
+void menu_show_all_shortcuts(ObMenu *self, gboolean show)
+{
+ self->show_all_shortcuts = show;
+}