[fractal/fractal-next] sidebar: Use GtkExpressions for RoomRow when possible
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] sidebar: Use GtkExpressions for RoomRow when possible
- Date: Tue, 18 Jan 2022 17:07:43 +0000 (UTC)
commit 87d1fbd5ecec2e2d5df427ca2a6a2677c23c143f
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Thu Jan 6 14:59:55 2022 +0100
sidebar: Use GtkExpressions for RoomRow when possible
data/resources/ui/sidebar-room-row.ui | 16 ++++++++++++-
src/session/sidebar/room_row.rs | 45 +++++++----------------------------
2 files changed, 23 insertions(+), 38 deletions(-)
---
diff --git a/data/resources/ui/sidebar-room-row.ui b/data/resources/ui/sidebar-room-row.ui
index 68410ddb..8236b411 100644
--- a/data/resources/ui/sidebar-room-row.ui
+++ b/data/resources/ui/sidebar-room-row.ui
@@ -7,11 +7,21 @@
<child>
<object class="ComponentsAvatar" id="avatar">
<property name="size">24</property>
+ <binding name="item">
+ <lookup name="avatar">
+ <lookup name="room">SidebarRoomRow</lookup>
+ </lookup>
+ </binding>
</object>
</child>
<child>
<object class="GtkLabel" id="display_name">
<property name="ellipsize">end</property>
+ <binding name="label">
+ <lookup name="display-name">
+ <lookup name="room">SidebarRoomRow</lookup>
+ </lookup>
+ </binding>
</object>
</child>
<child type="end">
@@ -20,6 +30,11 @@
<property name="halign">end</property>
<property name="valign">center</property>
<property name="yalign">1.0</property>
+ <binding name="label">
+ <lookup name="notification-count">
+ <lookup name="room">SidebarRoomRow</lookup>
+ </lookup>
+ </binding>
<style>
<class name="notification_count"/>
</style>
@@ -29,4 +44,3 @@
</child>
</template>
</interface>
-
diff --git a/src/session/sidebar/room_row.rs b/src/session/sidebar/room_row.rs
index fba21688..5b6540bb 100644
--- a/src/session/sidebar/room_row.rs
+++ b/src/session/sidebar/room_row.rs
@@ -1,4 +1,3 @@
-use crate::components::Avatar;
use adw::subclass::prelude::BinImpl;
use gtk::{glib, glib::clone, prelude::*, subclass::prelude::*, CompositeTemplate};
@@ -14,11 +13,9 @@ mod imp {
#[template(resource = "/org/gnome/FractalNext/sidebar-room-row.ui")]
pub struct RoomRow {
pub room: RefCell<Option<Room>>,
- pub bindings: RefCell<Vec<glib::Binding>>,
+ pub binding: RefCell<Option<glib::Binding>>,
pub signal_handler: RefCell<Option<SignalHandlerId>>,
#[template_child]
- pub avatar: TemplateChild<Avatar>,
- #[template_child]
pub display_name: TemplateChild<gtk::Label>,
#[template_child]
pub notification_count: TemplateChild<gtk::Label>,
@@ -31,7 +28,6 @@ mod imp {
type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) {
- Avatar::static_type();
Self::bind_template(klass);
}
@@ -117,31 +113,14 @@ impl RoomRow {
if let Some(id) = priv_.signal_handler.take() {
room.disconnect(id);
}
- }
-
- let mut bindings = priv_.bindings.borrow_mut();
- while let Some(binding) = bindings.pop() {
- binding.unbind();
+ if let Some(binding) = priv_.binding.take() {
+ binding.unbind();
+ }
}
if let Some(ref room) = room {
- let display_name_binding = room
- .bind_property("display-name", &priv_.display_name.get(), "label")
- .flags(glib::BindingFlags::SYNC_CREATE)
- .build()
- .unwrap();
-
- let notification_count_binding = room
- .bind_property(
- "notification-count",
- &priv_.notification_count.get(),
- "label",
- )
- .flags(glib::BindingFlags::SYNC_CREATE)
- .build()
- .unwrap();
- let notification_count_vislbe_binding = room
- .bind_property(
+ priv_.binding.replace(Some(
+ room.bind_property(
"notification-count",
&priv_.notification_count.get(),
"visible",
@@ -149,7 +128,8 @@ impl RoomRow {
.flags(glib::BindingFlags::SYNC_CREATE)
.transform_from(|_, value| Some((value.get::<u64>().unwrap() > 0).to_value()))
.build()
- .unwrap();
+ .unwrap(),
+ ));
priv_.signal_handler.replace(Some(room.connect_notify_local(
Some("highlight"),
@@ -159,16 +139,7 @@ impl RoomRow {
)));
self.set_highlight();
-
- bindings.append(&mut vec![
- display_name_binding,
- notification_count_binding,
- notification_count_vislbe_binding,
- ]);
}
- priv_
- .avatar
- .set_item(room.clone().map(|room| room.avatar().clone()));
priv_.room.replace(room);
self.notify("room");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]