Skip to content

Commit

Permalink
Toast: always send close and add close reason
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Jan 9, 2024
1 parent 978d80f commit 2ff5682
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
10 changes: 10 additions & 0 deletions data/granite.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
<update_contact>contact_at_elementary.io</update_contact>

<releases>
<release version="7.5.0" date="2024-01-09" urgency="medium">
<description>
<p>Improvements:</p>
<ul>
<li>Add close reasons for Granite.Toast</li>
<li>Updated translations</li>
</ul>
</description>
</release>

<release version="7.4.0" date="2023-11-16" urgency="medium">
<description>
<p>Improvements:</p>
Expand Down
18 changes: 15 additions & 3 deletions lib/Widgets/Toast.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@
* {{../doc/images/Toast.png}}
*/
public class Granite.Toast : Gtk.Widget {
/**
* Reason why a Toast was closed
* @since 7.5.0
*/
[Version (since = "7.5.0")]
public enum CloseReason {
EXPIRED = 1,
DISMISSED = 2,
WITHDRAWN = 3
}

/**
* Emitted when the Toast is closed by activating the close button
* Emitted when the Toast is closed
*/
public signal void closed ();
public signal void closed (int reason_id);

/**
* Emitted when the default action button is activated
Expand Down Expand Up @@ -100,7 +110,7 @@ public class Granite.Toast : Gtk.Widget {
close_button.clicked.connect (() => {
revealer.reveal_child = false;
stop_timeout ();
closed ();
closed (CloseReason.DISMISSED);
});

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

timeout_id = GLib.Timeout.add (duration, () => {
revealer.reveal_child = false;
closed (CloseReason.EXPIRED);
timeout_id = 0;
return GLib.Source.REMOVE;
});
Expand Down Expand Up @@ -180,5 +191,6 @@ public class Granite.Toast : Gtk.Widget {
public void withdraw () {
stop_timeout ();
revealer.reveal_child = false;
closed (CloseReason.WITHDRAWN);
}
}
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ project(
'granite-7',
'vala', 'c',
meson_version: '>= 0.56.0',
version: '7.4.0'
version: '7.5.0'
)

if meson.get_compiler('vala').version().version_compare('<0.48.0')
Expand Down

0 comments on commit 2ff5682

Please sign in to comment.