[shotwell/wip/dedeprecate: 58/64] WIP



commit 1ef7c20eb856994d2fe539e95c8b4a20a703c619
Author: Jens Georg <mail jensge org>
Date:   Thu Nov 10 21:05:16 2016 +0100

    WIP

 src/Page.vala         |   61 ++++++++++++++++++++++++++++++++++++++++++------
 src/tags/TagPage.vala |   50 +++++++++++++++++-----------------------
 ui/tags.ui            |    9 +++++--
 3 files changed, 80 insertions(+), 40 deletions(-)
---
diff --git a/src/Page.vala b/src/Page.vala
index 911e7b4..03453f0 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -59,7 +59,7 @@ public class InjectionGroup {
 public abstract class Page : Gtk.ScrolledWindow {
     private const int CONSIDER_CONFIGURE_HALTED_MSEC = 400;
     
-    protected Gtk.Builder builder;
+    protected Gtk.Builder builder = new Gtk.Builder ();
     protected Gtk.Toolbar toolbar;
     protected bool in_view = false;
     
@@ -163,7 +163,6 @@ public abstract class Page : Gtk.ScrolledWindow {
         assert(this.container == null);
         
         this.container = container;
-        this.builder = new Gtk.Builder ();
     }
     
     public virtual void clear_container() {
@@ -222,7 +221,7 @@ public abstract class Page : Gtk.ScrolledWindow {
                     var submenu = model.get_item_link (i, GLib.Menu.LINK_SUBMENU);
 
                     var section = this.find_extension_point (submenu,
-                            group.get_path ());
+                                                             group.get_path ());
 
                     if (section == null) {
                         continue;
@@ -329,10 +328,11 @@ public abstract class Page : Gtk.ScrolledWindow {
 
         if (action == null)
             return;
-#if 0
+
         if (label != null)
-            action.label = label;
-        
+            this.update_menu_item_label (name, label);
+
+#if 0
         if (tooltip != null)
             action.tooltip = tooltip;
 #endif
@@ -1187,8 +1187,53 @@ public abstract class Page : Gtk.ScrolledWindow {
         return false;
     }
 
-    private GLib.MenuModel? find_extension_point (GLib.MenuModel model,
-                                                  string extension_point) {
+    protected void update_menu_item_label (string id,
+                                           string new_label) {
+        var bar = this.builder.get_object ("MenuBar") as GLib.Menu;
+
+        if (bar == null) {
+            return;
+        }
+
+        var items = bar.get_n_items ();
+        for (var i = 0; i< items; i++) {
+            var model = bar.get_item_link (i, GLib.Menu.LINK_SUBMENU);
+            if (bar == null) {
+                continue;
+            }
+
+            var model_items = model.get_n_items ();
+            for (var j = 0; j < model_items; j++) {
+                var subsection = model.get_item_link (j, GLib.Menu.LINK_SECTION);
+
+                if (subsection == null)
+                    continue;
+
+                // Recurse into submenus
+                var sub_items = subsection.get_n_items ();
+                for (var k = 0; k < sub_items; k++) {
+                    var it = subsection.iterate_item_attributes (k);
+                    while (it.next ()) {
+                        if (it.get_name () == "id") {
+                            if (it.get_value ().get_string () == id) {
+                                var md = subsection as GLib.Menu;
+                                var m = new GLib.MenuItem.from_model
+                                    (subsection, k);
+                                m.set_label (new_label);
+                                md.remove (k);
+                                md.insert_item (k, m);
+
+                                return;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    protected GLib.MenuModel? find_extension_point (GLib.MenuModel model,
+                                                    string extension_point) {
         var items = model.get_n_items ();
         GLib.MenuModel? section = null;
 
diff --git a/src/tags/TagPage.vala b/src/tags/TagPage.vala
index f3799e3..04696c5 100644
--- a/src/tags/TagPage.vala
+++ b/src/tags/TagPage.vala
@@ -39,44 +39,36 @@ public class TagPage : CollectionPage {
     protected override void set_config_photos_sort(bool sort_order, int sort_by) {
         Config.Facade.get_instance().set_event_photos_sort(sort_order, sort_by);
     }
-    
-    protected override Gtk.ActionEntry[] init_collect_action_entries() {
-        Gtk.ActionEntry[] actions = base.init_collect_action_entries();
-        
-        Gtk.ActionEntry delete_tag = { "DeleteTag", null, TRANSLATABLE, null, null, on_delete_tag };
-        // label and tooltip are assigned when the menu is displayed
-        actions += delete_tag;
-        
-        Gtk.ActionEntry rename_tag = { "RenameTag", null, TRANSLATABLE, null, null, on_rename_tag };
-        // label and tooltip are assigned when the menu is displayed
-        actions += rename_tag;
-        
-        Gtk.ActionEntry remove_tag = { "RemoveTagFromPhotos", null, TRANSLATABLE, null, null, 
-            on_remove_tag_from_photos };
-        // label and tooltip are assigned when the menu is displayed
-        actions += remove_tag;
-        
-        Gtk.ActionEntry delete_tag_sidebar = { "DeleteTagSidebar", null, Resources.DELETE_TAG_SIDEBAR_MENU, 
-            null, null, on_delete_tag };
-        actions += delete_tag_sidebar;
-        
-        Gtk.ActionEntry rename_tag_sidebar = { "RenameTagSidebar", null, Resources.RENAME_TAG_SIDEBAR_MENU, 
-            null, null, on_rename_tag };
-        actions += rename_tag_sidebar;
 
-        Gtk.ActionEntry new_child_tag_sidebar = { "NewChildTagSidebar", null, 
Resources.NEW_CHILD_TAG_SIDEBAR_MENU,
-            null, null, on_new_child_tag_sidebar };
-        actions += new_child_tag_sidebar;
+    private const GLib.ActionEntry entries[] = {
+        { "DeleteTag", on_delete_tag },
+        { "RenameTag", on_rename_tag },
+        { "RemoveTagFromPhotos", on_remove_tag_from_photos },
+        { "NewChildTagSidebar", on_new_child_tag_sidebar }
+    };
+
+    protected override void add_actions () {
+        base.add_actions ();
 
-        return actions;
+        AppWindow.get_instance ().add_action_entries (entries, this);
     }
-    
+
     private void on_tags_altered(Gee.Map<DataObject, Alteration> map) {
         if (map.has_key(tag)) {
             set_page_name(tag.get_name());
             update_actions(get_view().get_selected_count(), get_view().get_count());
         }
     }
+
+    public override void switched_to () {
+        base.switched_to ();
+        this.update_menu_item_label ("DeleteTag",
+            Resources.delete_tag_menu(tag.get_user_visible_name()));
+        this.update_menu_item_label ("RenameTag",
+            Resources.rename_tag_menu(tag.get_user_visible_name()));
+        this.update_menu_item_label ("RemoveTagFromPhotos",
+            Resources.untag_photos_menu(tag.get_user_visible_name(), 0));
+     }
     
     protected override void update_actions(int selected_count, int count) {
         set_action_details("DeleteTag",
diff --git a/ui/tags.ui b/ui/tags.ui
index ac5392c..06f9f4b 100644
--- a/ui/tags.ui
+++ b/ui/tags.ui
@@ -395,17 +395,20 @@
       </section>
       <section>
         <item>
-          <attribute name="label" translatable="yes">RemoveTagFromPhotos</attribute>
+          <attribute name="id">RemoveTagFromPhotos</attribute>
+          <attribute name="label" translatable="yes"></attribute>
           <attribute name="action">win.RemoveTagFromPhotos</attribute>
         </item>
       </section>
       <section>
         <item>
-          <attribute name="label" translatable="yes">RenameTag</attribute>
+          <attribute name="id">RenameTag</attribute>
+          <attribute name="label" translatable="yes"></attribute>
           <attribute name="action">win.RenameTag</attribute>
         </item>
         <item>
-          <attribute name="label" translatable="yes">DeleteTag</attribute>
+          <attribute name="id">DeleteTag</attribute>
+          <attribute name="label" translatable="yes"></attribute>
           <attribute name="action">win.DeleteTag</attribute>
         </item>
       </section>


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