Selaa lähdekoodia

BOTA注释列表-收起面板时,在PDFView中选择注释,当选中视图中的注释时,左侧注释列表需要跳转到该注释位置并选中

OYXH\oyxh 1 vuosi sitten
vanhempi
commit
adaa13430f

+ 22 - 14
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -301,6 +301,7 @@ namespace PDF_Master.ViewModels.BOTA
         public string Unicode { get; private set; }
         private bool IsFirst = true;
         private bool isHiddenAnnot = false;
+
         //判断是否为属性修改进入,属性修改,改变后不让再次其选中注释
         public bool IsModified = true;
 
@@ -330,10 +331,8 @@ namespace PDF_Master.ViewModels.BOTA
         private void OnNotifyEvent(PageEditNotifyEventArgs obj)
         {
             RefreshAnnotationListItems();
-        }
-
-        
-
+        }
+
         public void HiddenAnnot()
         {
             isHiddenAnnot = true;
@@ -350,6 +349,10 @@ namespace PDF_Master.ViewModels.BOTA
 
         public void DisplayAnnot()
         {
+            if (ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown)
+            {
+                return;
+            }
             isHiddenAnnot = false;
 
             colors.Clear();
@@ -1079,7 +1082,7 @@ namespace PDF_Master.ViewModels.BOTA
             }
         }
 
-        public void ScrollToAnnot(int pageindex, int annotindex, ListBox AnnotationList)
+        public async void ScrollToAnnot(int pageindex, int annotindex, ListBox AnnotationList)
         {
             //var list = PdfViewer.GetAnnotCommentList(pageindex, PdfViewer.Document);
             for (int i = 0; i < AnnotationList.Items.Count; i++)
@@ -1092,15 +1095,15 @@ namespace PDF_Master.ViewModels.BOTA
                         if (item.EventType != AnnotArgsType.AnnotLink)
                         {
                             //需要手动搜寻在哪一个分组 展开分组头
-                            //ExpandGroupHeader(item, AnnotationList);
-                            //if (AnnotationList.SelectedItems.IndexOf(item) == -1)
-                            //{
-                            //    AnnotationList.SelectedItem = item;
-                            //}
+                            ExpandGroupHeader(item, AnnotationList);
+                            if (AnnotationList.SelectedItems.IndexOf(item) == -1)
+                            {
+                                AnnotationList.SelectedItem = item;
+                            }
 
-                            //await Task.Delay(5);
-                            //AnnotationList.ScrollIntoView(item);
-                            events.GetEvent<RefreshAnnotationEvent>().Publish(new RefreshAnnotationArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsAll = false, IsSelect = true, annotHandlerArgs = item });
+                            await Task.Delay(5);
+                            AnnotationList.ScrollIntoView(item);
+                            //events.GetEvent<RefreshAnnotationEvent>().Publish(new RefreshAnnotationArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsAll = false, IsSelect = true, annotHandlerArgs = item });
                         }
                     }
                 }
@@ -1123,12 +1126,17 @@ namespace PDF_Master.ViewModels.BOTA
             }
             if (obj is AnnotationHandlerEventArgs annotation)
             {
+                ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = true;
                 PdfViewer.SelectAnnotation(annotation.PageIndex, annotation.AnnotIndex);
             }
+            else
+            {
+                ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = false;
+            }
             if (obj is Dictionary<int, List<int>> eventArgs)
             {
                 PdfViewer.SelectAnnotation(eventArgs);
-            }
+            }
         }
 
         public async void UpdateAddedAnnot(int pageIndex, int annotIndex)

+ 13 - 16
PDF Office/ViewModels/MainContentViewModel.cs

@@ -88,13 +88,17 @@ namespace PDF_Master.ViewModels
             T_CloseAll = App.MainPageLoader.GetString("MultipleTabs_ CloseAll");
         }
 
+        #endregion 文案
 
-        #endregion
+        /// <summary>
+        /// 是否是注释列表点击
+        /// </summary>
+        public bool AnnotMouseLeftButtonDown { get; set; } = false;
 
         /// <summary>
         /// 是否使用了高级功能
         /// </summary>
-            public bool IsUsedVIP = false;
+        public bool IsUsedVIP = false;
 
         /// <summary>
         /// 是否处于阅读模式
@@ -203,9 +207,8 @@ namespace PDF_Master.ViewModels
             }
         }
 
-
-
         private bool newFile = false;
+
         /// <summary>
         /// 是否是新建的文档
         /// </summary>
@@ -222,7 +225,6 @@ namespace PDF_Master.ViewModels
             }
         }
 
-
         public IRegionManager toolregion;
 
         public IEventAggregator eventer;
@@ -319,12 +321,11 @@ namespace PDF_Master.ViewModels
             if (!result)
             {
                 AlertsMessage alertsMessage = new AlertsMessage();
-                alertsMessage.ShowDialog("",App.MainPageLoader.GetString("Main_OpenFileFailedWarning"), App.ServiceLoader.GetString("Text_ok"));
+                alertsMessage.ShowDialog("", App.MainPageLoader.GetString("Main_OpenFileFailedWarning"), App.ServiceLoader.GetString("Text_ok"));
                 return;
             }
             FilePath = filePath;
 
-
             NavigateToViewContent();
 
             if (App.OpenedFileList.Contains(filePath) == false)
@@ -470,7 +471,6 @@ namespace PDF_Master.ViewModels
 
             SaveToTempFile();
 
-
             PDFViewer.UndoManager.CanSave = true;
             FileChanged = Visibility.Visible;
 
@@ -549,8 +549,7 @@ namespace PDF_Master.ViewModels
                 AlertsMessage alertsMessage = new AlertsMessage();
                 if (str != "没有安装")
                 {
-
-                    alertsMessage.ShowDialog("",App.MainPageLoader.GetString("NoOffice_Warning"), App.ServiceLoader.GetString("Text_ok"));
+                    alertsMessage.ShowDialog("", App.MainPageLoader.GetString("NoOffice_Warning"), App.ServiceLoader.GetString("Text_ok"));
                 }
                 else
                 {
@@ -568,7 +567,7 @@ namespace PDF_Master.ViewModels
             if (PDFViewer != null)
             {
                 string tempfile = CacheFilePath.Instance.CreatedFilePath;
-                string file = CommonHelper.CreateFilePath(Path.Combine(tempfile,App.UntitledFileNmae));
+                string file = CommonHelper.CreateFilePath(Path.Combine(tempfile, App.UntitledFileNmae));
                 PDFViewer.Document.WriteToFilePath(file);
 
                 PDFViewer.CloseDocument();
@@ -579,7 +578,6 @@ namespace PDF_Master.ViewModels
             }
         }
 
-
         private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
         {
             if (e.PropertyName == "CanSave")
@@ -594,9 +592,9 @@ namespace PDF_Master.ViewModels
                 }
 
                 //保存完后,需要更新产品名字
-                if (!PDFViewer.UndoManager.CanSave&&!string.IsNullOrEmpty(PDFViewer.Document.FileName))
+                if (!PDFViewer.UndoManager.CanSave && !string.IsNullOrEmpty(PDFViewer.Document.FileName))
                 {
-                    FileName =System.IO.Path.GetFileName(PDFViewer.Document.FilePath);
+                    FileName = System.IO.Path.GetFileName(PDFViewer.Document.FilePath);
                 }
             }
         }
@@ -638,7 +636,7 @@ namespace PDF_Master.ViewModels
                 }
                 else
                 {
-                    result =CreateFileFromOffice(filepath);
+                    result = CreateFileFromOffice(filepath);
                 }
                 homeContentViewModel.IsLoading = Visibility.Collapsed;
                 if (!result)
@@ -646,7 +644,6 @@ namespace PDF_Master.ViewModels
                     mainWindowViewModel.CloseTabItem(mainWindowViewModel.SelectedItem);
                     return;
                 }
-           
 
                 if (!App.OpenedFileList.Contains(filepath))
                 {

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

@@ -527,6 +527,7 @@ namespace PDF_Master.ViewModels.Tools
             }
             if (e == null)
             {
+                ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = false;
                 if (ViewContentViewModel.IsRightMenuSelectedTextAddLink || ViewContentViewModel.IsRightMenuCreateLink)
                 {
                     ViewContentViewModel.IsRightMenuSelectedTextAddLink = false;
@@ -660,6 +661,7 @@ namespace PDF_Master.ViewModels.Tools
             {
                 if (e.IsMouseRightActive)
                 {
+                    ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = true;
                     CloseAnnotToolTip();
                     if (string.IsNullOrEmpty(StrAnnotToolChecked))
                     {
@@ -846,11 +848,9 @@ namespace PDF_Master.ViewModels.Tools
                         ViewContentViewModel.IsMultiSelected = true;
                         //viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
 
-                        #region MVP 在对多选注释做处理
+                        // MVP 在对多选注释做处理
                         bool isDifferentAnnotTyle = AnnotTransfer.IsDifferentTypeAnnots(e.AnnotItemsList);
 
-                        #endregion MVP 在对多选注释做处理
-
                         if (ViewContentViewModel.mainViewModel.IsBookMode)
                         {
                             ShowPropertyPanel(false);
@@ -922,14 +922,35 @@ namespace PDF_Master.ViewModels.Tools
         /// <param name="e"></param>
         private void SelectedBotaAnnotationList(AnnotAttribEvent e)
         {
-            var list = e.GetPageAnnotsIndex();
-            bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
-            //if (viewContentViewModel.OpenBOTA == false || isTabItemAnnotation == false || bOTAContent.TabItemAnnotation.IsSelected == false)
+            #region 之前版本
+            //var list = e.GetPageAnnotsIndex();
+            //bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
+            ////if (viewContentViewModel.OpenBOTA == false || isTabItemAnnotation == false || bOTAContent.TabItemAnnotation.IsSelected == false)
+            ////{
+            ////    viewContentViewModel.OpenBOTA = true;
+            ////    bOTAContent.TabItemAnnotation.IsSelected = true;
+            ////}
+            //if (ViewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true /*&& bOTAContent.TabItemAnnotation.IsSelected == true*/ && list != null && list.Count > 0)
             //{
-            //    viewContentViewModel.OpenBOTA = true;
-            //    bOTAContent.TabItemAnnotation.IsSelected = true;
+            //    if (list.Keys.Count == 0)
+            //    {
+            //        return;
+            //    }
+            //    var pageindex = new List<int>(list.Keys);
+            //    List<int> annotes = new List<int>();
+            //    list.TryGetValue(pageindex[0], out annotes);
+            //    int annoteindex = annotes[0];
+            //    AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
+
+            //    if (viewModel != null)
+            //    {
+            //        selectedAnnotation = viewModel.AnnotationListItems.FindFirst(a => a.PageIndex == pageindex[0] && a.AnnotIndex == annoteindex);
+            //        viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
+            //    }
             //}
-            if (ViewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true /*&& bOTAContent.TabItemAnnotation.IsSelected == true*/ && list != null && list.Count > 0)
+            #endregion 之前版本
+            var list = e.GetPageAnnotsIndex();
+            if (list != null && list.Count > 0 && ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown == false)
             {
                 if (list.Keys.Count == 0)
                 {
@@ -939,11 +960,22 @@ namespace PDF_Master.ViewModels.Tools
                 List<int> annotes = new List<int>();
                 list.TryGetValue(pageindex[0], out annotes);
                 int annoteindex = annotes[0];
+
+                bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
+                if (ViewContentViewModel.OpenBOTA == false)
+                {
+                    bOTAContentViewModel.OpenBOTA();
+                }
+                if (bOTAContent.TabItemAnnotation.IsSelected == false)
+                {
+                    bOTAContent.TabItemAnnotation.IsSelected = true;
+                }
+
                 AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
 
                 if (viewModel != null)
                 {
-                    selectedAnnotation = viewModel.AnnotationListItems.FindFirst(a => a.PageIndex == pageindex[0] && a.AnnotIndex == annoteindex);
+                    //selectedAnnotation = viewModel.AnnotationListItems.FindFirst(a => a.PageIndex == pageindex[0] && a.AnnotIndex == annoteindex);
                     viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
                 }
             }

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

@@ -145,6 +145,7 @@ namespace PDF_Master.ViewModels.Tools
             PDFViewer.SetDrawAnnot((bool)annotBtn.IsChecked);
             PDFViewer.ReloadVisibleAnnots();
             bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
+            ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = false;
             if (annotBtn.IsChecked == true)
             {
                 ViewContentViewModel.IsHiddenAnnot = false;
@@ -312,36 +313,45 @@ namespace PDF_Master.ViewModels.Tools
                 case "HighLight":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Highlight");
                     break;
+
                 case "UnderLine":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Underline");
                     break;
+
                 case "Strikeout":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Strikethrough");
                     break;
+
                 case "Freehand":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Draw");
                     break;
+
                 case "Freetext":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Text");
                     break;
+
                 case "StickyNote":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Note");
                     break;
+
                 case "Rect":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Shape");
                     break;
+
                 case "Link":
                     DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_Annotation, DataTrackingHelper.EntryPathKeyType.SubTbr_Annotation);
                     DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Home, DataTrackingHelper.SecondaryPath.Link);
                     DataTrackingHelper.IsClearEntryPath = true;
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Link");
                     break;
+
                 case "Stamp":
                     DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_Annotation, DataTrackingHelper.EntryPathKeyType.SubTbr_Annotation);
                     DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Home, DataTrackingHelper.SecondaryPath.Stamp);
                     DataTrackingHelper.IsClearEntryPath = true;
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Stamp");
                     break;
+
                 case "Signature":
                     DataTrackingHelper.SetSendInformation(DataTrackingHelper.EventType.Purchase_Annotation, DataTrackingHelper.EntryPathKeyType.SubTbr_Annotation);
                     DataTrackingHelper.AddFirstAndSecondaryPath(DataTrackingHelper.FirstPath.Home, DataTrackingHelper.SecondaryPath.Sign);
@@ -349,7 +359,6 @@ namespace PDF_Master.ViewModels.Tools
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.SubTbr_Annotation, "SubTbr_Btn", "Btn_SubTbr_Sign");
                     break;
             }
-
         }
 
         private void UncheckAnnot()
@@ -603,7 +612,6 @@ namespace PDF_Master.ViewModels.Tools
                     case "HighLight"://字体高亮
                         TextHighlightAnnotArgs highlightArgs = (TextHighlightAnnotArgs)GetHighLight();
                         highlightArgs.ClientRect = annotCommand.TextRect;
-                        highlightArgs.Content = annotCommand.Text;
                         highlightArgs.Author = Settings.Default.AppProperties.Description.Author;
                         PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                         PDFViewer.SetToolParam(highlightArgs);
@@ -614,7 +622,6 @@ namespace PDF_Master.ViewModels.Tools
                     case "UnderLine"://下划线
                         TextUnderlineAnnotArgs underlineArgs = (TextUnderlineAnnotArgs)GetUnderLine();
                         underlineArgs.ClientRect = annotCommand.TextRect;
-                        underlineArgs.Content = annotCommand.Text;
                         underlineArgs.Author = Settings.Default.AppProperties.Description.Author;
                         PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                         PDFViewer.SetToolParam(underlineArgs);
@@ -625,7 +632,6 @@ namespace PDF_Master.ViewModels.Tools
                     case "Strikeout"://删除线
                         TextStrikeoutAnnotArgs strikeoutArgs = (TextStrikeoutAnnotArgs)GetStrikeout();
                         strikeoutArgs.ClientRect = annotCommand.TextRect;
-                        strikeoutArgs.Content = annotCommand.Text;
                         strikeoutArgs.Author = Settings.Default.AppProperties.Description.Author;
                         PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
                         PDFViewer.SetToolParam(strikeoutArgs);
@@ -1092,7 +1098,7 @@ namespace PDF_Master.ViewModels.Tools
             BtnShowAnnotIsChecked = true;
 
             bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
-
+            ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = false;
             if (ViewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
             {
                 AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);

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

@@ -62,6 +62,7 @@
                 ItemTemplate="{StaticResource AnnotationListItemTemplate}"
                 ItemsSource="{Binding AnnotationListItems}"
                 MouseDown="ListBox_MouseDown"
+                PreviewMouseLeftButtonDown="AnnotationList_PreviewMouseLeftButtonDown"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 SelectionChanged="AnnotationList_SelectionChanged"
                 SelectionMode="Extended">
@@ -122,7 +123,7 @@
                                                     </Grid>
                                                 </Expander.Header>
                                                 <!--<Expander.Content>
-                                                    <ItemsPresenter  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
+                                                <ItemsPresenter  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                                                 </Expander.Content>-->
                                                 <ItemsPresenter />
                                             </Expander>

+ 22 - 15
PDF Office/Views/BOTA/AnnotationContent.xaml.cs

@@ -98,7 +98,7 @@ namespace PDF_Master.Views.BOTA
                         }
                     }
                 }
-                catch{ }
+                catch { }
             }
             else
             {
@@ -118,19 +118,22 @@ namespace PDF_Master.Views.BOTA
                                     var scroller = GetScrollHost(AnnotationList);
                                     var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
                                     var groupItem = VisualTreeHelper.GetChild(stackpanel, i) as GroupItem;
-                                    var g = CommonHelper.FindVisualChild<Expander>(groupItem);
-                                    if (g != null)
-                                    {
-                                        g.IsExpanded = true;
-                                    }
-                                    else
+                                    if (groupItem != null)
                                     {
-                                        await Task.Delay(5);
-                                        g = CommonHelper.FindVisualChild<Expander>(groupItem);
+                                        var g = CommonHelper.FindVisualChild<Expander>(groupItem);
                                         if (g != null)
                                         {
                                             g.IsExpanded = true;
                                         }
+                                        else
+                                        {
+                                            await Task.Delay(5);
+                                            g = CommonHelper.FindVisualChild<Expander>(groupItem);
+                                            if (g != null)
+                                            {
+                                                g.IsExpanded = true;
+                                            }
+                                        }
                                     }
                                 }
                                 else
@@ -447,13 +450,17 @@ namespace PDF_Master.Views.BOTA
 
         private void AnnotationList_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
         {
-            if (AnnotationList.SelectedItems.Count > 1)
-            {
-                viewModel.ListBoxItemPreviewMouseLeftButtonDown.Execute(AnnotationList.SelectedItems);
-            }
-            else if (AnnotationList.SelectedItems.Count == 1)
+            var pos = e.GetPosition(AnnotationList);
+
+            var result = VisualTreeHelper.HitTest(AnnotationList, pos);
+            if (result != null)
             {
-                viewModel.ListBoxItemPreviewMouseLeftButtonDown.Execute(AnnotationList.SelectedItem);
+                //获取当前鼠标指针下的容器
+                var listBoxItem = CommonHelper.FindVisualParent<ListBoxItem>(result.VisualHit);
+                if (listBoxItem == null)
+                {
+                    viewModel.ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown = false;
+                }
             }
         }