diff --git a/HISTORY.md b/HISTORY.md index bef6fd8..e002098 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,4 @@ + Version 2.0.0-alpha.3 (2015-07-31) ======================================================================== diff --git a/Tests/Controller/SettingsRepositoryTest.cs b/Tests/Controller/SettingsRepositoryTest.cs index 687aa36..e6b789a 100755 --- a/Tests/Controller/SettingsRepositoryTest.cs +++ b/Tests/Controller/SettingsRepositoryTest.cs @@ -56,27 +56,5 @@ namespace Tests.Controller Assert.AreEqual(1, sr.SettingsList.Count); Assert.AreEqual(testName, sr.SettingsList[0].Name); } - - [Test] - public void CreateDefaultSettings() - { - SettingsRepository sr = new SettingsRepository(); - sr.SettingsList.Add(new Settings("test1", null)); - sr.SettingsList.Add(new Settings("test2", null)); - sr.SettingsList.Add(new Settings("test3", null)); - sr.ResetDefault(); - - // Assert that there are now only the 2 default settings - Assert.AreEqual(2, sr.SettingsList.Count); - - Assert.AreEqual( - zaaReloaded2.Properties.Settings.Default.SettingsNameWard, - sr.SettingsList[0].Name, - "Settings for ward expected as #1 (index 0) in list"); - Assert.AreEqual( - zaaReloaded2.Properties.Settings.Default.SettingsNameClinic, - sr.SettingsList[1].Name, - "Settings for outpatient clinic expected as #2 (index 1) in list"); - } } } diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 4caecda..fb63329 100755 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -91,7 +91,7 @@ - + diff --git a/Tests/ViewModels/SettingsRepositoryViewModelTest.cs b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs new file mode 100755 index 0000000..ff434a1 --- /dev/null +++ b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs @@ -0,0 +1,72 @@ +/* SettingsRepositoryViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using zaaReloaded2.Controller; +using zaaReloaded2.ViewModels; + +namespace Tests.ViewModels +{ + [TestFixture] + class SettingsRepositoryViewModelTest + { + SettingsRepositoryViewModel _vm; + const string TESTNAME = "hello world"; + + [SetUp] + public void SetUp() + { + SettingsRepository rep = new SettingsRepository(); + rep.SettingsList.Add(new Settings(TESTNAME)); + _vm = new SettingsRepositoryViewModel(rep); + } + + [Test] + public void CanDeleteNonDefaultSettings() + { + _vm.SettingsList[_vm.SettingsList.Count - 1].IsSelected = true; + Assert.IsTrue(_vm.DeleteSettingsCommand.CanExecute(null)); + } + + [Test] + public void CannotDeleteDefaultSettings() + { + _vm.SettingsList[0].IsSelected = true; + Assert.IsFalse(_vm.DeleteSettingsCommand.CanExecute(null)); + } + + [Test] + public void CopySettings() + { + SettingsViewModel orig = _vm.SettingsList[0]; + orig.IsSelected = true; + _vm.CopySettingsCommand.Execute(null); + SettingsViewModel copy = _vm.SettingsList[_vm.SettingsList.Count-1]; + + // Make sure we have a new object + Assert.AreNotSame(orig, copy); + Assert.AreNotSame(orig.RevealModelObject(), copy.RevealModelObject()); + + Assert.AreEqual(String.Format("Kopie von {0}", orig.Name), copy.Name); + Assert.IsTrue(copy.IsSelected); + } + } +} diff --git a/Tests/ViewModels/SettingsViewModelTest.cs b/Tests/ViewModels/SettingsViewModelTest.cs index f06d5d8..65a1d56 100755 --- a/Tests/ViewModels/SettingsViewModelTest.cs +++ b/Tests/ViewModels/SettingsViewModelTest.cs @@ -22,6 +22,7 @@ using System.Text; using NUnit.Framework; using zaaReloaded2.ViewModels; using zaaReloaded2.Controller; +using zaaReloaded2.Controller.Elements; namespace Tests.ViewModels { @@ -51,7 +52,16 @@ namespace Tests.ViewModels [Test] public void CannotAddChildElementToFormatElement() { - + ControlElementViewModel parent = new ControlElementViewModel( + new SelectFirstDay()); + _settingsVM.AddElementViewModel(parent); + parent.IsSelected = true; + Assert.IsTrue(_settingsVM.AddChildElementCommand.CanExecute(null)); + FormatElementViewModel child = new FormatElementViewModel(new Items()); + parent.AddChildElement(child); + parent.IsSelected = false; + child.IsSelected = true; + Assert.IsFalse(_settingsVM.AddChildElementCommand.CanExecute(null)); } [Test] diff --git a/www/versioninfo.txt b/www/versioninfo.txt index 8e94de9..51f57b2 100644 --- a/www/versioninfo.txt +++ b/www/versioninfo.txt @@ -1,4 +1,4 @@ -2.0.0-alpha.3 -http://zaa.nephrowiki.de/downloads/zaaReloaded-2.0.0-alpha.3.exe -c9bb1062acdf2d8181a3915e34d5cfe96d26934a publish/release/zaaReloaded-2.0.0-alpha.3.exe +2.0.0-alpha.4 +http://zaa.nephrowiki.de/downloads/zaaReloaded-2.0.0-alpha.4.exe +3f511ac90dbfbb14318948a3be1d1f9d2eb059d1 publish/release/zaaReloaded-2.0.0-alpha.4.exe diff --git a/zaaReloaded2/Controller/Elements/CustomText.cs b/zaaReloaded2/Controller/Elements/CustomText.cs index f3ebe9f..cbe1576 100755 --- a/zaaReloaded2/Controller/Elements/CustomText.cs +++ b/zaaReloaded2/Controller/Elements/CustomText.cs @@ -36,5 +36,12 @@ namespace zaaReloaded2.Controller.Elements { formatter.WriteParagraph(Content); } + + protected override ElementBase CreateInstance() + { + CustomText clone = new CustomText(); + clone.Content = Content; + return clone; + } } } diff --git a/zaaReloaded2/Controller/Elements/ElementBase.cs b/zaaReloaded2/Controller/Elements/ElementBase.cs index ae91011..ce13628 100755 --- a/zaaReloaded2/Controller/Elements/ElementBase.cs +++ b/zaaReloaded2/Controller/Elements/ElementBase.cs @@ -28,7 +28,7 @@ namespace zaaReloaded2.Controller.Elements /// Base class for formatting elements. /// [Serializable] - public abstract class ElementBase + public abstract class ElementBase : ICloneable { /// /// Returns the label for this formatting element. @@ -44,5 +44,16 @@ namespace zaaReloaded2.Controller.Elements /// Element belongs to. The Formatter object provides access /// to the current Word document etc. abstract public void Run(zaaReloaded2.Formatter.Formatter formatter); + + public object Clone() + { + return CreateInstance(); + } + + /// + /// Creates a new instance that can be used for cloning. + /// + /// New instance of a derived class. + protected abstract ElementBase CreateInstance(); } } diff --git a/zaaReloaded2/Controller/Elements/SelectEachDay.cs b/zaaReloaded2/Controller/Elements/SelectEachDay.cs index ef42a56..eed0093 100755 --- a/zaaReloaded2/Controller/Elements/SelectEachDay.cs +++ b/zaaReloaded2/Controller/Elements/SelectEachDay.cs @@ -43,5 +43,10 @@ namespace zaaReloaded2.Controller.Elements public SelectEachDay(IList formatElements) : base(formatElements) { } + + protected override ElementBase CreateInstance() + { + return new SelectEachDay(); + } } } diff --git a/zaaReloaded2/Controller/Elements/SelectFirstDay.cs b/zaaReloaded2/Controller/Elements/SelectFirstDay.cs index 930a585..f635948 100755 --- a/zaaReloaded2/Controller/Elements/SelectFirstDay.cs +++ b/zaaReloaded2/Controller/Elements/SelectFirstDay.cs @@ -47,5 +47,10 @@ namespace zaaReloaded2.Controller.Elements public SelectFirstDay(IList formatElements) : base(formatElements) { } + + protected override ElementBase CreateInstance() + { + return new SelectFirstDay(); + } } } diff --git a/zaaReloaded2/Controller/Elements/SelectLastDay.cs b/zaaReloaded2/Controller/Elements/SelectLastDay.cs index 2e2230d..2f5107a 100755 --- a/zaaReloaded2/Controller/Elements/SelectLastDay.cs +++ b/zaaReloaded2/Controller/Elements/SelectLastDay.cs @@ -48,5 +48,10 @@ namespace zaaReloaded2.Controller.Elements public SelectLastDay(IList formatElements) : base(formatElements) { } + + protected override ElementBase CreateInstance() + { + return new SelectLastDay(); + } } } diff --git a/zaaReloaded2/Controller/Settings.cs b/zaaReloaded2/Controller/Settings.cs index d4a120a..46b1593 100755 --- a/zaaReloaded2/Controller/Settings.cs +++ b/zaaReloaded2/Controller/Settings.cs @@ -28,7 +28,7 @@ namespace zaaReloaded2.Controller /// Holds settings related to controlling laboratory output. /// [Serializable] - public class Settings + public class Settings : ICloneable { #region Properties @@ -47,13 +47,26 @@ namespace zaaReloaded2.Controller /// public IList Elements { get; private set; } + /// + /// Gets the unique ID of this Settings object. The unique + /// ID is not included in deep-copying (cloning). + /// + public Guid Uid { get; private set; } + #endregion - #region Constructor + #region Constructors public Settings() { Elements = new List(); + Uid = Guid.NewGuid(); + } + + public Settings(string name) + : this() + { + Name = name; } /// @@ -94,5 +107,19 @@ namespace zaaReloaded2.Controller } #endregion + + #region Implementation of ICloneable + + public object Clone() + { + Settings clone = new Settings( + String.Format("Kopie von {0}", Name), + Elements.Select(e => e.Clone() as ElementBase).ToList() + ); + clone.ReferenceStyle = ReferenceStyle; + return clone; + } + + #endregion } } diff --git a/zaaReloaded2/Controller/SettingsRepository.cs b/zaaReloaded2/Controller/SettingsRepository.cs index 64ce8e4..a8e55cb 100755 --- a/zaaReloaded2/Controller/SettingsRepository.cs +++ b/zaaReloaded2/Controller/SettingsRepository.cs @@ -62,22 +62,42 @@ namespace zaaReloaded2.Controller #endregion - #region Constructor + #region Constructors + /// + /// Creates a new instance of a settings repository that will + /// contain a default set of settings. + /// public SettingsRepository() { SettingsList = new List(); + CreateDefault(); } #endregion #region Public methods + /// + /// Looks up a Settings object contained in this repository + /// by unique ID. + /// + /// GUID to look for. + /// Settings object with this GUID, or null if the + /// GUID was not found. + public Settings FindByGuid(Guid uid) + { + return SettingsList.FirstOrDefault(s => s.Uid == uid); + } + #endregion + + #region Private methods + /// /// Resets the Settings contained in this SettingsRepository /// to the default set of settings. /// - public void ResetDefault() + private void CreateDefault() { SettingsList.Clear(); diff --git a/zaaReloaded2/Formatter/DanielsStyle.cs b/zaaReloaded2/Formatter/DanielsStyle.cs index a2ab215..03ed7ff 100755 --- a/zaaReloaded2/Formatter/DanielsStyle.cs +++ b/zaaReloaded2/Formatter/DanielsStyle.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Interop.Word; +using System.Text.RegularExpressions; namespace zaaReloaded2.Formatter { @@ -32,6 +33,7 @@ namespace zaaReloaded2.Formatter { FixWords(document); FormatDiagnoses(selection); + FixSalutation(document); } static void FormatDiagnoses(Selection selection) @@ -59,6 +61,7 @@ namespace zaaReloaded2.Formatter static void FixWords(Document document) { Find find = document.Range().Find; + find.Execute2007(FindText: "Körperlicher Untersuchungsbefund", ReplaceWith: "Körperl. Untersuchung", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "Dr.D.Kraus", ReplaceWith: "Dr. D. Kraus", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "Z. n.", ReplaceWith: "Z.n.", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "Zust. n.", ReplaceWith: "Z.n.", Replace: WdReplace.wdReplaceAll); @@ -66,6 +69,23 @@ namespace zaaReloaded2.Formatter find.Execute2007(FindText: "Assistent der Klinik", ReplaceWith: "Internist/Nephrologe", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "Professor Dr.", ReplaceWith: "Prof. Dr.", Replace: WdReplace.wdReplaceAll); find.Execute2007(FindText: "mmHg", ReplaceWith: "mm Hg", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "RR ", ReplaceWith: "", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "HF ", ReplaceWith: "", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "TAC-Spiegel", ReplaceWith: "Tacrolimus-Talspiegel", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "4-7", ReplaceWith: "4 bis 7", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "5-8", ReplaceWith: "5 bis 8", Replace: WdReplace.wdReplaceAll); + find.Execute2007(FindText: "8-10", ReplaceWith: "8 bis 10", Replace: WdReplace.wdReplaceAll); + } + + static void FixSalutation(Document document) + { + Regex sal = new Regex(@"^Mit.*(freundl|kolleg)"); + Regex med = new Regex(@"^((Häusl|Empf).*Medikat)|Therapieempf"); + foreach (Paragraph p in document.Paragraphs) + { + if (sal.IsMatch(p.Range.Text)) p.Range.Text = "Mit freundlichen, kollegialen Grüßen,"; + if (med.IsMatch(p.Range.Text)) p.Range.Text = "Aktuelle Medikation:"; + } } } } diff --git a/zaaReloaded2/VERSION b/zaaReloaded2/VERSION index 4f67e82..a4c6686 100755 --- a/zaaReloaded2/VERSION +++ b/zaaReloaded2/VERSION @@ -1,2 +1,2 @@ -2.0.0-alpha.3 -2.0.0.3 +2.0.0-alpha.4 +2.0.0.4 diff --git a/Tests/ViewModels/SettingsRepositoryViewModel.cs b/zaaReloaded2/ViewModels/CategoryViewModel.cs similarity index 51% rename from Tests/ViewModels/SettingsRepositoryViewModel.cs rename to zaaReloaded2/ViewModels/CategoryViewModel.cs index badb4ef..8402275 100755 --- a/Tests/ViewModels/SettingsRepositoryViewModel.cs +++ b/zaaReloaded2/ViewModels/CategoryViewModel.cs @@ -1,4 +1,4 @@ -/* SettingsRepositoryViewModel.cs +/* CategoryViewModel.cs * part of zaaReloaded2 * * Copyright 2015 Daniel Kraus @@ -19,18 +19,28 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; -using NUnit.Framework; -using zaaReloaded2.Controller; +using Bovender.Mvvm.ViewModels; -namespace Tests.ViewModels +namespace zaaReloaded2.ViewModels { - [TestFixture] - class SettingsRepositoryViewModel + /// + /// A simple view model that can be used to categorize items + /// in a tree view. It has a custom DisplayString and holds + /// a collection of child view model items. + /// + class CategoryViewModel : ViewModelBase { - [Test] - public void CannotDeleteDefaultSettings() - { + public IEnumerable Children { get; private set; } + public CategoryViewModel(string name, IEnumerable children) + { + DisplayString = name; + Children = children; + } + + public override object RevealModelObject() + { + throw new NotImplementedException(); } } } diff --git a/zaaReloaded2/ViewModels/ControlElementViewModel.cs b/zaaReloaded2/ViewModels/ControlElementViewModel.cs index 1826c42..c5452b1 100755 --- a/zaaReloaded2/ViewModels/ControlElementViewModel.cs +++ b/zaaReloaded2/ViewModels/ControlElementViewModel.cs @@ -46,5 +46,16 @@ namespace zaaReloaded2.ViewModels { } #endregion + + #region Public methods + + public void AddChildElement(FormatElementViewModel viewModel) + { + Elements.Add(viewModel); + ControlElementBase e = Element as ControlElementBase; + e.FormatElements.Add(viewModel.RevealModelObject() as FormatElementBase); + } + + #endregion } } diff --git a/zaaReloaded2/ViewModels/ElementPickerViewModel.cs b/zaaReloaded2/ViewModels/ElementPickerViewModel.cs new file mode 100755 index 0000000..24d75eb --- /dev/null +++ b/zaaReloaded2/ViewModels/ElementPickerViewModel.cs @@ -0,0 +1,122 @@ +/* ElementPickerViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Bovender.Mvvm; +using Bovender.Mvvm.Messaging; +using Bovender.Mvvm.ViewModels; +using System.Collections.ObjectModel; +using zaaReloaded2.Controller.Elements; + +namespace zaaReloaded2.ViewModels +{ + /// + /// View model that presents a list of zaaReloaded2.Contorller.Elements.ElementBase + /// classes to choose from. + /// + class ElementPickerViewModel : ViewModelBase + { + #region Properties + + /// + /// A two-dimensional tree + /// + public IList AvailableElements { get; private set; } + + #endregion + + #region Constructors + + public ElementPickerViewModel(SettingsViewModel caller, bool allowControlElements) + { + _caller = caller; + AvailableElements = new List(); + if (allowControlElements) + { + AvailableElements.Add( + new CategoryViewModel( + "Kontroll-Elemente", + new Collection() + { + CreateControlElementViewModel(new SelectFirstDay()), + CreateControlElementViewModel(new SelectLastDay()), + CreateControlElementViewModel(new SelectEachDay()) + } + ) + ); + } + AvailableElements.Add( + new CategoryViewModel( + "Ausgabe-Elemente", + new Collection() + { + CreateFormatElementViewModel("Laborparameter", new Items()), + CreateFormatElementViewModel("Beliebiger Text", new CustomText()), + } + ) + ); + } + + #endregion + + #region Private methods + + /// + /// Creates a new ControlElementViewModel that wraps a ControlElementBase + /// object. The display string of the ControlElementViewModel is taken + /// from the canonical Label of the control element. + /// + ViewModelBase CreateControlElementViewModel(ControlElementBase element) + { + ControlElementViewModel vm = new ControlElementViewModel(element); + vm.DisplayString = element.Label; + return vm; + } + + /// + /// Creates a new FormatElementViewModel that wraps a FormatElementBase + /// object and has a custom display string. The custom display string + /// is necessary because format elements do not have a canonical label. + /// + ViewModelBase CreateFormatElementViewModel(string name, FormatElementBase element) + { + FormatElementViewModel vm = new FormatElementViewModel(element); + vm.DisplayString = name; + return vm; + } + + #endregion + + #region Implementation ov ViewModelBase + + public override object RevealModelObject() + { + throw new NotImplementedException(); + } + + #endregion + + #region Fields + + SettingsViewModel _caller; + + #endregion + } +} diff --git a/zaaReloaded2/ViewModels/ElementViewModel.cs b/zaaReloaded2/ViewModels/ElementViewModel.cs index b46a9e8..a14a865 100755 --- a/zaaReloaded2/ViewModels/ElementViewModel.cs +++ b/zaaReloaded2/ViewModels/ElementViewModel.cs @@ -26,7 +26,7 @@ using System.Collections.ObjectModel; namespace zaaReloaded2.ViewModels { - abstract class ElementViewModel : ViewModelBase + public abstract class ElementViewModel : ViewModelBase { #region Properties diff --git a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs new file mode 100755 index 0000000..11a764b --- /dev/null +++ b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs @@ -0,0 +1,342 @@ +/* SettingsRepositoryViewModel.cs + * part of zaaReloaded2 + * + * Copyright 2015 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Bovender.Mvvm; +using Bovender.Mvvm.ViewModels; +using Bovender.Mvvm.Messaging; +using zaaReloaded2.Controller; + +namespace zaaReloaded2.ViewModels +{ + public class SettingsRepositoryViewModel : ViewModelBase + { + #region Properties + + public IList SettingsList { get; private set; } + + public SettingsViewModel Selected { get; private set; } + + #endregion + + #region Commands + + public DelegatingCommand AddSettingsCommand + { + get + { + if (_addSettingsCommand == null) + { + _addSettingsCommand = new DelegatingCommand( + param => DoAddSettings()); + } + return _addSettingsCommand; + } + } + + public DelegatingCommand EditSettingsCommand + { + get + { + if (_editSettingsCommand == null) + { + _editSettingsCommand = new DelegatingCommand( + param => DoEditSettings(), + param => CanEditSettings()); + } + return _editSettingsCommand; + } + } + + public DelegatingCommand UseSettingsCommand + { + get + { + if (_useSettingsCommand == null) + { + _useSettingsCommand = new DelegatingCommand( + param => DoUseSettings(), + param => CanUseSettings()); + } + return _useSettingsCommand; + } + } + + public DelegatingCommand DeleteSettingsCommand + { + get + { + if (_deleteSettingsCommand == null) + { + _deleteSettingsCommand = new DelegatingCommand( + param => DoDeleteSettings(), + param => CanDeleteSettings()); + } + return _deleteSettingsCommand; + } + } + + public DelegatingCommand CopySettingsCommand + { + get + { + if (_copySettingsCommand == null) + { + _copySettingsCommand = new DelegatingCommand( + param => DoCopySettings()); + } + return _copySettingsCommand; + } + } + + public DelegatingCommand ResetSettingsCommand + { + get + { + if (_resetSettingsCommand == null) + { + _resetSettingsCommand = new DelegatingCommand( + param => DoResetSettings()); + } + return _resetSettingsCommand; + } + } + + #endregion + + #region Messages + + Message EditSettingsMessage + { + get + { + if (_editSettingsMessage == null) + { + _editSettingsMessage = new Message(); + } + return _editSettingsMessage; + } + } + + Message UseSettingsMessage + { + get + { + if (_useSettingsMessage == null) + { + _useSettingsMessage = new Message(); + } + return _useSettingsMessage; + } + } + + Message ConfirmDeleteSettingsMessage + { + get + { + if (_confirmDeleteSettingsMessage == null) + { + _confirmDeleteSettingsMessage = new Message(); + } + return _confirmDeleteSettingsMessage; + } + } + + Message ConfirmResetSettingsMessage + { + get + { + if (_confirmResetSettingsMessage == null) + { + _confirmResetSettingsMessage = new Message(); + } + return _confirmResetSettingsMessage; + } + } + + #endregion + + #region Constructors + + public SettingsRepositoryViewModel(SettingsRepository repository) + { + _repository = repository; + SettingsList = new List(); + foreach (Settings s in repository.SettingsList) + { + SettingsViewModel vm = new SettingsViewModel(s); + AddSettingsViewModel(vm); + } + } + + #endregion + + #region Private methods + + void DoEditSettings() + { + if (CanEditSettings()) + { + EditSettingsMessage.Send(new ViewModelMessageContent(Selected)); + } + } + + bool CanEditSettings() + { + return Selected != null && !IsDefaultSettings(); + } + + void DoUseSettings() + { + UseSettingsMessage.Send(new ViewModelMessageContent(Selected)); + } + + bool CanUseSettings() + { + return Selected != null; + } + + void DoAddSettings() + { + Settings s = new Settings("Neu"); + SettingsViewModel vm = new SettingsViewModel(s); + _repository.SettingsList.Add(s); + SettingsList.Add(vm); + vm.IsSelected = true; + } + + bool CanDeleteSettings() + { + return Selected != null && !IsDefaultSettings(); + } + + void DoDeleteSettings() + { + if (CanDeleteSettings()) + { + ConfirmDeleteSettingsMessage.Send( + new ViewModelMessageContent(Selected), + param => ConfirmDeleteSettings(param)); + } + } + + void ConfirmDeleteSettings(ViewModelMessageContent content) + { + SettingsViewModel vm = content.ViewModel as SettingsViewModel; + if (CanDeleteSettings() && content.Confirmed) + { + _repository.SettingsList.Remove(vm.RevealModelObject() as Settings); + SettingsList.Remove(vm); + } + } + + void DoResetSettings() + { + ConfirmResetSettingsMessage.Send( + new ViewModelMessageContent(this), + param => ConfirmResetSettings(param)); + } + + void ConfirmResetSettings(ViewModelMessageContent content) + { + if (content.Confirmed) + { + + } + } + + void DoCopySettings() + { + if (Selected != null) + { + SettingsViewModel copy = Selected.Clone() as SettingsViewModel; + _repository.SettingsList.Add(copy.RevealModelObject() as Settings); + AddSettingsViewModel(copy); + Selected.IsSelected = false; + copy.IsSelected = true; + } + } + + void SettingsViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) + { + SettingsViewModel vm = sender as SettingsViewModel; + if (vm != null && e.PropertyName == "IsSelected") + { + Selected = vm.IsSelected ? vm : null; + } + } + + /// + /// Determines whether the selected SettingsViewModel belongs + /// to one of the default settings. + /// + bool IsDefaultSettings() + { + if (Selected != null) + { + return + (Selected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameClinic + || Selected.Name == zaaReloaded2.Properties.Settings.Default.SettingsNameWard); + } + else + { + return false; + } + } + + /// + /// Adds a settings view model to the collection and wires the + /// PropertyChanged event. + /// + /// SettingsViewModel to add. + void AddSettingsViewModel(SettingsViewModel settingsViewModel) + { + settingsViewModel.PropertyChanged += SettingsViewModel_PropertyChanged; + SettingsList.Add(settingsViewModel); + } + + #endregion + + #region Implementation of ViewModelBase + + public override object RevealModelObject() + { + return _repository; + } + + #endregion + + #region Fields + + SettingsRepository _repository; + DelegatingCommand _useSettingsCommand; + DelegatingCommand _addSettingsCommand; + DelegatingCommand _editSettingsCommand; + DelegatingCommand _deleteSettingsCommand; + DelegatingCommand _resetSettingsCommand; + DelegatingCommand _copySettingsCommand; + Message _confirmDeleteSettingsMessage; + Message _confirmResetSettingsMessage; + Message _editSettingsMessage; + Message _useSettingsMessage; + + #endregion + } +} diff --git a/zaaReloaded2/ViewModels/SettingsViewModel.cs b/zaaReloaded2/ViewModels/SettingsViewModel.cs index 6ab8849..c662f1b 100755 --- a/zaaReloaded2/ViewModels/SettingsViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsViewModel.cs @@ -22,6 +22,7 @@ using System.Linq; using System.Text; using Bovender.Mvvm; using Bovender.Mvvm.ViewModels; +using Bovender.Mvvm.Messaging; using zaaReloaded2.Controller; using zaaReloaded2.Controller.Elements; using zaaReloaded2.Formatter; @@ -31,7 +32,7 @@ namespace zaaReloaded2.ViewModels /// /// View model for the zaaReloaded2.Controller.Settings class. /// - class SettingsViewModel : ViewModelBase + public class SettingsViewModel : ViewModelBase, ICloneable { #region Properties @@ -161,6 +162,20 @@ namespace zaaReloaded2.ViewModels } } + public DelegatingCommand AddChildElementCommand + { + get + { + if (_addChildElementCommand == null) + { + _addChildElementCommand = new DelegatingCommand( + param => DoAddChildElement(), + param => CanAddChildElement()); + } + return _addChildElementCommand; + } + } + public DelegatingCommand DeleteElementCommand { get @@ -191,10 +206,31 @@ namespace zaaReloaded2.ViewModels #endregion + #region Public methods + + /// + /// Wires the OnProperty changed event of an ElementViewModel's + /// wrapped model and adds the view model to the Elements collection. + /// + public void AddElementViewModel(ElementViewModel elementViewModel) + { + elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged; + Elements.Add(elementViewModel); + } + + #endregion + #region Private methods void DoAddElement() { } + void DoAddChildElement() { } + + bool CanAddChildElement() + { + return SelectedElement is ControlElementViewModel; + } + void DoDeleteElement() { } bool CanDeleteElement() { return _selectedElement != null; } @@ -203,17 +239,6 @@ namespace zaaReloaded2.ViewModels bool CanCopyElement() { return _selectedElement != null; } - /// - /// Internal function that creates wires the OnProperty changed event - /// of an ElementViewModel's wrapped model and adds the view model - /// to the Elements collection. - /// - void AddElementViewModel(ElementViewModel elementViewModel) - { - elementViewModel.PropertyChanged += ElementViewModel_PropertyChanged; - Elements.Add(elementViewModel); - } - /// /// Sets or unsets the SelectedElement property whenever the IsSelected /// property of an ElementViewModel changes. @@ -238,12 +263,23 @@ namespace zaaReloaded2.ViewModels #endregion + #region Implementation of ICloneable + + public object Clone() + { + return new SettingsViewModel(_settings.Clone() as Settings); + } + + #endregion + #region Fields Settings _settings; DelegatingCommand _addElementCommand; + DelegatingCommand _addChildElementCommand; DelegatingCommand _deleteElementCommand; DelegatingCommand _copyElementCommand; + List _elements; ElementViewModel _selectedElement; EnumProvider _referenceStyle; diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj index 0258aff..d595215 100755 --- a/zaaReloaded2/zaaReloaded2.csproj +++ b/zaaReloaded2/zaaReloaded2.csproj @@ -219,9 +219,12 @@ + + + AboutView.xaml