Skip to content

Commit

Permalink
Dialogs: connect to response, use present (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Feb 2, 2023
1 parent 398d173 commit b5f1aba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 23 deletions.
18 changes: 11 additions & 7 deletions src/Dialogs/FileSelectDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
17 changes: 11 additions & 6 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
13 changes: 7 additions & 6 deletions src/PreferencesWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ());
Expand Down
9 changes: 5 additions & 4 deletions src/Widgets/TorrentListRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit b5f1aba

Please sign in to comment.