Initial implementation of ItemComments.

This commit is contained in:
Daniel Kraus
2015-08-29 03:16:44 +02:00
parent efbff88b1a
commit a89a8103e5
9 changed files with 442 additions and 12 deletions

View File

@ -34,7 +34,20 @@ namespace zaaReloaded2.Formatter
{
#region Properties
public Settings Settings { get; set; }
/// <summary>
/// Gets or sets the Settings that this Formatter works with.
/// </summary>
public Settings Settings
{
get { return _settings; }
set
{
_settings = value;
// Listen to the FillInComment event of
_settings.Elements.OfType<Items>().ToList().ForEach(
items => items.FillInComment += items_FillInComment);
}
}
/// <summary>
/// Gets or sets the <see cref="Laboratory"/> that shall be
@ -66,9 +79,28 @@ 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
#region Event
/// <summary>
/// Relays the FillInComment events of any Items elements
/// in the Settings, which in turn relay the FillInComment
/// events of their collected items' ItemComments.
/// </summary>
public event EventHandler<ItemCommentEventArgs> FillInComment;
#endregion
@ -119,7 +151,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.");
}
int current = 0;
while (current < Settings.Elements.Count)
@ -147,12 +186,19 @@ namespace zaaReloaded2.Formatter
}
// Write everything to the Word document
Globals.ThisAddIn.Application.UndoRecord.StartCustomRecord(
String.Format("Laborformatierung ({0})", Properties.Settings.Default.AddinName)
);
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>
@ -385,6 +431,23 @@ namespace zaaReloaded2.Formatter
#endregion
#region Private methods
/// <summary>
/// Relays the FillInComment event of Items elements in the
/// Settings.
/// </summary>
void items_FillInComment(object sender, ItemCommentEventArgs e)
{
EventHandler<ItemCommentEventArgs> h = FillInComment;
if (h != null)
{
h(this, e);
}
}
#endregion
#region Protected properties
/// <summary>
@ -396,6 +459,7 @@ namespace zaaReloaded2.Formatter
#region Fields
Settings _settings;
TimePointFormatterDictionary _timePointFormatters;
Laboratory _laboratory;
DocumentWriter _primaryBuffer;