MainWindow: Fix unused view clean-up (Fix #261)

This commit is contained in:
Adrien Plazas 2020-11-12 11:49:00 +01:00 committed by GitHub
parent cc9404aabc
commit af9c0dcffb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 20 deletions

View File

@ -11,9 +11,9 @@
<object class="HdyDeck" id="deck"> <object class="HdyDeck" id="deck">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="transition_type">slide</property>
<property name="can_swipe_back">True</property> <property name="can_swipe_back">True</property>
<property name="can_swipe_forward">True</property> <signal name="notify::transition-running" handler="on_child_transition"/>
<signal name="notify::visible-child" handler="on_child_transition"/>
<child> <child>
<placeholder/> <placeholder/>
</child> </child>

View File

@ -40,26 +40,18 @@ public class Tootle.Dialogs.MainWindow: Hdy.Window, ISavedWindow {
} }
public bool back () { public bool back () {
var children = deck.get_children (); deck.navigate (Hdy.NavigationDirection.BACK);
unowned var current = children.find (deck.visible_child);
if (current != null) {
unowned var prev = current.prev;
if (current.prev != null) {
deck.visible_child = prev.data;
(current.data as Views.Base).unused = true;
Timeout.add (deck.transition_duration, clean_unused_views);
}
}
return true; return true;
} }
bool clean_unused_views () { [GtkCallback]
deck.get_children ().foreach (c => { void on_child_transition () {
var view = c as Views.Base; if (deck.transition_running)
if (view != null && view.unused) return;
view.destroy ();
}); Widget unused_child;
return Source.REMOVE; while ((unused_child = deck.get_adjacent_child (Hdy.NavigationDirection.FORWARD)) != null)
unused_child.destroy ();
} }
public override bool delete_event (Gdk.EventAny event) { public override bool delete_event (Gdk.EventAny event) {

View File

@ -10,7 +10,6 @@ public class Tootle.Views.Base : Box {
public string label { get; set; default = ""; } public string label { get; set; default = ""; }
public bool needs_attention { get; set; default = false; } public bool needs_attention { get; set; default = false; }
public bool current { get; set; default = false; } public bool current { get; set; default = false; }
public bool unused { get; set; default = false; }
public SimpleActionGroup? actions { get; set; } public SimpleActionGroup? actions { get; set; }
public Container content { get; set; } public Container content { get; set; }