Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: global toast feedback #620

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions data/ui/dialogs/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
</object>
</child>
<child>
<object class="GtkOverlay">
<child type="overlay">
<object class="TubaViewsMediaViewer" id="media_viewer">
<property name="visible">0</property>
</object>
</child>
<object class="AdwToastOverlay" id="toast_overlay">
<property name="child">
<object class="AdwOverlaySplitView" id="split_view">
<property name="sidebar">
<object class="TubaViewsSidebar" id="sidebar" />
</property>
<property name="content">
<object class="AdwNavigationView" id="navigation_view">
<signal name="notify::visible-page" handler="on_visible_page_changed" />
<object class="GtkOverlay">
<child type="overlay">
<object class="TubaViewsMediaViewer" id="media_viewer">
<property name="visible">0</property>
</object>
</child>
<property name="child">
<object class="AdwOverlaySplitView" id="split_view">
<property name="sidebar">
<object class="TubaViewsSidebar" id="sidebar" />
</property>
<property name="content">
<object class="AdwNavigationView" id="navigation_view">
<signal name="notify::visible-page" handler="on_visible_page_changed" />
</object>
</property>
</object>
</property>
</object>
Expand Down
2 changes: 1 addition & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace Tuba {
public Streams app_streams { get {return Tuba.streams; } }

public signal void refresh ();
public signal void toast (string title);
public signal void toast (string title, uint timeout = 5);

#if DEV_MODE
public signal void dev_new_post (Json.Node node);
Expand Down
9 changes: 9 additions & 0 deletions src/Dialogs/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
// [GtkChild] unowned Gtk.Stack main_stack;
[GtkChild] unowned Views.MediaViewer media_viewer;
[GtkChild] unowned Adw.Breakpoint breakpoint;
[GtkChild] unowned Adw.ToastOverlay toast_overlay;

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

Expand All @@ -19,6 +20,14 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
notify["is-mobile"].connect (update_selected_home_item);
media_viewer.bind_property ("visible", split_view, "can-focus", GLib.BindingFlags.SYNC_CREATE | GLib.BindingFlags.INVERT_BOOLEAN);
media_viewer.notify["visible"].connect (on_media_viewer_toggle);

app.toast.connect (add_toast);
}

private void add_toast (string content, uint timeout = 0) {
toast_overlay.add_toast (new Adw.Toast (content) {
timeout = timeout
});
}

private weak Gtk.Widget? media_viewer_source_widget;
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Network/Network.vala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class Tuba.Network : GLib.Object {

public void on_error (int32 code, string message) {
warning (message);
app.toast (message);
app.toast (message, 0);
}

public Json.Node parse_node (Json.Parser parser) {
Expand Down
2 changes: 2 additions & 0 deletions src/Views/MediaViewer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
if (page == null) return;

Host.copy (page.url);
app.toast (_("Copied media url to clipboard"));
}

private void open_in_browser () {
Expand Down Expand Up @@ -913,6 +914,7 @@ public class Tuba.Views.MediaViewer : Gtk.Widget, Gtk.Buildable, Adw.Swipeable {
if (texture == null) return;

clipboard.set_texture (texture);
app.toast (_("Copied image to clipboard"));
debug ("End copy-media action");
}
}
1 change: 1 addition & 0 deletions src/Views/Profile.vala
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public class Tuba.Views.Profile : Views.Timeline {
var copy_handle_action = new SimpleAction ("copy_handle", null);
copy_handle_action.activate.connect (v => {
Host.copy (profile.account.full_handle);
app.toast (_("Copied handle to clipboard"));
});
actions.add_action (copy_handle_action);

Expand Down
1 change: 1 addition & 0 deletions src/Widgets/Attachment/Image.vala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class Tuba.Widgets.Attachment.Image : Widgets.Attachment.Item {

Gdk.Clipboard clipboard = Gdk.Display.get_default ().get_clipboard ();
clipboard.set_texture (texture);
app.toast (_("Copied image to clipboard"));
} catch (Error e) {
var dlg = app.inform (_("Error"), e.message);
dlg.present ();
Expand Down
2 changes: 2 additions & 0 deletions src/Widgets/Attachment/Item.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Tuba.Widgets.Attachment.Item : Adw.Bin {

private void copy_url () {
Host.copy (entity.url);
app.toast (_("Copied attachment url to clipboard"));
}

private void open_in_browser () {
Expand All @@ -43,6 +44,7 @@ public class Tuba.Widgets.Attachment.Item : Adw.Bin {
debug (@"Downloading file: $(url)…");
download.begin (url, file, (obj, res) => {
download.end (res);
app.toast (_("Saved Media"));
});
}
} catch (Error e) {
Expand Down
1 change: 1 addition & 0 deletions src/Widgets/Status.vala
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@

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

private void open_in_browser () {
Expand Down