Merge branch 'item-comments' into develop

Conflicts:
	zaaReloaded2/Formatter/Formatter.cs
	zaaReloaded2/zaaReloaded2.csproj
This commit is contained in:
Daniel Kraus 2015-09-04 17:08:13 +02:00
commit dccb3145db
30 changed files with 1259 additions and 16 deletions

View File

@ -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);
}
}
}

View File

@ -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: <default> µg/l)\"");
i.Value = String.Empty;
Assert.AreEqual(String.Empty, i.BuildComment());
}
}
}

View File

@ -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: <default> µ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);

View File

@ -80,6 +80,8 @@
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="Controller\Comments\CommentPoolTest.cs" />
<Compile Include="Controller\Comments\ItemCommentTest.cs" />
<Compile Include="SerializationTest.cs" />
<Compile Include="Controller\SettingsRepositoryTest.cs" />
<Compile Include="Controller\SettingsTest.cs" />
@ -96,6 +98,7 @@
<Compile Include="Importer\ZaaImporter\TimePointTest.cs" />
<Compile Include="TestHelpers.cs" />
<Compile Include="ViewModels\ElementPickerViewModelTest.cs" />
<Compile Include="ViewModels\ItemCommentViewModelTest.cs" />
<Compile Include="ViewModels\SettingsRepositoryViewModelTest.cs" />
<Compile Include="ViewModels\SettingsViewModelTest.cs" />
</ItemGroup>

View File

@ -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);
}
}
}

BIN
www/img/itemcomment.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
www/img/itemcommentresult.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
www/img/itemcommentview.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

BIN
www/img/preferences.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
www/img/ribbon.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -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
{
/// <summary>
/// A pool of comments.
/// </summary>
class CommentPool
{
#region Singleton
/// <summary>
/// Gets the singleton instance of the CommentPool.
/// </summary>
public static CommentPool Default
{
get
{
return _instance;
}
}
private static readonly CommentPool _instance = new CommentPool();
#endregion
#region Properties
/// <summary>
/// Gets the number of ItemComments in the pool.
/// </summary>
public int Count { get { return _itemComments.Count; } }
#endregion
#region Event
public event EventHandler<ItemCommentEventArgs> FillInComment;
#endregion
#region Constructor
/// <summary>
/// Static constructor to support the singleton implementation.
/// </summary>
/// <remarks>
/// See http://csharpindepth.com/Articles/General/Singleton.aspx#cctor
/// </remarks>
static CommentPool() { }
private CommentPool()
{
_itemComments = new List<ItemComment>();
}
#endregion
#region Methods
/// <summary>
/// Clear the pool of ItemComments and sets the event handler
/// to null.
/// </summary>
public void Reset()
{
_itemComments.Clear();
FillInComment = null;
}
/// <summary>
/// Retrieves the ItemComment for a given definitionString;
/// creates a new ItemComment object if necessary.
/// </summary>
/// <param name="definitionString"></param>
/// <returns>ItemComment derived from the
/// <paramref name="definitionString"/></returns>
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<ItemCommentEventArgs> h = FillInComment;
if (h != null)
{
h(this, args);
}
}
#endregion
#region Fields
List<ItemComment> _itemComments;
#endregion
}
}

View File

@ -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
{
/// <summary>
/// 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.
/// </summary>
/// <example>
/// TAC "(Zielspiegel: &lt;8-10&gt; µg/l)"
/// </example>
/// <remarks>
/// 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 ("&lt;&gt;").
/// </remarks>
public class ItemComment
{
#region Factory
/// <summary>
/// Creates a new ItemComment object from a definition string.
/// </summary>
/// <param name="definitionString">String that complies
/// with the definition pattern (item "optional prefix &lt;optional
/// default value&gt; optioal suffix").</param>
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
/// <summary>
/// Gets or sets the item name that this comment is for.
/// </summary>
public string Item { get; set; }
/// <summary>
/// Prefix of this comment, e.g. "(target trough level: "
/// </summary>
public string Prefix { get; set; }
/// <summary>
/// Value of this comment; String.Empty represents a
/// cancelled comment.
/// </summary>
public string Value { get; set; }
/// <summary>
/// Suffix of this comment, e.g. " µg/l)"
/// </summary>
public string Suffix { get; set; }
/// <summary>
/// Gets the original definition string that this ItemComment
/// was created from.
/// </summary>
public string Definition { get; private set; }
#endregion
#region Event
/// <summary>
/// Event that is raised when the comment value needs to be
/// filled in by someone or something.
/// </summary>
public event EventHandler<ItemCommentEventArgs> 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
/// <summary>
/// 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.
/// </summary>
/// <returns>Comment string with filled-in value, or String.Empty
/// if the value is an empty string.</returns>
public string BuildComment()
{
OnFillInComment();
if (String.IsNullOrEmpty(Value))
return String.Empty;
return Prefix + Value + Suffix;
}
#endregion
#region Private methods
/// <summary>
/// Raises the FillInComment event.
/// </summary>
protected virtual void OnFillInComment()
{
EventHandler<ItemCommentEventArgs> 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(@"(?<item>[^""]+)""(?<prefix>[^<]+)?<(?<value>[^>]*)>(?<suffix>[^""]+)?""");
#endregion
}
}

View File

@ -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
{
/// <summary>
/// Event arguments used in item commenting.
/// </summary>
public class ItemCommentEventArgs : EventArgs
{
#region Properties
/// <summary>
/// Gets the comment object for this parameter.
/// </summary>
public ItemComment Comment { get; private set; }
/// <summary>
/// Gets or sets whether the commenting was cancelled.
/// </summary>
public bool IsCancelled { get; set; }
#endregion
#region Constructor
public ItemCommentEventArgs(
ItemComment comment)
{
Comment = comment;
}
#endregion
}
}

View File

@ -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(@"((?<caption>[^:]+):\s*)?((?<items>[^,]+),\s*)*(?<items>[^,]+)");
Regex r = new Regex(@"((?<caption>[^:""]+):\s*)?((?<items>[^,]+),\s*)*(?<items>[^,]+)");
Match m = r.Match(Content);
if (m.Success)
{
@ -186,9 +187,20 @@ namespace zaaReloaded2.Controller.Elements
/// <summary>
/// Collects items for output by name.
/// </summary>
/// <param name="name">Item name to look for.</param>
/// <param name="name">Item name to look for. If the item name contains
/// a comment definition (see example in the description of the
/// <see cref="RequestParameterComment"/> event), </param>
List<ItemFormatter> 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<ItemFormatter> items = new List<ItemFormatter>();
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,7 +224,7 @@ namespace zaaReloaded2.Controller.Elements
string _caption;
List<string> _items;
static Regex _wildcard = new Regex(@"(?<material>[^-]+-)?\*");
static readonly Regex _wildcard = new Regex(@"^(?<material>[^-]+-)?\*$");
#endregion
}

View File

@ -34,6 +34,9 @@ namespace zaaReloaded2.Formatter
{
#region Properties
/// <summary>
/// Gets or sets the Settings that this Formatter works with.
/// </summary>
public Settings Settings { get; set; }
/// <summary>
@ -66,9 +69,17 @@ namespace zaaReloaded2.Formatter
/// <summary>
/// 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.
/// </summary>
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).</param>
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();
}
}
/// <summary>

View File

@ -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
/// </summary>
public bool IsBlacklisted { get { return LabItem.IsBlacklisted; } }
/// <summary>
/// Gets or sets the item's comment.
/// </summary>
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;
}

73
zaaReloaded2/Preferences.cs Executable file
View File

@ -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
{
/// <summary>
/// Holds user preferences.
/// </summary>
public class Preferences
{
#region Singleton
public static Preferences Default
{
get
{
return _instance;
}
}
static readonly Preferences _instance = new Preferences();
static Preferences() { }
#endregion
#region Properties
/// <summary>
/// Gets or sets whether the add-in should not ask for
/// item comments (i.e. typist mode).
/// </summary>
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
}
}

View File

@ -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;
}
}
}
}

View File

@ -65,5 +65,8 @@
<Setting Name="AbnormalStyle" Type="zaaReloaded2.Formatter.AbnormalStyle" Scope="Application">
<Value Profile="(Default)">None</Value>
</Setting>
<Setting Name="SuppressItemCommentInteraction" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -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<Views.AboutView>().ShowDialog();
break;
case "zrlPreferences":
ViewModels.PreferencesViewModel.Default.InjectInto<Views.PreferencesView>()
.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<ItemCommentView>().ShowDialog();
}
void DoChooseSettings()
{
SettingsRepository repository = SettingsRepository.Load();

View File

@ -36,6 +36,9 @@
<button id="zrlDemo" label="Demo" image="d.png" onAction="Ribbon_Click" size="large"
screentip="Demo-Dokument öffnen"
supertip="Öffnet ein eingebautes Demo-Dokument, das zum Ausprobieren verwendet werden kann." />
<button id="zrlPreferences" label="Einstellungen" image="gear.png" onAction="Ribbon_Click" size="large"
screentip="Benutzer-Einstellungen"
supertip="Erlaubt das Einschalten des Sekretariats-Modus." />
<button id="zrlAbout" label="Über..." image="i.png" onAction="Ribbon_Click" size="large"
screentip="Über zaaReloaded"
supertip="Zeigt Informationen über das Add-in an." />

View File

@ -27,6 +27,10 @@ using Microsoft.Office.Tools.Word;
using Bovender.Versioning;
using Bovender.Mvvm.Messaging;
using zaaReloaded2.ExceptionHandler;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Media;
namespace zaaReloaded2
{
@ -48,6 +52,7 @@ namespace zaaReloaded2
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Bovender.ExceptionHandler.CentralHandler.ManageExceptionCallback += CentralHandler_ManageExceptionCallback;
RegisterTextBoxSelectAll();
CheckForUpdates();
_oldCaption = Globals.ThisAddIn.Application.Caption;
Globals.ThisAddIn.Application.Caption =
@ -156,5 +161,49 @@ namespace zaaReloaded2
}
#endregion
/// <summary>
/// Make text boxes select all text on focus.
/// </summary>
/// <remarks>
/// http://stackoverflow.com/a/2553297/270712
/// </remarks>
void RegisterTextBoxSelectAll()
{
// Select the text in a TextBox when it receives focus.
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.PreviewMouseLeftButtonDownEvent,
new MouseButtonEventHandler(SelectivelyIgnoreMouseButton));
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent,
new RoutedEventHandler(SelectAllText));
EventManager.RegisterClassHandler(typeof(TextBox), TextBox.MouseDoubleClickEvent,
new RoutedEventHandler(SelectAllText));
}
void SelectivelyIgnoreMouseButton(object sender, MouseButtonEventArgs e)
{
// Find the TextBox
DependencyObject parent = e.OriginalSource as UIElement;
while (parent != null && !(parent is TextBox))
parent = VisualTreeHelper.GetParent(parent);
if (parent != null)
{
var textBox = (TextBox)parent;
if (!textBox.IsKeyboardFocusWithin)
{
// If the text box is not yet focused, give it the focus and
// stop further processing of this click event.
textBox.Focus();
e.Handled = true;
}
}
}
void SelectAllText(object sender, RoutedEventArgs e)
{
var textBox = e.OriginalSource as TextBox;
if (textBox != null)
textBox.SelectAll();
}
}
}

View File

@ -0,0 +1,126 @@
/* ItemCommentViewModel.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.Comments;
namespace zaaReloaded2.ViewModels
{
/// <summary>
/// View model for zaaReloaded2.Controller.Comments.ItemComment.
/// </summary>
public class ItemCommentViewModel : ViewModelBase
{
#region Properties
public string Item { get { return _itemComment.Item; } }
public string Prefix { get { return _itemComment.Prefix; } }
public string Value
{
get
{
return _itemComment.Value;
}
set
{
_itemComment.Value = value;
OnPropertyChanged("Value");
}
}
public string Suffix { get { return _itemComment.Suffix; } }
#endregion
#region Commands
DelegatingCommand CancelCommand
{
get
{
if (_cancelCommand == null)
{
_cancelCommand = new DelegatingCommand(
param => DoCancel());
}
return _cancelCommand;
}
}
#endregion
#region Message
public Message<ViewModelMessageContent> CancelMessage
{
get
{
if (_cancelMessage == null)
{
_cancelMessage = new Message<ViewModelMessageContent>();
}
return _cancelMessage;
}
}
#endregion
#region Constructor
public ItemCommentViewModel(ItemComment itemComment)
{
_itemComment = itemComment;
}
#endregion
#region Implementation of ViewModelBase
public override object RevealModelObject()
{
return _itemComment;
}
#endregion
#region Private methods
void DoCancel()
{
CancelMessage.Send(new ViewModelMessageContent(this));
DoCloseView();
}
#endregion
#region Fields
DelegatingCommand _cancelCommand;
Message<ViewModelMessageContent> _cancelMessage;
ItemComment _itemComment;
#endregion
}
}

View File

@ -0,0 +1,111 @@
/* PreferencesViewModel.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;
namespace zaaReloaded2.ViewModels
{
/// <summary>
/// View model for zaaReloaded2.Preferences.
/// </summary>
public class PreferencesViewModel : ViewModelBase
{
#region Singleton
public static PreferencesViewModel Default
{
get
{
return _instance;
}
}
static PreferencesViewModel() { }
static readonly PreferencesViewModel _instance = new PreferencesViewModel();
#endregion
#region Properties
public bool SuppressItemCommentInteraction { get; set; }
#endregion
#region Command
public DelegatingCommand SaveCommand
{
get
{
if (_saveCommand == null)
{
_saveCommand = new DelegatingCommand(
param => DoSave(),
param => CanSave());
}
return _saveCommand;
}
}
#endregion
#region Constructor
public PreferencesViewModel()
{
SuppressItemCommentInteraction = Preferences.Default.SuppressItemCommentInteraction;
}
#endregion
#region Private methods
void DoSave()
{
Preferences.Default.SuppressItemCommentInteraction = SuppressItemCommentInteraction;
DoCloseView();
}
bool CanSave()
{
return true;
}
#endregion
#region Field
DelegatingCommand _saveCommand;
#endregion
#region ViewModelBase implementation
public override object RevealModelObject()
{
throw new NotImplementedException();
}
#endregion
}
}

View File

@ -0,0 +1,50 @@
<!--
ItemCommentView.xaml
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.
-->
<Window x:Class="zaaReloaded2.Views.ItemCommentView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender"
ResizeMode="CanResizeWithGrip" ShowInTaskbar="False"
WindowStyle="ToolWindow" Topmost="True"
SizeToContent="WidthAndHeight"
b:WindowState.CenterScreen="True" b:WindowState.Save="True"
Title="Kommentar angeben"
FocusManager.FocusedElement="{Binding ElementName=ValueTextBox}"
>
<Window.Resources>
<ResourceDictionary Source="/zaaReloaded2;component/Style.xaml" />
</Window.Resources>
<DockPanel Margin="10">
<Label DockPanel.Dock="Top" Content="{Binding Item}"
FontSize="16" FontWeight="Bold"
Target="{Binding ElementName=ValueTextBox}" Padding="0" />
<UniformGrid DockPanel.Dock="Bottom" HorizontalAlignment="Right" Columns="2" Rows="1" Margin="0 10 0 0">
<Button Content="OK" Command="{Binding CloseViewCommand}" IsDefault="True" Margin="0 0 5 0" />
<Button Content="Abbrechen" Command="{Binding CancelCommand}" IsCancel="True" Margin="5 0 0 0" />
</UniformGrid>
<DockPanel Margin="0 10 0 10">
<TextBlock DockPanel.Dock="Left" Text="{Binding Prefix}" VerticalAlignment="Center" />
<TextBlock DockPanel.Dock="Right" Text="{Binding Suffix}" VerticalAlignment="Center" />
<TextBox Text="{Binding Value,Mode=TwoWay,UpdateSourceTrigger=LostFocus}"
MinWidth="120" MaxWidth="240" VerticalAlignment="Center"
x:Name="ValueTextBox" Margin="5 0 5 0" />
</DockPanel>
</DockPanel>
</Window>

View File

@ -0,0 +1,33 @@
/* ItemCommentView.xaml.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.Windows;
namespace zaaReloaded2.Views
{
/// <summary>
/// Interaction logic for ItemCommentView.xaml
/// </summary>
public partial class ItemCommentView : Window
{
public ItemCommentView()
{
InitializeComponent();
}
}
}

View File

@ -0,0 +1,44 @@
<!--
PreferencesView.xaml
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.
-->
<Window x:Class="zaaReloaded2.Views.PreferencesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:action="clr-namespace:Bovender.Mvvm.Actions;assembly=Bovender"
SizeToContent="WidthAndHeight" ResizeMode="NoResize" ShowInTaskbar="False"
b:WindowState.CenterScreen="True" b:WindowState.Save="True"
Title="Einstellungen"
>
<Window.Resources>
<ResourceDictionary Source="/zaaReloaded2;component/Style.xaml" />
</Window.Resources>
<DockPanel Margin="10">
<UniformGrid DockPanel.Dock="Bottom" Columns="2" Rows="1"
HorizontalAlignment="Right" Margin="0 10 0 0">
<Button Command="{Binding SaveCommand}" Content="OK" IsDefault="True" Margin="0 0 5 0" />
<Button Command="{Binding CloseViewCommand}" Content="Abbrechen" IsCancel="True" Margin="5 0 0 0" />
</UniformGrid>
<GroupBox Header="Sekretariatsmodus" Padding="10">
<CheckBox IsChecked="{Binding SuppressItemCommentInteraction}" Content="Keine Interaktion für _Kommentare">
</CheckBox>
</GroupBox>
</DockPanel>
</Window>

View File

@ -0,0 +1,33 @@
/* PreferencesView.xaml.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.Windows;
namespace zaaReloaded2.Views
{
/// <summary>
/// Interaction logic for PreferencesView.xaml
/// </summary>
public partial class PreferencesView : Window
{
public PreferencesView()
{
InitializeComponent();
}
}
}

View File

@ -96,6 +96,9 @@
<setting name="ImportExportPath" serializeAs="String">
<value />
</setting>
<setting name="SuppressItemCommentInteraction" serializeAs="String">
<value>False</value>
</setting>
</zaaReloaded2.Properties.Settings>
</userSettings>
</configuration>

View File

@ -193,9 +193,12 @@
-->
<ItemGroup>
<Compile Include="Importer\ZaaImporter\AutoDetect.cs" />
<Compile Include="Controller\Comments\CommentPool.cs" />
<Compile Include="Controller\Elements\ControlElementBase.cs" />
<Compile Include="Controller\Elements\FormatElementBase.cs" />
<Compile Include="Controller\Elements\NextColumn.cs" />
<Compile Include="Controller\Comments\ItemComment.cs" />
<Compile Include="Controller\Comments\ItemCommentEventArgs.cs" />
<Compile Include="Controller\Elements\SelectEachDay.cs" />
<Compile Include="Controller\Elements\SelectLastDay.cs" />
<Compile Include="Controller\Elements\SelectFirstDay.cs" />
@ -216,6 +219,7 @@
<Compile Include="Formatter\DanielsStyle.cs" />
<Compile Include="Formatter\DocumentWriter.cs" />
<Compile Include="Formatter\NoLaboratoryDataException.cs" />
<Compile Include="Preferences.cs" />
<Compile Include="Ribbon.cs" />
<Compile Include="Thesaurus\ThesaurusBase.cs" />
<Compile Include="Formatter\IItemFormatterDictionary.cs" />
@ -255,7 +259,12 @@
<Compile Include="ViewModels\FormatElementViewModel.cs" />
<Compile Include="ViewModels\ControlElementViewModel.cs" />
<Compile Include="ViewModels\IoErrorViewModel.cs" />
<Compile Include="ViewModels\ItemCommentViewModel.cs" />
<Compile Include="ViewModels\PreferencesViewModel.cs" />
<Compile Include="ViewModels\SettingsRepositoryViewModel.cs" />
<Compile Include="Views\ItemCommentView.xaml.cs">
<DependentUpon>ItemCommentView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\IoErrorView.xaml.cs">
<DependentUpon>IoErrorView.xaml</DependentUpon>
</Compile>
@ -265,6 +274,9 @@
<Compile Include="Views\ElementView.xaml.cs">
<DependentUpon>ElementView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\PreferencesView.xaml.cs">
<DependentUpon>PreferencesView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SettingsView.xaml.cs">
<DependentUpon>SettingsView.xaml</DependentUpon>
</Compile>
@ -341,6 +353,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Resource>
<Page Include="Views\ItemCommentView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\IoErrorView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -353,6 +369,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\PreferencesView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\SettingsView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -413,6 +433,9 @@
<ItemGroup>
<Resource Include="Icons\icon.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Icons\gear.png" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>