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 a2715ec7..97f47071 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 @@ -28,6 +28,9 @@ impl Form { gobject.append(list.gobject()); gobject.append(name.gobject()); + // Connect events + list.on_select(move |key| name.gobject().set_visible(key.is_none())); + // Return activated `Self` Self { gobject } } 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 7cadebbc..57cf347f 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 @@ -42,22 +42,20 @@ impl List { self.model.append(&item); } + /* @TODO not in use /// Get selected `key` or panic on selection not found /// * return `None` if current selection key match `PROPERTY_KEY_NONE_VALUE` pub fn selected(&self) -> Option { - match self.gobject.selected_item() { - Some(gobject) => { - // Convert back from C-based GObject type - let key = gobject.property::(PROPERTY_KEY_NAME); + selected(&self.gobject) + }*/ - if key == PROPERTY_KEY_NONE_VALUE { - None - } else { - Some(key) - } - } - None => panic!(), - } + // Events + + /// Run callback function on `connect_selected_notify` + /// * return formatted key as result + pub fn on_select(&self, callback: impl Fn(Option) + 'static) { + self.gobject + .connect_selected_notify(move |this| callback(selected(this))); } // Getters @@ -66,3 +64,23 @@ impl List { &self.gobject } } + +// Tools + +/// Get selected `key` or panic on selection not found +/// * return `None` if current selection key match `PROPERTY_KEY_NONE_VALUE` +fn selected(list: &DropDown) -> Option { + match list.selected_item() { + Some(this) => { + // Convert back from C-based GObject type + let key = this.property::(PROPERTY_KEY_NAME); + + if key == PROPERTY_KEY_NONE_VALUE { + None + } else { + Some(key) + } + } + None => panic!(), + } +}