disable apply button on auth match previous or active selection (or contain parent relation), reorganize getters

This commit is contained in:
yggverse 2024-12-05 11:13:03 +02:00
parent 10edad5cb2
commit 44d34c46bb
3 changed files with 16 additions and 17 deletions

View File

@ -93,7 +93,7 @@ impl Widget {
this.set_response_enabled(response, false);
// Result
callback(form.list.value())
callback(form.list.selected_item().value_enum())
}
});
}

View File

@ -93,9 +93,10 @@ impl Form {
/// Validate `Self` components match current selection
pub fn is_applicable(&self) -> bool {
match self.list.value() {
match self.list.selected_item().value_enum() {
Value::GenerateNewAuth => self.name.is_valid(),
Value::ImportPem => self.file.is_valid(),
Value::ProfileIdentityGeminiId(_) => !self.list.selected_item().is_active(),
_ => true,
}
}

View File

@ -120,24 +120,22 @@ impl List {
/// Run callback function on `connect_selected_notify` event
/// * return `Value` enum match selected item
pub fn on_select(&self, callback: impl Fn(Value) + 'static) {
self.dropdown.connect_selected_notify(move |this| {
callback(
this.selected_item()
.and_downcast::<Item>()
.unwrap()
.value_enum(),
)
});
self.dropdown
.connect_selected_notify(move |this| callback(selected_item(this).value_enum()));
}
// Getters
/// Get formatted `value` match selected item
pub fn value(&self) -> Value {
self.dropdown
.selected_item()
.and_downcast::<Item>()
.unwrap()
.value_enum()
/// Get selected `Item` GObject
pub fn selected_item(&self) -> Item {
selected_item(&self.dropdown)
}
}
// Tools
/// Cast and return selected `Item` GObject for any internal
/// [DropDown](https://docs.gtk.org/gtk4/class.DropDown.html) widget
fn selected_item(dropdown: &DropDown) -> Item {
dropdown.selected_item().and_downcast::<Item>().unwrap()
}