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 fe6bcccc..34494afe 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 @@ -5,10 +5,7 @@ use list::{item::value::Value, List}; use name::Name; use super::Action; -use gtk::{ - prelude::{BoxExt, WidgetExt}, - Box, Orientation, -}; +use gtk::{prelude::BoxExt, Box, Orientation}; use std::rc::Rc; pub struct Form { @@ -39,7 +36,7 @@ impl Form { let update = action.update.clone(); move |key| { // Change name entry visibility - name.gobject.set_visible(match key { + name.show(match key { Value::GENERATE_NEW_AUTH => true, _ => false, }); diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs index 0ed2dcfa..144421c4 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/name.rs @@ -1,7 +1,7 @@ use super::Action; use gtk::{ glib::GString, - prelude::{EditableExt, EntryExt}, + prelude::{EditableExt, EntryExt, WidgetExt}, Entry, }; use std::rc::Rc; @@ -22,9 +22,10 @@ impl Name { pub fn new(action: Rc) -> Self { // Init `GObject` let gobject = Entry::builder() + .margin_top(MARGIN) .max_length(MAX_LENGTH as i32) .placeholder_text(PLACEHOLDER_TEXT) - .margin_top(MARGIN) + .visible(false) .build(); // Init events @@ -36,12 +37,21 @@ impl Name { // Actions - pub fn is_valid(&self) -> bool { - self.gobject.text_length() >= MIN_LENGTH && self.gobject.text_length() <= MAX_LENGTH + /// Change visibility status + /// * grab focus on `is_visible` + pub fn show(&self, is_visible: bool) { + self.gobject.set_visible(is_visible); + if is_visible { + self.gobject.grab_focus(); + } } // Getters + pub fn is_valid(&self) -> bool { + self.gobject.text_length() >= MIN_LENGTH && self.gobject.text_length() <= MAX_LENGTH + } + pub fn value(&self) -> Option { let text = self.gobject.text(); if text.is_empty() {