diff --git a/frontend/src/policylist_state.rs b/frontend/src/policylist_state.rs index 9d344ef..c6733b8 100644 --- a/frontend/src/policylist_state.rs +++ b/frontend/src/policylist_state.rs @@ -13,7 +13,7 @@ pub enum Action { NewEntry(Entity), RemoveFocus(Entity), RemoveEntry(usize), - OpenPolicyList(Entity), + OpenPolicyList(usize), SetEntry(Entity), TextChanged(Entity, usize), } @@ -24,7 +24,7 @@ pub struct PolicyListState { action:Option, add_button: Entity, items_widget: Entity, - policylist_view: Entity, + policydata_view: Entity, last_focused: Option, text_box: Entity, } @@ -54,45 +54,38 @@ impl PolicyListState { } else { 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); } - /// update number of available policy data entries. + /// update number of available policy list entries. fn adjust_count(&self, ctx: &mut Context) { - if let Some(index) = ctx.widget().clone::>("list_index") { - if let Some(policy_data) = ctx - .widget() - .clone::("policy_list") - .get(index) - { - ctx.widget().set("policy_list_count", policy_data.len()); - } - } + let policy_lists_count = ctx.widget().get::(PROP_POLICY_LISTS).len(); + ctx.widget().set(PROP_POLICY_LISTS_COUNT, policy_lists_count); } // 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() - .get_mut::(PROP_POLICY_LIST) - .push(PolicyList::new(text)); + .get_mut::(PROP_POLICY_LISTS) + .push(PolicyData::new(name)); self.adjust_count(ctx); self.save(registry, ctx); } - // opens a policy list. - fn open_policy_list(&self, index: usize, ctx: &mut Context) { + // opens a given policy list name. + fn open_policy_lists(&self, index: usize, ctx: &mut Context) { ctx.get_widget(self.text_box) - .set("name", String::from("")); - ctx.get_widget(self.policy_list) + .set("text", String16::from("")); + ctx.get_widget(self.policydata_view) .set("list_index", Some(index)); - self.navigate(self.policy_list, ctx); + self.navigate(self.policydata_view, ctx); } // removes a policy list. fn remove_entry(&self, index: usize, registry: &mut Registry, ctx: &mut Context) { ctx.widget() - .get_mut::(PROP_POLICY_LIST) + .get_mut::(PROP_POLICY_LISTS) .remove(index); self.adjust_count(ctx); self.save(registry, ctx); @@ -122,72 +115,27 @@ impl PolicyListState { 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::>("list_index") { - if let Some(policy_list) = ctx - .widget() - .get_mut::("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::>("list_index") { - if let Some(policy_list) = ctx - .widget() - .get_mut::("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 { fn init(&mut self, registry: &mut Registry, ctx: &mut Context) { 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."); 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."); 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."); - self.policy_list = (*ctx.widget().get::("policy_list_view")).into(); + self.policydata_view = (*ctx.widget() + .get::("policy_lists_view")).into(); if let Ok(tasks) = registry .get::("settings") - .load::(PROP_POLICY_LIST) + .load::(PROP_POLICY_LISTS) { - ctx.widget().set(PROP_POLICY_LIST, tasks); + ctx.widget().set(PROP_POLICY_LISTS, tasks); } self.adjust_count(ctx); @@ -221,7 +169,7 @@ impl State for PolicyListState { if let Some(header) = ctx .widget() - .get_mut::("policy_list") + .get_mut::("policy_lists") .get_mut(index) { header.name = text.to_string(); @@ -238,7 +186,7 @@ impl State for PolicyListState { ctx.push_event_by_window(FocusEvent::RemoveFocus(text_box)); } Action::OpenPolicyList(index) => { - self.open_policy_list(index, ctx); + self.open_policy_lists(index, ctx); } } } diff --git a/frontend/src/policylist_view.rs b/frontend/src/policylist_view.rs index 9f9f829..0f20359 100644 --- a/frontend/src/policylist_view.rs +++ b/frontend/src/policylist_view.rs @@ -3,17 +3,19 @@ use orbtk::prelude::*; use crate::{ data::PolicyList, keys::*, - policylist_state::{Action, PolicyListState}, + //policylist_state::{Action, PolicyListState}, + policylist_state::*, }; -type ListIndex = Option; +//type ListIndex = Option; widget!( /// Starter page that offers the dialog to enter an identifier of a policy. /// This identifier is checked agains a map of valid policy codes. PolicyListView { - policy_list: PolicyList, - policy_list_count: u32 + policy_lists: PolicyList, + policy_lists_count: usize, + policy_data: u32 } ); @@ -21,19 +23,18 @@ impl Template for PolicyListView { fn template(self, id: Entity, ctx: &mut BuildContext) -> Self { // all items of our policy lists let items_widget = ItemsWidget::new() - .id(ID_POLICY_LIST_ITEMS_WIDGET) + .id(ID_POLICY_LISTS_ITEMS_WIDGET) .v_align("start") .items_builder(move |ctx, index| { 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::(PROP_POLICY_LIST) - .get(index) - { - name = policy_list.name.clone(); - } + .get::(PROP_POLICY_LISTS) + .get(index) { + name = policy_lists.name.clone(); + } // plus button: open new policy let helper_button = Button::new() @@ -62,7 +63,7 @@ impl Template for PolicyListView { .margin((8.0, 0.0, 0.0, 0.0)) .visibility("collapsed") .v_align("center") - .water_mark("Insert policy name...") + .water_mark("Insert name of a new policy list...") .attach(Grid::column(0)) .text(text_block) .on_changed(move |ctx, entity| { @@ -136,12 +137,12 @@ impl Template for PolicyListView { ) .build(ctx) }) - .policy_list_count(PROP_POLICY_LIST_COUNT, id) + .count((PROP_POLICY_LISTS_COUNT, id)) .build(ctx); // create new policy list element - let policy_list_text_box = TextBox::new() - .id(ID_POLICY_LIST_TEXT_BOX) + let policy_lists_text_box = TextBox::new() + .id(ID_POLICY_LISTS_TEXT_BOX) .attach(Grid::row(4)) .v_align("center") .margin((4.0, 0.0, 0.0, 2.0)) @@ -162,8 +163,8 @@ impl Template for PolicyListView { .build(ctx); self.name("Policy Lists") - .policy_list(PolicyList::default()) - .policy_list_count(0) + .policy_lists(PolicyList::default()) + .policy_lists_count(0) .child( Grid::new() .rows( @@ -254,10 +255,10 @@ impl Template for PolicyListView { .class(CLASS_TRANSPARENT) .build(ctx), ) - .child(policy_list_text_box) + .child(policy_lists_text_box) .child( Button::new() - .id(ID_POLICY_LIST_ADD_BUTTON) + .id(ID_POLICY_LISTS_ADD_BUTTON) .class(CLASS_ICON_ONLY) .attach(Grid::row(4)) .attach(Grid::column(2)) @@ -265,10 +266,10 @@ impl Template for PolicyListView { .enabled(false) .min_size(32.0, 32.0) .v_align("center") - .icon(material_font_icons::ADD_FONT_ICON) + .icon(material_icons_font::ADD_FONT_ICON) .on_click(move |ctx, _| { ctx.get_mut::(id) - .action(Action::NewEntry(policy_list_text_box)); + .action(Action::NewEntry(policy_lists_text_box)); true }) .build(ctx),