Commit 092a86ec authored by Jens Georg's avatar Jens Georg

Remove local actions from Page when switching away

https://bugzilla.gnome.org/show_bug.cgi?id=776527
parent 6fc59123
......@@ -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();
......
......@@ -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;
......
......@@ -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];
......
......@@ -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())
......
......@@ -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;
}
......
......@@ -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();
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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));
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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));
......
......@@ -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());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment