Skip to content

Commit

Permalink
Toast: add dismiss signal with dismissal reason (#677)
Browse files Browse the repository at this point in the history
* Toast: always send close and add close reason

* Add new signal, deprecate old signal

* Update granite.metainfo.xml.in

---------

Co-authored-by: Jeremy Wootten <jeremywootten@gmail.com>
Co-authored-by: Ryan Kornheisl <ryan@skarva.tech>
  • Loading branch information
3 people authored May 1, 2024
1 parent ad95186 commit 2858234
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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);
}
}

0 comments on commit 2858234

Please sign in to comment.