diff --git a/Tests/Controller/Comments/CommentPoolTest.cs b/Tests/Controller/Comments/CommentPoolTest.cs index d993e4f..e29fd52 100755 --- a/Tests/Controller/Comments/CommentPoolTest.cs +++ b/Tests/Controller/Comments/CommentPoolTest.cs @@ -48,13 +48,13 @@ namespace Tests.Controller.Comments public void BuildingCommentRaisesEvent() { ItemComment i = CommentPool.Default.GetCommentFor("item \"<>\""); - bool eventRaised = false; + int eventRaised = 0; CommentPool.Default.FillInComment += (sender, args) => { - eventRaised = true; + eventRaised += 1; }; string comment = i.BuildComment(); - Assert.IsTrue(eventRaised); + Assert.AreEqual(1, eventRaised); } } } diff --git a/Tests/Controller/Elements/ItemsTest.cs b/Tests/Controller/Elements/ItemsTest.cs index ff473f3..28401cb 100755 --- a/Tests/Controller/Elements/ItemsTest.cs +++ b/Tests/Controller/Elements/ItemsTest.cs @@ -16,9 +16,6 @@ * 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; @@ -26,7 +23,6 @@ using zaaReloaded2.Formatter; using zaa = zaaReloaded2.Controller.Elements; using zaaReloaded2.Controller.Comments; using System.Text.RegularExpressions; -using zaaReloaded2.Controller.Comments; namespace Tests.Controller.Elements { diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index e6a43dc..edc784d 100755 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -98,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/zaaReloaded2/Controller/Comments/CommentPool.cs b/zaaReloaded2/Controller/Comments/CommentPool.cs index 4c9f9cd..69775e6 100755 --- a/zaaReloaded2/Controller/Comments/CommentPool.cs +++ b/zaaReloaded2/Controller/Comments/CommentPool.cs @@ -78,6 +78,16 @@ namespace zaaReloaded2.Controller.Comments #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. @@ -103,7 +113,7 @@ namespace zaaReloaded2.Controller.Comments #endregion - #region Pribate methods + #region Private methods protected virtual void itemComment_FillInComment(object sender, ItemCommentEventArgs e) { diff --git a/zaaReloaded2/Controller/Elements/Items.cs b/zaaReloaded2/Controller/Elements/Items.cs index d8f8b63..0ce89fc 100755 --- a/zaaReloaded2/Controller/Elements/Items.cs +++ b/zaaReloaded2/Controller/Elements/Items.cs @@ -224,7 +224,7 @@ namespace zaaReloaded2.Controller.Elements string _caption; List _items; - static readonly Regex _wildcard = new Regex(@"(?[^-]+-)?\*"); + static readonly Regex _wildcard = new Regex(@"^(?[^-]+-)?\*$"); #endregion } diff --git a/zaaReloaded2/Ribbon.cs b/zaaReloaded2/Ribbon.cs index a556054..99412c6 100755 --- a/zaaReloaded2/Ribbon.cs +++ b/zaaReloaded2/Ribbon.cs @@ -31,6 +31,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; using Bovender.Mvvm.Messaging; @@ -201,6 +202,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(); @@ -215,6 +218,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/ViewModels/ItemCommentViewModel.cs b/zaaReloaded2/ViewModels/ItemCommentViewModel.cs new file mode 100755 index 0000000..5cef561 --- /dev/null +++ b/zaaReloaded2/ViewModels/ItemCommentViewModel.cs @@ -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 +{ + /// + /// View model for zaaReloaded2.Controller.Comments.ItemComment. + /// + 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 CancelMessage + { + get + { + if (_cancelMessage == null) + { + _cancelMessage = new Message(); + } + 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 _cancelMessage; + ItemComment _itemComment; + + #endregion + } +} diff --git a/zaaReloaded2/Views/ItemCommentView.xaml b/zaaReloaded2/Views/ItemCommentView.xaml new file mode 100755 index 0000000..954a2ec --- /dev/null +++ b/zaaReloaded2/Views/ItemCommentView.xaml @@ -0,0 +1,50 @@ + + + + + + + +