From bb6c6dd4ede1fae96f49424e68cc40028b5c0f91 Mon Sep 17 00:00:00 2001 From: cloppingemu <12227963+cloppingemu@users.noreply.github.com> Date: Fri, 13 Dec 2024 10:03:28 +1100 Subject: [PATCH] Feature/default focus (#7102) * Setting default focus in Open URL and Add Tracker dialog box * Additional cleanup to remove duplication of responsibility in setting focus * Removing now un-necessary code in TorrentUrlChooserDialog.ui * Using activates-default property to enable default action in torrent url chooser and tracker adder * removing un-necessary focus * Adding missing property to the accept buttons. * Removing unintended whitespace change in TorrentUrlChooserDialog * Use `True` instead of `1` for booleans (GTK3) --- gtk/DetailsDialog.cc | 7 +++++++ gtk/OptionsDialog.cc | 16 +++++++--------- gtk/ui/gtk3/AddTrackerDialog.ui | 2 ++ gtk/ui/gtk3/TorrentUrlChooserDialog.ui | 2 ++ gtk/ui/gtk4/AddTrackerDialog.ui | 1 + gtk/ui/gtk4/TorrentUrlChooserDialog.ui | 1 + 6 files changed, 20 insertions(+), 9 deletions(-) diff --git a/gtk/DetailsDialog.cc b/gtk/DetailsDialog.cc index fd3a5ec8f..4200412ba 100644 --- a/gtk/DetailsDialog.cc +++ b/gtk/DetailsDialog.cc @@ -2341,6 +2341,13 @@ AddTrackerDialog::AddTrackerDialog( set_title(fmt::format(_("{torrent_name} - Add Tracker"), fmt::arg("torrent_name", tr_torrentName(torrent)))); set_transient_for(parent); + auto* const accept = get_widget_for_response(TR_GTK_RESPONSE_TYPE(ACCEPT)); +#if GTKMM_CHECK_VERSION(4, 0, 0) + set_default_widget(*accept); +#else + set_default(*accept); +#endif + gtr_paste_clipboard_url_into_entry(*url_entry_); } diff --git a/gtk/OptionsDialog.cc b/gtk/OptionsDialog.cc index 63463f014..06b83d511 100644 --- a/gtk/OptionsDialog.cc +++ b/gtk/OptionsDialog.cc @@ -427,16 +427,14 @@ TorrentUrlChooserDialog::TorrentUrlChooserDialog( set_transient_for(parent); auto* const e = gtr_get_widget(builder, "url_entry"); + auto* const accept = get_widget_for_response(TR_GTK_RESPONSE_TYPE(ACCEPT)); gtr_paste_clipboard_url_into_entry(*e); - signal_response().connect([this, e, core](int response) { onOpenURLResponse(response, *e, core); }); +#if GTKMM_CHECK_VERSION(4, 0, 0) + set_default_widget(*accept); +#else + set_default(*accept); +#endif - if (e->get_text_length() == 0) - { - e->grab_focus(); - } - else - { - get_widget_for_response(TR_GTK_RESPONSE_TYPE(ACCEPT))->grab_focus(); - } + signal_response().connect([this, e, core](int response) { onOpenURLResponse(response, *e, core); }); } diff --git a/gtk/ui/gtk3/AddTrackerDialog.ui b/gtk/ui/gtk3/AddTrackerDialog.ui index 9a31dfe9f..399932fbe 100644 --- a/gtk/ui/gtk3/AddTrackerDialog.ui +++ b/gtk/ui/gtk3/AddTrackerDialog.ui @@ -34,6 +34,7 @@ _Add True True + True True True @@ -94,6 +95,7 @@ 400 True True + True True diff --git a/gtk/ui/gtk3/TorrentUrlChooserDialog.ui b/gtk/ui/gtk3/TorrentUrlChooserDialog.ui index 2b71e63ad..9ad13bbc0 100644 --- a/gtk/ui/gtk3/TorrentUrlChooserDialog.ui +++ b/gtk/ui/gtk3/TorrentUrlChooserDialog.ui @@ -34,6 +34,7 @@ _Open True True + True True True @@ -94,6 +95,7 @@ 400 True True + True True diff --git a/gtk/ui/gtk4/AddTrackerDialog.ui b/gtk/ui/gtk4/AddTrackerDialog.ui index b8b09c318..0e8937e32 100644 --- a/gtk/ui/gtk4/AddTrackerDialog.ui +++ b/gtk/ui/gtk4/AddTrackerDialog.ui @@ -42,6 +42,7 @@ 400 1 + 1 1 1 diff --git a/gtk/ui/gtk4/TorrentUrlChooserDialog.ui b/gtk/ui/gtk4/TorrentUrlChooserDialog.ui index fa5d576ad..a96fa6f6c 100644 --- a/gtk/ui/gtk4/TorrentUrlChooserDialog.ui +++ b/gtk/ui/gtk4/TorrentUrlChooserDialog.ui @@ -42,6 +42,7 @@ 400 1 + 1 1 1