Browse Source

ComPDFKit.Demo(win) - 处理点击打开文件按钮时,当前文档无法被保存的问题

TangJinZhou 3 months ago
parent
commit
cad0d08de1
1 changed files with 16 additions and 1 deletions
  1. 16 1
      Demo/Examples/PDFViewer/MainPage.xaml.cs

+ 16 - 1
Demo/Examples/PDFViewer/MainPage.xaml.cs

@@ -909,8 +909,8 @@ namespace PDFViewer
                 {
                     filePath = ComPDFKit.Controls.Helper.CommonHelper.GetExistedPathOrEmpty();
                 }
-                string oldFilePath = pdfDoc.FilePath;
 
+                string oldFilePath = pdfDoc.FilePath;
                 if (!string.IsNullOrEmpty(filePath) && regularViewerControl.PdfViewControl != null)
                 {
                     if (oldFilePath.ToLower() == filePath.ToLower())
@@ -923,6 +923,21 @@ namespace PDFViewer
                         return;
                     }
 
+                    if (CanSave)
+                    {
+                        string fileName = pdfDoc.FileName;
+                        var message = fileName + " " + LanguageHelper.CommonManager.GetString("Warn_NotSave");
+                        var result = MessageBox.Show(message, LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
+                        if (result == MessageBoxResult.Yes)
+                        {
+                            SaveFile();
+                        }
+                        else if (result == MessageBoxResult.Cancel)
+                        {
+                            return;
+                        }
+                    }
+
                     passwordViewer = new PDFViewControl();
                     passwordViewer.InitDocument(filePath);
                     CPDFViewer tempViewer = passwordViewer.PDFViewTool?.GetCPDFViewer();