add file validate option

This commit is contained in:
yggverse 2024-11-21 13:47:14 +02:00
parent ae24a727c8
commit e49a607e78
2 changed files with 13 additions and 2 deletions

View File

@ -74,6 +74,7 @@ impl Form {
pub fn is_valid(&self) -> bool { pub fn is_valid(&self) -> bool {
match self.list.selected() { match self.list.selected() {
Value::GENERATE_NEW_AUTH => self.name.is_valid(), Value::GENERATE_NEW_AUTH => self.name.is_valid(),
Value::IMPORT_PEM => self.file.is_valid(),
_ => true, _ => true,
} }
} }

View File

@ -4,12 +4,13 @@ use gtk::{
Button, Button,
}; };
use std::rc::Rc; use std::{cell::RefCell, rc::Rc};
const LABEL: &str = "Select file.."; const LABEL: &str = "Select file..";
const MARGIN: i32 = 8; const MARGIN: i32 = 8;
pub struct File { pub struct File {
pem: RefCell<Option<String>>,
pub gobject: Button, pub gobject: Button,
} }
@ -18,6 +19,9 @@ impl File {
/// Create new `Self` /// Create new `Self`
pub fn new(action: Rc<Action>) -> Self { pub fn new(action: Rc<Action>) -> Self {
// Init PEM
let pem = RefCell::new(None);
// Init `GObject` // Init `GObject`
let gobject = Button::builder() let gobject = Button::builder()
.label(LABEL) .label(LABEL)
@ -29,7 +33,7 @@ impl File {
gobject.connect_clicked(move |_| todo!()); gobject.connect_clicked(move |_| todo!());
// Return activated `Self` // Return activated `Self`
Self { gobject } Self { pem, gobject }
} }
// Actions // Actions
@ -42,4 +46,10 @@ impl File {
self.gobject.grab_focus(); self.gobject.grab_focus();
} }
} }
// Getters
pub fn is_valid(&self) -> bool {
self.pem.borrow().is_some()
}
} }