From 44d34c46bb4d56d1acd14bf81e5578e21e690c96 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 5 Dec 2024 11:13:03 +0200 Subject: [PATCH] disable apply button on auth match previous or active selection (or contain parent relation), reorganize getters --- .../window/tab/item/identity/gemini/widget.rs | 2 +- .../tab/item/identity/gemini/widget/form.rs | 3 +- .../item/identity/gemini/widget/form/list.rs | 28 +++++++++---------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/app/browser/window/tab/item/identity/gemini/widget.rs b/src/app/browser/window/tab/item/identity/gemini/widget.rs index f6aacfe0..a1e4f300 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget.rs @@ -93,7 +93,7 @@ impl Widget { this.set_response_enabled(response, false); // Result - callback(form.list.value()) + callback(form.list.selected_item().value_enum()) } }); } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form.rs index 07ae19c3..bf0e542f 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form.rs @@ -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, } } 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 a06b8caf..4dd9b3b5 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 @@ -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::() - .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::() - .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::().unwrap() +}