Bladeren bron

注释列表 快捷键,二次确认弹窗

OYXH\oyxh 2 jaren geleden
bovenliggende
commit
b1394ace54

+ 57 - 9
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -39,6 +39,7 @@ using System.Windows.Controls;
 using System.Windows.Data;
 using System.Windows.Documents;
 using System.Windows.Forms;
+using System.Windows.Input;
 using System.Windows.Markup;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
@@ -62,7 +63,6 @@ namespace PDF_Office.ViewModels.BOTA
     {
         #region 文案
 
-
         private string T_expand;
 
         public string T_Expand
@@ -73,7 +73,6 @@ namespace PDF_Office.ViewModels.BOTA
                 SetProperty(ref T_expand, value);
             }
         }
-        
 
         private string T_collapse;
 
@@ -85,7 +84,6 @@ namespace PDF_Office.ViewModels.BOTA
                 SetProperty(ref T_collapse, value);
             }
         }
-        
 
         private string T_import;
 
@@ -142,7 +140,6 @@ namespace PDF_Office.ViewModels.BOTA
             }
         }
 
-
         private void InitString()
         {
             T_Expand = App.MainPageLoader.GetString("Annotation_MenuExpand");
@@ -154,7 +151,7 @@ namespace PDF_Office.ViewModels.BOTA
             T_EmptyContext = App.MainPageLoader.GetString("Annotation_EmptyContext");
         }
 
-        #endregion
+        #endregion 文案
 
         private ListBox listBox;
         private IRegionManager region;
@@ -364,10 +361,15 @@ namespace PDF_Office.ViewModels.BOTA
                     pagelist.Add(item.AnnotIndex);
                 }
             }
-            PdfViewer.RemovePageAnnot(deleteLists);
-            AnnotationListItems.Clear();
-            CurrentAnnotationLists.Clear();
-            PdfViewer.UndoManager.CanSave = true;
+            AlertsMessage alertsMessage = new AlertsMessage();
+            alertsMessage.ShowDialog(" ", "This action will permanently delete all comments,\r\nWhether to continue??", "Cancel", "OK");
+            if (alertsMessage.result == ContentResult.Ok)
+            {
+                PdfViewer.RemovePageAnnot(deleteLists);
+                AnnotationListItems.Clear();
+                CurrentAnnotationLists.Clear();
+                PdfViewer.UndoManager.CanSave = true;
+            }
         }
 
         /// <summary>
@@ -1121,6 +1123,7 @@ namespace PDF_Office.ViewModels.BOTA
 
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
+            KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)
@@ -1132,6 +1135,51 @@ namespace PDF_Office.ViewModels.BOTA
                 ViewContentViewModel = viewContentViewModel;
                 PdfViewer = pdfview;
             }
+
+            KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
+            KeyEventsHelper.KeyDown += ShortCut_KeyDown;
+        }
+
+        private void ShortCut_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
+        {
+            if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Escape))
+            {
+                if (listBox != null)
+                {
+                    if (listBox.SelectedItems == null)
+                    {
+                        return;
+                    }
+                    listBox.SelectedItems.Clear();
+                }
+            }
+            if (KeyEventsHelper.IsSingleKey(System.Windows.Input.Key.Delete))
+            {
+                if (listBox != null)
+                {
+                    if (listBox.SelectedItems == null)
+                    {
+                        return;
+                    }
+                    List<int> pagelist = new List<int>();
+                    for (int i = 0; i < listBox.SelectedItems.Count; i++)
+                    {
+                        AnnotationHandlerEventArgs annotation = listBox.SelectedItems[i] as AnnotationHandlerEventArgs;
+                        pagelist.Add(listBox.Items.IndexOf(annotation));
+                    }
+                    pagelist.Sort();
+                    for (int i = 0; i < pagelist.Count; i++)
+                    {
+                        AnnotationHandlerEventArgs annotation = listBox.Items[pagelist[pagelist.Count - i - 1]] as AnnotationHandlerEventArgs;
+                        if (annotation == null)
+                        {
+                            continue;
+                        }
+
+                        DeleteCommand.Execute(annotation);
+                    }
+                }
+            }
         }
 
         /// <summary>

+ 4 - 11
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -118,7 +118,7 @@ namespace PDF_Office.ViewModels.Tools
                 {
                     if (item is CustomIconToggleBtn customIconToggle)
                     {
-                        if(customIconToggle.Name == "BtnHand")
+                        if (customIconToggle.Name == "BtnHand")
                         {
                             HandToolIsCheckedEvent((bool)customIconToggle.IsChecked);
                         }
@@ -243,8 +243,6 @@ namespace PDF_Office.ViewModels.Tools
             }
         }
 
-
-
         #endregion Command实现
 
         #region BOTA
@@ -627,18 +625,16 @@ namespace PDF_Office.ViewModels.Tools
 
         private void ShortCut_KeyDown(object sender, KeyEventArgs e)
         {
-            if(KeyEventsHelper.IsSingleKey(Key.Escape))
+            if (KeyEventsHelper.IsSingleKey(Key.Escape))
             {
                 BtnHandIsChecked = true;
                 PDFViewer.SetMouseMode(MouseModes.PanTool);
                 PDFViewer.ClearSelectAnnots();
                 StrAnnotToolChecked = "";
-
             }
-            else if(KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
+            else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
             {
                 //按住Shift等比缩放
-
             }
 
             AnnotToolCtrlAltKey();
@@ -649,9 +645,8 @@ namespace PDF_Office.ViewModels.Tools
         /// </summary>
         private void AnnotToolCtrlAltKey()
         {
-
             var tuple = GetCtrlAltKey();
-            if(tuple != null)
+            if (tuple != null)
             {
                 if (tuple.Item1 == Key.L)
                     BtnLinkIsChecked = false;
@@ -667,7 +662,6 @@ namespace PDF_Office.ViewModels.Tools
                     PDFViewer.ToolManager.EnableClickCreate = false;
                 }
             }
-
         }
 
         private Tuple<Key, string> GetCtrlAltKey()
@@ -742,7 +736,6 @@ namespace PDF_Office.ViewModels.Tools
 
         #endregion 快捷键
 
-
         #region Navigation
 
         public bool IsNavigationTarget(NavigationContext navigationContext)

+ 1 - 1
PDF Office/Views/BOTA/AnnotationContent.xaml

@@ -68,7 +68,7 @@
                 ItemsSource="{Binding AnnotationListItems}"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 SelectionChanged="AnnotationList_SelectionChanged"
-                SelectionMode="Extended" KeyDown="AnnotationList_KeyDown">
+                SelectionMode="Extended">
                 <ListBox.ItemContainerStyle>
                     <Style TargetType="ListBoxItem">
                         <Setter Property="HorizontalContentAlignment" Value="Stretch" />