Skip to content

Commit 4703749

Browse files
authored
feat: global toast feedback (#620)
1 parent e92cf29 commit 4703749

File tree

9 files changed

+35
-15
lines changed

9 files changed

+35
-15
lines changed

data/ui/dialogs/main.ui

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@
1010
</object>
1111
</child>
1212
<child>
13-
<object class="GtkOverlay">
14-
<child type="overlay">
15-
<object class="TubaViewsMediaViewer" id="media_viewer">
16-
<property name="visible">0</property>
17-
</object>
18-
</child>
13+
<object class="AdwToastOverlay" id="toast_overlay">
1914
<property name="child">
20-
<object class="AdwOverlaySplitView" id="split_view">
21-
<property name="sidebar">
22-
<object class="TubaViewsSidebar" id="sidebar" />
23-
</property>
24-
<property name="content">
25-
<object class="AdwNavigationView" id="navigation_view">
26-
<signal name="notify::visible-page" handler="on_visible_page_changed" />
15+
<object class="GtkOverlay">
16+
<child type="overlay">
17+
<object class="TubaViewsMediaViewer" id="media_viewer">
18+
<property name="visible">0</property>
19+
</object>
20+
</child>
21+
<property name="child">
22+
<object class="AdwOverlaySplitView" id="split_view">
23+
<property name="sidebar">
24+
<object class="TubaViewsSidebar" id="sidebar" />
25+
</property>
26+
<property name="content">
27+
<object class="AdwNavigationView" id="navigation_view">
28+
<signal name="notify::visible-page" handler="on_visible_page_changed" />
29+
</object>
30+
</property>
2731
</object>
2832
</property>
2933
</object>

src/Application.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ namespace Tuba {
4040
public Streams app_streams { get {return Tuba.streams; } }
4141

4242
public signal void refresh ();
43-
public signal void toast (string title);
43+
public signal void toast (string title, uint timeout = 5);
4444

4545
#if DEV_MODE
4646
public signal void dev_new_post (Json.Node node);

src/Dialogs/MainWindow.vala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
66
// [GtkChild] unowned Gtk.Stack main_stack;
77
[GtkChild] unowned Views.MediaViewer media_viewer;
88
[GtkChild] unowned Adw.Breakpoint breakpoint;
9+
[GtkChild] unowned Adw.ToastOverlay toast_overlay;
910

1011
public bool is_mobile { get; set; default = false; }
1112

@@ -19,6 +20,14 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
1920
notify["is-mobile"].connect (update_selected_home_item);
2021
media_viewer.bind_property ("visible", split_view, "can-focus", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
2122
media_viewer.notify["visible"].connect (on_media_viewer_toggle);
23+
24+
app.toast.connect (add_toast);
25+
}
26+
27+
private void add_toast (string content, uint timeout = 0) {
28+
toast_overlay.add_toast (new Adw.Toast (content) {
29+
timeout = timeout
30+
});
2231
}
2332

2433
private weak Gtk.Widget? media_viewer_source_widget;

src/Services/Network/Network.vala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class Tuba.Network : GLib.Object {
7373

7474
public void on_error (int32 code, string message) {
7575
warning (message);
76-
app.toast (message);
76+
app.toast (message, 0);
7777
}
7878

7979
public Json.Node parse_node (Json.Parser parser) {

src/Views/MediaViewer.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
573573
if (page == null) return;
574574

575575
Host.copy (page.url);
576+
app.toast (_("Copied media url to clipboard"));
576577
}
577578

578579
private void open_in_browser () {
@@ -928,6 +929,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
928929
if (texture == null) return;
929930

930931
clipboard.set_texture (texture);
932+
app.toast (_("Copied image to clipboard"));
931933
debug ("End copy-media action");
932934
}
933935
}

src/Views/Profile.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ public class Tuba.Views.Profile : Views.Timeline {
221221
var copy_handle_action = new SimpleAction ("copy_handle", null);
222222
copy_handle_action.activate.connect (v => {
223223
Host.copy (profile.account.full_handle);
224+
app.toast (_("Copied handle to clipboard"));
224225
});
225226
actions.add_action (copy_handle_action);
226227

src/Widgets/Attachment/Image.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class Tuba.Widgets.Attachment.Image : Widgets.Attachment.Item {
8282

8383
Gdk.Clipboard clipboard = Gdk.Display.get_default ().get_clipboard ();
8484
clipboard.set_texture (texture);
85+
app.toast (_("Copied image to clipboard"));
8586
} catch (Error e) {
8687
var dlg = app.inform (_("Error"), e.message);
8788
dlg.present ();

src/Widgets/Attachment/Item.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class Tuba.Widgets.Attachment.Item : Adw.Bin {
1919

2020
private void copy_url () {
2121
Host.copy (entity.url);
22+
app.toast (_("Copied attachment url to clipboard"));
2223
}
2324

2425
private void open_in_browser () {
@@ -43,6 +44,7 @@ public class Tuba.Widgets.Attachment.Item : Adw.Bin {
4344
debug (@"Downloading file: $(url)");
4445
download.begin (url, file, (obj, res) => {
4546
download.end (res);
47+
app.toast (_("Saved Media"));
4648
});
4749
}
4850
} catch (Error e) {

src/Widgets/Status.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275

276276
private void copy_url () {
277277
Host.copy (status.formal.url ?? status.formal.account.url);
278+
app.toast (_("Copied post url to clipboard"));
278279
}
279280

280281
private void open_in_browser () {

0 commit comments

Comments
 (0)