From b5f1aba5c001130036d50139b1b869e14f04b64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Danielle=20For=C3=A9?= Date: Thu, 2 Feb 2023 14:02:17 -0800 Subject: [PATCH] Dialogs: connect to response, use present (#178) --- src/Dialogs/FileSelectDialog.vala | 18 +++++++++++------- src/MainWindow.vala | 17 +++++++++++------ src/PreferencesWindow.vala | 13 +++++++------ src/Widgets/TorrentListRow.vala | 9 +++++---- 4 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/Dialogs/FileSelectDialog.vala b/src/Dialogs/FileSelectDialog.vala index ade6273..1ada564 100644 --- a/src/Dialogs/FileSelectDialog.vala +++ b/src/Dialogs/FileSelectDialog.vala @@ -34,18 +34,22 @@ public class Torrential.Dialogs.FileSelectDialog : Granite.Dialog { } construct { - deletable = false; set_default_size (450, 300); var view = new Widgets.FileSelectTreeView (torrent); - var scrolled = new Gtk.ScrolledWindow (null, null); - scrolled.margin = 6; - scrolled.shadow_type = Gtk.ShadowType.IN; - scrolled.expand = true; + + var scrolled = new Gtk.ScrolledWindow (null, null) { + hexpand = true, + vexpand = true, + margin_end = 10, + margin_bottom = 9, + margin_start = 10 + }; scrolled.add (view); + scrolled.get_style_context ().add_class (Gtk.STYLE_CLASS_FRAME); + scrolled.show_all (); - Gtk.Box content = get_content_area () as Gtk.Box; - content.pack_start (scrolled, true, true, 0); + get_content_area ().add (scrolled); add_button (_("Close"), 0); diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 427bb03..6db966e 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -353,21 +353,26 @@ public class Torrential.MainWindow : Gtk.ApplicationWindow { } private void on_open (SimpleAction action) { - var filech = new Gtk.FileChooserNative (_("Open some torrents"), this, Gtk.FileChooserAction.OPEN, _("Open"), _("Cancel")); - filech.set_select_multiple (true); - var all_files_filter = new Gtk.FileFilter (); all_files_filter.set_filter_name (_("All files")); all_files_filter.add_pattern ("*"); + var torrent_files_filter = new Gtk.FileFilter (); torrent_files_filter.set_filter_name (_("Torrent files")); torrent_files_filter.add_mime_type ("application/x-bittorrent"); + + var filech = new Gtk.FileChooserNative (_("Open some torrents"), this, Gtk.FileChooserAction.OPEN, _("Open"), _("Cancel")); + filech.set_select_multiple (true); filech.add_filter (torrent_files_filter); filech.add_filter (all_files_filter); - if (filech.run () == Gtk.ResponseType.ACCEPT) { - add_files (filech.get_uris ()); - } + filech.show (); + + filech.response.connect ((response) => { + if (response == Gtk.ResponseType.ACCEPT) { + add_files (filech.get_uris ()); + } + }); } private void on_open_magnet () { diff --git a/src/PreferencesWindow.vala b/src/PreferencesWindow.vala index f77f81e..1db534e 100644 --- a/src/PreferencesWindow.vala +++ b/src/PreferencesWindow.vala @@ -118,14 +118,15 @@ public class Torrential.PreferencesWindow : Granite.Dialog { _("Cancel"), Gtk.ResponseType.CANCEL, _("Select"), Gtk.ResponseType.ACCEPT ); + chooser.present (); - var res = chooser.run (); + chooser.response.connect ((response) => { + if (response == Gtk.ResponseType.ACCEPT) { + settings.set_string ("download-folder", chooser.get_file ().get_path ()); + } - if (res == Gtk.ResponseType.ACCEPT) { - settings.set_string ("download-folder", chooser.get_file ().get_path ()); - } - - chooser.destroy (); + chooser.destroy (); + }); }); location_chooser_label = new Gtk.Label (Utils.get_downloads_folder ()); diff --git a/src/Widgets/TorrentListRow.vala b/src/Widgets/TorrentListRow.vala index 2136deb..513d068 100644 --- a/src/Widgets/TorrentListRow.vala +++ b/src/Widgets/TorrentListRow.vala @@ -137,10 +137,11 @@ public class Torrential.Widgets.TorrentListRow : Gtk.ListBoxRow { } public void edit_files () { - var dialog = new Dialogs.FileSelectDialog (torrent); - dialog.show_all (); - dialog.run (); - dialog.destroy (); + var dialog = new Dialogs.FileSelectDialog (torrent) { + transient_for = (Gtk.Window) get_toplevel () + }; + dialog.present (); + dialog.response.connect (dialog.destroy); } private string generate_completeness_text () {