Browse Source

补充-注释列表,刷新

OYXH\oyxh 2 years ago
parent
commit
6d39bcda20

+ 81 - 20
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -6,6 +6,7 @@ using ComPDFKitViewer;
 using ComPDFKitViewer.AnnotEvent;
 using ComPDFKitViewer.PdfViewer;
 using DryIoc;
+using ImTools;
 using Microsoft.Office.Interop.Excel;
 using Microsoft.Office.Interop.PowerPoint;
 using Microsoft.Office.Interop.Word;
@@ -33,6 +34,7 @@ using System.Windows;
 using System.Windows.Annotations.Storage;
 using System.Windows.Controls;
 using System.Windows.Data;
+using System.Windows.Documents;
 using System.Windows.Forms;
 using System.Windows.Markup;
 using System.Windows.Media;
@@ -760,6 +762,57 @@ namespace PDF_Office.ViewModels.BOTA
             }
         }
 
+        public async void UpdateAddedAnnot(int pageIndex, int annotIndex)
+        {
+            var annots = PdfViewer.GetAnnotCommentList(pageIndex, PdfViewer.Document);
+            foreach (var item in annots)
+            {
+                if (item.AnnotIndex == annotIndex && item.EventType != AnnotArgsType.AnnotRedaction)
+                {
+                    AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(item);
+                    if (args.AnnotHandlerEventArgs != null)
+                    {
+                        AnnotationListItems.Add(args);
+                        await Task.Delay(1);//不加延时 每页的第一个注释不会展开
+                        ExpandGroupHeader(args, listBox);
+                        listBox.SelectedItem = item;
+                        await Task.Delay(1);//不加延时 会有不滚动的现象
+                        listBox.ScrollIntoView(item);
+                    }
+                }
+            }
+            if (IsEmptyPanelVisibility == Visibility.Visible && AnnotationListItems.Count > 0)
+            {
+                IsEmptyPanelVisibility = Visibility.Collapsed;
+            }
+        }
+
+        /// <summary>
+        /// 展开item所在分组
+        /// </summary>
+        private void ExpandGroupHeader(AnnotationHandlerEventArgs item, ListBox listBox)
+        {
+            try
+            {
+                var groups = listBox.Items.Groups;
+                for (int i = 0; i < groups.Count; i++)
+                {
+                    var l = groups[i] as CollectionViewGroup;
+                    if (l.Items.Contains(item))
+                    {
+                        var scroller = GetScrollHost(listBox);
+                        var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
+                        int count = VisualTreeHelper.GetChildrenCount(stackpanel);
+                        var groupItem = VisualTreeHelper.GetChild(stackpanel, i) as GroupItem;
+                        var g = CommonHelper.FindVisualChild<Expander>(groupItem);
+                        if (g != null)
+                            g.IsExpanded = true;
+                    }
+                }
+            }
+            catch { }
+        }
+
         /// <summary>
         /// 页面加载时
         /// </summary>
@@ -887,26 +940,11 @@ namespace PDF_Office.ViewModels.BOTA
                     //原型图上,目前对波浪线的类型,在注释列表不显示
                     if (item.EventType != AnnotArgsType.AnnotRedaction && item.EventType != AnnotArgsType.AnnotSquiggly)
                     {
-                        AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
-                        if (item.EventType == AnnotArgsType.AnnotFreehand)
+                        AnnotationHandlerEventArgs args = GetAddAnnotEventArgs(item);
+                        if (args.AnnotHandlerEventArgs != null)
                         {
-                            WriteableBitmap bitmap = GetAnnotImage(PdfViewer.Document, item.PageIndex, item.AnnotIndex);
-                            args.WriteableBitmap = bitmap;
+                            list.Add(args);
                         }
-                        args.AnnotHandlerEventArgs = item;
-                        args.PageIndex = item.PageIndex;
-                        args.AnnotIndex = item.AnnotIndex;
-                        args.EventType = item.EventType;
-                        args.CreateTime = item.CreateTime;
-                        args.UpdateTime = item.UpdateTime;
-                        args.Content = item.Content;
-                        args.MarkupContent = item.MarkupContent;
-                        args.Author = item.Author;
-                        args.Locked = item.Locked;
-                        args.ReadOnly = item.ReadOnly;
-                        args.FormField = item.FormField;
-                        args.Document = PdfViewer.Document;
-                        list.Add(args);
                     }
                 }
             }
@@ -914,6 +952,30 @@ namespace PDF_Office.ViewModels.BOTA
             return list;
         }
 
+        private AnnotationHandlerEventArgs GetAddAnnotEventArgs(AnnotHandlerEventArgs item)
+        {
+            AnnotationHandlerEventArgs args = new AnnotationHandlerEventArgs();
+            if (item.EventType == AnnotArgsType.AnnotFreehand)
+            {
+                WriteableBitmap bitmap = GetAnnotImage(PdfViewer.Document, item.PageIndex, item.AnnotIndex);
+                args.WriteableBitmap = bitmap;
+            }
+            args.AnnotHandlerEventArgs = item;
+            args.PageIndex = item.PageIndex;
+            args.AnnotIndex = item.AnnotIndex;
+            args.EventType = item.EventType;
+            args.CreateTime = item.CreateTime;
+            args.UpdateTime = item.UpdateTime;
+            args.Content = item.Content;
+            args.MarkupContent = item.MarkupContent;
+            args.Author = item.Author;
+            args.Locked = item.Locked;
+            args.ReadOnly = item.ReadOnly;
+            args.FormField = item.FormField;
+            args.Document = PdfViewer.Document;
+            return args;
+        }
+
         /// <summary>
         /// 获取手绘图案
         /// </summary>
@@ -962,8 +1024,7 @@ namespace PDF_Office.ViewModels.BOTA
         /// <param name="e"></param>
         private void AnnotationListItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
         {
-            ObservableCollection<AnnotationHandlerEventArgs> obsSender = sender as ObservableCollection<AnnotationHandlerEventArgs>;
-            if (obsSender != null)
+            if (sender is ObservableCollection<AnnotationHandlerEventArgs> obsSender)
             {
                 currentAnnotationArgs.Clear();
                 currentAnnotationArgs.AddRange(obsSender);

+ 3 - 0
PDF Office/ViewModels/BOTA/BOTAContentViewModel.cs

@@ -37,6 +37,8 @@ namespace PDF_Office.ViewModels.BOTA
             }
         }
 
+        public string CurrentBar = "";
+
         public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
 
         public BOTAContentViewModel(IRegionManager regionManager, IDialogService dialogService)
@@ -80,6 +82,7 @@ namespace PDF_Office.ViewModels.BOTA
         /// <param name="currentBar"></param>
         private void EnterSelectedBar(string currentBar)
         {
+            CurrentBar = currentBar;
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.PDFViewer, pdfViewer);
             param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);

+ 85 - 0
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -8,8 +8,10 @@ using PDF_Office.EventAggregators;
 using PDF_Office.Helper;
 using PDF_Office.Model;
 using PDF_Office.Properties;
+using PDF_Office.ViewModels.BOTA;
 using PDF_Office.ViewModels.PropertyPanel;
 using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
+using PDF_Office.Views.BOTA;
 using PDF_Office.Views.PropertyPanel.AnnotPanel;
 using PDFSettings;
 using Prism.Commands;
@@ -497,6 +499,89 @@ namespace PDF_Office.ViewModels.Tools
 
         private void PDFViewer_AnnotEditHandler(object sender, List<AnnotEditEvent> e)
         {
+            if (e != null && e.Count > 0)
+            {
+                for (int i = 0; i < e.Count; i++)
+                {
+                    AnnotEditEvent editEvent = e[i];
+                    switch (editEvent.EditAction)
+                    {
+                        case ActionType.Add:
+                            BOTAContentViewModel bOTAContentViewModel = null;
+                            bool isTabItemAnnotation = IsTabItemAnnotationShow(out bOTAContentViewModel);
+
+                            if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
+                            {
+                                AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
+
+                                if (viewModel != null)
+                                {
+                                    int pageindex = editEvent.PageIndex;
+                                    int annotindex = editEvent.AnnotIndex;
+                                    viewModel.UpdateAddedAnnot(pageindex, annotindex);
+                                }
+                            }
+                            break;
+
+                        case ActionType.Del:
+                            break;
+
+                        case ActionType.Modify:
+                            break;
+
+                        case ActionType.TextEdit:
+                            break;
+
+                        default:
+                            break;
+                    }
+                }
+            }
+        }
+
+        private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel)
+        {
+            AnnotationContentViewModel viewModel = null;
+            if (bOTAContentViewModel != null)
+            {
+                if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
+                {
+                    var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
+                    foreach (var item in views)
+                    {
+                        if (item is AnnotationContent annotation)
+                        {
+                            viewModel = annotation.DataContext as AnnotationContentViewModel;
+                            break;
+                        }
+                    }
+                }
+            }
+            return viewModel;
+        }
+
+        private bool IsTabItemAnnotationShow(out BOTAContentViewModel bOTAContentViewModel)
+        {
+            bool isTabItemAnnotation = false;
+            bOTAContentViewModel = null;
+            if (region.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
+            {
+                var views = region.Regions[viewContentViewModel.BOTARegionName].Views;
+                foreach (var item in views)
+                {
+                    if (item is BOTAContent bOTAContent)
+                    {
+                        bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
+                        if (bOTAContentViewModel.CurrentBar == "TabItemAnnotation")
+                        {
+                            isTabItemAnnotation = true;
+
+                            break;
+                        }
+                    }
+                }
+            }
+            return isTabItemAnnotation;
         }
 
         private void PDFViewer_AnnotActiveHandler(object sender, AnnotAttribEvent e)