policylist: wip: view and state handling updates
Signed-off-by: Ralf Zerres <ralf.zerres@networkx.de>
This commit is contained in:
@@ -13,7 +13,7 @@ pub enum Action {
|
|||||||
NewEntry(Entity),
|
NewEntry(Entity),
|
||||||
RemoveFocus(Entity),
|
RemoveFocus(Entity),
|
||||||
RemoveEntry(usize),
|
RemoveEntry(usize),
|
||||||
OpenPolicyList(Entity),
|
OpenPolicyList(usize),
|
||||||
SetEntry(Entity),
|
SetEntry(Entity),
|
||||||
TextChanged(Entity, usize),
|
TextChanged(Entity, usize),
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ pub struct PolicyListState {
|
|||||||
action:Option<Action>,
|
action:Option<Action>,
|
||||||
add_button: Entity,
|
add_button: Entity,
|
||||||
items_widget: Entity,
|
items_widget: Entity,
|
||||||
policylist_view: Entity,
|
policydata_view: Entity,
|
||||||
last_focused: Option<Entity>,
|
last_focused: Option<Entity>,
|
||||||
text_box: Entity,
|
text_box: Entity,
|
||||||
}
|
}
|
||||||
@@ -54,45 +54,38 @@ impl PolicyListState {
|
|||||||
} else {
|
} else {
|
||||||
Button::get(ctx.child("add_button")).set_enabled(true);
|
Button::get(ctx.child("add_button")).set_enabled(true);
|
||||||
}
|
}
|
||||||
// new syntax missing
|
// new syntax not implemented yet
|
||||||
ctx.get_widget(self.add_button).update_theme_by_state(true);
|
ctx.get_widget(self.add_button).update_theme_by_state(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// update number of available policy data entries.
|
/// update number of available policy list entries.
|
||||||
fn adjust_count(&self, ctx: &mut Context) {
|
fn adjust_count(&self, ctx: &mut Context) {
|
||||||
if let Some(index) = ctx.widget().clone::<Option<usize>>("list_index") {
|
let policy_lists_count = ctx.widget().get::<PolicyList>(PROP_POLICY_LISTS).len();
|
||||||
if let Some(policy_data) = ctx
|
ctx.widget().set(PROP_POLICY_LISTS_COUNT, policy_lists_count);
|
||||||
.widget()
|
|
||||||
.clone::<PolicyList>("policy_list")
|
|
||||||
.get(index)
|
|
||||||
{
|
|
||||||
ctx.widget().set("policy_list_count", policy_data.len());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new policy list.
|
// Creates a new policy list.
|
||||||
fn new_entry(&self, text: String, registry: &mut Registry, ctx: &mut Context) {
|
fn new_entry(&self, name: String, registry: &mut Registry, ctx: &mut Context) {
|
||||||
ctx.widget()
|
ctx.widget()
|
||||||
.get_mut::<PolicyList>(PROP_POLICY_LIST)
|
.get_mut::<PolicyList>(PROP_POLICY_LISTS)
|
||||||
.push(PolicyList::new(text));
|
.push(PolicyData::new(name));
|
||||||
self.adjust_count(ctx);
|
self.adjust_count(ctx);
|
||||||
self.save(registry, ctx);
|
self.save(registry, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// opens a policy list.
|
// opens a given policy list name.
|
||||||
fn open_policy_list(&self, index: usize, ctx: &mut Context) {
|
fn open_policy_lists(&self, index: usize, ctx: &mut Context) {
|
||||||
ctx.get_widget(self.text_box)
|
ctx.get_widget(self.text_box)
|
||||||
.set("name", String::from(""));
|
.set("text", String16::from(""));
|
||||||
ctx.get_widget(self.policy_list)
|
ctx.get_widget(self.policydata_view)
|
||||||
.set("list_index", Some(index));
|
.set("list_index", Some(index));
|
||||||
self.navigate(self.policy_list, ctx);
|
self.navigate(self.policydata_view, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes a policy list.
|
// removes a policy list.
|
||||||
fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) {
|
fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) {
|
||||||
ctx.widget()
|
ctx.widget()
|
||||||
.get_mut::<PolicyList>(PROP_POLICY_LIST)
|
.get_mut::<PolicyList>(PROP_POLICY_LISTS)
|
||||||
.remove(index);
|
.remove(index);
|
||||||
self.adjust_count(ctx);
|
self.adjust_count(ctx);
|
||||||
self.save(registry, ctx);
|
self.save(registry, ctx);
|
||||||
@@ -122,72 +115,27 @@ impl PolicyListState {
|
|||||||
ctx.push_event_by_window(FocusEvent::RequestFocus(text_box));
|
ctx.push_event_by_window(FocusEvent::RequestFocus(text_box));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Toggle the invalid element of the given policy data entry
|
|
||||||
fn toggle_invalid(
|
|
||||||
&self,
|
|
||||||
entry: Entity,
|
|
||||||
index: usize,
|
|
||||||
registry: &mut Registry,
|
|
||||||
ctx: &mut Context,
|
|
||||||
) {
|
|
||||||
let invalid: bool = *ctx.get_widget(entry).get("invalid");
|
|
||||||
|
|
||||||
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
|
|
||||||
if let Some(policy_list) = ctx
|
|
||||||
.widget()
|
|
||||||
.get_mut::<PolicyData>("policy_list")
|
|
||||||
.get_mut(idx)
|
|
||||||
{
|
|
||||||
if let Some(policy_list) = policy_list.get_mut(index) {
|
|
||||||
policy_list.selected = selected;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.save(registry, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update_entry(
|
|
||||||
&self,
|
|
||||||
text_box: Entity,
|
|
||||||
index: usize,
|
|
||||||
registry: &mut Registry,
|
|
||||||
ctx: &mut Context,
|
|
||||||
) {
|
|
||||||
let text: String16 = ctx.get_widget(text_box).clone("text");
|
|
||||||
|
|
||||||
if let Some(idx) = ctx.widget().clone::<Option<usize>>("list_index") {
|
|
||||||
if let Some(policy_list) = ctx
|
|
||||||
.widget()
|
|
||||||
.get_mut::<PolicyList>("policy_list")
|
|
||||||
.get_mut(idx)
|
|
||||||
{
|
|
||||||
if let Some(task) = policy_list.get_mut(index) {
|
|
||||||
task.text = text.to_string();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.save(registry, ctx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State for PolicyListState {
|
impl State for PolicyListState {
|
||||||
fn init(&mut self, registry: &mut Registry, ctx: &mut Context) {
|
fn init(&mut self, registry: &mut Registry, ctx: &mut Context) {
|
||||||
self.text_box = ctx
|
self.text_box = ctx
|
||||||
.entity_of_child(ID_POLICY_LIST_TEXT_BOX)
|
.entity_of_child(ID_POLICY_LISTS_TEXT_BOX)
|
||||||
.expect("PolicyListState.init: Child 'Text box' not found.");
|
.expect("PolicyListState.init: Child 'Text box' not found.");
|
||||||
self.add_button = ctx
|
self.add_button = ctx
|
||||||
.entity_of_child(ID_POLICY_LIST_ADD_BUTTON)
|
.entity_of_child(ID_POLICY_LISTS_ADD_BUTTON)
|
||||||
.expect("PolicyListState.init: Child 'Add button' not found.");
|
.expect("PolicyListState.init: Child 'Add button' not found.");
|
||||||
self.items_widget = ctx
|
self.items_widget = ctx
|
||||||
.entity_of_child(ID_POLICY_LIST_ITEMS_WIDGET)
|
.entity_of_child(ID_POLICY_LISTS_ITEMS_WIDGET)
|
||||||
.expect("PolicyListState.init: Child 'Items widget' not found.");
|
.expect("PolicyListState.init: Child 'Items widget' not found.");
|
||||||
self.policy_list = (*ctx.widget().get::<u32>("policy_list_view")).into();
|
self.policydata_view = (*ctx.widget()
|
||||||
|
.get::<u32>("policy_lists_view")).into();
|
||||||
|
|
||||||
if let Ok(tasks) = registry
|
if let Ok(tasks) = registry
|
||||||
.get::<Settings>("settings")
|
.get::<Settings>("settings")
|
||||||
.load::<PolicyList>(PROP_POLICY_LIST)
|
.load::<PolicyList>(PROP_POLICY_LISTS)
|
||||||
{
|
{
|
||||||
ctx.widget().set(PROP_POLICY_LIST, tasks);
|
ctx.widget().set(PROP_POLICY_LISTS, tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.adjust_count(ctx);
|
self.adjust_count(ctx);
|
||||||
@@ -221,7 +169,7 @@ impl State for PolicyListState {
|
|||||||
|
|
||||||
if let Some(header) = ctx
|
if let Some(header) = ctx
|
||||||
.widget()
|
.widget()
|
||||||
.get_mut::<PolicyList>("policy_list")
|
.get_mut::<PolicyList>("policy_lists")
|
||||||
.get_mut(index)
|
.get_mut(index)
|
||||||
{
|
{
|
||||||
header.name = text.to_string();
|
header.name = text.to_string();
|
||||||
@@ -238,7 +186,7 @@ impl State for PolicyListState {
|
|||||||
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
|
ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box));
|
||||||
}
|
}
|
||||||
Action::OpenPolicyList(index) => {
|
Action::OpenPolicyList(index) => {
|
||||||
self.open_policy_list(index, ctx);
|
self.open_policy_lists(index, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,17 +3,19 @@ use orbtk::prelude::*;
|
|||||||
use crate::{
|
use crate::{
|
||||||
data::PolicyList,
|
data::PolicyList,
|
||||||
keys::*,
|
keys::*,
|
||||||
policylist_state::{Action, PolicyListState},
|
//policylist_state::{Action, PolicyListState},
|
||||||
|
policylist_state::*,
|
||||||
};
|
};
|
||||||
|
|
||||||
type ListIndex = Option<usize>;
|
//type ListIndex = Option<usize>;
|
||||||
|
|
||||||
widget!(
|
widget!(
|
||||||
/// Starter page that offers the dialog to enter an identifier of a policy.
|
/// Starter page that offers the dialog to enter an identifier of a policy.
|
||||||
/// This identifier is checked agains a map of valid policy codes.
|
/// This identifier is checked agains a map of valid policy codes.
|
||||||
PolicyListView<PolicyListState> {
|
PolicyListView<PolicyListState> {
|
||||||
policy_list: PolicyList,
|
policy_lists: PolicyList,
|
||||||
policy_list_count: u32
|
policy_lists_count: usize,
|
||||||
|
policy_data: u32
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -21,19 +23,18 @@ impl Template for PolicyListView {
|
|||||||
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
fn template(self, id: Entity, ctx: &mut BuildContext) -> Self {
|
||||||
// all items of our policy lists
|
// all items of our policy lists
|
||||||
let items_widget = ItemsWidget::new()
|
let items_widget = ItemsWidget::new()
|
||||||
.id(ID_POLICY_LIST_ITEMS_WIDGET)
|
.id(ID_POLICY_LISTS_ITEMS_WIDGET)
|
||||||
.v_align("start")
|
.v_align("start")
|
||||||
.items_builder(move |ctx, index| {
|
.items_builder(move |ctx, index| {
|
||||||
let mut name = "".to_string();
|
let mut name = "".to_string();
|
||||||
let mut selected = false;
|
//let mut selected = false;
|
||||||
|
|
||||||
if let Some(policy_list) = ctx
|
if let Some(policy_lists) = ctx
|
||||||
.get_widget(id)
|
.get_widget(id)
|
||||||
.get::<PolicyList>(PROP_POLICY_LIST)
|
.get::<PolicyList>(PROP_POLICY_LISTS)
|
||||||
.get(index)
|
.get(index) {
|
||||||
{
|
name = policy_lists.name.clone();
|
||||||
name = policy_list.name.clone();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// plus button: open new policy
|
// plus button: open new policy
|
||||||
let helper_button = Button::new()
|
let helper_button = Button::new()
|
||||||
@@ -62,7 +63,7 @@ impl Template for PolicyListView {
|
|||||||
.margin((8.0, 0.0, 0.0, 0.0))
|
.margin((8.0, 0.0, 0.0, 0.0))
|
||||||
.visibility("collapsed")
|
.visibility("collapsed")
|
||||||
.v_align("center")
|
.v_align("center")
|
||||||
.water_mark("Insert policy name...")
|
.water_mark("Insert name of a new policy list...")
|
||||||
.attach(Grid::column(0))
|
.attach(Grid::column(0))
|
||||||
.text(text_block)
|
.text(text_block)
|
||||||
.on_changed(move |ctx, entity| {
|
.on_changed(move |ctx, entity| {
|
||||||
@@ -136,12 +137,12 @@ impl Template for PolicyListView {
|
|||||||
)
|
)
|
||||||
.build(ctx)
|
.build(ctx)
|
||||||
})
|
})
|
||||||
.policy_list_count(PROP_POLICY_LIST_COUNT, id)
|
.count((PROP_POLICY_LISTS_COUNT, id))
|
||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
// create new policy list element
|
// create new policy list element
|
||||||
let policy_list_text_box = TextBox::new()
|
let policy_lists_text_box = TextBox::new()
|
||||||
.id(ID_POLICY_LIST_TEXT_BOX)
|
.id(ID_POLICY_LISTS_TEXT_BOX)
|
||||||
.attach(Grid::row(4))
|
.attach(Grid::row(4))
|
||||||
.v_align("center")
|
.v_align("center")
|
||||||
.margin((4.0, 0.0, 0.0, 2.0))
|
.margin((4.0, 0.0, 0.0, 2.0))
|
||||||
@@ -162,8 +163,8 @@ impl Template for PolicyListView {
|
|||||||
.build(ctx);
|
.build(ctx);
|
||||||
|
|
||||||
self.name("Policy Lists")
|
self.name("Policy Lists")
|
||||||
.policy_list(PolicyList::default())
|
.policy_lists(PolicyList::default())
|
||||||
.policy_list_count(0)
|
.policy_lists_count(0)
|
||||||
.child(
|
.child(
|
||||||
Grid::new()
|
Grid::new()
|
||||||
.rows(
|
.rows(
|
||||||
@@ -254,10 +255,10 @@ impl Template for PolicyListView {
|
|||||||
.class(CLASS_TRANSPARENT)
|
.class(CLASS_TRANSPARENT)
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
)
|
)
|
||||||
.child(policy_list_text_box)
|
.child(policy_lists_text_box)
|
||||||
.child(
|
.child(
|
||||||
Button::new()
|
Button::new()
|
||||||
.id(ID_POLICY_LIST_ADD_BUTTON)
|
.id(ID_POLICY_LISTS_ADD_BUTTON)
|
||||||
.class(CLASS_ICON_ONLY)
|
.class(CLASS_ICON_ONLY)
|
||||||
.attach(Grid::row(4))
|
.attach(Grid::row(4))
|
||||||
.attach(Grid::column(2))
|
.attach(Grid::column(2))
|
||||||
@@ -265,10 +266,10 @@ impl Template for PolicyListView {
|
|||||||
.enabled(false)
|
.enabled(false)
|
||||||
.min_size(32.0, 32.0)
|
.min_size(32.0, 32.0)
|
||||||
.v_align("center")
|
.v_align("center")
|
||||||
.icon(material_font_icons::ADD_FONT_ICON)
|
.icon(material_icons_font::ADD_FONT_ICON)
|
||||||
.on_click(move |ctx, _| {
|
.on_click(move |ctx, _| {
|
||||||
ctx.get_mut::<PolicyListState>(id)
|
ctx.get_mut::<PolicyListState>(id)
|
||||||
.action(Action::NewEntry(policy_list_text_box));
|
.action(Action::NewEntry(policy_lists_text_box));
|
||||||
true
|
true
|
||||||
})
|
})
|
||||||
.build(ctx),
|
.build(ctx),
|
||||||
|
|||||||
Reference in New Issue
Block a user