X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fmenu.c;h=7197868b79c76230fd335813b57bc20f5b43854a;hb=9aa42c2ae7b457db6efc1703dd47d1e3ac5e75e8;hp=1f335c787dac724b26bc3b0a97c3f964b4cf861d;hpb=569b5aebbd64641486ca97c715089af0dbca5f97;p=chaz%2Fopenbox diff --git a/openbox/menu.c b/openbox/menu.c index 1f335c78..7197868b 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -54,8 +54,8 @@ static void parse_menu_separator(ObParseInst *i, 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 gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut, + gchar **strippedlabel, guint *position); static void client_dest(ObClient *client, gpointer data) @@ -185,8 +185,8 @@ static ObMenu* menu_from_name(gchar *name) ((c) >= 'A' && (c) <= 'Z') || \ ((c) >= 'a' && (c) <= 'z')) -static gunichar parse_shortcut(const gchar *label, gchar **strippedlabel, - guint *position) +static gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut, + gchar **strippedlabel, guint *position) { gunichar shortcut = 0; @@ -201,8 +201,12 @@ static gunichar parse_shortcut(const gchar *label, gchar **strippedlabel, *strippedlabel = g_strdup(label); + /* if allow_shortcut is false, then you can't use the &, instead you + have to just use the first valid character + */ + i = strchr(*strippedlabel, '&'); - if (i != NULL) { + if (allow_shortcut && i != NULL) { /* there is an ampersand in the string */ /* you have to use a printable ascii character for shortcuts @@ -248,7 +252,7 @@ static void parse_menu_item(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, if (a) acts = g_slist_append(acts, a); } - menu_add_normal(state->parent, -1, label, acts); + menu_add_normal(state->parent, -1, label, acts, FALSE); g_free(label); } } @@ -285,7 +289,7 @@ static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, if (!parse_attr_string("label", node, &title)) goto parse_menu_fail; - if ((menu = menu_new(name, title, NULL))) { + if ((menu = menu_new(name, title, FALSE, NULL))) { menu->pipe_creator = state->pipe_creator; if (parse_attr_string("execute", node, &script)) { menu->execute = parse_expand_tilde(script); @@ -309,7 +313,8 @@ parse_menu_fail: g_free(script); } -ObMenu* menu_new(const gchar *name, const gchar *title, gpointer data) +ObMenu* menu_new(const gchar *name, const gchar *title, + gboolean allow_shortcut, gpointer data) { ObMenu *self; @@ -317,7 +322,7 @@ ObMenu* menu_new(const gchar *name, const gchar *title, gpointer data) self->name = g_strdup(name); self->data = data; - self->shortcut = parse_shortcut(title, &self->title, + self->shortcut = parse_shortcut(title, allow_shortcut, &self->title, &self->shortcut_position); g_hash_table_replace(menu_hash, self->name, self); @@ -459,14 +464,14 @@ void menu_entry_remove(ObMenuEntry *self) } ObMenuEntry* menu_add_normal(ObMenu *self, gint id, const gchar *label, - GSList *actions) + GSList *actions, gboolean allow_shortcut) { ObMenuEntry *e; e = menu_entry_new(self, OB_MENU_ENTRY_TYPE_NORMAL, id); e->data.normal.actions = actions; - menu_entry_set_label(e, label); + menu_entry_set_label(e, label, allow_shortcut); self->entries = g_list_append(self->entries, e); return e; @@ -489,7 +494,7 @@ ObMenuEntry* menu_add_separator(ObMenu *self, gint id, const gchar *label) e = menu_entry_new(self, OB_MENU_ENTRY_TYPE_SEPARATOR, id); - menu_entry_set_label(e, label); + menu_entry_set_label(e, label, FALSE); self->entries = g_list_append(self->entries, e); return e; @@ -538,7 +543,8 @@ void menu_find_submenus(ObMenu *self) } } -void menu_entry_set_label(ObMenuEntry *self, const gchar *label) +void menu_entry_set_label(ObMenuEntry *self, const gchar *label, + gboolean allow_shortcut) { switch (self->type) { case OB_MENU_ENTRY_TYPE_SEPARATOR: @@ -548,7 +554,7 @@ void menu_entry_set_label(ObMenuEntry *self, const gchar *label) case OB_MENU_ENTRY_TYPE_NORMAL: g_free(self->data.normal.label); self->data.normal.shortcut = - parse_shortcut(label, &self->data.normal.label, + parse_shortcut(label, allow_shortcut, &self->data.normal.label, &self->data.normal.shortcut_position); break; default: