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

@ -94,6 +94,15 @@ namespace zaaReloaded2.Controller.Elements
#endregion
#region Events
/// <summary>
/// Propagates the FillInComment events of collected items.
/// </summary>
public event EventHandler<ItemCommentEventArgs> FillInComment;
#endregion
#region Constructors
public Items() : base() { }
@ -123,7 +132,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 +195,22 @@ 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 = ItemComment.FromDefinition(name);
if (comment != null)
{
name = comment.Item;
// Enable propagation of FillInComment events
comment.FillInComment += comment_FillInComment;
}
// 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,19 +222,37 @@ namespace zaaReloaded2.Controller.Elements
ItemFormatter i = tpf.ItemFormatters[name];
i.HasBeenUsed = true;
i.IncludeMaterial = false;
i.Comment = comment;
items.Add(i);
}
return items;
}
void comment_FillInComment(object sender, ItemCommentEventArgs e)
{
OnFillInComment(e);
}
#endregion
#region Protected methods
protected virtual void OnFillInComment(ItemCommentEventArgs args)
{
EventHandler<ItemCommentEventArgs> h = FillInComment;
if (h != null)
{
h(this, args);
}
}
#endregion
#region Fields
string _caption;
List<string> _items;
static Regex _wildcard = new Regex(@"(?<material>[^-]+-)?\*");
static readonly Regex _wildcard = new Regex(@"(?<material>[^-]+-)?\*");
#endregion
}
}