[gnome-boxes/toast-revolution: 3/6] toast: Introduce a thin ToastOverlay derived from GtkOverlay




commit 79bca4d37c819e94e74bb33e10c44e85b4797a61
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Jan 20 18:52:40 2022 +0100

    toast: Introduce a thin ToastOverlay derived from GtkOverlay
    
    So we can abstract the dismissal of an old toast when popping a new
    one.

 data/ui/preferences/snapshots-page.ui |  2 +-
 src/preferences/snapshots-page.vala   | 29 ++++++-----------------------
 src/ui/meson.build                    |  1 +
 src/ui/toast-overlay.vala             | 24 ++++++++++++++++++++++++
 4 files changed, 32 insertions(+), 24 deletions(-)
---
diff --git a/data/ui/preferences/snapshots-page.ui b/data/ui/preferences/snapshots-page.ui
index 196ff9a8..71620cdb 100644
--- a/data/ui/preferences/snapshots-page.ui
+++ b/data/ui/preferences/snapshots-page.ui
@@ -11,7 +11,7 @@
         <property name="title" translatable="yes">Snapshots</property>
 
         <child>
-          <object class="GtkOverlay" id="toast_overlay">
+          <object class="BoxesToastOverlay" id="toast_overlay">
             <property name="visible">True</property>
             <property name="vexpand">True</property>
 
diff --git a/src/preferences/snapshots-page.vala b/src/preferences/snapshots-page.vala
index ef74481b..9f0438fe 100644
--- a/src/preferences/snapshots-page.vala
+++ b/src/preferences/snapshots-page.vala
@@ -6,22 +6,7 @@
     private LibvirtMachine machine;
 
     [GtkChild]
-    private unowned Gtk.Overlay toast_overlay;
-    private Boxes.Toast _toast;
-    private Boxes.Toast toast {
-        set {
-            if (_toast != null) {
-                _toast.dismiss ();
-            }
-
-            _toast = value;
-            toast_overlay.add_overlay (_toast);
-        }
-
-        get {
-            return _toast;
-        }
-    }
+    private unowned Boxes.ToastOverlay toast_overlay;
 
     [GtkChild]
     private unowned Hdy.PreferencesGroup preferences_group;
@@ -87,7 +72,9 @@ private async void fetch_snapshots () {
     private SnapshotListRow create_snapshot_row (GVir.DomainSnapshot snapshot) {
         var row = new SnapshotListRow (snapshot, machine);
         row.notify["activity-message"].connect (row_activity_changed);
-        row.display_toast.connect (display_toast);
+        row.display_toast.connect ((toast) => {
+            toast_overlay.display_toast (toast);
+        });
         row.is_current.connect (select_row);
 
         try {
@@ -118,10 +105,6 @@ private void select_row (SnapshotListRow selected_row) {
         listbox.select_row (selected_row);
     }
 
-    private void display_toast (Boxes.Toast new_toast) {
-        toast = new_toast;
-    }
-
     private int config_sort_func (Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
         if (row1.get_child () == add_button)
             return 1;
@@ -156,9 +139,9 @@ private async void create_snapshot () {
             var msg = _("Failed to create snapshot of %s").printf (machine.name);
             warning (e.message);
 
-            toast = new Boxes.Toast () {
+            toast_overlay.display_toast (new Boxes.Toast () {
                 message = msg
-            };
+            });
         }
         this.activity = null;
 
diff --git a/src/ui/meson.build b/src/ui/meson.build
index 3e1c96f6..094049f1 100644
--- a/src/ui/meson.build
+++ b/src/ui/meson.build
@@ -1,4 +1,5 @@
 vala_sources += files(
   'thumbnail.vala',
   'toast.vala',
+  'toast-overlay.vala',
 )
diff --git a/src/ui/toast-overlay.vala b/src/ui/toast-overlay.vala
new file mode 100644
index 00000000..0e2f9bd7
--- /dev/null
+++ b/src/ui/toast-overlay.vala
@@ -0,0 +1,24 @@
+// This file is part of GNOME Boxes. License: LGPLv2+
+
+private class Boxes.ToastOverlay : Gtk.Overlay {
+    private Boxes.Toast _toast;
+    private Boxes.Toast toast {
+        set {
+            if (_toast != null) {
+                _toast.dismiss ();
+            }
+
+            _toast = value;
+            add_overlay (_toast);
+        }
+
+        get {
+            return _toast;
+        }
+    }
+
+    public void display_toast (Boxes.Toast toast) {
+        this.toast = toast;
+    }
+
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]