From bb42239749e1f8f97fa0a7d77537210627811a31 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 20 Nov 2024 10:36:21 +0200 Subject: [PATCH] use ActionRow widget for DropDown menu --- .../window/tab/item/identity/gemini.rs | 23 ++++++++----------- .../item/identity/gemini/widget/form/list.rs | 21 +++++++++-------- .../identity/gemini/widget/form/list/item.rs | 6 ++--- .../gemini/widget/form/list/item/imp.rs | 4 ++-- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/app/browser/window/tab/item/identity/gemini.rs b/src/app/browser/window/tab/item/identity/gemini.rs index 00266711..f85dc2bd 100644 --- a/src/app/browser/window/tab/item/identity/gemini.rs +++ b/src/app/browser/window/tab/item/identity/gemini.rs @@ -23,7 +23,10 @@ impl Gemini { let widget = Rc::new(Widget::new()); // Add new identity option - widget.form.list.append(None, "Create new..", true); + widget + .form + .list + .append(None, "Create new..", "Auto-generated certificate"); // Collect additional options from database match profile.identity.gemini.database.records() { @@ -35,21 +38,15 @@ impl Gemini { Err(reason) => todo!("{reason}"), }; - // Get name from subject - let name = certificate.subject_name().unwrap(); - - // Get expiration time - let expires = certificate - .not_valid_after() - .unwrap() - .format_iso8601() - .unwrap(); - // Append record option widget.form.list.append( Some(identity.id), - &format!("{name} ({expires})"), - true, + &certificate.subject_name().unwrap(), + &certificate + .not_valid_after() + .unwrap() + .format_iso8601() + .unwrap(), ); } } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs index 298c2b19..d62aad63 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/list.rs @@ -1,13 +1,14 @@ mod item; use item::Item; +use adw::ActionRow; use gtk::{ gio::{ prelude::{Cast, CastNone}, ListStore, }, prelude::ListItemExt, - DropDown, Label, ListItem, SignalListItemFactory, + DropDown, ListItem, SignalListItemFactory, }; pub struct List { @@ -33,12 +34,12 @@ impl List { let item = list_item.item().and_downcast::().unwrap(); // Update menu item - list_item.set_child(Some(&Label::new(Some(&item.label())))); - - // @TODO - println!("{:?}", item.profile_identity_gemini_id_option()); - println!("{:?}", item.label()); - println!("{:?}", item.is_enabled()); + list_item.set_child(Some( + &ActionRow::builder() + .title(item.title()) + .subtitle(item.subtitle()) + .build(), + )); }); // Init list `GObject` @@ -50,10 +51,10 @@ impl List { // Actions - /// Append new item with `profile_identity_gemini_id` as `key` and label as `value` - pub fn append(&self, profile_identity_gemini_id: Option, label: &str, is_enabled: bool) { + /// Append new item + pub fn append(&self, profile_identity_gemini_id: Option, title: &str, subtitle: &str) { self.model - .append(&Item::new(profile_identity_gemini_id, label, is_enabled)); + .append(&Item::new(profile_identity_gemini_id, title, subtitle)); } // Events diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/list/item.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/list/item.rs index 31bff156..55994f0a 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/list/item.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/list/item.rs @@ -12,7 +12,7 @@ impl Item { // Constructors /// Create new `GObject` with formatted properties - pub fn new(profile_identity_gemini_id: Option, label: &str, is_enabled: bool) -> Self { + pub fn new(profile_identity_gemini_id: Option, title: &str, subtitle: &str) -> Self { Object::builder() .property( "profile_identity_gemini_id", @@ -21,8 +21,8 @@ impl Item { None => PROFILE_IDENTITY_GEMINI_ID_NONE, }, ) - .property("label", label) - .property("is_enabled", is_enabled) + .property("title", title) + .property("subtitle", subtitle) .build() } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/list/item/imp.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/list/item/imp.rs index cfe45a69..1cf8791b 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/list/item/imp.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/list/item/imp.rs @@ -14,9 +14,9 @@ pub struct Item { #[property(get, set)] profile_identity_gemini_id: Cell, #[property(get, set)] - label: RefCell, + title: RefCell, #[property(get, set)] - is_enabled: Cell, + subtitle: RefCell, } #[glib::object_subclass]