use ActionRow widget for DropDown menu

This commit is contained in:
yggverse 2024-11-20 10:36:21 +02:00
parent fa9c2b4fbc
commit bb42239749
4 changed files with 26 additions and 28 deletions

View File

@ -23,7 +23,10 @@ impl Gemini {
let widget = Rc::new(Widget::new()); let widget = Rc::new(Widget::new());
// Add new identity option // 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 // Collect additional options from database
match profile.identity.gemini.database.records() { match profile.identity.gemini.database.records() {
@ -35,21 +38,15 @@ impl Gemini {
Err(reason) => todo!("{reason}"), 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 // Append record option
widget.form.list.append( widget.form.list.append(
Some(identity.id), Some(identity.id),
&format!("{name} ({expires})"), &certificate.subject_name().unwrap(),
true, &certificate
.not_valid_after()
.unwrap()
.format_iso8601()
.unwrap(),
); );
} }
} }

View File

@ -1,13 +1,14 @@
mod item; mod item;
use item::Item; use item::Item;
use adw::ActionRow;
use gtk::{ use gtk::{
gio::{ gio::{
prelude::{Cast, CastNone}, prelude::{Cast, CastNone},
ListStore, ListStore,
}, },
prelude::ListItemExt, prelude::ListItemExt,
DropDown, Label, ListItem, SignalListItemFactory, DropDown, ListItem, SignalListItemFactory,
}; };
pub struct List { pub struct List {
@ -33,12 +34,12 @@ impl List {
let item = list_item.item().and_downcast::<Item>().unwrap(); let item = list_item.item().and_downcast::<Item>().unwrap();
// Update menu item // Update menu item
list_item.set_child(Some(&Label::new(Some(&item.label())))); list_item.set_child(Some(
&ActionRow::builder()
// @TODO .title(item.title())
println!("{:?}", item.profile_identity_gemini_id_option()); .subtitle(item.subtitle())
println!("{:?}", item.label()); .build(),
println!("{:?}", item.is_enabled()); ));
}); });
// Init list `GObject` // Init list `GObject`
@ -50,10 +51,10 @@ impl List {
// Actions // Actions
/// Append new item with `profile_identity_gemini_id` as `key` and label as `value` /// Append new item
pub fn append(&self, profile_identity_gemini_id: Option<i64>, label: &str, is_enabled: bool) { pub fn append(&self, profile_identity_gemini_id: Option<i64>, title: &str, subtitle: &str) {
self.model self.model
.append(&Item::new(profile_identity_gemini_id, label, is_enabled)); .append(&Item::new(profile_identity_gemini_id, title, subtitle));
} }
// Events // Events

View File

@ -12,7 +12,7 @@ impl Item {
// Constructors // Constructors
/// Create new `GObject` with formatted properties /// Create new `GObject` with formatted properties
pub fn new(profile_identity_gemini_id: Option<i64>, label: &str, is_enabled: bool) -> Self { pub fn new(profile_identity_gemini_id: Option<i64>, title: &str, subtitle: &str) -> Self {
Object::builder() Object::builder()
.property( .property(
"profile_identity_gemini_id", "profile_identity_gemini_id",
@ -21,8 +21,8 @@ impl Item {
None => PROFILE_IDENTITY_GEMINI_ID_NONE, None => PROFILE_IDENTITY_GEMINI_ID_NONE,
}, },
) )
.property("label", label) .property("title", title)
.property("is_enabled", is_enabled) .property("subtitle", subtitle)
.build() .build()
} }

View File

@ -14,9 +14,9 @@ pub struct Item {
#[property(get, set)] #[property(get, set)]
profile_identity_gemini_id: Cell<i64>, profile_identity_gemini_id: Cell<i64>,
#[property(get, set)] #[property(get, set)]
label: RefCell<String>, title: RefCell<String>,
#[property(get, set)] #[property(get, set)]
is_enabled: Cell<bool>, subtitle: RefCell<String>,
} }
#[glib::object_subclass] #[glib::object_subclass]