[libdazzle] menus: allow use of non-standard "id" field in menu item



commit 518bcc868e42fe95c41016eadd8f1e09f6b20b3e
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jul 5 13:57:59 2017 -0700

    menus: allow use of non-standard "id" field in menu item
    
    Using the translated label string can be somewhat tricky, so
    this allows a fallback of adding an "id" attribute to an item
    and then keying off of that id for position.

 src/menus/dzl-menu-manager.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/src/menus/dzl-menu-manager.c b/src/menus/dzl-menu-manager.c
index 6894ef0..1e22dd9 100644
--- a/src/menus/dzl-menu-manager.c
+++ b/src/menus/dzl-menu-manager.c
@@ -183,10 +183,23 @@ find_position_for_item (GMenuModel *model,
     before = NULL;
 
   if (after != NULL)
-    after_pos = find_with_attribute_string (model, G_MENU_ATTRIBUTE_LABEL, after);
+    {
+      after_pos = find_with_attribute_string (model, G_MENU_ATTRIBUTE_LABEL, after);
+
+      /* Adding an "id" is non-standard, but can be useful as an alternative to
+       * translated strings.
+       */
+      if (after_pos == -1)
+        after_pos = find_with_attribute_string (model, "id", after);
+    }
 
   if (before != NULL)
-    before_pos = find_with_attribute_string (model, G_MENU_ATTRIBUTE_LABEL, before);
+    {
+      before_pos = find_with_attribute_string (model, G_MENU_ATTRIBUTE_LABEL, before);
+
+      if (before_pos == -1)
+        before_pos = find_with_attribute_string (model, "id", before);
+    }
 
   /*
    * TODO: Perform resort after all items have been inserted.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]