From e49a607e780c551b13d46c07d45956817c54c2f4 Mon Sep 17 00:00:00 2001 From: yggverse Date: Thu, 21 Nov 2024 13:47:14 +0200 Subject: [PATCH] add file validate option --- .../window/tab/item/identity/gemini/widget/form.rs | 1 + .../tab/item/identity/gemini/widget/form/file.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) 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 c34f1337..dd13ec5d 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 @@ -74,6 +74,7 @@ impl Form { pub fn is_valid(&self) -> bool { match self.list.selected() { Value::GENERATE_NEW_AUTH => self.name.is_valid(), + Value::IMPORT_PEM => self.file.is_valid(), _ => true, } } diff --git a/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs b/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs index eb584181..c7ebe7a9 100644 --- a/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs +++ b/src/app/browser/window/tab/item/identity/gemini/widget/form/file.rs @@ -4,12 +4,13 @@ use gtk::{ Button, }; -use std::rc::Rc; +use std::{cell::RefCell, rc::Rc}; const LABEL: &str = "Select file.."; const MARGIN: i32 = 8; pub struct File { + pem: RefCell>, pub gobject: Button, } @@ -18,6 +19,9 @@ impl File { /// Create new `Self` pub fn new(action: Rc) -> Self { + // Init PEM + let pem = RefCell::new(None); + // Init `GObject` let gobject = Button::builder() .label(LABEL) @@ -29,7 +33,7 @@ impl File { gobject.connect_clicked(move |_| todo!()); // Return activated `Self` - Self { gobject } + Self { pem, gobject } } // Actions @@ -42,4 +46,10 @@ impl File { self.gobject.grab_focus(); } } + + // Getters + + pub fn is_valid(&self) -> bool { + self.pem.borrow().is_some() + } }