main_view: introduce configuration view
* allow to load and save config parameters to ron file Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -56,13 +56,17 @@ impl Template for MainView {
|
||||
TabWidget::new()
|
||||
.tab("Policynumber check", policycheck_view)
|
||||
.tab("Localization", LocalizationView::new().build(ctx))
|
||||
.tab("Configuration", ConfigurationView::new().build(ctx))
|
||||
.build(ctx),
|
||||
)
|
||||
//.child(policycheck_view)
|
||||
}
|
||||
}
|
||||
|
||||
widget!(LocalizationView<LocalizationState> { languages: List, selected_index: i32 });
|
||||
widget!(LocalizationView<LocalizationState> {
|
||||
languages: List,
|
||||
selected_index: i32 }
|
||||
);
|
||||
|
||||
impl Template for LocalizationView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
@@ -97,6 +101,123 @@ impl Template for LocalizationView {
|
||||
}
|
||||
}
|
||||
|
||||
widget!(
|
||||
ConfigurationView<ConfigurationState> {
|
||||
configuration_file: String,
|
||||
language_id: String
|
||||
}
|
||||
);
|
||||
|
||||
impl Template for ConfigurationView {
|
||||
fn template(self, id: Entity, ctx: &mut BuildContext<'_>) -> Self {
|
||||
self.child(
|
||||
Grid::new()
|
||||
.margin(4)
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push(120)
|
||||
.push(12)
|
||||
.push("auto")
|
||||
)
|
||||
.rows(Rows::create()
|
||||
.push("auto")
|
||||
.push(4)
|
||||
.push("auto")
|
||||
.push(4)
|
||||
.push("auto")
|
||||
.push(12)
|
||||
.push("auto"),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.h_align("start")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(0))
|
||||
.attach(Grid::column_span(3))
|
||||
.text("Configuration settings")
|
||||
.style("header")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(2))
|
||||
.v_align("center")
|
||||
.h_align("end")
|
||||
.text("Configuration file")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(2))
|
||||
.text(("configuration_file", id))
|
||||
.water_mark("Filename...")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBlock::new()
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(4))
|
||||
.v_align("center")
|
||||
.h_align("end")
|
||||
.text("Language Id")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
TextBox::new()
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(4))
|
||||
.text(("language_id", id))
|
||||
.water_mark("Locale Identifier...")
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Grid::new()
|
||||
.h_align("center")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(6))
|
||||
.attach(Grid::column_span(3))
|
||||
.columns(
|
||||
Columns::create()
|
||||
.push("auto")
|
||||
.push(8)
|
||||
.push("auto")
|
||||
)
|
||||
.rows(Rows::create()
|
||||
.push("auto")
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.style("button_single_content")
|
||||
.attach(Grid::column(0))
|
||||
.attach(Grid::row(0))
|
||||
.text("load")
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.send_message(ConfigurationAction::LoadConfiguration, id);
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.child(
|
||||
Button::new()
|
||||
.text("save")
|
||||
.style("button_single_content")
|
||||
.attach(Grid::column(2))
|
||||
.attach(Grid::row(0))
|
||||
.on_click(move |ctx, _| {
|
||||
ctx.send_message(ConfigurationAction::SaveConfiguration, id);
|
||||
true
|
||||
})
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
.build(ctx),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// [END] views
|
||||
|
||||
// [START] states
|
||||
@@ -131,4 +252,67 @@ impl State for LocalizationState {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, AsAny)]
|
||||
struct ConfigurationState {}
|
||||
|
||||
impl State for ConfigurationState {
|
||||
fn messages(
|
||||
&mut self,
|
||||
mut messages: MessageReader,
|
||||
registry: &mut Registry,
|
||||
ctx: &mut Context<'_>,
|
||||
) {
|
||||
for message in messages.read::<ConfigurationAction>() {
|
||||
match message {
|
||||
ConfigurationAction::LoadConfiguration => registry
|
||||
.get::<Settings>("settings")
|
||||
.load_async::<ConfigurationData>("configuration_data".to_string(), ctx.entity()),
|
||||
ConfigurationAction::SaveConfiguration => {
|
||||
let configuration_file: String = ConfigurationView::configuration_file_clone(&ctx.widget());
|
||||
let language_id: String = ConfigurationView::language_id_clone(&ctx.widget());
|
||||
registry.get::<Settings>("settings").save_async(
|
||||
"configuration_data".to_string(),
|
||||
ConfigurationData(
|
||||
configuration_file,
|
||||
language_id
|
||||
),
|
||||
ctx.entity(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// save result
|
||||
for message in messages.read::<SettingsResult<()>>() {
|
||||
println!("Result {:?}", message);
|
||||
}
|
||||
|
||||
// load result
|
||||
for message in messages.read::<SettingsResult<ConfigurationData>>() {
|
||||
if let Ok(data) = message {
|
||||
ConfigurationView::configuration_file_set(&mut ctx.widget(), data.0);
|
||||
ConfigurationView::language_id_set(&mut ctx.widget(), data.1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [END] states
|
||||
|
||||
// [START] Configuration data
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
enum ConfigurationAction {
|
||||
SaveConfiguration,
|
||||
LoadConfiguration,
|
||||
}
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct ConfigurationData(
|
||||
pub String,
|
||||
pub String
|
||||
);
|
||||
|
||||
// [END] Configuration data
|
||||
|
||||
Reference in New Issue
Block a user