diff --git a/Tests/Controller/Comments/CommentPoolTest.cs b/Tests/Controller/Comments/CommentPoolTest.cs new file mode 100755 index 0000000..e29fd52 --- /dev/null +++ b/Tests/Controller/Comments/CommentPoolTest.cs @@ -0,0 +1,60 @@ +/* CommentPoolTest.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.Comments; + +namespace Tests.Controller.Comments +{ + [TestFixture] + class CommentPoolTest + { + [Test] + public void CreateCommentIfDoesNotExist() + { + int n = CommentPool.Default.Count; + ItemComment i = CommentPool.Default.GetCommentFor("item \"<>\""); + Assert.AreEqual(n + 1, CommentPool.Default.Count); + } + + [Test] + public void ReturnExistingComment() + { + ItemComment i = CommentPool.Default.GetCommentFor("item \"<>\""); + int n = CommentPool.Default.Count; + i = CommentPool.Default.GetCommentFor("item \"<>\""); + Assert.AreEqual(n, CommentPool.Default.Count); + } + + [Test] + public void BuildingCommentRaisesEvent() + { + ItemComment i = CommentPool.Default.GetCommentFor("item \"<>\""); + int eventRaised = 0; + CommentPool.Default.FillInComment += (sender, args) => + { + eventRaised += 1; + }; + string comment = i.BuildComment(); + Assert.AreEqual(1, eventRaised); + } + } +} diff --git a/Tests/Controller/Comments/ItemCommentTest.cs b/Tests/Controller/Comments/ItemCommentTest.cs new file mode 100755 index 0000000..bb1aaa2 --- /dev/null +++ b/Tests/Controller/Comments/ItemCommentTest.cs @@ -0,0 +1,58 @@ +/* ItemCommentTest.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.Formatter; +using zaaReloaded2.Controller.Comments; + +namespace Tests.Controller.Comments +{ + [TestFixture] + class ItemCommentTest + { + [Test] + public void FactoryWithGoodDefinition() + { + ItemComment i = ItemComment.FromDefinitionString("TAC \"(Zielbereich: <4-7> µg/l)\""); + Assert.IsNotNull(i); + Assert.AreEqual("(Zielbereich: ", i.Prefix); + Assert.AreEqual("4-7", i.Value); + Assert.AreEqual(" µg/l)", i.Suffix); + Assert.AreEqual("TAC", i.Item); + Assert.AreEqual("(Zielbereich: 4-7 µg/l)", i.BuildComment()); + } + + [Test] + public void FactoryWithBadDefinition() + { + ItemComment i = ItemComment.FromDefinitionString("some bogus definition"); + Assert.IsNull(i); + } + + [Test] + public void EmptyValueProducesEmptyComment() + { + ItemComment i = ItemComment.FromDefinitionString("TAC \"(Zielbereich: µg/l)\""); + i.Value = String.Empty; + Assert.AreEqual(String.Empty, i.BuildComment()); + } + } +} diff --git a/Tests/Controller/Elements/ItemsTest.cs b/Tests/Controller/Elements/ItemsTest.cs index 8bfc489..28401cb 100755 --- a/Tests/Controller/Elements/ItemsTest.cs +++ b/Tests/Controller/Elements/ItemsTest.cs @@ -16,14 +16,12 @@ * limitations under the License. */ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; using NUnit.Framework; using Microsoft.Office.Interop.Word; using zaaReloaded2.LabModel; using zaaReloaded2.Formatter; using zaa = zaaReloaded2.Controller.Elements; +using zaaReloaded2.Controller.Comments; using System.Text.RegularExpressions; namespace Tests.Controller.Elements @@ -152,7 +150,7 @@ namespace Tests.Controller.Elements StripMarkup( TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) )+ - "Klinische Chemie: Na 133, SU-Protein 2,8\r\r").Replace(Environment.NewLine, "\r"); + "Klinische Chemie: Na 133, SU-Protein 3\r\r").Replace(Environment.NewLine, "\r"); Assert.AreEqual(expected, _document.Range().Text); } @@ -176,11 +174,62 @@ namespace Tests.Controller.Elements StripMarkup( TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) ) + - "Klinische Chemie: Na 133, SU-Protein 2,8, Cl 110, U-Na 99\r\r") + "Klinische Chemie: Na 133, SU-Protein 3, Cl 110, U-Na 99\r\r") .Replace(Environment.NewLine, "\r"); Assert.AreEqual(expected, _document.Range().Text); } + [Test] + public void ItemCommentWithoutHandler() + { + Laboratory lab = new Laboratory(); + TimePoint tp = new TimePoint(); + tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00); + tp.AddItem(new LabItem("Na", "133", "133")); + tp.AddItem(new LabItem("K", "6", "5")); + lab.AddTimePoint(tp); + + _formatter.Laboratory = lab; + _formatter.Settings.Elements.Add( + new zaa.Items("Na \"(Zielbereich: <> mmol/l)\"")); + _formatter.Run(); + string expected = ( + StripMarkup( + TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) + + "Na 133\r\r").Replace(Environment.NewLine, "\r") + ); + Assert.AreEqual(expected, _document.Range().Text); + } + + [Test] + public void ItemCommentWithHandler() + { + Laboratory lab = new Laboratory(); + TimePoint tp = new TimePoint(); + tp.TimeStamp = new DateTime(2015, 7, 13, 13, 31, 00); + tp.AddItem(new LabItem("Na", "133", "133")); + tp.AddItem(new LabItem("K", "6", "5")); + lab.AddTimePoint(tp); + + _formatter.Laboratory = lab; + _formatter.Settings.Elements.Add( + new zaa.Items("Na \"(Zielbereich: µg/l)\"")); + bool messageSent = false; + CommentPool.Default.FillInComment += (sender, args) => + { + messageSent = true; + args.Comment.Value = "4-7"; + }; + _formatter.Run(); + Assert.IsTrue(messageSent, "FillInComment message was not sent"); + string expected = ( + StripMarkup( + TimePointFormatter.DateAndTimeHeader(new DateTime(2015, 07, 13, 13, 31, 00)) + + "Na 133 (Zielbereich: 4-7 µg/l)\r\r").Replace(Environment.NewLine, "\r") + ); + Assert.AreEqual(expected, _document.Range().Text); + } + static string StripMarkup(string s) { return _markupStripper.Replace(s, string.Empty); diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 644547a..edc784d 100755 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -80,6 +80,8 @@ + + @@ -96,6 +98,7 @@ + diff --git a/Tests/ViewModels/ItemCommentViewModelTest.cs b/Tests/ViewModels/ItemCommentViewModelTest.cs new file mode 100755 index 0000000..5d3b3bd --- /dev/null +++ b/Tests/ViewModels/ItemCommentViewModelTest.cs @@ -0,0 +1,42 @@ +/* ItemCommentViewModelTest.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.Comments; +using zaaReloaded2.ViewModels; + +namespace Tests.ViewModels +{ + [TestFixture] + class ItemCommentViewModelTest + { + [Test] + public void Properties() + { + ItemComment comment = new ItemComment("item", "pre", "val", "suf"); + ItemCommentViewModel vm = new ItemCommentViewModel(comment); + Assert.AreEqual(comment.Item, vm.Item); + Assert.AreEqual(comment.Prefix, vm.Prefix); + Assert.AreEqual(comment.Suffix, vm.Suffix); + Assert.AreEqual(comment.Value, vm.Value); + } + } +} diff --git a/www/img/itemcomment.png b/www/img/itemcomment.png new file mode 100755 index 0000000..2c745e2 Binary files /dev/null and b/www/img/itemcomment.png differ diff --git a/www/img/itemcommentresult.png b/www/img/itemcommentresult.png new file mode 100755 index 0000000..800e257 Binary files /dev/null and b/www/img/itemcommentresult.png differ diff --git a/www/img/itemcommentview.png b/www/img/itemcommentview.png new file mode 100755 index 0000000..5b3c77d Binary files /dev/null and b/www/img/itemcommentview.png differ diff --git a/www/img/preferences.png b/www/img/preferences.png new file mode 100755 index 0000000..159b16d Binary files /dev/null and b/www/img/preferences.png differ diff --git a/www/img/ribbon.png b/www/img/ribbon.png old mode 100644 new mode 100755 index a7aae9b..8299f30 Binary files a/www/img/ribbon.png and b/www/img/ribbon.png differ diff --git a/zaaReloaded2/Controller/Comments/CommentPool.cs b/zaaReloaded2/Controller/Comments/CommentPool.cs new file mode 100755 index 0000000..21214bf --- /dev/null +++ b/zaaReloaded2/Controller/Comments/CommentPool.cs @@ -0,0 +1,147 @@ +/* CommentPool.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; + +namespace zaaReloaded2.Controller.Comments +{ + /// + /// A pool of comments. + /// + class CommentPool + { + #region Singleton + + /// + /// Gets the singleton instance of the CommentPool. + /// + public static CommentPool Default + { + get + { + return _instance; + } + } + + private static readonly CommentPool _instance = new CommentPool(); + + #endregion + + #region Properties + + /// + /// Gets the number of ItemComments in the pool. + /// + public int Count { get { return _itemComments.Count; } } + + #endregion + + #region Event + + public event EventHandler FillInComment; + + #endregion + + #region Constructor + + /// + /// Static constructor to support the singleton implementation. + /// + /// + /// See http://csharpindepth.com/Articles/General/Singleton.aspx#cctor + /// + static CommentPool() { } + + private CommentPool() + { + _itemComments = new List(); + } + + #endregion + + #region Methods + + /// + /// Clear the pool of ItemComments and sets the event handler + /// to null. + /// + public void Reset() + { + _itemComments.Clear(); + FillInComment = null; + } + + /// + /// Retrieves the ItemComment for a given definitionString; + /// creates a new ItemComment object if necessary. + /// + /// + /// ItemComment derived from the + /// + public ItemComment GetCommentFor(string definitionString) + { + ItemComment itemComment = _itemComments.FirstOrDefault( + i => i.Definition == definitionString); + if (itemComment == null) + { + itemComment = ItemComment.FromDefinitionString(definitionString); + if (itemComment != null) + { + _itemComments.Add(itemComment); + itemComment.FillInComment += itemComment_FillInComment; + } + } + return itemComment; + } + + #endregion + + #region Private methods + + protected virtual void itemComment_FillInComment(object sender, ItemCommentEventArgs e) + { + OnFillInComment(e); + } + + #endregion + + #region Protected methods + + protected virtual void OnFillInComment(ItemCommentEventArgs args) + { + if (Preferences.Default.SuppressItemCommentInteraction) + return; + + EventHandler h = FillInComment; + if (h != null) + { + h(this, args); + } + } + + #endregion + + #region Fields + + List _itemComments; + + #endregion + } +} diff --git a/zaaReloaded2/Controller/Comments/ItemComment.cs b/zaaReloaded2/Controller/Comments/ItemComment.cs new file mode 100755 index 0000000..dac8c8a --- /dev/null +++ b/zaaReloaded2/Controller/Comments/ItemComment.cs @@ -0,0 +1,191 @@ +/* ParameterComment.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 System.Text.RegularExpressions; + +namespace zaaReloaded2.Controller.Comments +{ + /// + /// Represents an optional comment for a laboratory item. + /// The zaaReloaded2.Controller.Elements.Items class can + /// parse these optional comment strings which may be used + /// to prompt users to enter target ranges etc. + /// + /// + /// TAC "(Zielspiegel: <8-10> µg/l)" + /// + /// + /// In the example, the tacrolimus trough level TAC carries a comment about the + /// recommended range. The comment must be enclosed in quotes in order for it + /// to be recognized. The quotes will be stripped. The angle brackets denote + /// a place holder that will be replaced by the comment that is set in the + /// RequestParameterComment's event args. The text between the angle brackets + /// ("8-10") is an optional default value. One could also just use 'empty' + /// brackets ("<>"). + /// + public class ItemComment + { + #region Factory + + /// + /// Creates a new ItemComment object from a definition string. + /// + /// String that complies + /// with the definition pattern (item "optional prefix <optional + /// default value> optioal suffix"). + public static ItemComment FromDefinitionString(string definitionString) + { + Match match = _definition.Match(definitionString); + if (match.Success) + { + return new ItemComment( + definitionString, + match.Groups["item"].Value.Trim(), + match.Groups["prefix"].Value, + match.Groups["value"].Value, + match.Groups["suffix"].Value); + } + else + { + return null; + } + } + + + #endregion + + #region Properties + + /// + /// Gets or sets the item name that this comment is for. + /// + public string Item { get; set; } + + /// + /// Prefix of this comment, e.g. "(target trough level: " + /// + public string Prefix { get; set; } + + /// + /// Value of this comment; String.Empty represents a + /// cancelled comment. + /// + public string Value { get; set; } + + /// + /// Suffix of this comment, e.g. " µg/l)" + /// + public string Suffix { get; set; } + + /// + /// Gets the original definition string that this ItemComment + /// was created from. + /// + public string Definition { get; private set; } + + #endregion + + #region Event + + /// + /// Event that is raised when the comment value needs to be + /// filled in by someone or something. + /// + public event EventHandler FillInComment; + + #endregion + + #region Constructors + + public ItemComment() + { + Item = String.Empty; + Prefix = String.Empty; + Value = String.Empty; + Suffix = String.Empty; + } + + public ItemComment(string item, string prefix, string value, string suffix) + : this() + { + Item = item; + Prefix = prefix; + Value = value; + Suffix = suffix; + } + + public ItemComment(string definition, string item, string prefix, string value, string suffix) + : this(item, prefix, value, suffix) + { + Definition = definition; + } + + #endregion + + #region Methods + + /// + /// Builds the comment string from the prefix, the value, and + /// the suffix. Raises the FillInComment event to get the value + /// first. If the value is an empty string, the entire comment + /// string will be an empty string. + /// + /// Comment string with filled-in value, or String.Empty + /// if the value is an empty string. + public string BuildComment() + { + OnFillInComment(); + + if (String.IsNullOrEmpty(Value)) + return String.Empty; + + return Prefix + Value + Suffix; + } + + #endregion + + #region Private methods + + /// + /// Raises the FillInComment event. + /// + protected virtual void OnFillInComment() + { + EventHandler h = FillInComment; + if (h != null) + { + ItemCommentEventArgs args = new ItemCommentEventArgs(this); + h(this, args); + if (args.IsCancelled) + args.Comment.Value = String.Empty; + } + } + + #endregion + + #region Fields + + static readonly Regex _definition = + new Regex(@"(?[^""]+)""(?[^<]+)?<(?[^>]*)>(?[^""]+)?"""); + + #endregion + } +} diff --git a/zaaReloaded2/Controller/Comments/ItemCommentEventArgs.cs b/zaaReloaded2/Controller/Comments/ItemCommentEventArgs.cs new file mode 100755 index 0000000..b6deaec --- /dev/null +++ b/zaaReloaded2/Controller/Comments/ItemCommentEventArgs.cs @@ -0,0 +1,54 @@ +/* ParameterCommentEventArgs.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; + +namespace zaaReloaded2.Controller.Comments +{ + /// + /// Event arguments used in item commenting. + /// + public class ItemCommentEventArgs : EventArgs + { + #region Properties + + /// + /// Gets the comment object for this parameter. + /// + public ItemComment Comment { get; private set; } + + /// + /// Gets or sets whether the commenting was cancelled. + /// + public bool IsCancelled { get; set; } + + #endregion + + #region Constructor + + public ItemCommentEventArgs( + ItemComment comment) + { + Comment = comment; + } + + #endregion + } +} diff --git a/zaaReloaded2/Controller/Elements/Items.cs b/zaaReloaded2/Controller/Elements/Items.cs index 61f403d..0ce89fc 100755 --- a/zaaReloaded2/Controller/Elements/Items.cs +++ b/zaaReloaded2/Controller/Elements/Items.cs @@ -24,6 +24,7 @@ using Microsoft.Office.Interop.Word; using zaaReloaded2.LabModel; using zaaReloaded2.Formatter; using System.Runtime.Serialization; +using zaaReloaded2.Controller.Comments; namespace zaaReloaded2.Controller.Elements { @@ -123,7 +124,7 @@ namespace zaaReloaded2.Controller.Elements { _items = null; _caption = null; - Regex r = new Regex(@"((?[^:]+):\s*)?((?[^,]+),\s*)*(?[^,]+)"); + Regex r = new Regex(@"((?[^:""]+):\s*)?((?[^,]+),\s*)*(?[^,]+)"); Match m = r.Match(Content); if (m.Success) { @@ -186,9 +187,20 @@ namespace zaaReloaded2.Controller.Elements /// /// Collects items for output by name. /// - /// Item name to look for. + /// Item name to look for. If the item name contains + /// a comment definition (see example in the description of the + /// event), List CollectByName(zaaReloaded2.Formatter.Formatter formatter, string name) { + // First, check if the item name contains an optional comment + // definition + ItemComment comment = CommentPool.Default.GetCommentFor(name); + if (comment != null) + { + name = comment.Item; + } + + // Then, see if we have such an item List items = new List(); TimePointFormatter tpf = formatter.WorkingTimePoints .FirstOrDefault(tp => tp.Value.ContainsItem(name)) @@ -200,6 +212,7 @@ namespace zaaReloaded2.Controller.Elements ItemFormatter i = tpf.ItemFormatters[name]; i.HasBeenUsed = true; i.IncludeMaterial = false; + i.Comment = comment; items.Add(i); } return items; @@ -211,8 +224,8 @@ namespace zaaReloaded2.Controller.Elements string _caption; List _items; - static Regex _wildcard = new Regex(@"(?[^-]+-)?\*"); - + static readonly Regex _wildcard = new Regex(@"^(?[^-]+-)?\*$"); + #endregion } } diff --git a/zaaReloaded2/Formatter/Formatter.cs b/zaaReloaded2/Formatter/Formatter.cs index 185e1cd..6de6ba2 100755 --- a/zaaReloaded2/Formatter/Formatter.cs +++ b/zaaReloaded2/Formatter/Formatter.cs @@ -34,6 +34,9 @@ namespace zaaReloaded2.Formatter { #region Properties + /// + /// Gets or sets the Settings that this Formatter works with. + /// public Settings Settings { get; set; } /// @@ -66,9 +69,17 @@ namespace zaaReloaded2.Formatter /// /// Is true if this Formatter object carries a Laboratory with - /// at least one time point. + /// at least one time point, and if there are Settings to work with. /// - public bool CanRun { get { return Laboratory.TimePoints.Count > 0; } } + public bool CanRun + { + get + { + return (Settings != null) + && (Laboratory != null) + && (Laboratory.TimePoints.Count > 0); + } + } #endregion @@ -119,7 +130,14 @@ namespace zaaReloaded2.Formatter /// current position of the cursor). public void Run() { - if (!CanRun) throw new NoLaboratoryDataException("No laboratory data to format."); + if (!CanRun) + { + if (Settings == null) + throw new InvalidOperationException("No settings data to work with."); + if ((Laboratory == null) || Laboratory.TimePoints.Count == 0) + throw new NoLaboratoryDataException("No laboratory data to format."); + throw new InvalidOperationException("Cannot run formatter."); + } // Create undo record and styles prior to iterating over the elements // because a column switching element might trigger output to the @@ -154,8 +172,20 @@ namespace zaaReloaded2.Formatter } } + // Write everything to the Word document + bool hasAddin = Globals.ThisAddIn != null; + if (hasAddin) + { + Globals.ThisAddIn.Application.UndoRecord.StartCustomRecord( + String.Format("Laborformatierung ({0})", Properties.Settings.Default.AddinName) + ); + } + CreateStyles(); _secondaryBuffer.Flush(); - Globals.ThisAddIn.Application.UndoRecord.EndCustomRecord(); + if (hasAddin) + { + Globals.ThisAddIn.Application.UndoRecord.EndCustomRecord(); + } } /// diff --git a/zaaReloaded2/Formatter/ItemFormatter.cs b/zaaReloaded2/Formatter/ItemFormatter.cs index c71baf9..cc27a14 100755 --- a/zaaReloaded2/Formatter/ItemFormatter.cs +++ b/zaaReloaded2/Formatter/ItemFormatter.cs @@ -21,6 +21,7 @@ using System.Linq; using System.Text; using Microsoft.Office.Interop.Word; using zaaReloaded2.LabModel; +using zaaReloaded2.Controller.Comments; namespace zaaReloaded2.Formatter { @@ -70,6 +71,11 @@ namespace zaaReloaded2.Formatter /// public bool IsBlacklisted { get { return LabItem.IsBlacklisted; } } + /// + /// Gets or sets the item's comment. + /// + public ItemComment Comment { get; set; } + #endregion #region Constructor @@ -169,21 +175,31 @@ namespace zaaReloaded2.Formatter value = LabItem.Value; } + string comment = String.Empty; + if (Comment != null) + { + comment = Comment.BuildComment(); + if (comment != String.Empty) comment = " " + comment; + } + string name = IncludeMaterial ? LabItem.QualifiedName : LabItem.Name; + string output = String.Format( - "{0} {1}{2}{3}", + "{0} {1}{2}{3}{4}", name, value, unit, - reference + reference, + comment ); if (!LabItem.IsNormal) { output = AbnormalStyle.ToMarkup(false) + output + AbnormalStyle.ToMarkup(true); } + formatter.Write(output); HasBeenUsed = true; } diff --git a/zaaReloaded2/Preferences.cs b/zaaReloaded2/Preferences.cs new file mode 100755 index 0000000..87146fe --- /dev/null +++ b/zaaReloaded2/Preferences.cs @@ -0,0 +1,73 @@ +/* Preferences.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; + +namespace zaaReloaded2 +{ + /// + /// Holds user preferences. + /// + public class Preferences + { + #region Singleton + + public static Preferences Default + { + get + { + return _instance; + } + } + + static readonly Preferences _instance = new Preferences(); + + static Preferences() { } + + #endregion + + #region Properties + + /// + /// Gets or sets whether the add-in should not ask for + /// item comments (i.e. typist mode). + /// + public bool SuppressItemCommentInteraction + { + get + { + return Properties.Settings.Default.SuppressItemCommentInteraction; + } + set + { + Properties.Settings.Default.SuppressItemCommentInteraction = value; + Properties.Settings.Default.Save(); + } + } + + #endregion + + #region Constructors + + protected Preferences() { } + + #endregion + } +} diff --git a/zaaReloaded2/Properties/Settings.Designer.cs b/zaaReloaded2/Properties/Settings.Designer.cs index 735da12..6eb64bf 100755 --- a/zaaReloaded2/Properties/Settings.Designer.cs +++ b/zaaReloaded2/Properties/Settings.Designer.cs @@ -222,5 +222,17 @@ namespace zaaReloaded2.Properties { return ((global::zaaReloaded2.Formatter.AbnormalStyle)(this["AbnormalStyle"])); } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool SuppressItemCommentInteraction { + get { + return ((bool)(this["SuppressItemCommentInteraction"])); + } + set { + this["SuppressItemCommentInteraction"] = value; + } + } } } diff --git a/zaaReloaded2/Properties/Settings.settings b/zaaReloaded2/Properties/Settings.settings index ebde00b..7a1c310 100755 --- a/zaaReloaded2/Properties/Settings.settings +++ b/zaaReloaded2/Properties/Settings.settings @@ -65,5 +65,8 @@ None + + False + \ No newline at end of file diff --git a/zaaReloaded2/Ribbon.cs b/zaaReloaded2/Ribbon.cs index 58bed47..eb8245e 100755 --- a/zaaReloaded2/Ribbon.cs +++ b/zaaReloaded2/Ribbon.cs @@ -28,6 +28,7 @@ using zaaReloaded2.ViewModels; using zaaReloaded2.Importer.ZaaImporter; using zaaReloaded2.Formatter; using zaaReloaded2.Controller; +using zaaReloaded2.Controller.Comments; using Word = Microsoft.Office.Interop.Word; using Bovender.Mvvm.Actions; @@ -104,6 +105,10 @@ namespace zaaReloaded2 ViewModels.AboutViewModel vm = new ViewModels.AboutViewModel(); vm.InjectInto().ShowDialog(); break; + case "zrlPreferences": + ViewModels.PreferencesViewModel.Default.InjectInto() + .ShowDialog(); + break; case "zrlDaniel": Formatter.DanielsStyle.Apply( Globals.ThisAddIn.Application.ActiveDocument, @@ -216,6 +221,8 @@ namespace zaaReloaded2 Globals.ThisAddIn.Application.ActiveDocument); formatter.Settings = settings; formatter.Laboratory = importer.Laboratory; + CommentPool.Default.Reset(); + CommentPool.Default.FillInComment += CommentPool_FillInComment; try { formatter.Run(); @@ -230,6 +237,16 @@ namespace zaaReloaded2 } } + void CommentPool_FillInComment(object sender, ItemCommentEventArgs e) + { + ItemCommentViewModel vm = new ItemCommentViewModel(e.Comment); + vm.CancelMessage.Sent += (cancelSender, cancelArgs) => + { + e.IsCancelled = true; + }; + vm.InjectInto().ShowDialog(); + } + void DoChooseSettings() { SettingsRepository repository = SettingsRepository.Load(); diff --git a/zaaReloaded2/Ribbon.xml b/zaaReloaded2/Ribbon.xml index 6c83da5..0fb6d2e 100755 --- a/zaaReloaded2/Ribbon.xml +++ b/zaaReloaded2/Ribbon.xml @@ -36,6 +36,9 @@