Selaa lähdekoodia

Made "Form" public for DynamicEditorForm; added way to disable OK button if unchanged.

Kenric Nugteren 8 kuukautta sitten
vanhempi
commit
b401d2180e

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicEditorForm/DynamicEditorForm.xaml

@@ -34,5 +34,5 @@
         </local:MyObservableCollection>-->
     </syncfusion:ChromelessWindow.Resources>
 
-    <local:EmbeddedDynamicEditorForm x:Name="Form" OnChanged="Form_OnOnChanged" Margin="5"/>
+    <local:EmbeddedDynamicEditorForm x:Name="Form" x:FieldModifier="public" OnChanged="Form_OnOnChanged" Margin="5"/>
 </wpf:ThemableChromelessWindow>

+ 15 - 8
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml.cs

@@ -26,8 +26,11 @@ namespace InABox.DynamicGrid
 
         public event EventHandler OnChanged;
 
+        private bool bChanged = false;
+
         public void DoChanged()
         {
+            bChanged = true;
             //OKButton.IsEnabled = true;
             //CancelButton.IsEnabled = true;
             OnChanged?.Invoke(this, EventArgs.Empty);
@@ -59,22 +62,20 @@ namespace InABox.DynamicGrid
             get => Editor.ReadOnly;
             set
             {
-                OKButton.IsEnabled = !DisableButtons && !value;
-                CancelButton.IsEnabled = !DisableButtons && !value;
                 Editor.ReadOnly = value;
+                UpdateButtonEnabled();
             }
         }
 
-        private bool _disableButtons = false;
+        private bool _disableIfUnchanged = false;
 
-        public bool DisableButtons
+        public bool DisableOKIfUnchanged
         {
-            get => _disableButtons;
+            get => _disableIfUnchanged;
             set
             {
-                _disableButtons = value;
-                OKButton.IsEnabled = !ReadOnly && !value; 
-                CancelButton.IsEnabled = !ReadOnly && !value;
+                _disableIfUnchanged = value;
+                UpdateButtonEnabled();
             }
         }
         
@@ -103,6 +104,12 @@ namespace InABox.DynamicGrid
             }
         }
 
+        private void UpdateButtonEnabled()
+        {
+            OKButton.IsEnabled = !ReadOnly && (!DisableOKIfUnchanged || bChanged);
+            CancelButton.IsEnabled = !ReadOnly;
+        }
+
         private void UpdateButtonHighlight(Button button, Color border, Color background, Color foreground)
         {
             button.BorderBrush = _highlightButtons

+ 16 - 0
inabox.wpf/Reports/ReportUtils.cs

@@ -350,8 +350,24 @@ namespace InABox.Wpf.Reports
             }
         }
 
+        /// <summary>
+        ///     Populate the <paramref name="menu"/> with a list of reports attached to this data model, loaded through <see cref="LoadReports(string, DataModel, Columns{ReportTemplate}?)"/>.
+        /// </summary>
+        /// <remarks>
+        ///     This is used for the various places we have context menus for printing reports.
+        /// </remarks>
+        /// <param name="allowdesign">Allow designing reports; if <see langword="true"/>, then also adds a "Manage Reports" button.</param>
+        /// <param name="populate">Determines whether the datamodel should be reloaded when printing a report.<br/>Set to <see langword="false"/> if all the data has already been loaded.</param>
         public static void PopulateMenu(MenuItem menu, string sectionName, DataModel model, bool allowdesign, bool populate = false) => 
             PopulateMenu(menu as ItemsControl, sectionName, model, allowdesign, populate);
+        /// <summary>
+        ///     Populate the <paramref name="menu"/> with a list of reports attached to this data model, loaded through <see cref="LoadReports(string, DataModel, Columns{ReportTemplate}?)"/>.
+        /// </summary>
+        /// <remarks>
+        ///     This is used for the various places we have context menus for printing reports.
+        /// </remarks>
+        /// <param name="allowdesign">Allow designing reports; if <see langword="true"/>, then also adds a "Manage Reports" button.</param>
+        /// <param name="populate">Determines whether the datamodel should be reloaded when printing a report.<br/>Set to <see langword="false"/> if all the data has already been loaded.</param>
         public static void PopulateMenu(ContextMenu menu, string sectionName, DataModel model, bool allowdesign, bool populate = false) => 
             PopulateMenu(menu as ItemsControl, sectionName, model, allowdesign, populate);