diff options
| author | Dana Jansens <danakj@orodu.net> | 2007-04-25 02:50:59 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2007-04-25 02:50:59 +0000 |
| commit | 9aa42c2ae7b457db6efc1703dd47d1e3ac5e75e8 (patch) | |
| tree | a5f8c62a3a0f890ca92e43b1a7c01159028656da /openbox/menu.c | |
| parent | 569b5aebbd64641486ca97c715089af0dbca5f97 (diff) | |
cleanups for keyboard menu shotcuts. dont let & set a shortcut from stuff like menu titles and what not, they are only for strigns oenbox provides.
Diffstat (limited to 'openbox/menu.c')
| -rw-r--r-- | openbox/menu.c | 34 |
1 files changed, 20 insertions, 14 deletions
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: |
