From f1c8b09391189e54a4f89742e87a3c2441f32c47 Mon Sep 17 00:00:00 2001 From: Evan Paterakis Date: Tue, 9 Jul 2024 22:35:07 +0300 Subject: [PATCH] feat: get rid of weak ref --- src/Dialogs/MainWindow.vala | 1 + src/Views/Base.vala | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Dialogs/MainWindow.vala b/src/Dialogs/MainWindow.vala index c309642a1..6efe13af0 100644 --- a/src/Dialogs/MainWindow.vala +++ b/src/Dialogs/MainWindow.vala @@ -186,6 +186,7 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable { var content_base = navigation_view.visible_page.child as Views.Base; if (content_base != null && content_base.last_widget != null && (content_base.last_widget as Gtk.Widget) != null) content_base.last_widget.grab_focus (); + content_base.update_last_widget (true); } public bool back () { diff --git a/src/Views/Base.vala b/src/Views/Base.vala index 1eeba8c4a..b6ee8270e 100644 --- a/src/Views/Base.vala +++ b/src/Views/Base.vala @@ -13,7 +13,7 @@ public class Tuba.Views.Base : Adw.BreakpointBin { public int badge_number { get; set; default = 0; } public int uid { get; set; default = -1; } protected SimpleActionGroup actions { get; set; default = new SimpleActionGroup (); } - public weak Gtk.Widget? last_widget { get; private set; default=null; } + public Gtk.Widget? last_widget { get; private set; default=null; } public string empty_timeline_icon { get; set; default="tuba-background-app-ghost-symbolic"; } private bool _show_back_button = true; @@ -210,8 +210,8 @@ public class Tuba.Views.Base : Adw.BreakpointBin { status_button.sensitive = true; } - public void update_last_widget () { - this.last_widget = app.main_window.get_focus (); + public void update_last_widget (bool clear = false) { + this.last_widget = clear ? null : app.main_window.get_focus (); // Alternative way to grab focus of label links // Currently replaced by RichLabel's activate_link's // grab_focus as it's more reliable for this use case