diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs index 052fd32b..ae5e4936 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common.rs @@ -4,7 +4,7 @@ mod form; use crate::Profile; use action::Action as WidgetAction; use adw::AlertDialog; -use gtk::glib::Uri; +use gtk::{glib::Uri, prelude::EditableExt}; use std::rc::Rc; // Select options @@ -69,10 +69,7 @@ impl Common for AlertDialog { Value::ProfileIdentityId(value) => Some(value), Value::GuestSession => None, Value::GeneratePem => Some( - profile - .identity - .make(None, &form.name.value().unwrap()) - .unwrap(), // @TODO handle + profile.identity.make(None, &form.name.text()).unwrap(), // @TODO handle ), Value::ImportPem => Some( profile diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form.rs index cce4a8e1..74225ceb 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form.rs @@ -17,7 +17,7 @@ use crate::Profile; use gtk::{ glib::Uri, prelude::{BoxExt, WidgetExt}, - Box, Button, Orientation, + Box, Button, Entry, Orientation, }; use std::rc::Rc; @@ -27,7 +27,7 @@ pub struct Form { pub exit: Button, pub file: Rc, pub list: Rc, - pub name: Rc, + pub name: Entry, pub save: Rc, pub g_box: Box, profile: Rc, @@ -41,7 +41,7 @@ impl Form { // Init components let list = Rc::new(List::build(widget_action, profile, request)); let file = Rc::new(File::build(widget_action)); - let name = Rc::new(Name::build(widget_action)); + let name = Entry::name(widget_action); let save = Rc::new(Save::build(profile, &list)); let drop = Rc::new(Drop::build(profile, &list)); let exit = Button::exit(widget_action, profile, &list, request); @@ -50,7 +50,7 @@ impl Form { let g_box = Box::builder().orientation(Orientation::Vertical).build(); g_box.append(&list.dropdown); - g_box.append(&name.entry); + g_box.append(&name); g_box.append(&file.button); g_box.append(&exit); g_box.append(&drop.button); diff --git a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/name.rs b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/name.rs index 4a968d8f..015c1c2f 100644 --- a/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/name.rs +++ b/src/app/browser/window/tab/item/page/navigation/request/identity/common/form/name.rs @@ -1,25 +1,35 @@ use super::WidgetAction; use gtk::{ - glib::GString, prelude::{EditableExt, EntryExt, WidgetExt}, Entry, }; use std::rc::Rc; -const PLACEHOLDER_TEXT: &str = "Identity name (required)"; -const MARGIN: i32 = 8; const MIN_LENGTH: u16 = 1; const MAX_LENGTH: u16 = 36; -pub struct Name { - pub entry: Entry, +pub trait Name { + // Constructors + + fn name(widget_action: &Rc) -> Self; + + // Actions + + fn update(&self, is_visible: bool); + + // Getters + + fn is_valid(&self) -> bool; } -impl Name { +impl Name for Entry { // Constructors /// Create new `Self` - pub fn build(widget_action: &Rc) -> Self { + fn name(widget_action: &Rc) -> Self { + const PLACEHOLDER_TEXT: &str = "Identity name (required)"; + const MARGIN: i32 = 8; + // Init main gobject let entry = Entry::builder() .margin_top(MARGIN) @@ -35,32 +45,23 @@ impl Name { }); // Return activated `Self` - Self { entry } + entry } // Actions /// Change visibility status /// * grab focus on `is_visible` is `true` - pub fn update(&self, is_visible: bool) { - self.entry.set_visible(is_visible); - if is_visible && self.entry.focus_child().is_none() { - self.entry.grab_focus(); + fn update(&self, is_visible: bool) { + self.set_visible(is_visible); + if is_visible && self.focus_child().is_none() { + self.grab_focus(); } } // Getters - pub fn is_valid(&self) -> bool { - self.entry.text_length() >= MIN_LENGTH && self.entry.text_length() <= MAX_LENGTH - } - - pub fn value(&self) -> Option { - let text = self.entry.text(); - if text.is_empty() { - None - } else { - Some(text) - } + fn is_valid(&self) -> bool { + self.text_length() >= MIN_LENGTH && self.text_length() <= MAX_LENGTH } }