Browse Source

Fixed Save Confirmation behaviour when closing modified reports
Added progress indicator when saving reports

frogsoftware 1 year ago
parent
commit
b12d6f0725
2 changed files with 29 additions and 4 deletions
  1. 3 1
      inabox.wpf/Reports/PreviewWindow.xaml
  2. 26 3
      inabox.wpf/Reports/PreviewWindow.xaml.cs

+ 3 - 1
inabox.wpf/Reports/PreviewWindow.xaml

@@ -9,13 +9,15 @@
         xmlns:preview="clr-namespace:FastReport.Preview;assembly=FastReport.WPF"
         xmlns:design="clr-namespace:FastReport.Design;assembly=FastReport.WPF"
         mc:Ignorable="d"
-        Title="PreviewWindow" Height="450" Width="800">
+        Title="PreviewWindow" Height="450" Width="800"
+        Closing="PreviewWindow_OnClosing">
     <Grid x:Name="MainGrid">
         <Grid.RowDefinitions>
             <RowDefinition Height="*"/>
             <RowDefinition Height="0"/>
             <RowDefinition Height="0"/>
         </Grid.RowDefinitions>
+        
         <Grid Grid.Row="0" Name="PreviewGrid">
             <Grid.ColumnDefinitions>
                 <ColumnDefinition Width="*" />

+ 26 - 3
inabox.wpf/Reports/PreviewWindow.xaml.cs

@@ -22,6 +22,7 @@ using InABox.Core.Reports;
 using ICSharpCode.AvalonEdit.Highlighting;
 using System.Drawing;
 using System.Collections.Generic;
+using System.ComponentModel;
 using System.Linq;
 using System.Threading.Tasks;
 using System.Windows.Threading;
@@ -87,7 +88,8 @@ namespace InABox.Wpf.Reports
             Designer.InnerDesigner.cmdSave.CustomAction += (sender, args) => SaveReport();
             Designer.InnerDesigner.cmdSaveAs.CustomAction += (sender, args) => SaveReportAs();
             Designer.InnerDesigner.cmdPreview.CustomAction += (sender, args) => ShowPreview();
-            
+            Designer.InnerDesigner.AskSave = false;
+
 
         }
 
@@ -386,6 +388,7 @@ namespace InABox.Wpf.Reports
             _template.RDL = _report.SaveToString();
             DoSave(_template);
             Designer.Report = _report;
+            Designer.InnerDesigner.Modified = false;
         }
 
         private void DesignButton_Click(object sender, RoutedEventArgs e)
@@ -408,7 +411,12 @@ namespace InABox.Wpf.Reports
         private void DoSave(ReportTemplate template)
         {
             if (SaveTemplate is null)
-                new Client<ReportTemplate>().Save(template, "Updated by Designer");
+            {
+                Progress.ShowModal("Saving", p =>
+                {
+                    new Client<ReportTemplate>().Save(template, "Updated by Designer");
+                });
+            }
             else
                 SaveTemplate?.Invoke(template);
         }
@@ -419,6 +427,21 @@ namespace InABox.Wpf.Reports
             DoSave(_template);
             _report = null;
             ShowPreview();
-        }       
+        }
+
+        private void PreviewWindow_OnClosing(object? sender, CancelEventArgs e)
+        {
+            if (Designer.InnerDesigner.Modified)
+            {
+                var result = MessageWindow.ShowYesNoCancel("There are unsaved changes in this report!\nDo you wish to save them now?","Save Changes");
+                if (result == MessageWindowResult.Cancel)
+                {
+                    e.Cancel = true;
+                    return;
+                }
+                if (result == MessageWindowResult.Yes)
+                    SaveReport();
+            }
+        }
     }
 }