]> Dogcows Code - chaz/openbox/blobdiff - openbox/menu.c
don't use client_move() to end a move
[chaz/openbox] / openbox / menu.c
index a78cd6129cc93617f8c0ab04ae56ace68a121232..634a0d9c83cc7311ebc4542bc30ada93783cf78f 100644 (file)
@@ -218,6 +218,7 @@ static gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut,
         *strippedlabel = NULL;
     } else {
         gchar *i;
+        gboolean escape;
 
         *strippedlabel = g_strdup(label);
 
@@ -225,20 +226,33 @@ static gunichar parse_shortcut(const gchar *label, gboolean allow_shortcut,
            have to just use the first valid character
         */
 
-        i = strchr(*strippedlabel, '_');
+        /* allow __ to escape an underscore */
+        i = *strippedlabel;
+        do {
+            escape = FALSE;
+            i = strchr(i, '_');
+            if (i && *(i+1) == '_') {
+                gchar *j;
+
+                /* remove the escape '_' from the string */
+                for (j = i; *j != '\0'; ++j)
+                    *j = *(j+1);
+
+                ++i;
+                escape = TRUE;
+            }
+        } while (escape);
+
         if (allow_shortcut && i != NULL) {
             /* there is an underscore 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)) || *(i+1) == '_') {
-                /* Allow you to escape the first _ by putting __ */
-                if (*(i+1) != '_') {
-                    shortcut = g_unichar_tolower(g_utf8_get_char(i+1));
-                    *position = i - *strippedlabel;
-                    *always_show = TRUE;
-                }
+            if (VALID_SHORTCUT(*(i+1))) {
+                shortcut = g_unichar_tolower(g_utf8_get_char(i+1));
+                *position = i - *strippedlabel;
+                *always_show = TRUE;
 
                 /* remove the '_' from the string */
                 for (; *i != '\0'; ++i)
@@ -269,18 +283,48 @@ static void parse_menu_item(xmlNodePtr node,  gpointer data)
 {
     ObMenuParseState *state = data;
     gchar *label;
+    gchar *icon;
+    ObMenuEntry *e;
 
     if (state->parent) {
+        /* Don't try to extract "icon" attribute if icons in user-defined
+           menus are not enabled. */
+
         if (obt_xml_attr_string(node, "label", &label)) {
+            xmlNodePtr c;
             GSList *acts = NULL;
 
-            for (node = node->children; node; node = node->next)
-                if (!xmlStrcasecmp(node->name, (const xmlChar*) "action")) {
-                    ObActionsAct *a = actions_parse(node);
-                    if (a)
-                        acts = g_slist_append(acts, a);
+            c = obt_xml_find_node(node->children, "action");
+            while (c) {
+                ObActionsAct *action = actions_parse(c);
+                if (action)
+                    acts = g_slist_append(acts, action);
+                c = obt_xml_find_node(node->next, "action");
+            }
+            e = menu_add_normal(state->parent, -1, label, acts, TRUE);
+            
+            if (config_menu_show_icons &&
+                obt_xml_attr_string(node, "icon", &icon))
+            {
+                RrImage *ic;
+
+                ic = RrImageCacheFindName(ob_rr_icons, icon);
+                if (ic)
+                    RrImageRef(ic);
+                else {
+                    ic = RrImageNew(ob_rr_icons);
+                    if (!RrImageAddPictureName(ic, icon)) {
+                        RrImageUnref(ic); /* no need to keep it around */
+                        ic = NULL;
+                    }
                 }
-            menu_add_normal(state->parent, -1, label, acts, TRUE);
+                e->data.normal.icon = ic;
+
+                if (e->data.normal.icon)
+                    e->data.normal.icon_alpha = 0xff;
+
+                g_free(icon);
+            }
             g_free(label);
         }
     }
This page took 0.021935 seconds and 4 git commands to generate.