[fractal/fractal-next] room: Emit order-changed signal



commit a975513cb7d8663654b2fac96673d9a65573408e
Author: Kai A. Hiller <V02460 gmail com>
Date:   Tue Aug 10 12:26:09 2021 +0200

    room: Emit order-changed signal

 src/session/room/room.rs | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
---
diff --git a/src/session/room/room.rs b/src/session/room/room.rs
index c7a6f902..ab32b8b1 100644
--- a/src/session/room/room.rs
+++ b/src/session/room/room.rs
@@ -41,6 +41,7 @@ use crate::RUNTIME;
 
 mod imp {
     use super::*;
+    use glib::subclass::Signal;
     use once_cell::sync::{Lazy, OnceCell};
     use std::cell::Cell;
     use std::collections::HashMap;
@@ -210,6 +211,13 @@ mod imp {
             }
         }
 
+        fn signals() -> &'static [Signal] {
+            static SIGNALS: Lazy<Vec<Signal>> = Lazy::new(|| {
+                vec![Signal::builder("order-changed", &[], <()>::static_type().into()).build()]
+            });
+            SIGNALS.as_ref()
+        }
+
         fn constructed(&self, obj: &Self::Type) {
             self.parent_constructed(obj);
 
@@ -293,6 +301,7 @@ impl Room {
 
         priv_.category.set(category);
         self.notify("category");
+        self.emit_by_name("order-changed", &[]).unwrap();
     }
 
     /// Set the category of this room.
@@ -596,6 +605,7 @@ impl Room {
         priv_.timeline.get().unwrap().append(batch);
         priv_.latest_change.replace(latest_change);
         self.notify("latest-change");
+        self.emit_by_name("order-changed", &[]).unwrap();
     }
 
     /// Returns the point in time this room received its latest event.
@@ -849,6 +859,15 @@ impl Room {
                 .collect(),
         )
     }
+
+    pub fn connect_order_changed<F: Fn(&Self) + 'static>(&self, f: F) -> glib::SignalHandlerId {
+        self.connect_local("order-changed", true, move |values| {
+            let obj = values[0].get::<Self>().unwrap();
+            f(&obj);
+            None
+        })
+        .unwrap()
+    }
 }
 
 trait GlibDateTime {


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