diff --git a/zaaReloaded2/Commands.cs b/zaaReloaded2/Commands.cs index 82f5ad8..6cd54ec 100755 --- a/zaaReloaded2/Commands.cs +++ b/zaaReloaded2/Commands.cs @@ -39,24 +39,6 @@ namespace zaaReloaded2 public static void Format() { - // If no "real" selection exists, attempt to auto-detect the lab data. - // (NB Technically, there is never _no_ selection in a document.) - Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow; - Word.Selection sel = activeWindow.Selection; - if (!(sel.Paragraphs.Count > 1 - || (sel.Text.Length > 1 && sel.Text.EndsWith("\r")))) - { - if (!AutoDetect.Detect(activeWindow.Document)) - { - NotificationAction a = new NotificationAction(); - a.Caption = "Formatieren nicht möglich"; - a.Message = "Das Dokument scheint keine Lauris-Labordaten zu enthalten."; - a.OkButtonLabel = "Schließen"; - a.Invoke(); - return; - } - } - if (CanFormat()) { SettingsRepository repository = SettingsRepository.Load(); @@ -162,6 +144,24 @@ namespace zaaReloaded2 private static void DoFormat(Settings settings) { + // If no "real" selection exists, attempt to auto-detect the lab data. + // (NB Technically, there is never _no_ selection in a document.) + Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow; + Word.Selection sel = activeWindow.Selection; + if (!(sel.Paragraphs.Count > 1 + || (sel.Text.Length > 1 && sel.Text.EndsWith("\r")))) + { + if (!AutoDetect.Detect(activeWindow.Document)) + { + NotificationAction a = new NotificationAction(); + a.Caption = "Formatieren nicht möglich"; + a.Message = "Das Dokument scheint keine Lauris-Labordaten zu enthalten."; + a.OkButtonLabel = "Schließen"; + a.Invoke(); + return; + } + } + ZaaImporter importer = new ZaaImporter(); importer.Import(Globals.ThisAddIn.Application.ActiveWindow.Selection.Text); Formatter.Formatter formatter = new Formatter.Formatter( @@ -186,12 +186,15 @@ namespace zaaReloaded2 private static void CommentPool_FillInComment(object sender, ItemCommentEventArgs e) { - ItemCommentViewModel vm = new ItemCommentViewModel(e.Comment); - vm.CancelMessage.Sent += (cancelSender, cancelArgs) => + if (Preferences.Default.SuppressItemCommentInteraction) { - e.IsCancelled = true; - }; - vm.InjectInto().ShowDialog(); + e.Comment.IsCancelled = true; + } + else + { + ItemCommentViewModel vm = new ItemCommentViewModel(e.Comment); + vm.InjectInto().ShowDialog(); + } } #endregion diff --git a/zaaReloaded2/Controller/Comments/CommentPool.cs b/zaaReloaded2/Controller/Comments/CommentPool.cs index 21214bf..69775e6 100755 --- a/zaaReloaded2/Controller/Comments/CommentPool.cs +++ b/zaaReloaded2/Controller/Comments/CommentPool.cs @@ -126,9 +126,6 @@ namespace zaaReloaded2.Controller.Comments protected virtual void OnFillInComment(ItemCommentEventArgs args) { - if (Preferences.Default.SuppressItemCommentInteraction) - return; - EventHandler h = FillInComment; if (h != null) { diff --git a/zaaReloaded2/Controller/Comments/ItemComment.cs b/zaaReloaded2/Controller/Comments/ItemComment.cs index dac8c8a..1b17dd8 100755 --- a/zaaReloaded2/Controller/Comments/ItemComment.cs +++ b/zaaReloaded2/Controller/Comments/ItemComment.cs @@ -101,6 +101,11 @@ namespace zaaReloaded2.Controller.Comments /// public string Definition { get; private set; } + /// + /// Gets or sets whether this comment has been cancelled.mo + /// + public bool IsCancelled { get; set; } + #endregion #region Event @@ -154,10 +159,33 @@ namespace zaaReloaded2.Controller.Comments { OnFillInComment(); - if (String.IsNullOrEmpty(Value)) - return String.Empty; + string value = Value; + if (String.IsNullOrEmpty(value)) + { + // If the comment was not cancelled and an empty + // value was deliberately entered, return an + // empty string. + if (!IsCancelled) + { + return String.Empty; + } + // If the comment was cancelled and the default + // value is an empty string, insert a prompt + // to manually enter the comment. + else + { + value = Properties.Settings.Default.ManualCommentPrompt; + } + } - return Prefix + Value + Suffix; + if (!IsCancelled) + { + return Prefix + value + Suffix; + } + else + { + return Prefix + "" + value + "" + Suffix; + } } #endregion @@ -172,10 +200,7 @@ namespace zaaReloaded2.Controller.Comments EventHandler h = FillInComment; if (h != null) { - ItemCommentEventArgs args = new ItemCommentEventArgs(this); - h(this, args); - if (args.IsCancelled) - args.Comment.Value = String.Empty; + h(this, new ItemCommentEventArgs(this)); } } diff --git a/zaaReloaded2/Controller/Comments/ItemCommentEventArgs.cs b/zaaReloaded2/Controller/Comments/ItemCommentEventArgs.cs index b6deaec..c5ab263 100755 --- a/zaaReloaded2/Controller/Comments/ItemCommentEventArgs.cs +++ b/zaaReloaded2/Controller/Comments/ItemCommentEventArgs.cs @@ -34,11 +34,6 @@ namespace zaaReloaded2.Controller.Comments /// public ItemComment Comment { get; private set; } - /// - /// Gets or sets whether the commenting was cancelled. - /// - public bool IsCancelled { get; set; } - #endregion #region Constructor diff --git a/zaaReloaded2/Formatter/DocumentWriter.cs b/zaaReloaded2/Formatter/DocumentWriter.cs index e7535a7..d1b38bf 100755 --- a/zaaReloaded2/Formatter/DocumentWriter.cs +++ b/zaaReloaded2/Formatter/DocumentWriter.cs @@ -21,6 +21,7 @@ using System.Linq; using System.Text; using Microsoft.Office.Interop.Word; using System.Text.RegularExpressions; +using System.Collections.ObjectModel; namespace zaaReloaded2.Formatter { @@ -192,6 +193,7 @@ namespace zaaReloaded2.Formatter { string[] substrings = _markupRegex.Split(text); Selection sel = Document.ActiveWindow.Selection; + Highlights hightlights = new Highlights(); foreach (string substring in substrings) { switch (substring) @@ -214,6 +216,12 @@ namespace zaaReloaded2.Formatter case "": sel.Font.Underline = WdUnderline.wdUnderlineNone; break; + case "": + hightlights.Start(sel.Range); + break; + case "": + hightlights.Stop(sel.Range); + break; case "": sel.ClearCharacterStyle(); break; @@ -230,6 +238,7 @@ namespace zaaReloaded2.Formatter break; } } + hightlights.ApplyHighlights(); } #endregion @@ -241,8 +250,53 @@ namespace zaaReloaded2.Formatter // The splitting pattern must not contain subgroups! static readonly Regex _markupRegex = new Regex(@"(<[^ >]+>)"); static readonly Regex _styleRegex = new Regex(@"[^>]+)>"); + static Range _highlightStart; + #endregion + #region Helper class for highlighting + + /// + /// Embedded helper class to manage highlights. + /// + class Highlights + { + public void Start(Range start) + { + if (_currentHighlight == null) + { + _currentHighlight = start; + _highlights.Add(_currentHighlight); + } + } + + public void Stop(Range stop) + { + if (_currentHighlight != null) + { + _currentHighlight.End = stop.End; + _currentHighlight = null; + } + } + + public void ApplyHighlights() + { + foreach (Range r in _highlights) + { + r.HighlightColorIndex = WdColorIndex.wdYellow; + } + } + + public Highlights() + { + _highlights = new Collection(); + _currentHighlight = null; + } + + Collection _highlights; + Range _currentHighlight; + } + #endregion } } diff --git a/zaaReloaded2/Properties/Settings.Designer.cs b/zaaReloaded2/Properties/Settings.Designer.cs index dcdaf95..61a49df 100755 --- a/zaaReloaded2/Properties/Settings.Designer.cs +++ b/zaaReloaded2/Properties/Settings.Designer.cs @@ -246,5 +246,14 @@ namespace zaaReloaded2.Properties { this["FirstRunWizardShown"] = value; } } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("BITTE_ERGÄNZEN")] + public string ManualCommentPrompt { + get { + return ((string)(this["ManualCommentPrompt"])); + } + } } } diff --git a/zaaReloaded2/Properties/Settings.settings b/zaaReloaded2/Properties/Settings.settings index 559ef0f..59e93fd 100755 --- a/zaaReloaded2/Properties/Settings.settings +++ b/zaaReloaded2/Properties/Settings.settings @@ -71,5 +71,8 @@ False + + BITTE_ERGÄNZEN + \ No newline at end of file diff --git a/zaaReloaded2/ViewModels/ItemCommentViewModel.cs b/zaaReloaded2/ViewModels/ItemCommentViewModel.cs index 5cef561..8615c1e 100755 --- a/zaaReloaded2/ViewModels/ItemCommentViewModel.cs +++ b/zaaReloaded2/ViewModels/ItemCommentViewModel.cs @@ -45,7 +45,7 @@ namespace zaaReloaded2.ViewModels } set { - _itemComment.Value = value; + _value = value; OnPropertyChanged("Value"); } } @@ -56,42 +56,28 @@ namespace zaaReloaded2.ViewModels #region Commands - DelegatingCommand CancelCommand + DelegatingCommand SaveCommand { get { - if (_cancelCommand == null) + if (_saveCommand == null) { - _cancelCommand = new DelegatingCommand( - param => DoCancel()); + _saveCommand = new DelegatingCommand( + param => DoSave()); } - return _cancelCommand; + return _saveCommand; } } #endregion - #region Message - - public Message CancelMessage - { - get - { - if (_cancelMessage == null) - { - _cancelMessage = new Message(); - } - return _cancelMessage; - } - } - - #endregion - #region Constructor public ItemCommentViewModel(ItemComment itemComment) { _itemComment = itemComment; + _value = _itemComment.Value; + _itemComment.IsCancelled = true; } #endregion @@ -107,9 +93,10 @@ namespace zaaReloaded2.ViewModels #region Private methods - void DoCancel() + void DoSave() { - CancelMessage.Send(new ViewModelMessageContent(this)); + _itemComment.Value = Value; + _itemComment.IsCancelled = false; DoCloseView(); } @@ -117,8 +104,8 @@ namespace zaaReloaded2.ViewModels #region Fields - DelegatingCommand _cancelCommand; - Message _cancelMessage; + string _value; + DelegatingCommand _saveCommand; ItemComment _itemComment; #endregion diff --git a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs index b70c1f6..34ee606 100755 --- a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs @@ -319,7 +319,7 @@ namespace zaaReloaded2.ViewModels bool CanUseSettings() { - Commands.CanFormat(); + return Commands.CanFormat(); } void DoAddSettings() diff --git a/zaaReloaded2/Views/ItemCommentView.xaml b/zaaReloaded2/Views/ItemCommentView.xaml index 247b293..e3681bc 100755 --- a/zaaReloaded2/Views/ItemCommentView.xaml +++ b/zaaReloaded2/Views/ItemCommentView.xaml @@ -36,8 +36,8 @@ FontSize="16" FontWeight="Bold" Target="{Binding ElementName=ValueTextBox}" Padding="0" /> -