浏览代码

Fixed inconsistencies in Notes handling

Kenric Nugteren 7 月之前
父节点
当前提交
7d9635d62b

+ 9 - 1
InABox.Core/Objects/Editors/NotesEditor.cs

@@ -1,4 +1,7 @@
-namespace InABox.Core
+using System.Linq;
+using System.Text.RegularExpressions;
+
+namespace InABox.Core
 {
 {
     public class NotesEditor : BaseEditor
     public class NotesEditor : BaseEditor
     {
     {
@@ -8,5 +11,10 @@
         {
         {
             return new NotesEditor { AlwaysEnabled = AlwaysEnabled };
             return new NotesEditor { AlwaysEnabled = AlwaysEnabled };
         }
         }
+
+        public static string FormatNotes(string[] notes)
+        {
+            return string.Join("\n===================================\n", notes);
+        }
     }
     }
 }
 }

+ 1 - 1
inabox.wpf/DynamicGrid/Columns/DynamicProblemsColumn.cs

@@ -66,7 +66,7 @@ public class DynamicProblemsColumn<TEntity> : DynamicImageColumn
     private FrameworkElement? CreateIssuesToolTip(DynamicActionColumn column, CoreRow? row)
     private FrameworkElement? CreateIssuesToolTip(DynamicActionColumn column, CoreRow? row)
     {
     {
         var text = row?.Get<TEntity, string[]>(x => x.Problem.Notes) ?? new string[] { };
         var text = row?.Get<TEntity, string[]>(x => x.Problem.Notes) ?? new string[] { };
-        return TextToolTip(string.Join("\n==================================\n", text));
+        return TextToolTip(NotesEditor.FormatNotes(text));
     }
     }
 
 
     private MenuItem CreateMenu(string caption, RoutedEventHandler click)
     private MenuItem CreateMenu(string caption, RoutedEventHandler click)

+ 16 - 9
inabox.wpf/DynamicGrid/Editors/NotesEditor/NotesEditorControl.cs

@@ -7,6 +7,7 @@ using System.Windows.Media;
 using InABox.Clients;
 using InABox.Clients;
 using InABox.Core;
 using InABox.Core;
 using InABox.WPF;
 using InABox.WPF;
+using java.util;
 
 
 namespace InABox.DynamicGrid
 namespace InABox.DynamicGrid
 {
 {
@@ -74,6 +75,8 @@ namespace InABox.DynamicGrid
         private TextBox History;
         private TextBox History;
         private TextBoxDecorator Scroll;
         private TextBoxDecorator Scroll;
 
 
+        private string[]? _value = [];
+
         public override int DesiredHeight()
         public override int DesiredHeight()
         {
         {
             return int.MaxValue;
             return int.MaxValue;
@@ -189,13 +192,13 @@ namespace InABox.DynamicGrid
             {
             {
                 if (string.IsNullOrEmpty(History.Text))
                 if (string.IsNullOrEmpty(History.Text))
                 {
                 {
-                    History.AppendText(popup.Text);
+                    _value = [popup.Text];
                 }
                 }
                 else
                 else
                 {
                 {
-                    var note = string.Format("{0:yyyy-MM-dd HH:mm:ss} {1}: {2}", DateTime.Now, ClientFactory.UserID, popup.Text);
-                    History.AppendText("\n===================================\n" + note);
+                    _value = (_value ?? []).Concatenate([string.Format("{0:yyyy-MM-dd HH:mm:ss} {1}: {2}", DateTime.Now, ClientFactory.UserID, popup.Text)]);
                 }
                 }
+                History.Text = NotesEditor.FormatNotes(_value);
 
 
                 History.ScrollToEnd();
                 History.ScrollToEnd();
                 CheckChanged();
                 CheckChanged();
@@ -204,18 +207,22 @@ namespace InABox.DynamicGrid
 
 
         protected override string[] RetrieveValue()
         protected override string[] RetrieveValue()
         {
         {
-            var results = new List<string>();
-            if (!string.IsNullOrWhiteSpace(History.Text))
-                results.AddRange(History.Text.Split('\n'));
-            return results.ToArray();
+            return _value;
         }
         }
 
 
         protected override void UpdateValue(string[] value)
         protected override void UpdateValue(string[] value)
         {
         {
-            if (value != null)
-                History.Text = string.Join("\n", value);
+            if(value is not null)
+            {
+                _value = value;
+                History.Text = NotesEditor.FormatNotes(_value);
+            }
             else
             else
+            {
+                _value = null;
                 History.Text = "";
                 History.Text = "";
+            }
+
             var AlwaysEnabled = EditorDefinition is NotesEditor && ((NotesEditor)EditorDefinition).AlwaysEnabled;
             var AlwaysEnabled = EditorDefinition is NotesEditor && ((NotesEditor)EditorDefinition).AlwaysEnabled;
             History.IsReadOnly = !AlwaysEnabled && !string.IsNullOrWhiteSpace(History.Text);
             History.IsReadOnly = !AlwaysEnabled && !string.IsNullOrWhiteSpace(History.Text);
             History.Background = History.IsReadOnly ? new SolidColorBrush(Colors.Gainsboro) : new SolidColorBrush(BGColor);
             History.Background = History.IsReadOnly ? new SolidColorBrush(Colors.Gainsboro) : new SolidColorBrush(BGColor);