Skip to content

Commit bb60f42

Browse files
authored
feat: open containing folder action (#1592)
1 parent 2165daa commit bb60f42

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

src/Application.vala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ namespace Tuba {
5050
public signal void refresh_featured ();
5151
public signal void relationship_invalidated (API.Relationship new_relationship);
5252
public signal void remove_user_id (string user_id);
53-
public signal void toast (string title, uint timeout = 5);
53+
// TODO: maybe just pass Adw.Toasts at this point
54+
public signal void toast (string title, uint timeout = 5, string? action_name = null, GLib.Variant? action_target = null, string? action_label = null);
5455

5556
#if DEV_MODE
5657
public signal void dev_new_post (Json.Node node);
@@ -94,7 +95,8 @@ namespace Tuba {
9495
{ "open-scheduled-posts", open_scheduled_posts },
9596
{ "open-draft-posts", open_draft_posts },
9697
{ "open-admin-dashboard", open_admin_dashboard },
97-
{ "open-last-fediwrapped", open_last_fediwrapped }
98+
{ "open-last-fediwrapped", open_last_fediwrapped },
99+
{ "open-containing-folder", open_containing_folder, "s" }
98100
};
99101

100102
#if DEV_MODE
@@ -547,6 +549,11 @@ namespace Tuba {
547549
accounts.active.open_latest_wrapped ();
548550
}
549551

552+
public void open_containing_folder (GLib.SimpleAction action, GLib.Variant? value) {
553+
if (value == null) return;
554+
Utils.Host.open_containing_folder.begin (value.get_string ());
555+
}
556+
550557
private void close_sidebar () {
551558
var split_view = app.main_window.split_view;
552559
if (split_view.collapsed)

src/Dialogs/MainWindow.vala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
3838
Tuba.toggle_css (split_view, settings.darken_images_on_dark_mode, "ttl-darken-images");
3939
}
4040

41-
private void add_toast (string content, uint timeout = 0) {
41+
private void add_toast (string content, uint timeout = 0, string? action_name = null, GLib.Variant? action_target = null, string? action_label = null) {
4242
toast_overlay.add_toast (new Adw.Toast (content) {
43-
timeout = timeout
43+
timeout = timeout,
44+
action_name = action_name,
45+
action_target = action_target,
46+
button_label = action_label
4447
});
4548
}
4649

src/Dialogs/NewAccount.vala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ public class Tuba.Dialogs.NewAccount: Adw.Window {
7373
instance_entry.grab_focus ();
7474
}
7575

76-
private void add_toast (string content, uint timeout = 0) {
76+
private void add_toast (string content, uint timeout = 0, string? action_name = null, GLib.Variant? action_target = null, string? action_label = null) {
7777
toast_overlay.add_toast (new Adw.Toast (content) {
78-
timeout = timeout
78+
timeout = timeout,
79+
action_name = action_name,
80+
action_target = action_target,
81+
button_label = action_label
7982
});
8083
}
8184

src/Utils/Host.vala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public class Tuba.Utils.Host {
4949
return true;
5050
}
5151

52+
public static async void open_containing_folder (string path) {
53+
debug (@"Opening containing folder for $path");
54+
55+
try {
56+
yield (new Gtk.FileLauncher (File.new_for_path (path))).open_containing_folder (app.active_window, null);
57+
} catch (Error e) {
58+
warning (@"Error opening containing folder for \"$path\": $(e.message)");
59+
}
60+
}
61+
5262
public static void copy (string str) {
5363
Gdk.Display display = Gdk.Display.get_default ();
5464
if (display == null) return;

src/Widgets/Attachment/Item.vala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,17 @@ public class Tuba.Widgets.Attachment.Item : Adw.Bin {
4141
if (file != null) {
4242
debug (@"Downloading file: $(url)");
4343
bool success = yield download (url, file);
44-
app.toast (success ? _("Saved Media") : _("Couldn't Save Media"));
44+
45+
if (success) {
46+
app.toast (
47+
_("Saved Media"), 5, "app.open-containing-folder",
48+
new GLib.Variant.string (file.get_path ()),
49+
// translators: label on toast shown when downloading an attachment that opens the folder containing the file
50+
_("Open Folder")
51+
);
52+
} else {
53+
app.toast (_("Couldn't Save Media"));
54+
}
4555
}
4656
} catch (Error e) {
4757
// User dismissing the dialog also ends here so don't make it sound like

0 commit comments

Comments
 (0)