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 5758e600..f4377ed2 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 form with it children 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 15e73c3a..e9b3aca2 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 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, } @@ -35,7 +35,7 @@ impl Form { pub fn new(profile: Rc, action: Rc, auth_url: &str) -> Self { // Init components let file = Rc::new(File::new(action.clone())); - let list = Rc::new(List::new(profile.clone(), auth_url)); + let list = Rc::new(List::new(profile.clone(), action.clone(), auth_url)); let name = Rc::new(Name::new(action.clone())); let save = Rc::new(Save::new(profile.clone())); let drop = Rc::new(Drop::new(profile.clone(), action.clone(), list.clone())); @@ -51,49 +51,15 @@ impl Form { g_box.append(&drop.button); g_box.append(&save.button); - // Connect events - list.on_select({ - let drop = drop.clone(); - let exit = exit.clone(); - let file = file.clone(); - let name = name.clone(); - let save = save.clone(); - let update = action.update.clone(); - move |item| { - // Change name entry visibility - name.update(matches!(item, Value::GeneratePem)); - - // Change file choose button visibility - file.update(matches!(item, Value::ImportPem)); - - // Change other components visibility by update it holder value - match item { - Value::ProfileIdentityGeminiId(value) => { - drop.update(Some(value)); - exit.update(Some(value)); - save.update(Some(value)); - } - _ => { - drop.update(None); - exit.update(None); - save.update(None); - } - } - - // Update widget - update.activate(); - } - }); - // Return activated `Self` Self { // action, - // drop, - // exit, + drop, + exit, file, list, name, - // save, + save, g_box, } } @@ -109,4 +75,31 @@ impl Form { _ => true, } } + + pub fn update(&self) { + // Get selected item + let item = self.list.selected_item(); + + // Update name entry visibility + self.name + .update(matches!(item.value_enum(), Value::GeneratePem)); + + // Update file choose button visibility + self.file + .update(matches!(item.value_enum(), Value::ImportPem)); + + // Update ID-related components + match item.value_enum() { + Value::ProfileIdentityGeminiId(value) => { + self.drop.update(Some(value)); + self.exit.update(Some(value)); + self.save.update(Some(value)); + } + _ => { + self.drop.update(None); + self.exit.update(None); + self.save.update(None); + } + } + } } 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 4e69a827..fd53362a 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,8 +1,9 @@ pub mod item; use std::rc::Rc; -use item::{value::Value, Item}; +use item::Item; +use super::Action; use crate::profile::Profile; use gtk::{ gdk::Cursor, @@ -23,7 +24,7 @@ impl List { // Constructors /// Create new `Self` - pub fn new(profile: Rc, auth_url: &str) -> Self { + pub fn new(profile: Rc, action: Rc, auth_url: &str) -> Self { // Init model let list_store = ListStore::new::(); @@ -131,6 +132,9 @@ impl List { .factory(&factory) .build(); + // Connect events + dropdown.connect_selected_notify(move |_| action.update.activate()); + // Return activated `Self` Self { list_store, @@ -159,21 +163,6 @@ impl List { } } - // Events - - /// 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(), - ) - }); - } - // Getters /// Get selected `Item` GObject