using rabi_splitter_WPF.Annotations; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; namespace rabi_splitter_WPF { public class VariableExportContext : INotifyPropertyChanged { private List _variableExportSettings; private List _variables; private Dictionary variableValues; private ItemCollection variableListBoxItems; private ItemCollection variableExportListBoxItems; public VariableExportContext() { _variableExportSettings = new List(); _variables = new List(); variableValues = new Dictionary(); } #region Update Logic public void UpdateVariables(bool updateFile) { foreach (var variable in _variables) { variable.UpdateValue(); variableValues[variable.Handle] = variable.Value; } foreach (var ves in _variableExportSettings) { ves.UpdateText(variableValues); if (updateFile) ves.MaybeUpdateFile(); } } internal void SetItemControls(ItemCollection variableListBoxItems, ItemCollection variableExportListBoxItems) { this.variableListBoxItems = variableListBoxItems; this.variableExportListBoxItems = variableExportListBoxItems; } public void DefineVariableExports(ExportableVariable[] exports) { Variables = exports.ToList(); variableValues.Clear(); } #endregion #region Properties public List Variables { get { return _variables; } private set { _variables = value; variableListBoxItems.Refresh(); } } public List VariableExportSettings { get { return _variableExportSettings; } } internal void Add(VariableExportSetting ves) { _variableExportSettings.Add(ves); variableExportListBoxItems.Refresh(); } internal void Delete(VariableExportSetting ves) { _variableExportSettings.Remove(ves); variableExportListBoxItems.Refresh(); } #endregion public event PropertyChangedEventHandler PropertyChanged; [NotifyPropertyChangedInvocator] protected virtual void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }