mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
add file chooser widget
This commit is contained in:
parent
83d474a192
commit
d0f61aab5e
@ -1,6 +1,8 @@
|
|||||||
|
mod file;
|
||||||
pub mod list;
|
pub mod list;
|
||||||
mod name;
|
mod name;
|
||||||
|
|
||||||
|
use file::File;
|
||||||
use list::{item::value::Value, List};
|
use list::{item::value::Value, List};
|
||||||
use name::Name;
|
use name::Name;
|
||||||
|
|
||||||
@ -10,6 +12,7 @@ use std::rc::Rc;
|
|||||||
|
|
||||||
pub struct Form {
|
pub struct Form {
|
||||||
// pub action: Rc<Action>,
|
// pub action: Rc<Action>,
|
||||||
|
pub file: Rc<File>,
|
||||||
pub list: Rc<List>,
|
pub list: Rc<List>,
|
||||||
pub name: Rc<Name>,
|
pub name: Rc<Name>,
|
||||||
pub gobject: Box,
|
pub gobject: Box,
|
||||||
@ -23,15 +26,18 @@ impl Form {
|
|||||||
// Init components
|
// Init components
|
||||||
let list = Rc::new(List::new());
|
let list = Rc::new(List::new());
|
||||||
let name = Rc::new(Name::new(action.clone()));
|
let name = Rc::new(Name::new(action.clone()));
|
||||||
|
let file = Rc::new(File::new(action.clone()));
|
||||||
|
|
||||||
// Init main container
|
// Init main container
|
||||||
let gobject = Box::builder().orientation(Orientation::Vertical).build();
|
let gobject = Box::builder().orientation(Orientation::Vertical).build();
|
||||||
|
|
||||||
gobject.append(&list.gobject);
|
gobject.append(&list.gobject);
|
||||||
gobject.append(&name.gobject);
|
gobject.append(&name.gobject);
|
||||||
|
gobject.append(&file.gobject);
|
||||||
|
|
||||||
// Connect events
|
// Connect events
|
||||||
list.on_select({
|
list.on_select({
|
||||||
|
let file = file.clone();
|
||||||
let name = name.clone();
|
let name = name.clone();
|
||||||
let update = action.update.clone();
|
let update = action.update.clone();
|
||||||
move |key| {
|
move |key| {
|
||||||
@ -41,6 +47,12 @@ impl Form {
|
|||||||
_ => false,
|
_ => false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Change name entry visibility
|
||||||
|
file.show(match key {
|
||||||
|
Value::IMPORT_PEM => true,
|
||||||
|
_ => false,
|
||||||
|
});
|
||||||
|
|
||||||
// Update widget
|
// Update widget
|
||||||
update.activate();
|
update.activate();
|
||||||
}
|
}
|
||||||
@ -50,6 +62,7 @@ impl Form {
|
|||||||
Self {
|
Self {
|
||||||
// action,
|
// action,
|
||||||
gobject,
|
gobject,
|
||||||
|
file,
|
||||||
list,
|
list,
|
||||||
name,
|
name,
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
use super::Action;
|
||||||
|
use gtk::{
|
||||||
|
prelude::{ButtonExt, WidgetExt},
|
||||||
|
Button,
|
||||||
|
};
|
||||||
|
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
const LABEL: &str = "Select file..";
|
||||||
|
const MARGIN: i32 = 8;
|
||||||
|
|
||||||
|
pub struct File {
|
||||||
|
pub gobject: Button,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl File {
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
/// Create new `Self`
|
||||||
|
pub fn new(action: Rc<Action>) -> Self {
|
||||||
|
// Init `GObject`
|
||||||
|
let gobject = Button::builder().label(LABEL).margin_top(MARGIN).build();
|
||||||
|
|
||||||
|
// Init events
|
||||||
|
gobject.connect_clicked(move |_| todo!());
|
||||||
|
|
||||||
|
// Return activated `Self`
|
||||||
|
Self { gobject }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
|
||||||
|
/// 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user