diff --git a/HISTORY.md b/HISTORY.md index e002098..6394dbd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,12 @@ +Version 2.0.0-alpha.5 (2015-08-04) +======================================================================== + +- FIX: Daniels Spezial löscht nicht mehr die Unterschriften. +- NEU: Eingebautes Demo-Dokument zum Ausprobieren. + +* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + + Version 2.0.0-alpha.3 (2015-07-31) ======================================================================== diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index fb63329..fc37c1f 100755 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -91,6 +91,7 @@ + diff --git a/Tests/ViewModels/ElementPickerViewModelTest.cs b/Tests/ViewModels/ElementPickerViewModelTest.cs new file mode 100755 index 0000000..6240d0b --- /dev/null +++ b/Tests/ViewModels/ElementPickerViewModelTest.cs @@ -0,0 +1,54 @@ +/* ElementPickerViewModelTest.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 Bovender.Mvvm.ViewModels; +using zaaReloaded2.ViewModels; + +namespace Tests.ViewModels +{ + [TestFixture] + class ElementPickerViewModelTest + { + [Test] + public void ChooseElement() + { + ElementPickerViewModel vm = new ElementPickerViewModel(true); + ViewModelBase elementVM = vm.Categories.First().Children.First(); + elementVM.IsSelected = true; + string expectedLabel = elementVM.DisplayString; + + Assert.IsTrue(vm.ChooseElementCommand.CanExecute(null), + "Cannot execute ChooseElementCommand"); + + bool messageSent = false; + vm.ElementChosenMessage.Sent += (sender, args) => + { + messageSent = true; + ViewModelBase messageContentVM = args.Content.ViewModel as ViewModelBase; + Assert.AreEqual(expectedLabel, messageContentVM.DisplayString); + }; + + vm.ChooseElementCommand.Execute(null); + Assert.IsTrue(messageSent, "No message was sent when element was chosen"); + } + } +} diff --git a/Tests/ViewModels/SettingsViewModelTest.cs b/Tests/ViewModels/SettingsViewModelTest.cs index 65a1d56..695e62c 100755 --- a/Tests/ViewModels/SettingsViewModelTest.cs +++ b/Tests/ViewModels/SettingsViewModelTest.cs @@ -40,13 +40,52 @@ namespace Tests.ViewModels [Test] public void AddElement() { - + bool messageSent = false; + Settings model = _settingsVM.RevealModelObject() as Settings; + int oldViewModelElementCount = _settingsVM.Elements.Count; + int oldModelElementCount = model.Elements.Count; + _settingsVM.AddElementMessage.Sent += (sender, args) => + { + messageSent = true; + ElementPickerViewModel picker = args.Content.ViewModel as ElementPickerViewModel; + Assert.IsNotNull(picker, "ViewModel in MessageContent is not an ElementPickerViewModel"); + picker.Categories.First().Children.First().IsSelected = true; + picker.ChooseElementCommand.Execute(null); + }; + _settingsVM.AddElementCommand.Execute(null); + Assert.IsTrue(messageSent, "Message was not sent"); + Assert.AreEqual(oldViewModelElementCount + 1, _settingsVM.Elements.Count, + "Count of elements in ViewModel was not increased by 1"); + Assert.AreEqual(oldModelElementCount + 1, model.Elements.Count, + "Count of elements in settings Model was not increased by 1"); } [Test] public void AddChildElement() { - + bool messageSent = false; + SelectEachDay model = new SelectEachDay(); + ControlElementViewModel viewModel = new ControlElementViewModel(model); + _settingsVM.AddElementViewModel(viewModel); + viewModel.IsSelected = true; + int oldViewModelChildrenCount = viewModel.Elements.Count; + int oldModelChildrenCount = model.FormatElements.Count; + _settingsVM.AddChildElementMessage.Sent += (sender, args) => + { + messageSent = true; + ElementPickerViewModel picker = args.Content.ViewModel as ElementPickerViewModel; + Assert.IsNotNull(picker, "ViewModel in MessageContent is not an ElementPickerViewModel"); + picker.Categories.First().Children.First().IsSelected = true; + Assert.IsTrue(picker.ChooseElementCommand.CanExecute(null), + "Cannot execute element picker's ChooseElementCommand."); + picker.ChooseElementCommand.Execute(null); + }; + _settingsVM.AddChildElementCommand.Execute(null); + Assert.IsTrue(messageSent, "Message was not sent"); + Assert.AreEqual(oldViewModelChildrenCount + 1, viewModel.Elements.Count, + "Count of children in ViewModel was not increased by 1"); + Assert.AreEqual(oldModelChildrenCount + 1, model.FormatElements.Count, + "Count of children in Model was not increased by 1"); } [Test] @@ -58,7 +97,7 @@ namespace Tests.ViewModels parent.IsSelected = true; Assert.IsTrue(_settingsVM.AddChildElementCommand.CanExecute(null)); FormatElementViewModel child = new FormatElementViewModel(new Items()); - parent.AddChildElement(child); + _settingsVM.AddChildElementViewModel(parent, child); parent.IsSelected = false; child.IsSelected = true; Assert.IsFalse(_settingsVM.AddChildElementCommand.CanExecute(null)); @@ -67,13 +106,13 @@ namespace Tests.ViewModels [Test] public void DeleteElement() { - + throw new NotImplementedException(); } [Test] public void CopyElement() { - + throw new NotImplementedException(); } } } diff --git a/gimp/d.xcf b/gimp/d.xcf new file mode 100644 index 0000000..e6402aa Binary files /dev/null and b/gimp/d.xcf differ diff --git a/www/versioninfo.txt b/www/versioninfo.txt index 51f57b2..4db5701 100644 --- a/www/versioninfo.txt +++ b/www/versioninfo.txt @@ -1,4 +1,4 @@ -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 +2.0.0-alpha.5 +http://zaa.nephrowiki.de/downloads/zaaReloaded-2.0.0-alpha.5.exe +423cbe81b42ddfc293cf5b387c1d8d269dce3f61 publish/release/zaaReloaded-2.0.0-alpha.5.exe diff --git a/zaaReloaded2/Controller/Elements/ControlElementBase.cs b/zaaReloaded2/Controller/Elements/ControlElementBase.cs index f23b9de..65a4564 100755 --- a/zaaReloaded2/Controller/Elements/ControlElementBase.cs +++ b/zaaReloaded2/Controller/Elements/ControlElementBase.cs @@ -31,7 +31,9 @@ namespace zaaReloaded2.Controller.Elements /// public IList FormatElements { get; private set; } - public ControlElementBase() { } + public ControlElementBase() + : this(new List()) + { } public ControlElementBase(IList formatElements) { diff --git a/zaaReloaded2/Controller/Settings.cs b/zaaReloaded2/Controller/Settings.cs index 46b1593..5691988 100755 --- a/zaaReloaded2/Controller/Settings.cs +++ b/zaaReloaded2/Controller/Settings.cs @@ -58,16 +58,12 @@ namespace zaaReloaded2.Controller #region Constructors public Settings() - { - Elements = new List(); - Uid = Guid.NewGuid(); - } + : this(string.Empty, new List()) + { } public Settings(string name) - : this() - { - Name = name; - } + : this(name, null) + { } /// /// Creates a new Settings object with an initial @@ -76,9 +72,8 @@ namespace zaaReloaded2.Controller /// Set of ElementBase /// object (or derived ones). public Settings(IList initialElements) - { - Elements = initialElements; - } + : this(String.Empty, initialElements) + { } /// /// Creates a new Settings object with an initial @@ -88,9 +83,10 @@ namespace zaaReloaded2.Controller /// object (or derived ones). /// Name of these settings. public Settings(string name, IList initialElements) - : this(initialElements) { + Uid = Guid.NewGuid(); Name = name; + Elements = initialElements; } #endregion diff --git a/zaaReloaded2/Demo/Demo.cs b/zaaReloaded2/Demo/Demo.cs new file mode 100755 index 0000000..54e9478 --- /dev/null +++ b/zaaReloaded2/Demo/Demo.cs @@ -0,0 +1,75 @@ +/* Demo.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.IO; +using System.Linq; +using System.Text; +using Microsoft.Office.Interop.Word; + +namespace zaaReloaded2.Demo +{ + /// + /// Static class that serves to load an embedded Word document + /// into a temporary file and open that temporary file in Word. + /// + static class Demo + { + #region Public methods + + /// + /// Opens a demo document. The document's Saved property is set to + /// false so that a user who wants to save changes will be prompted + /// for a file name. + /// + public static void OpenDemoDocument() + { + string tempFile = CreateTempFileFromResource(); + Document demoDoc = Globals.ThisAddIn.Application.Documents + .Add(Template: tempFile); + File.Delete(tempFile); + } + + #endregion + + #region Private methods + + /// + /// Copies the built-in demo file from a resource stream to a + /// temporary file and returns the path to that file. + /// + /// Path to the newly created temporary file. + static string CreateTempFileFromResource() + { + string resourceName = "zaaReloaded2.Demo.Demo.docx"; + Stream resourceStream = typeof(Demo).Assembly + .GetManifestResourceStream(resourceName); + if (resourceStream == null) + { + throw new IOException("Unable to open stream " + resourceName); + } + string fileName = Path.GetTempFileName() + ".docx"; + Stream tempStream = File.Create(fileName); + resourceStream.CopyTo(tempStream); + tempStream.Close(); + return fileName; + } + + #endregion + } +} diff --git a/zaaReloaded2/Demo/Demo.docx b/zaaReloaded2/Demo/Demo.docx new file mode 100755 index 0000000..6164d7b Binary files /dev/null and b/zaaReloaded2/Demo/Demo.docx differ diff --git a/zaaReloaded2/Formatter/DanielsStyle.cs b/zaaReloaded2/Formatter/DanielsStyle.cs index 03ed7ff..8da4d84 100755 --- a/zaaReloaded2/Formatter/DanielsStyle.cs +++ b/zaaReloaded2/Formatter/DanielsStyle.cs @@ -79,8 +79,8 @@ namespace zaaReloaded2.Formatter static void FixSalutation(Document document) { - Regex sal = new Regex(@"^Mit.*(freundl|kolleg)"); - Regex med = new Regex(@"^((Häusl|Empf).*Medikat)|Therapieempf"); + Regex sal = new Regex(@"^Mit.*?Grüßen"); + 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,"; diff --git a/zaaReloaded2/Icons/d.png b/zaaReloaded2/Icons/d.png new file mode 100644 index 0000000..850496d Binary files /dev/null and b/zaaReloaded2/Icons/d.png differ diff --git a/zaaReloaded2/Properties/Settings.Designer.cs b/zaaReloaded2/Properties/Settings.Designer.cs index ec1e26e..902836a 100755 --- a/zaaReloaded2/Properties/Settings.Designer.cs +++ b/zaaReloaded2/Properties/Settings.Designer.cs @@ -233,5 +233,17 @@ namespace zaaReloaded2.Properties { return ((string)(this["DefaultItemsDrugs"])); } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("00000000-0000-0000-0000-000000000000")] + public global::System.Guid LastSettings { + get { + return ((global::System.Guid)(this["LastSettings"])); + } + set { + this["LastSettings"] = value; + } + } } } diff --git a/zaaReloaded2/Properties/Settings.settings b/zaaReloaded2/Properties/Settings.settings index 6d11aea..0fab6e4 100755 --- a/zaaReloaded2/Properties/Settings.settings +++ b/zaaReloaded2/Properties/Settings.settings @@ -71,5 +71,8 @@ Medikamente: TAC, CSA, SIR, Vancomycin, Gentamicin, Tobramicin + + 00000000-0000-0000-0000-000000000000 + \ No newline at end of file diff --git a/zaaReloaded2/Ribbon.cs b/zaaReloaded2/Ribbon.cs index a9a1791..f5428d8 100755 --- a/zaaReloaded2/Ribbon.cs +++ b/zaaReloaded2/Ribbon.cs @@ -26,6 +26,11 @@ using System.Windows; using System.Drawing; using System.Windows.Resources; using Office = Microsoft.Office.Core; +using zaaReloaded2.Views; +using zaaReloaded2.ViewModels; +using zaaReloaded2.Importer.ZaaImporter; +using zaaReloaded2.Formatter; +using zaaReloaded2.Controller; // TODO: Follow these steps to enable the Ribbon (XML) item: @@ -51,12 +56,14 @@ namespace zaaReloaded2 [ComVisible(true)] public class Ribbon : Office.IRibbonExtensibility { - private Office.IRibbonUI ribbon; + #region Constructor public Ribbon() { } + #endregion + #region IRibbonExtensibility Members public string GetCustomUI(string ribbonID) @@ -71,7 +78,8 @@ namespace zaaReloaded2 public void Ribbon_Load(Office.IRibbonUI ribbonUI) { - this.ribbon = ribbonUI; + _ribbon = ribbonUI; + Globals.ThisAddIn.Application.WindowSelectionChange += Application_WindowSelectionChange; } /// @@ -86,6 +94,12 @@ namespace zaaReloaded2 { switch (control.Id) { + case "zrlFormat": + DoFormat(); + break; + case "zrlSettings": + DoChooseSettings(); + break; case "zrlAbout": ViewModels.AboutViewModel vm = new ViewModels.AboutViewModel(); vm.InjectInto().ShowDialog(); @@ -95,6 +109,9 @@ namespace zaaReloaded2 Globals.ThisAddIn.Application.ActiveDocument, Globals.ThisAddIn.Application.Selection); break; + case "zrlDemo": + Demo.Demo.OpenDemoDocument(); + break; default: throw new InvalidOperationException("No operation defined for " + control.Id); } @@ -135,6 +152,67 @@ namespace zaaReloaded2 } } + public bool CanFormat(Office.IRibbonControl control) + { + return Globals.ThisAddIn.Application.Selection.Paragraphs.Count > 0; + } + + #endregion + + #region Private methods + + void DoFormat() + { + if (CanFormat(null)) + { + SettingsRepository repository = SettingsRepository.Load(); + Guid lastSettingsUid = Properties.Settings.Default.LastSettings; + Settings lastSettings = repository.FindByGuid(lastSettingsUid); + if (lastSettings != null) + { + DoFormat(lastSettings); + } + else + { + DoChooseSettings(); + } + } + } + + void DoFormat(Settings settings) + { + ZaaImporter importer = new ZaaImporter(); + importer.Import(Globals.ThisAddIn.Application.Selection.Text); + Formatter.Formatter formatter =new Formatter.Formatter( + Globals.ThisAddIn.Application.ActiveDocument); + formatter.Settings = settings; + formatter.Laboratory = importer.Laboratory; + formatter.Run(); + } + + void DoChooseSettings() + { + SettingsRepository repository = SettingsRepository.Load(); + SettingsRepositoryViewModel vm = new SettingsRepositoryViewModel(repository); + vm.UseSettingsMessage.Sent += (sender, args) => + { + SettingsViewModel settingsVM = args.Content.ViewModel as SettingsViewModel; + Settings settings = settingsVM.RevealModelObject() as Settings; + DoFormat(settings); + Properties.Settings.Default.LastSettings = settings.Uid; + }; + vm.RequestCloseView += (sender, args) => + { + repository.Save(); + }; + vm.InjectInto().ShowDialog(); + } + + public void Application_WindowSelectionChange(Microsoft.Office.Interop.Word.Selection Sel) + { + _ribbon.Invalidate(); + } + #endregion #region Helpers @@ -160,5 +238,11 @@ namespace zaaReloaded2 } #endregion + + #region Fields + + private Office.IRibbonUI _ribbon; + + #endregion } } diff --git a/zaaReloaded2/Ribbon.xml b/zaaReloaded2/Ribbon.xml index 07d2a1f..6c83da5 100755 --- a/zaaReloaded2/Ribbon.xml +++ b/zaaReloaded2/Ribbon.xml @@ -25,13 +25,17 @@