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/SettingsRepositoryViewModel.cs b/Tests/ViewModels/SettingsRepositoryViewModel.cs
deleted file mode 100755
index badb4ef..0000000
--- a/Tests/ViewModels/SettingsRepositoryViewModel.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-/* 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;
-
-namespace Tests.ViewModels
-{
- [TestFixture]
- class SettingsRepositoryViewModel
- {
- [Test]
- public void CannotDeleteDefaultSettings()
- {
-
- }
- }
-}
diff --git a/Tests/ViewModels/SettingsRepositoryViewModelTest.cs b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs
new file mode 100755
index 0000000..2adb414
--- /dev/null
+++ b/Tests/ViewModels/SettingsRepositoryViewModelTest.cs
@@ -0,0 +1,71 @@
+/* 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);
+ }
+ }
+}
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..ba595ed 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
@@ -49,13 +49,19 @@ namespace zaaReloaded2.Controller
#endregion
- #region Constructor
+ #region Constructors
public Settings()
{
Elements = new List();
}
+ public Settings(string name)
+ : this()
+ {
+ Name = name;
+ }
+
///
/// Creates a new Settings object with an initial
/// set of elements.
@@ -94,5 +100,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..0cf5cd4 100755
--- a/zaaReloaded2/Controller/SettingsRepository.cs
+++ b/zaaReloaded2/Controller/SettingsRepository.cs
@@ -62,22 +62,27 @@ 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
+ #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/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..24ea5b1
--- /dev/null
+++ b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs
@@ -0,0 +1,330 @@
+/* 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);
+ vm.PropertyChanged += SettingsViewModel_PropertyChanged;
+ SettingsList.Add(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;
+ SettingsList.Add(copy);
+ _repository.SettingsList.Add(copy.RevealModelObject() as Settings);
+ }
+ }
+
+ 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;
+ }
+ }
+
+ #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..b573097 100755
--- a/zaaReloaded2/ViewModels/SettingsViewModel.cs
+++ b/zaaReloaded2/ViewModels/SettingsViewModel.cs
@@ -31,7 +31,7 @@ namespace zaaReloaded2.ViewModels
///
/// View model for the zaaReloaded2.Controller.Settings class.
///
- class SettingsViewModel : ViewModelBase
+ public class SettingsViewModel : ViewModelBase, ICloneable
{
#region Properties
@@ -238,6 +238,15 @@ namespace zaaReloaded2.ViewModels
#endregion
+ #region Implementation of ICloneable
+
+ public object Clone()
+ {
+ return new SettingsViewModel(_settings.Clone() as Settings);
+ }
+
+ #endregion
+
#region Fields
Settings _settings;
diff --git a/zaaReloaded2/zaaReloaded2.csproj b/zaaReloaded2/zaaReloaded2.csproj
index 0258aff..07a446a 100755
--- a/zaaReloaded2/zaaReloaded2.csproj
+++ b/zaaReloaded2/zaaReloaded2.csproj
@@ -222,6 +222,7 @@
+
AboutView.xaml