From 2ba39436bc15ca6e56e3a8b1f9d7cc7bc77c4045 Mon Sep 17 00:00:00 2001 From: Ralf Zerres Date: Fri, 3 Jul 2020 01:05:33 +0200 Subject: [PATCH] callbacks: global_state: save data vector to ron file on disk * new functionality * save imported / edited data-structures persitantliy on disk to file in 'ron' format Signed-off-by: Ralf Zerres --- advotracker/src/callbacks/global_state.rs | 33 +++++++++++++---------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/advotracker/src/callbacks/global_state.rs b/advotracker/src/callbacks/global_state.rs index ffb9733..46cd69c 100644 --- a/advotracker/src/callbacks/global_state.rs +++ b/advotracker/src/callbacks/global_state.rs @@ -8,10 +8,10 @@ use orbtk::prelude::*; //use crate::data::keys; -// use crate::{ -// //data::structures::PolicyList, -// data::keys::* -// }; +use crate::{ + data::structures::PolicyList, + data::keys::* +}; /// Provides generic methods to handle states of datatypes (e.g. used in `PolicyList`). pub trait GlobalState { @@ -41,14 +41,19 @@ pub trait GlobalState { Some(copy) } - // Save the data. - // fn save(&self, registry: &mut Registry, ctx: &mut Context) { - // registry - // .get::("settings") - // .save( - // PROP_POLICY_LIST, - // ctx.widget().get::(PROP_POLICY_LIST), - // ) - // .unwrap(); - // } + /// Save the our data structure and convert it to `ron` file format. + /// The cargo package identifier (here: 'nwx.advotracker') is taken to create the app directory. + /// in users 'settings directory'. The directory location is OS dependant + /// (Windows: AppData, Unix: XDG_CONFIG_HOME, MacOS: $HOME/Library/Preferences). + /// The data is stored in filename PROP_ADVOTRACKER (here: `advotracker.ron`) + + fn save(&self, registry: &mut Registry, ctx: &mut Context<'_>) { + registry + .get::("settings") + .save( + PROP_ADVOTRACKER, + ctx.widget().get::(PROP_ADVOTRACKER), + ) + .unwrap(); + } }