diff --git a/data/resources/style.css b/data/resources/style.css index 0a57ceb9..cc2847e7 100644 --- a/data/resources/style.css +++ b/data/resources/style.css @@ -289,12 +289,12 @@ sidebar-row:not(.drop-mode) > *:hover { background-color: alpha(currentColor, 0.19); } -sidebar-row sidebar-entry { +sidebar-row icon-item { background: none; font-weight: bold; } -sidebar-row sidebar-entry image { +sidebar-row icon-item image { min-width: 24px; /* Same width as avatars, so the text is aligned */ } @@ -345,7 +345,7 @@ sidebar-row.drop-empty > * { color: @accent_color; } -sidebar-row entry.forget { +sidebar-row icon-item.forget { color: @error_color; background: none; } diff --git a/po/POTFILES.in b/po/POTFILES.in index 199889f9..d766a7a3 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -31,7 +31,7 @@ src/session/model/room/member_role.rs src/session/model/room/mod.rs src/session/model/room_list/mod.rs src/session/model/sidebar/category/category_type.rs -src/session/model/sidebar/entry/entry_type.rs +src/session/model/sidebar/icon_item.rs src/session/view/account_settings/devices_page/device_list.rs src/session/view/account_settings/devices_page/device_row.rs src/session/view/account_settings/devices_page/device_row.ui diff --git a/src/session/model/mod.rs b/src/session/model/mod.rs index 371af709..3d34dcee 100644 --- a/src/session/model/mod.rs +++ b/src/session/model/mod.rs @@ -21,7 +21,7 @@ pub use self::{ session::{Session, SessionState}, settings::SessionSettings, sidebar::{ - Category, CategoryType, Entry, EntryType, ItemList, Selection, SidebarItem, + Category, CategoryType, IconItem, ItemList, ItemType, Selection, SidebarItem, SidebarItemImpl, SidebarListModel, }, user::{User, UserActions, UserExt}, diff --git a/src/session/model/sidebar/entry/entry_type.rs b/src/session/model/sidebar/entry/entry_type.rs deleted file mode 100644 index 609c0545..00000000 --- a/src/session/model/sidebar/entry/entry_type.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::fmt; - -use gettextrs::gettext; -use gtk::glib; - -#[derive(Debug, Default, Hash, Eq, PartialEq, Clone, Copy, glib::Enum)] -#[repr(u32)] -#[enum_type(name = "EntryType")] -pub enum EntryType { - #[default] - Explore = 0, - Forget = 1, -} - -impl fmt::Display for EntryType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let label = match self { - EntryType::Explore => gettext("Explore"), - EntryType::Forget => gettext("Forget Room"), - }; - - f.write_str(&label) - } -} diff --git a/src/session/model/sidebar/entry/mod.rs b/src/session/model/sidebar/icon_item.rs similarity index 54% rename from src/session/model/sidebar/entry/mod.rs rename to src/session/model/sidebar/icon_item.rs index 418bd50d..41672bc3 100644 --- a/src/session/model/sidebar/entry/mod.rs +++ b/src/session/model/sidebar/icon_item.rs @@ -1,33 +1,63 @@ +use std::fmt; + +use gettextrs::gettext; use gtk::{glib, prelude::*, subclass::prelude::*}; -mod entry_type; - -pub use self::entry_type::EntryType; use super::{CategoryType, SidebarItem, SidebarItemExt, SidebarItemImpl}; +#[derive(Debug, Default, Hash, Eq, PartialEq, Clone, Copy, glib::Enum)] +#[repr(u32)] +#[enum_type(name = "ItemType")] +pub enum ItemType { + #[default] + Explore = 0, + Forget = 1, +} + +impl ItemType { + /// The icon name for this item type. + pub fn icon_name(&self) -> &'static str { + match self { + Self::Explore => "explore-symbolic", + Self::Forget => "user-trash-symbolic", + } + } +} + +impl fmt::Display for ItemType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let label = match self { + Self::Explore => gettext("Explore"), + Self::Forget => gettext("Forget Room"), + }; + + f.write_str(&label) + } +} + mod imp { use std::cell::Cell; use super::*; #[derive(Debug, Default)] - pub struct Entry { - pub type_: Cell, + pub struct IconItem { + pub type_: Cell, } #[glib::object_subclass] - impl ObjectSubclass for Entry { - const NAME: &'static str = "Entry"; - type Type = super::Entry; + impl ObjectSubclass for IconItem { + const NAME: &'static str = "IconItem"; + type Type = super::IconItem; type ParentType = SidebarItem; } - impl ObjectImpl for Entry { + impl ObjectImpl for IconItem { fn properties() -> &'static [glib::ParamSpec] { use once_cell::sync::Lazy; static PROPERTIES: Lazy> = Lazy::new(|| { vec![ - glib::ParamSpecEnum::builder::("type") + glib::ParamSpecEnum::builder::("type") .construct_only() .build(), glib::ParamSpecString::builder("display-name") @@ -63,46 +93,40 @@ mod imp { } } - impl SidebarItemImpl for Entry { + impl SidebarItemImpl for IconItem { fn update_visibility(&self, for_category: CategoryType) { let obj = self.obj(); match obj.type_() { - EntryType::Explore => obj.set_visible(true), - EntryType::Forget => obj.set_visible(for_category == CategoryType::Left), + ItemType::Explore => obj.set_visible(true), + ItemType::Forget => obj.set_visible(for_category == CategoryType::Left), } } } } glib::wrapper! { - /// A top-level row in the sidebar without children. - /// - /// Entry is supposed to be used in a TreeListModel, but as it does not have - /// any children, implementing the ListModel interface is not required. - pub struct Entry(ObjectSubclass) @extends SidebarItem; + /// A top-level row in the sidebar with an icon. + pub struct IconItem(ObjectSubclass) @extends SidebarItem; } -impl Entry { - pub fn new(type_: EntryType) -> Self { +impl IconItem { + pub fn new(type_: ItemType) -> Self { glib::Object::builder().property("type", type_).build() } - /// The type of this entry. - pub fn type_(&self) -> EntryType { + /// The type of this item. + pub fn type_(&self) -> ItemType { self.imp().type_.get() } - /// The display name of this entry. + /// The display name of this item. pub fn display_name(&self) -> String { self.type_().to_string() } - /// The icon name used for this entry. - pub fn icon_name(&self) -> Option<&str> { - match self.type_() { - EntryType::Explore => Some("explore-symbolic"), - EntryType::Forget => Some("user-trash-symbolic"), - } + /// The icon name used for this item. + pub fn icon_name(&self) -> &'static str { + self.type_().icon_name() } } diff --git a/src/session/model/sidebar/item_list.rs b/src/session/model/sidebar/item_list.rs index 7fcc33a7..67366ccf 100644 --- a/src/session/model/sidebar/item_list.rs +++ b/src/session/model/sidebar/item_list.rs @@ -1,6 +1,6 @@ use gtk::{gio, glib, glib::clone, prelude::*, subclass::prelude::*}; -use super::{Category, CategoryType, Entry, EntryType, SidebarItem, SidebarItemExt}; +use super::{Category, CategoryType, IconItem, ItemType, SidebarItem, SidebarItemExt}; use crate::session::model::{RoomList, VerificationList}; mod imp { @@ -77,14 +77,14 @@ mod imp { let verification_list = obj.verification_list(); let list: [SidebarItem; 8] = [ - Entry::new(EntryType::Explore).upcast(), + IconItem::new(ItemType::Explore).upcast(), Category::new(CategoryType::VerificationRequest, verification_list).upcast(), Category::new(CategoryType::Invited, room_list).upcast(), Category::new(CategoryType::Favorite, room_list).upcast(), Category::new(CategoryType::Normal, room_list).upcast(), Category::new(CategoryType::LowPriority, room_list).upcast(), Category::new(CategoryType::Left, room_list).upcast(), - Entry::new(EntryType::Forget).upcast(), + IconItem::new(ItemType::Forget).upcast(), ]; self.list.set(list.clone()).unwrap(); diff --git a/src/session/model/sidebar/mod.rs b/src/session/model/sidebar/mod.rs index abfd3d32..0a994ec5 100644 --- a/src/session/model/sidebar/mod.rs +++ b/src/session/model/sidebar/mod.rs @@ -1,5 +1,5 @@ mod category; -mod entry; +mod icon_item; mod item; mod item_list; mod list_model; @@ -7,7 +7,7 @@ mod selection; pub use self::{ category::{Category, CategoryType}, - entry::{Entry, EntryType}, + icon_item::{IconItem, ItemType}, item::{SidebarItem, SidebarItemExt, SidebarItemImpl}, item_list::ItemList, list_model::SidebarListModel, diff --git a/src/session/view/content/mod.rs b/src/session/view/content/mod.rs index d037b93c..bd575c8f 100644 --- a/src/session/view/content/mod.rs +++ b/src/session/view/content/mod.rs @@ -12,7 +12,7 @@ use self::{ verification::IdentityVerificationWidget, }; use crate::session::model::{ - Entry, EntryType, IdentityVerification, Room, RoomType, Session, VerificationMode, + IconItem, IdentityVerification, ItemType, Room, RoomType, Session, VerificationMode, }; mod imp { @@ -252,8 +252,8 @@ impl Content { } } Some(o) - if o.is::() - && o.downcast_ref::().unwrap().type_() == EntryType::Explore => + if o.downcast_ref::() + .is_some_and(|i| i.type_() == ItemType::Explore) => { imp.explore.init(); imp.stack.set_visible_child(&*imp.explore); diff --git a/src/session/view/sidebar/entry_row.rs b/src/session/view/sidebar/icon_item_row.rs similarity index 57% rename from src/session/view/sidebar/entry_row.rs rename to src/session/view/sidebar/icon_item_row.rs index 8d6ed815..00aa9883 100644 --- a/src/session/view/sidebar/entry_row.rs +++ b/src/session/view/sidebar/icon_item_row.rs @@ -1,7 +1,7 @@ use adw::subclass::prelude::BinImpl; use gtk::{self, glib, prelude::*, subclass::prelude::*, CompositeTemplate}; -use crate::session::model::{Entry, EntryType}; +use crate::session::model::{IconItem, ItemType}; mod imp { use std::cell::RefCell; @@ -11,20 +11,20 @@ mod imp { use super::*; #[derive(Debug, Default, CompositeTemplate)] - #[template(resource = "/org/gnome/Fractal/ui/session/view/sidebar/entry_row.ui")] - pub struct EntryRow { - pub entry: RefCell>, + #[template(resource = "/org/gnome/Fractal/ui/session/view/sidebar/icon_item_row.ui")] + pub struct IconItemRow { + pub icon_item: RefCell>, } #[glib::object_subclass] - impl ObjectSubclass for EntryRow { - const NAME: &'static str = "SidebarEntryRow"; - type Type = super::EntryRow; + impl ObjectSubclass for IconItemRow { + const NAME: &'static str = "SidebarIconItemRow"; + type Type = super::IconItemRow; type ParentType = adw::Bin; fn class_init(klass: &mut Self::Class) { Self::bind_template(klass); - klass.set_css_name("sidebar-entry"); + klass.set_css_name("icon-item"); } fn instance_init(obj: &InitializingObject) { @@ -32,11 +32,11 @@ mod imp { } } - impl ObjectImpl for EntryRow { + impl ObjectImpl for IconItemRow { fn properties() -> &'static [glib::ParamSpec] { use once_cell::sync::Lazy; static PROPERTIES: Lazy> = Lazy::new(|| { - vec![glib::ParamSpecObject::builder::("entry") + vec![glib::ParamSpecObject::builder::("icon-item") .explicit_notify() .build()] }); @@ -46,54 +46,54 @@ mod imp { fn set_property(&self, _id: usize, value: &glib::Value, pspec: &glib::ParamSpec) { match pspec.name() { - "entry" => self.obj().set_entry(value.get().unwrap()), + "icon-item" => self.obj().set_icon_item(value.get().unwrap()), _ => unimplemented!(), } } fn property(&self, _id: usize, pspec: &glib::ParamSpec) -> glib::Value { match pspec.name() { - "entry" => self.obj().entry().to_value(), + "icon-item" => self.obj().icon_item().to_value(), _ => unimplemented!(), } } } - impl WidgetImpl for EntryRow {} - impl BinImpl for EntryRow {} + impl WidgetImpl for IconItemRow {} + impl BinImpl for IconItemRow {} } glib::wrapper! { - pub struct EntryRow(ObjectSubclass) + pub struct IconItemRow(ObjectSubclass) @extends gtk::Widget, adw::Bin, @implements gtk::Accessible; } -impl EntryRow { +impl IconItemRow { pub fn new() -> Self { glib::Object::new() } - /// The entry of this row. - pub fn entry(&self) -> Option { - self.imp().entry.borrow().clone() + /// The [`IconItem`] of this row. + pub fn icon_item(&self) -> Option { + self.imp().icon_item.borrow().clone() } - /// Set the entry of this row. - pub fn set_entry(&self, entry: Option) { - if self.entry() == entry { + /// Set the [`IconItem`] of this row. + pub fn set_icon_item(&self, icon_item: Option) { + if self.icon_item() == icon_item { return; } - if entry + if icon_item .as_ref() - .map_or(false, |e| e.type_() == EntryType::Forget) + .is_some_and(|i| i.type_() == ItemType::Forget) { self.add_css_class("forget"); } else { self.remove_css_class("forget"); } - self.imp().entry.replace(entry); - self.notify("entry"); + self.imp().icon_item.replace(icon_item); + self.notify("icon-item"); } } diff --git a/src/session/view/sidebar/entry_row.ui b/src/session/view/sidebar/icon_item_row.ui similarity index 71% rename from src/session/view/sidebar/entry_row.ui rename to src/session/view/sidebar/icon_item_row.ui index fa87fb88..e8102e4f 100644 --- a/src/session/view/sidebar/entry_row.ui +++ b/src/session/view/sidebar/icon_item_row.ui @@ -1,14 +1,14 @@ -