Selaa lähdekoodia

权限-补充注释列表的权限限制

ZhouJieSheng 1 vuosi sitten
vanhempi
commit
243b9edbbc

+ 3 - 4
PDF Office/CustomControl/AlertsMessage.xaml

@@ -7,8 +7,8 @@
     xmlns:local="clr-namespace:PDF_Master.CustomControl"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     MinWidth="400"
-    MaxWidth="600"
     MinHeight="156"
+    MaxWidth="500"
     Background="Transparent"
     ResizeMode="NoResize"
     ShowInTaskbar="False"
@@ -16,11 +16,10 @@
     Style="{StaticResource DialogWindowStyle}"
     WindowStartupLocation="CenterScreen"
     mc:Ignorable="d">
-    
+
     <Border
-      
-        HorizontalAlignment="Stretch"
         Height="auto"
+        HorizontalAlignment="Stretch"
         Background="White"
         CornerRadius="6"
         MouseLeftButtonDown="Border_PreviewMouseLeftButtonDown">

+ 14 - 20
PDF Office/ViewModels/PageEdit/PageEditContentViewModel.cs

@@ -1162,7 +1162,12 @@ namespace PDF_Master.ViewModels.PageEdit
         /// 剪切
         /// </summary>
         private void cut()
-        {
+        {
+            //没有权限时,拦截剪切操作
+            if (!viewContentViewModel.CheckPermissionBeforeOption())
+            {
+                return;
+            }
             CacheFilePath.Instance.CopyDoc = null;
             CacheFilePath.Instance.CopyDoc = CPDFDocument.CreateDocument();
             List<int> pages = new List<int>();
@@ -1191,23 +1196,17 @@ namespace PDF_Master.ViewModels.PageEdit
         /// </summary>
         private void copy()
         {
-            if(!viewContentViewModel.IAPBeforeFunction())
+            if (!viewContentViewModel.IAPBeforeFunction())
             {
                 return;
-            }
-          
-            VerifyPasswordResult verifyResult = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, EnumPermissionsSet.StatusAllowsCopying, dialogs);
-            if (verifyResult.IsDiscryptied)
-            {
-                if (verifyResult.Password != null)
-                {
-                    PDFViewer.Document.CheckOwnerPassword(verifyResult.Password);
-                } 
-
+            }
+
+            if (viewContentViewModel.CheckPermissionBeforeOption())
+            {
                 CacheFilePath.Instance.CopyDoc = null;
                 CacheFilePath.Instance.CopyDoc = CPDFDocument.CreateDocument();
                 List<int> pages = new List<int>();
-                if(isMultiSelected)
+                if (isMultiSelected)
                 {
                     //确认是多选了页面时,通过页面的选中状态获取选中页面
                     for (int i = 0; i < PageEditItems.Count; i++)
@@ -1222,8 +1221,8 @@ namespace PDF_Master.ViewModels.PageEdit
                 {
                     //没有多选时,根据listbox的选中索引获取选中页面
                     pages.Add(ListSelectedIndex);
-                }
- 
+                }
+
                 bool result = CacheFilePath.Instance.CopyDoc.ImportPages(PDFViewer.Document, String.Join(",", pages));
                 if (!result)
                 {
@@ -1231,11 +1230,6 @@ namespace PDF_Master.ViewModels.PageEdit
                     return;
                 }
             }
-            else
-            {
-                ShowToast("复制失败");
-                return;
-            }
         }
 
         /// <summary>

+ 2 - 10
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

@@ -890,17 +890,9 @@ namespace PDF_Master.ViewModels.Tools
         {
             if (e.Command == ApplicationCommands.Copy || e.Command == ApplicationCommands.Cut)
             {
-                VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsCopying, dialogs);
-                if (result.IsDiscryptied)
-                {
-                    if (result.Password != null)
-                    {
-                        string filePath = PDFViewer.Document.FilePath;
-                        var unlockresult = PDFViewer.Document.CheckOwnerPassword(result.Password);
-                    }
-                }
-                else
+                if (!viewContentViewModel.CheckPermissionBeforeOption())
                 {
+                    //没有权限,或者权限解密不成功时,拦截该命令
                     e.Handled = true;
                 }
             }

+ 1 - 9
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Layout.cs

@@ -322,15 +322,7 @@ namespace PDF_Master.ViewModels.Tools
         private void CopyMenu_Click(object sender, RoutedEventArgs e)
         {
             //限制权限密码文档的图片复制
-            VerifyPasswordResult result = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, Model.Dialog.ToolsDialogs.SaftyDialogs.EnumPermissionsSet.StatusAllowsCopying, dialogs);
-            if (result.IsDiscryptied)
-            {
-                if (result.Password != null)
-                {
-                    var unlockresult = PDFViewer.Document.CheckOwnerPassword(result.Password);
-                }
-            }
-            else
+            if (!viewContentViewModel.CheckPermissionBeforeOption())
             {
                 return;
             }

+ 21 - 0
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -2818,6 +2818,27 @@ namespace PDF_Master.ViewModels
             return result;
         }
 
+        /// <summary>
+        /// 复制、剪切操作前校验是否有文档操作权限,没有则弹出权限解密弹窗
+        /// </summary>
+        /// <returns></returns>
+        public bool CheckPermissionBeforeOption()
+        {
+            VerifyPasswordResult verifyResult = SecurityHelper.VerifyPasswordForSelectedPermissions(PDFViewer.Document, EnumPermissionsSet.StatusAllowsCopying, dialogs);
+            if (verifyResult.IsDiscryptied)
+            {
+                if (verifyResult.Password != null)
+                {
+                    PDFViewer.Document.CheckOwnerPassword(verifyResult.Password);
+                }
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+
         /// <summary>
         /// 另存为Flatten
         /// </summary>

+ 5 - 0
PDF Office/Views/BOTA/AnnotationContent.xaml.cs

@@ -234,6 +234,11 @@ namespace PDF_Master.Views.BOTA
 
         private void MenuItemCopyText_Click(object sender, RoutedEventArgs e)
         {
+            //没有权限解密时,拦截复制文本操作
+            if (!viewModel.ViewContentViewModel.CheckPermissionBeforeOption())
+            {
+                return;
+            }
             if (AnnotationList.SelectedItems.Count == 1)
             {
                 if (AnnotationList.SelectedItem is AnnotationHandlerEventArgs annotation)

+ 2 - 8
PDF Office/Views/ViewContent.xaml.cs

@@ -499,17 +499,11 @@ namespace PDF_Master.Views
             //鼠标侧键无法在Xaml里绑定  因此写在后台代码里
             if (e.ChangedButton == MouseButton.XButton2)
             {
-                if (GlobalCommands.PreViewCommand.CanExecute(null))
-                {
-                    GlobalCommands.PreViewCommand.Execute(null);
-                }
+                viewModel.bottom?.NextViewCommnad.Execute();
             }
             else if (e.ChangedButton == MouseButton.XButton1)
             {
-                if (GlobalCommands.NextViewCommand.CanExecute(null))
-                {
-                    GlobalCommands.NextViewCommand.Execute(null);
-                }
+                viewModel.bottom?.PreViewCommand.Execute();
             }
         }