[gnome-games/wip/exalm/tnum: 12/24] ui: Introduce UndoNotification
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/tnum: 12/24] ui: Introduce UndoNotification
- Date: Wed, 19 Aug 2020 18:22:23 +0000 (UTC)
commit 70c340c7d6322b2f589fc8354ec93ca13e70ceb2
Author: Neville <nevilleantony98 gmail com>
Date: Sat Aug 8 21:26:13 2020 +0530
ui: Introduce UndoNotification
This is a notification widget which can be used to provide an interface
to undo an recently done action. It accepts a notification label.
It also emits undo_button_clicked and close_button_clicked signals.
This will be used in the upcoming commits to allow undoing collection
deletion.
data/org.gnome.Games.gresource.xml | 1 +
data/ui/undo-notification.ui | 56 +++++++++++++++++++++++++++++++++
src/meson.build | 1 +
src/ui/undo-notification.vala | 63 ++++++++++++++++++++++++++++++++++++++
4 files changed, 121 insertions(+)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 0f6a64217..e0b862117 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -55,5 +55,6 @@
<file preprocess="xml-stripblanks">ui/shortcuts-window.ui</file>
<file preprocess="xml-stripblanks">ui/snapshot-row.ui</file>
<file preprocess="xml-stripblanks">ui/snapshots-list.ui</file>
+ <file preprocess="xml-stripblanks">ui/undo-notification.ui</file>
</gresource>
</gresources>
diff --git a/data/ui/undo-notification.ui b/data/ui/undo-notification.ui
new file mode 100644
index 000000000..248242e97
--- /dev/null
+++ b/data/ui/undo-notification.ui
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="3.24"/>
+ <template class="GamesUndoNotification" parent="GtkEventBox">
+ <property name="visible">True</property>
+ <property name="valign">start</property>"
+ <property name="halign">center</property>
+ <child>
+ <object class="GtkRevealer">
+ <property name="visible">True</property>
+ <property name="reveal-child" bind-source="GamesUndoNotification" bind-property="reveal"/>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="notification_label">
+ <property name="visible">True</property>
+ <property name="ellipsize">end</property>
+ <property name="xalign">0</property>
+ <property name="label" bind-source="GamesUndoNotification" bind-property="label"/>
+ <property name="margin-end">12</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Undo</property>
+ <property name="use-underline">True</property>
+ <signal name="clicked" handler="on_undo_button_clicked"/>
+ </object>
+ </child>
+ <child>
+ <object class="GtkButton">
+ <property name="visible">True</property>
+ <signal name="clicked" handler="on_notification_closed"/>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="icon-name">window-close-symbolic</property>
+ </object>
+ </child>
+ <style>
+ <class name="flat"/>
+ </style>
+ </object>
+ </child>
+ <style>
+ <class name="app-notification"/>
+ </style>
+ </object>
+ </child>
+ </object>
+ </child>
+ </template>
+</interface>
diff --git a/src/meson.build b/src/meson.build
index 0d44a3f2c..ca368448a 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -170,6 +170,7 @@ vala_sources = [
'ui/snapshots-list.vala',
'ui/titlebar-box.vala',
'ui/ui-view.vala',
+ 'ui/undo-notification.vala',
'utils/cairo-blur.vala',
'utils/composite-cover.vala',
diff --git a/src/ui/undo-notification.vala b/src/ui/undo-notification.vala
new file mode 100644
index 000000000..a7d6a5eb4
--- /dev/null
+++ b/src/ui/undo-notification.vala
@@ -0,0 +1,63 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+[GtkTemplate (ui = "/org/gnome/Games/ui/undo-notification.ui")]
+private class Games.UndoNotification : Gtk.EventBox {
+ private const uint NOTIFICATION_TIMEOUT_SEC = 3;
+
+ public signal void undo ();
+ public signal void closed ();
+
+ private uint timeout_id = 0;
+ private Gtk.EventControllerMotion motion_controller;
+
+ public bool reveal { get; set; }
+ public string label { get; set; }
+
+ construct {
+ motion_controller = new Gtk.EventControllerMotion (this);
+ motion_controller.propagation_phase = Gtk.PropagationPhase.TARGET;
+ motion_controller.enter.connect (() => {
+ remove_current_timeout_if_exists ();
+ });
+ motion_controller.leave.connect (() => {
+ set_new_timeout ();
+ });
+ }
+
+ public void show_notification () {
+ reveal = true;
+ remove_current_timeout_if_exists ();
+ set_new_timeout ();
+ }
+
+ private void set_new_timeout () {
+ timeout_id = Timeout.add_seconds (NOTIFICATION_TIMEOUT_SEC, () => {
+ timeout_id = 0;
+ reveal = false;
+ closed ();
+
+ return Source.REMOVE;
+ });
+ }
+
+ private void remove_current_timeout_if_exists () {
+ if (timeout_id != 0) {
+ Source.remove (timeout_id);
+ timeout_id = 0;
+ }
+ }
+
+ [GtkCallback]
+ private void on_undo_button_clicked () {
+ remove_current_timeout_if_exists ();
+ reveal = false;
+ undo ();
+ }
+
+ [GtkCallback]
+ private void on_notification_closed () {
+ remove_current_timeout_if_exists ();
+ reveal = false;
+ closed ();
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]