From 073e035bb23c405cedcba48b3bd6f07a614199ab Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 7 Dec 2024 08:15:29 +0200 Subject: [PATCH] implement widget update action --- .../window/tab/item/identity/gemini/widget.rs | 3 + .../tab/item/identity/gemini/widget/form.rs | 70 ++++++++----------- .../item/identity/gemini/widget/form/list.rs | 6 +- 3 files changed, 37 insertions(+), 42 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 3c64660e..f195dbfe 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget.rs @@ -68,6 +68,9 @@ impl Widget { let form = form.clone(); let alert_dialog = alert_dialog.clone(); move || { + // Update child components + form.update(); + // Deactivate apply button if the form values could not be processed alert_dialog.set_response_enabled(RESPONSE_APPLY.0, form.is_applicable()); } 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 86c53011..4b088742 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 @@ -19,12 +19,12 @@ use std::rc::Rc; pub struct Form { // pub widget_action: Rc, - // pub drop: Rc, - // pub exit: Rc, + pub drop: Rc, + pub exit: Rc, pub file: Rc, pub list: Rc, pub name: Rc, - // pub save: Rc, + pub save: Rc, pub g_box: Box, } @@ -34,7 +34,7 @@ impl Form { /// Create new `Self` pub fn new(profile: Rc, widget_action: Rc, auth_url: &str) -> Self { // Init components - let list = Rc::new(List::new(profile.clone(), auth_url)); + let list = Rc::new(List::new(widget_action.clone(), profile.clone(), auth_url)); let file = Rc::new(File::new(widget_action.clone())); let name = Rc::new(Name::new(widget_action.clone())); let save = Rc::new(Save::new(profile.clone(), list.clone())); @@ -51,49 +51,15 @@ impl Form { g_box.append(&drop.button); g_box.append(&save.button); - // Connect events - list.dropdown.connect_selected_notify({ - let list = list.clone(); - let name = name.clone(); - let file = file.clone(); - // let drop = drop.clone(); - // let exit = exit.clone(); - // let save = save.clone(); - move |_| { - // Get selected item - let item = list.selected(); - - // Update name entry visibility - name.set_visible(matches!(item.value_enum(), Value::GeneratePem)); - - // Update file choose button visibility - file.set_visible(matches!(item.value_enum(), Value::ImportPem)); - - // Update ID-related components - match item.value_enum() { - Value::ProfileIdentityGeminiId(_) => { - drop.set_visible(true); - exit.set_visible(true); - save.set_visible(true); - } - _ => { - drop.set_visible(false); - exit.set_visible(false); - save.set_visible(false); - } - } - } - }); - // Return activated `Self` Self { // widget_action, - // drop, - // exit, + drop, + exit, file, list, name, - // save, + save, g_box, } } @@ -109,4 +75,26 @@ impl Form { _ => true, } } + + pub fn update(&self) { + // Get selected item value + let value = self.list.selected().value_enum(); + + // Toggle visibility for children components + self.name.set_visible(matches!(value, Value::GeneratePem)); + self.file.set_visible(matches!(value, Value::ImportPem)); + + match value { + Value::ProfileIdentityGeminiId(_) => { + self.drop.set_visible(true); + self.exit.set_visible(true); + self.save.set_visible(true); + } + _ => { + self.drop.set_visible(false); + self.exit.set_visible(false); + self.save.set_visible(false); + } + } + } } 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 2ecdeb6c..7b6547a3 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 @@ -3,6 +3,7 @@ use std::rc::Rc; use item::Item; +use super::Action; use crate::profile::Profile; use gtk::{ gdk::Cursor, @@ -24,7 +25,7 @@ impl List { // Constructors /// Create new `Self` - pub fn new(profile: Rc, auth_url: &str) -> Self { + pub fn new(widget_action: Rc, profile: Rc, auth_url: &str) -> Self { // Init model let list_store = ListStore::new::(); @@ -132,6 +133,9 @@ impl List { .factory(&factory) .build(); + // Connect events + dropdown.connect_selected_notify(move |_| widget_action.update.activate()); + // Return activated `Self` Self { dropdown,