[shotwell] Remove local actions from Page when switching away



commit 092a86ec0c9901385c257cd84eb178469da01b65
Author: Jens Georg <mail jensge org>
Date:   Wed Dec 28 00:08:16 2016 +0100

    Remove local actions from Page when switching away
    
    https://bugzilla.gnome.org/show_bug.cgi?id=776527

 src/CollectionPage.vala             |    7 +++++++
 src/MediaPage.vala                  |   24 +++++++++++++-----------
 src/Page.vala                       |   13 +++++--------
 src/PhotoPage.vala                  |   23 ++++++++++++++++++++---
 src/camera/ImportPage.vala          |    9 ++++++++-
 src/direct/DirectPhotoPage.vala     |    9 ++++++++-
 src/events/EventPage.vala           |    7 +++++++
 src/events/EventsDirectoryPage.vala |    7 +++++++
 src/library/ImportQueuePage.vala    |    9 ++++++++-
 src/library/OfflinePage.vala        |    7 +++++++
 src/library/TrashPage.vala          |    7 +++++++
 src/searches/SavedSearchPage.vala   |   10 +++++++++-
 src/tags/TagPage.vala               |    7 +++++++
 13 files changed, 113 insertions(+), 26 deletions(-)
---
diff --git a/src/CollectionPage.vala b/src/CollectionPage.vala
index c43c0c8..0c97bf9 100644
--- a/src/CollectionPage.vala
+++ b/src/CollectionPage.vala
@@ -176,6 +176,13 @@ public abstract class CollectionPage : MediaPage {
         AppWindow.get_instance ().add_action_entries (entries, this);
     }
 
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     protected override InjectionGroup[] init_collect_injection_groups() {
         InjectionGroup[] groups = base.init_collect_injection_groups();
         
diff --git a/src/MediaPage.vala b/src/MediaPage.vala
index ee5ef0e..b21517e 100644
--- a/src/MediaPage.vala
+++ b/src/MediaPage.vala
@@ -318,7 +318,6 @@ public abstract class MediaPage : CheckerboardPage {
         // Radio actions
         { "SortBy", on_action_radio, "s", "'1'", on_sort_changed },
         { "Sort", on_action_radio, "s", "'ascending'", on_sort_changed },
-        { "RawDeveloper", on_action_radio, "s", "'Shotwell'", on_raw_developer_changed }
     };
 
     protected override void add_actions () {
@@ -337,9 +336,20 @@ public abstract class MediaPage : CheckerboardPage {
         get_action ("Sort").change_state (sort_order ? "ascending" : "descending");
 
         var d = Config.Facade.get_instance().get_default_raw_developer();
-        get_action ("RawDeveloper").change_state (d == RawDeveloper.SHOTWELL ? "Shotwell" : "Camera");
+        var action = new GLib.SimpleAction.stateful("RawDeveloper",
+                GLib.VariantType.STRING, d == RawDeveloper.SHOTWELL ? "Shotwell" : "Camera");
+        action.change_state.connect(on_raw_developer_changed);
+        action.set_enabled(true);
+        AppWindow.get_instance().add_action(action);
     }
-    
+
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     protected override void update_actions(int selected_count, int count) {
         set_action_sensitive("Export", selected_count > 0);
         set_action_sensitive("EditTitle", selected_count > 0);
@@ -890,14 +900,6 @@ public abstract class MediaPage : CheckerboardPage {
         set_config_photos_sort(sort_order, sort_by);
     }
     
-    public void on_raw_developer_shotwell() {
-        developer_changed(RawDeveloper.SHOTWELL);
-    }
-    
-    public void on_raw_developer_camera() {
-        developer_changed(RawDeveloper.CAMERA);
-    }
-
     private void on_raw_developer_changed(GLib.SimpleAction action,
                                           Variant? value) {
         RawDeveloper developer = RawDeveloper.SHOTWELL;
diff --git a/src/Page.vala b/src/Page.vala
index a65a1e2..56e3d99 100644
--- a/src/Page.vala
+++ b/src/Page.vala
@@ -97,8 +97,6 @@ public abstract class Page : Gtk.ScrolledWindow {
 
         popup_menu.connect(on_context_keypress);
         
-        init_ui();
-        
         realize.connect(attach_view_signals);
     }
     
@@ -270,6 +268,7 @@ public abstract class Page : Gtk.ScrolledWindow {
     
     public virtual void switching_from() {
         in_view = false;
+        remove_actions();
         if (toolbar_path != null)
             toolbar = null;
     }
@@ -277,6 +276,7 @@ public abstract class Page : Gtk.ScrolledWindow {
     public virtual void switched_to() {
         in_view = true;
         add_ui();
+        add_actions();
         update_modifiers();
     }
     
@@ -469,6 +469,7 @@ public abstract class Page : Gtk.ScrolledWindow {
     }
 
     protected virtual void add_actions () { }
+    protected virtual void remove_actions () { }
 
     protected void on_action_toggle (GLib.Action action, Variant? value) {
         Variant new_state = ! (bool) action.get_state ();
@@ -479,10 +480,6 @@ public abstract class Page : Gtk.ScrolledWindow {
         action.change_state (value);
     }
 
-    private void init_ui() {
-        add_actions ();
-    }
-    
     private void add_ui() {
         // Collect all UI filenames and load them into the UI manager
         Gee.List<string> ui_filenames = new Gee.ArrayList<string>();
@@ -562,13 +559,13 @@ public abstract class Page : Gtk.ScrolledWindow {
         }
     }
     
-    // This is called during init_ui() to collect all the UI files to be loaded into the UI
+    // This is called during add_ui() to collect all the UI files to be loaded into the UI
     // manager.  Because order is important here, call the base method *first*, then add the
     // classes' filename.
     protected virtual void init_collect_ui_filenames(Gee.List<string> ui_filenames) {
     }
 
-    // This is called during init_ui() to collect all Page.InjectedUIElements for the page.  They
+    // This is called during add_ui() to collect all Page.InjectedUIElements for the page.  They
     // should be added to the MultiSet using the injection path as the key.
     protected virtual InjectionGroup[] init_collect_injection_groups() {
         return new InjectionGroup[0];
diff --git a/src/PhotoPage.vala b/src/PhotoPage.vala
index a6fb529..2c86acb 100644
--- a/src/PhotoPage.vala
+++ b/src/PhotoPage.vala
@@ -2431,7 +2431,6 @@ public class LibraryPhotoPage : EditingHostPage {
         { "ViewRatings", on_action_toggle, null, "false", on_display_ratings },
 
         // Radio actions
-        { "RawDeveloper", on_action_radio, "s", "'Shotwell'", on_raw_developer_changed }
     };
 
     protected override void add_actions () {
@@ -2440,8 +2439,18 @@ public class LibraryPhotoPage : EditingHostPage {
         AppWindow.get_instance ().add_action_entries (entries, this);
         (get_action ("ViewRatings") as GLib.SimpleAction).change_state (Config.Facade.get_instance 
().get_display_photo_ratings ());
         var d = Config.Facade.get_instance().get_default_raw_developer();
-        var action = get_action ("RawDeveloper") as GLib.SimpleAction;
-        action.change_state (d == RawDeveloper.SHOTWELL ? "Shotwell" : "Camera");
+        var action = new GLib.SimpleAction.stateful("RawDeveloper",
+                GLib.VariantType.STRING, d == RawDeveloper.SHOTWELL ? "Shotwell" : "Camera");
+        action.change_state.connect(on_raw_developer_changed);
+        action.set_enabled(true);
+        AppWindow.get_instance().add_action(action);
+    }
+
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
     }
 
     protected override InjectionGroup[] init_collect_injection_groups() {
@@ -2608,6 +2617,14 @@ public class LibraryPhotoPage : EditingHostPage {
         
         set_display_ratings(Config.Facade.get_instance().get_display_photo_ratings());
     }
+
+
+    public override void switching_from() {
+        base.switching_from();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
     
     protected override Gdk.Pixbuf? get_bottom_left_trinket(int scale) {
         if (!has_photo() || !Config.Facade.get_instance().get_display_photo_ratings())
diff --git a/src/camera/ImportPage.vala b/src/camera/ImportPage.vala
index 1200089..7cff258 100644
--- a/src/camera/ImportPage.vala
+++ b/src/camera/ImportPage.vala
@@ -886,7 +886,14 @@ public class ImportPage : CheckerboardPage {
 
         get_action ("ViewTitle").change_state (Config.Facade.get_instance ().get_display_photo_titles ());
     }
-    
+
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     public GPhoto.Camera get_camera() {
         return camera;
     }
diff --git a/src/direct/DirectPhotoPage.vala b/src/direct/DirectPhotoPage.vala
index 9688aa5..a07305d 100644
--- a/src/direct/DirectPhotoPage.vala
+++ b/src/direct/DirectPhotoPage.vala
@@ -70,7 +70,14 @@ public class DirectPhotoPage : EditingHostPage {
 
         AppWindow.get_instance ().add_action_entries (entries, this);
     }
-    
+
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     protected override InjectionGroup[] init_collect_injection_groups() {
         InjectionGroup[] groups = base.init_collect_injection_groups();
         
diff --git a/src/events/EventPage.vala b/src/events/EventPage.vala
index 848ec91..f4179c5 100644
--- a/src/events/EventPage.vala
+++ b/src/events/EventPage.vala
@@ -59,6 +59,13 @@ public class EventPage : CollectionPage {
         AppWindow.get_instance ().add_action_entries (entries, this);
     }
 
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     protected override void init_actions(int selected_count, int count) {
         base.init_actions(selected_count, count);
     }
diff --git a/src/events/EventsDirectoryPage.vala b/src/events/EventsDirectoryPage.vala
index af20d99..cc5ca22 100644
--- a/src/events/EventsDirectoryPage.vala
+++ b/src/events/EventsDirectoryPage.vala
@@ -122,6 +122,13 @@ public abstract class EventsDirectoryPage : CheckerboardPage {
         get_action ("ViewComment").change_state (display_comments);
     }
 
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     protected override void init_actions(int selected_count, int count) {
         base.init_actions(selected_count, count);
         
diff --git a/src/library/ImportQueuePage.vala b/src/library/ImportQueuePage.vala
index a2f2290..fc6e999 100644
--- a/src/library/ImportQueuePage.vala
+++ b/src/library/ImportQueuePage.vala
@@ -68,7 +68,14 @@ public class ImportQueuePage : SinglePhotoPage {
 
         AppWindow.get_instance ().add_action_entries (entries, this);
     }
-    
+
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     public void enqueue_and_schedule(BatchImport batch_import, bool allow_user_cancel) {
         assert(!queue.contains(batch_import));
         
diff --git a/src/library/OfflinePage.vala b/src/library/OfflinePage.vala
index bd916d0..115c592 100644
--- a/src/library/OfflinePage.vala
+++ b/src/library/OfflinePage.vala
@@ -62,6 +62,13 @@ public class OfflinePage : CheckerboardPage {
         AppWindow.get_instance ().add_action_entries (entries, this);
     }
 
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     public override Core.ViewTracker? get_view_tracker() {
         return tracker;
     }
diff --git a/src/library/TrashPage.vala b/src/library/TrashPage.vala
index 943c5e1..f01970b 100644
--- a/src/library/TrashPage.vala
+++ b/src/library/TrashPage.vala
@@ -58,6 +58,13 @@ public class TrashPage : CheckerboardPage {
         AppWindow.get_instance ().add_action_entries (entries, this);
     }
 
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     public override Core.ViewTracker? get_view_tracker() {
         return tracker;
     }
diff --git a/src/searches/SavedSearchPage.vala b/src/searches/SavedSearchPage.vala
index c57ec7d..2db26d3 100644
--- a/src/searches/SavedSearchPage.vala
+++ b/src/searches/SavedSearchPage.vala
@@ -58,7 +58,15 @@ public class SavedSearchPage : CollectionPage {
 
         AppWindow.get_instance ().add_action_entries (entries, this);
     }
-    
+
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
+
     private void on_delete_search() {
         if (Dialogs.confirm_delete_saved_search(search))
             AppWindow.get_command_manager().execute(new DeleteSavedSearchCommand(search));
diff --git a/src/tags/TagPage.vala b/src/tags/TagPage.vala
index 04696c5..fe31165 100644
--- a/src/tags/TagPage.vala
+++ b/src/tags/TagPage.vala
@@ -53,6 +53,13 @@ public class TagPage : CollectionPage {
         AppWindow.get_instance ().add_action_entries (entries, this);
     }
 
+    protected override void remove_actions() {
+        base.remove_actions();
+        foreach (var entry in entries) {
+            AppWindow.get_instance().remove_action(entry.name);
+        }
+    }
+
     private void on_tags_altered(Gee.Map<DataObject, Alteration> map) {
         if (map.has_key(tag)) {
             set_page_name(tag.get_name());


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