Browse Source

另存为-修复加密文件另存为自动打开后,文档内容为空的问题

ZhouJieSheng 1 year ago
parent
commit
1728896883
1 changed files with 40 additions and 25 deletions
  1. 40 25
      PDF Office/ViewModels/ViewContentViewModel.cs

+ 40 - 25
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -2217,6 +2217,42 @@ namespace PDF_Master.ViewModels
             CanSave = PDFViewer.UndoManager.CanSave;
             CanUndo = PDFViewer.UndoManager.CanUndo;
             CanRedo = PDFViewer.UndoManager.CanRedo;
+           
+            if(!CheckPassword())
+            {
+                return false;
+            }
+
+            PDFViewer.Load();
+            PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
+            PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
+            //设置移动注释参考线
+            ComPDFKitViewer.CommonDrawData.MovePen = new System.Windows.Media.Pen((System.Windows.Media.Brush)new BrushConverter().ConvertFromString("#1770F4"),1);
+            //还原上一次关闭前的视图设置
+            GetOpenFileInfo();
+
+            if (!string.IsNullOrEmpty(PassWord))
+            {
+                //加密文档解密后刷新底部工具栏页码总数
+                NavigationParameters parameters = new NavigationParameters();
+                parameters.Add(ParameterNames.PDFViewer, PDFViewer);
+                parameters.Add(ParameterNames.ViewContentViewModel, this);
+                region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
+            }
+            region.AddToRegion(ViwerRegionName, PDFViewer);
+
+            if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
+            {
+                App.OpenedFileList.Add(PDFViewer.Document.FilePath);
+            }
+            return true;
+        }
+
+        /// <summary>
+        /// 处理密码相关的内容
+        /// </summary>
+        private bool CheckPassword()
+        {
             if (passwordInfo != null && (!string.IsNullOrEmpty(passwordInfo.OpenPassword) || !string.IsNullOrEmpty(passwordInfo.PermissionsPassword)))
             {
                 if (!string.IsNullOrEmpty(passwordInfo.OpenPassword))
@@ -2258,29 +2294,6 @@ namespace PDF_Master.ViewModels
                     return false;
                 }
             }
-
-            PDFViewer.Load();
-            PDFViewer.SetFormFieldHighlight(Settings.Default.AppProperties.InitialVIew.HighlightLink);
-            PDFViewer.SetBackgroundBrush(new System.Windows.Media.SolidColorBrush(Settings.Default.AppProperties.InitialVIew.BackGround));
-            //设置移动注释参考线
-            ComPDFKitViewer.CommonDrawData.MovePen = new System.Windows.Media.Pen((System.Windows.Media.Brush)new BrushConverter().ConvertFromString("#1770F4"),1);
-            //还原上一次关闭前的视图设置
-            GetOpenFileInfo();
-
-            if (!string.IsNullOrEmpty(PassWord))
-            {
-                //加密文档解密后刷新底部工具栏页码总数
-                NavigationParameters parameters = new NavigationParameters();
-                parameters.Add(ParameterNames.PDFViewer, PDFViewer);
-                parameters.Add(ParameterNames.ViewContentViewModel, this);
-                region.RequestNavigate(BottomToolRegionName, "BottomToolContent", parameters);
-            }
-            region.AddToRegion(ViwerRegionName, PDFViewer);
-
-            if (!App.OpenedFileList.Contains(PDFViewer.Document.FilePath))
-            {
-                App.OpenedFileList.Add(PDFViewer.Document.FilePath);
-            }
             return true;
         }
 
@@ -2651,11 +2664,13 @@ namespace PDF_Master.ViewModels
         {
             PDFViewer.UndoManager.CanSave = false;
 
-            //从新路径重新加载
+            //从新路径重新加载 
+            //用mianviewmodel.openfile的方法会有其他模块的pdfview更新不过来的情况,需要调整成现有的方法
             PDFViewer.CloseDocument();
             PDFViewer.InitDocument(targetPath);
+            //处理解密相关的逻辑  现在的逻辑另存为自动打开后会需要重新输入密码
+            CheckPassword();
             PDFViewer.Load();
-            mainViewModel.OpenFile(targetPath, passwordInfo);
 
             //刷新最近文件列表
             OpenFileInfo isnew = SettingHelper.GetFileInfo(targetPath);