Browse Source

注释列表-修复筛选-数据刷新

OYXH\oyxh 2 years ago
parent
commit
50be4f9ab5

+ 34 - 17
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -31,6 +31,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
+using System.Windows.Annotations;
 using System.Windows.Annotations.Storage;
 using System.Windows.Controls;
 using System.Windows.Data;
@@ -74,6 +75,8 @@ namespace PDF_Office.ViewModels.BOTA
         }
 
         private ObservableCollection<AnnotationHandlerEventArgs> currentAnnotationArgs = new ObservableCollection<AnnotationHandlerEventArgs>();
+        public ObservableCollection<AnnotationHandlerEventArgs> CurrentAnnotationArgs { get => currentAnnotationArgs; set => currentAnnotationArgs = value; }
+
         private AnnotationSortOrder annotationSortOrder = AnnotationSortOrder.PageIndexAscending;
 
         public AnnotationSortOrder AnnotationSortOrder
@@ -151,10 +154,10 @@ namespace PDF_Office.ViewModels.BOTA
                 }
                 PdfViewer.ReloadVisibleAnnots();
                 //提取出来的注释文件 时间为空  则显示未系统当前时间
-                currentAnnotationArgs = GetDocumentAnnotionList();
+                CurrentAnnotationArgs = GetDocumentAnnotionList();
 
                 AnnotationListItems.Clear();
-                AnnotationListItems.AddRange(currentAnnotationArgs);
+                AnnotationListItems.AddRange(CurrentAnnotationArgs);
                 await Task.Delay(5);
                 RefreshAnnotationListItems(null);
 
@@ -230,7 +233,7 @@ namespace PDF_Office.ViewModels.BOTA
             }
             PdfViewer.RemovePageAnnot(deleteLists);
             AnnotationListItems.Clear();
-            currentAnnotationArgs.Clear();
+            CurrentAnnotationArgs.Clear();
             PdfViewer.UndoManager.CanSave = true;
         }
 
@@ -248,7 +251,8 @@ namespace PDF_Office.ViewModels.BOTA
                     if (result)
                     {
                         AnnotationListItems.Remove(annotation);
-                        currentAnnotationArgs.Remove(annotation);
+                        var annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == annotation.PageIndex && x.AnnotIndex == annotation.AnnotIndex);
+                        CurrentAnnotationArgs.Remove(annotation1);
                         //记录是删除了哪些页面的注释,然后更新对应页面的注释即可
                         UpdateAnnotListAfterDelete(annotation.PageIndex, annotation.AnnotIndex);
                         PdfViewer.UndoManager.CanSave = true;
@@ -341,7 +345,7 @@ namespace PDF_Office.ViewModels.BOTA
             if (obj is System.Windows.Controls.Button button)
             {
                 DialogParameters value = new DialogParameters();
-                value.Add(ParameterNames.AnnotationList, currentAnnotationArgs);
+                value.Add(ParameterNames.AnnotationList, CurrentAnnotationArgs);
                 value.Add(ParameterNames.AnnotArgsTypes, annotArgsTypes);
                 value.Add(ParameterNames.AnnotationColors, colors);
                 value.Add(ParameterNames.AnnotationAuthor, authors);
@@ -359,7 +363,7 @@ namespace PDF_Office.ViewModels.BOTA
                                   authors.Clear();
                                   annotArgsTypes.Clear();
                                   AnnotationListItems.Clear();
-                                  AnnotationListItems.AddRange(currentAnnotationArgs);
+                                  AnnotationListItems.AddRange(CurrentAnnotationArgs);
                                   RefreshAnnotationListItems(button);
                               }
                               else
@@ -391,7 +395,7 @@ namespace PDF_Office.ViewModels.BOTA
                           authors.Clear();
                           annotArgsTypes.Clear();
                           AnnotationListItems.Clear();
-                          AnnotationListItems.AddRange(currentAnnotationArgs);
+                          AnnotationListItems.AddRange(CurrentAnnotationArgs);
 
                           RefreshAnnotationListItems(button);
                       }
@@ -456,7 +460,7 @@ namespace PDF_Office.ViewModels.BOTA
 
             if (annotArgsTypes.Count > 0 && colors.Count > 0 && authors.Count > 0)
             {
-                foreach (var item in currentAnnotationArgs)
+                foreach (var item in CurrentAnnotationArgs)
                 {
                     foreach (var type in annotArgsTypes)
                     {
@@ -480,7 +484,7 @@ namespace PDF_Office.ViewModels.BOTA
 
             else if (colors.Count > 0 && authors.Count > 0)
             {
-                foreach (var item in currentAnnotationArgs)
+                foreach (var item in CurrentAnnotationArgs)
                 {
                     foreach (var color in colors)
                     {
@@ -501,7 +505,7 @@ namespace PDF_Office.ViewModels.BOTA
 
             else if (annotArgsTypes.Count > 0 && authors.Count > 0)
             {
-                foreach (var item in currentAnnotationArgs)
+                foreach (var item in CurrentAnnotationArgs)
                 {
                     foreach (var type in annotArgsTypes)
                     {
@@ -522,7 +526,7 @@ namespace PDF_Office.ViewModels.BOTA
 
             else if (annotArgsTypes.Count > 0 && colors.Count > 0)
             {
-                foreach (var item in currentAnnotationArgs)
+                foreach (var item in CurrentAnnotationArgs)
                 {
                     foreach (var type in annotArgsTypes)
                     {
@@ -543,7 +547,7 @@ namespace PDF_Office.ViewModels.BOTA
 
             else if (annotArgsTypes.Count > 0)
             {
-                foreach (var item in currentAnnotationArgs)
+                foreach (var item in CurrentAnnotationArgs)
                 {
                     foreach (var type in annotArgsTypes)
                     {
@@ -561,7 +565,7 @@ namespace PDF_Office.ViewModels.BOTA
 
             else if (colors.Count > 0)
             {
-                foreach (var item in currentAnnotationArgs)
+                foreach (var item in CurrentAnnotationArgs)
                 {
                     foreach (var color in colors)
                     {
@@ -576,7 +580,7 @@ namespace PDF_Office.ViewModels.BOTA
 
             else if (authors.Count > 0)
             {
-                foreach (var item in currentAnnotationArgs)
+                foreach (var item in CurrentAnnotationArgs)
                 {
                     foreach (var author in authors)
                     {
@@ -773,6 +777,7 @@ namespace PDF_Office.ViewModels.BOTA
                     if (args.AnnotHandlerEventArgs != null)
                     {
                         AnnotationListItems.Add(args);
+                        CurrentAnnotationArgs.Add(args);
                         await Task.Delay(1);//不加延时 每页的第一个注释不会展开
                         ExpandGroupHeader(args, listBox);
                         listBox.SelectedItem = item;
@@ -804,7 +809,8 @@ namespace PDF_Office.ViewModels.BOTA
                         if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
                         {
                             AnnotationListItems.RemoveAt(k);
-                            currentAnnotationArgs.RemoveAt(k);
+                            AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
+                            CurrentAnnotationArgs.Remove(annotation1);
                             UpdateAnnotListAfterDelete(pageIndex, annotIndex);
                             return;
                         }
@@ -819,7 +825,8 @@ namespace PDF_Office.ViewModels.BOTA
                         if (AnnotationListItems[k].PageIndex == pageIndex && AnnotationListItems[k].AnnotIndex == annotIndex)
                         {
                             AnnotationListItems.RemoveAt(k);
-                            currentAnnotationArgs.RemoveAt(k);
+                            AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
+                            CurrentAnnotationArgs.Remove(annotation1);
                             UpdateAnnotListAfterDelete(pageIndex, annotIndex);
                             return;
                         }
@@ -834,6 +841,15 @@ namespace PDF_Office.ViewModels.BOTA
                         {
                             AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(items[j]);
                             AnnotationListItems[k] = args;
+
+                            AnnotationHandlerEventArgs annotation1 = CurrentAnnotationArgs.FirstOrDefault(x => x.PageIndex == AnnotationListItems[k].PageIndex && x.AnnotIndex == AnnotationListItems[k].AnnotIndex);
+                            for (int i = 0; i < CurrentAnnotationArgs.Count; i++)
+                            {
+                                if (annotation1 == CurrentAnnotationArgs[i])
+                                {
+                                    CurrentAnnotationArgs[i] = args;
+                                }
+                            }
                             if (!listBox.SelectedItems.Contains(AnnotationListItems[k]))
                             {
                                 listBox.SelectedItem = AnnotationListItems[k];
@@ -914,7 +930,7 @@ namespace PDF_Office.ViewModels.BOTA
                 AnnotationListItems = new ObservableCollection<AnnotationHandlerEventArgs>();
 
                 AnnotationListItems = GetDocumentAnnotionList();
-                currentAnnotationArgs.AddRange(AnnotationListItems);
+                CurrentAnnotationArgs.AddRange(AnnotationListItems);
                 AnnotationListItems.CollectionChanged += AnnotationListItems_CollectionChanged;
             }
         }
@@ -1097,6 +1113,7 @@ namespace PDF_Office.ViewModels.BOTA
                 if (obsSender.Count < 1)
                 {
                     IsEmptyPanelVisibility = Visibility.Visible;
+                    //currentAnnotationArgs.Clear();
                 }
                 else
                 {

+ 2 - 3
PDF Office/ViewModels/Dialog/BOTA/ScreenAnnotationDialogViewModel.cs

@@ -141,7 +141,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
         /// <summary>
         /// 链接
         /// </summary>
-        private Visibility annotLinkVisible;
+        private Visibility annotLinkVisible = Visibility.Collapsed;
 
         public Visibility AnnotLinkVisible
         {
@@ -718,7 +718,7 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                         break;
 
                     case AnnotArgsType.AnnotLine:
-                        if(data is LineAnnotArgs lineAnnotArgs)
+                        if (data is LineAnnotArgs lineAnnotArgs)
                         {
                             if (lineAnnotArgs.HeadLineType >= (C_LINE_TYPE)1 || lineAnnotArgs.TailLineType >= (C_LINE_TYPE)1)
                             {
@@ -732,7 +732,6 @@ namespace PDF_Office.ViewModels.Dialog.BOTA
                             }
                             GetAnnotationColors(lineAnnotArgs.LineColor);
                         }
-                       
 
                         break;