Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MainWindow): check if last_widget is a GtkWidget before using #1061

Merged
merged 3 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Dialogs/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {

public void on_popped () {
var content_base = navigation_view.visible_page.child as Views.Base;
if (content_base != null && content_base.last_widget != null) content_base.last_widget.grab_focus ();
if (content_base != null && content_base.last_widget != null)
content_base.last_widget.grab_focus ();
content_base.update_last_widget (true);
}

public bool back () {
Expand Down
10 changes: 6 additions & 4 deletions src/Views/Base.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -171,7 +171,9 @@ public class Tuba.Views.Base : Adw.BreakpointBin {
}

#if !USE_LISTVIEW
public virtual void unbind_listboxes () {}
public virtual void unbind_listboxes () {
this.last_widget = null;
}
#endif

protected virtual void build_actions () {}
Expand Down Expand Up @@ -210,8 +212,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
Expand Down
Loading