[fractal/fractal-next] sidebar: Add selected-room property
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] sidebar: Add selected-room property
- Date: Wed, 5 May 2021 09:29:50 +0000 (UTC)
commit d97f425d99368358c3052dc4fe8271d698f0bb41
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Tue May 4 17:10:16 2021 +0200
sidebar: Add selected-room property
Bind it to Session's selected-room
data/resources/ui/session.ui | 1 +
src/session/sidebar/sidebar.rs | 36 +++++++++++++++++++++++++++++++++---
2 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/data/resources/ui/session.ui b/data/resources/ui/session.ui
index 4f5bcf58..a7784cd6 100644
--- a/data/resources/ui/session.ui
+++ b/data/resources/ui/session.ui
@@ -7,6 +7,7 @@
<object class="Sidebar" id="sidebar">
<property name="compact" bind-source="session" bind-property="folded" bind-flags="sync-create" />
<property name="categories" bind-source="Session" bind-property="categories"
bind-flags="sync-create" />
+ <property name="selected-room" bind-source="Session" bind-property="selected-room"
bind-flags="sync-create | bidirectional" />
</object>
</child>
<child>
diff --git a/src/session/sidebar/sidebar.rs b/src/session/sidebar/sidebar.rs
index feba712c..020ebd65 100644
--- a/src/session/sidebar/sidebar.rs
+++ b/src/session/sidebar/sidebar.rs
@@ -11,12 +11,13 @@ mod imp {
use super::*;
use glib::subclass::InitializingObject;
use once_cell::sync::Lazy;
- use std::cell::Cell;
+ use std::cell::{Cell, RefCell};
#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/org/gnome/FractalNext/sidebar.ui")]
pub struct Sidebar {
pub compact: Cell<bool>,
+ pub selected_room: RefCell<Option<Room>>,
#[template_child]
pub headerbar: TemplateChild<adw::HeaderBar>,
#[template_child]
@@ -60,6 +61,13 @@ mod imp {
Categories::static_type(),
glib::ParamFlags::WRITABLE,
),
+ glib::ParamSpec::new_object(
+ "selected-room",
+ "Selected Room",
+ "The selected room in this sidebar",
+ Room::static_type(),
+ glib::ParamFlags::READWRITE | glib::ParamFlags::EXPLICIT_NOTIFY,
+ ),
]
});
@@ -82,13 +90,18 @@ mod imp {
let categories = value.get().unwrap();
obj.set_categories(categories);
}
+ "selected-room" => {
+ let selected_room = value.get().unwrap();
+ obj.set_selected_room(selected_room);
+ }
_ => unimplemented!(),
}
}
- fn property(&self, _obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
+ fn property(&self, obj: &Self::Type, _id: usize, pspec: &glib::ParamSpec) -> glib::Value {
match pspec.name() {
"compact" => self.compact.get().to_value(),
+ "selected-room" => obj.selected_room().to_value(),
_ => unimplemented!(),
}
}
@@ -108,6 +121,11 @@ impl Sidebar {
glib::Object::new(&[]).expect("Failed to create Sidebar")
}
+ pub fn selected_room(&self) -> Option<Room> {
+ let priv_ = imp::Sidebar::from_instance(self);
+ priv_.selected_room.borrow().clone()
+ }
+
pub fn set_categories(&self, categories: Option<Categories>) {
let priv_ = imp::Sidebar::from_instance(self);
@@ -147,7 +165,7 @@ impl Sidebar {
let selection = gtk::SingleSelection::new(Some(&filter_model));
selection.connect_notify_local(Some("selected-item"), clone!(@weak self as obj => move |model,
_| {
if let Some(room) = model.selected_item().and_then(|row|
row.downcast_ref::<gtk::TreeListRow>().unwrap().item()).and_then(|o| o.downcast::<Room>().ok()) {
- obj.activate_action("session.show-room",
Some(&room.matrix_room().room_id().as_str().to_variant()));
+ obj.set_selected_room(Some(room));
}
}));
@@ -156,4 +174,16 @@ impl Sidebar {
priv_.listview.set_model(gtk::NONE_SELECTION_MODEL);
}
}
+
+ fn set_selected_room(&self, selected_room: Option<Room>) {
+ let priv_ = imp::Sidebar::from_instance(self);
+
+ if self.selected_room() == selected_room {
+ return;
+ }
+
+ priv_.selected_room.replace(selected_room);
+
+ self.notify("selected-room");
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]