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">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">slide</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>
<placeholder/>
</child>

View File

@ -40,26 +40,18 @@ public class Tootle.Dialogs.MainWindow: Hdy.Window, ISavedWindow {
}
public bool back () {
var children = deck.get_children ();
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);
}
}
deck.navigate (Hdy.NavigationDirection.BACK);
return true;
}
bool clean_unused_views () {
deck.get_children ().foreach (c => {
var view = c as Views.Base;
if (view != null && view.unused)
view.destroy ();
});
return Source.REMOVE;
[GtkCallback]
void on_child_transition () {
if (deck.transition_running)
return;
Widget unused_child;
while ((unused_child = deck.get_adjacent_child (Hdy.NavigationDirection.FORWARD)) != null)
unused_child.destroy ();
}
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 bool needs_attention { get; set; default = false; }
public bool current { get; set; default = false; }
public bool unused { get; set; default = false; }
public SimpleActionGroup? actions { get; set; }
public Container content { get; set; }