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

Toast: add dismiss signal with dismissal reason #677

Merged
merged 7 commits into from
May 1, 2024
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
4 changes: 4 additions & 0 deletions data/granite.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<releases>
<release version="7.5.0" date="2023-04-29" urgency="medium">
<description>
<p>New Features:</p>
<ul>
<li>Toast: add a new dismissed signal that includes the reason for dismissal</li>
</ul>
<p>Improvements:</p>
<ul>
<li>Make building Demo optional</li>
Expand Down
19 changes: 19 additions & 0 deletions lib/Widgets/Toast.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,28 @@
* {{../doc/images/Toast.png}}
*/
public class Granite.Toast : Gtk.Widget {
/**
* Reason why a Toast was dismissed
* @since 7.5.0
*/
[Version (since = "7.5.0")]
public enum DismissReason {
EXPIRED = 1,
CLOSED = 2,
WITHDRAWN = 3
}

/**
* Emitted when the Toast is closed by activating the close button
*/
[Version (deprecated = true, deprecated_since = "7.5.0", replacement = "dismissed")]
public signal void closed ();

/**
* Emitted when the Toast has been dismissed
*/
public signal void dismissed (DismissReason reason);

/**
* Emitted when the default action button is activated
*/
Expand Down Expand Up @@ -101,6 +117,7 @@ public class Granite.Toast : Gtk.Widget {
revealer.reveal_child = false;
stop_timeout ();
closed ();
dismissed (DismissReason.CLOSED);
});

default_action_button.clicked.connect (() => {
Expand Down Expand Up @@ -133,6 +150,7 @@ public class Granite.Toast : Gtk.Widget {

timeout_id = GLib.Timeout.add (duration, () => {
revealer.reveal_child = false;
dismissed (DismissReason.EXPIRED);
timeout_id = 0;
return GLib.Source.REMOVE;
});
Expand Down Expand Up @@ -180,5 +198,6 @@ public class Granite.Toast : Gtk.Widget {
public void withdraw () {
stop_timeout ();
revealer.reveal_child = false;
dismissed (DismissReason.WITHDRAWN);
}
}