Prechádzať zdrojové kódy

bota搜索-切換到其他tab 搜索结果清空,但搜索框输入内容保留,方便用户再次搜索

OYXH\oyxh 1 rok pred
rodič
commit
bfcbb0aab4

+ 2 - 1
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -1471,8 +1471,9 @@ namespace PDF_Master.ViewModels.BOTA
                 iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.PageIndex), ListSortDirection.Ascending));
                 iCollectionView.SortDescriptions.Add(new SortDescription(nameof(AnnotationHandlerEventArgs.AnnotIndex), ListSortDirection.Ascending));
 
+                //Load会触发 重复触发,暂时注释
                 //按照PageIndex,分组 排序
-                SetGroupHeader(listBox);
+                //SetGroupHeader(listBox);
                 Screen = Visibility.Collapsed;
                 colors.Clear();
                 authors.Clear();

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

@@ -15,6 +15,9 @@ using PDF_Master.Views.PageEdit;
 using PDF_Master.Properties;
 using PDF_Master.Helper;
 using PDFReader_WPF.Helper;
+using System.Drawing;
+using PDF_Master.Views.BOTA;
+using ImTools;
 
 namespace PDF_Master.ViewModels.BOTA
 {
@@ -138,6 +141,7 @@ namespace PDF_Master.ViewModels.BOTA
                 }
             }
         }
+
         /// <summary>
         /// 侧边按钮埋点
         /// </summary>
@@ -153,17 +157,21 @@ namespace PDF_Master.ViewModels.BOTA
                 case "TabItemThumbnail":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_Thumbnail");
                     break;
+
                 case "TabItemBookMark":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_BookMark");
                     break;
+
                 case "TabItemAnnotation":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_Annotation");
                     break;
+
                 case "TabItemSearch":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.LeftSideBar, "LeftSideBar_Btn", "Btn_LeftSideBar_Search");
                     break;
             }
         }
+
         private void InitString()
         {
             Tip_Annote = App.MainPageLoader.GetString("ViewTopToolbar_Annotation");
@@ -208,6 +216,13 @@ namespace PDF_Master.ViewModels.BOTA
                 if (viewNameByTabItem.ContainsKey(currentBar))
                 {
                     regions.RequestNavigate(BOTAContentRegionName, viewNameByTabItem[currentBar], param);
+
+                    var views = regions.Regions[BOTAContentRegionName].Views;
+                    var search = views.FindFirst(x => x is SearchContent);
+                    if (search is SearchContent searchContent)
+                    {
+                        viewContentViewModel.SearchTextFocus(searchContent);
+                    }
                 }
 
                 //增加判空逻辑
@@ -249,6 +264,7 @@ namespace PDF_Master.ViewModels.BOTA
         }
 
         #region Navigate
+
         public bool IsNavigationTarget(NavigationContext navigationContext)
         {
             return true;

+ 2 - 1
PDF Office/ViewModels/BOTA/SearchContentViewModel.cs

@@ -313,9 +313,10 @@ namespace PDF_Master.ViewModels.BOTA
         public void OnNavigatedFrom(NavigationContext navigationContext)
         {
             //切换到缩略图等模块时,需要清空搜索结果显示
-            if (SearchItemList.Count>0)
+            if (SearchItemList.Count > 0)
             {
                 PDFViewer.ClearPageSelectText();
+                SearchItemList.Clear();
             }
             return;
         }

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

@@ -1030,11 +1030,12 @@ namespace PDF_Master.ViewModels.Tools
             //    viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
             //}
             #endregion v1.3.0 第一版
-
-            if (PDFViewer.GetSelectAnnotCount() > 0 && ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown == false)
+            //形状、图章、签名等是添加后选中,如果注释列表数据量过大,会卡顿,影响用户体验
+            if (PDFViewer.GetSelectAnnotCount() > 0 && ViewContentViewModel.mainViewModel.AnnotMouseLeftButtonDown == false && string.IsNullOrEmpty(StrAnnotToolChecked))
             {
                 List<AnnotHandlerEventArgs> annotationHandlers = PDFViewer.GetSelectionAnnots();
                 bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
+
                 if (ViewContentViewModel.OpenBOTA == false)
                 {
                     bOTAContentViewModel.OpenBOTA();

+ 85 - 18
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -226,6 +226,11 @@ namespace PDF_Master.ViewModels
 
         #region 属性、变量
 
+        /// <summary>
+        /// 用于退出页面编辑 设置bota搜索框
+        /// </summary>
+        private SearchContent searchContent = null;
+
         /// <summary>
         /// 显示 隐藏注释
         /// </summary>
@@ -703,6 +708,7 @@ namespace PDF_Master.ViewModels
                 //关闭BOTA的逻辑在xaml.cs代码里控制,无法绑定后台
             }
         }
+
         /// <summary>
         /// 防止自动保存异步导致弹窗出现两次
         /// </summary>
@@ -1714,11 +1720,11 @@ namespace PDF_Master.ViewModels
 
         private async void share()
         {
-            if (IsPopupInProgress) 
+            if (IsPopupInProgress)
             {
                 return;
             }
-            IsPopupInProgress=true;
+            IsPopupInProgress = true;
             try
             {
                 DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Share");
@@ -1956,7 +1962,7 @@ namespace PDF_Master.ViewModels
         }
 
         public void ShowPrintDialog()
-        { 
+        {
             //保存并继续,使用了高级功能则弹窗权益弹窗
             if (!saveFile(true))
             {
@@ -2188,28 +2194,87 @@ namespace PDF_Master.ViewModels
                 var item = args.AddedItems[0] as TabItem;
                 CurrentBar = item.Name;
                 TabControlSelectonDataTracking(item.Name);
+
                 if (previousBar != CurrentBar)
                 {
                     if (CurrentBar == "TabItemPageEdit")//如果是页面编辑则进入页面编辑模式
                     {
                         EnterPageEdit();
+                        searchContent = CleanSearch();
                     }
                     else//其余情况直接导航至对应的工具栏即可,不需要清空之前的content,region里是单例模式
                     {
                         EnterSelectedBar(CurrentBar);
                         isInPageEdit = false;
+                        SearchTextFocus(searchContent);
                     }
                     previousBar = CurrentBar;
                 }
             }
         }
+
+        public void SearchTextFocus(SearchContent searchContent)
+        {
+            if (string.IsNullOrEmpty(searchContent.SearchText.Text) == false)
+            {
+                searchContent.SearchText.Dispatcher.BeginInvoke(new Action(() =>
+                {
+                    searchContent.SearchText.Focus();
+                    searchContent.SearchText.SelectAll();
+                }));
+            }
+        }
+
+        private SearchContent CleanSearch()
+        {
+            SearchContent searchContent = null;
+            if (this.OpenBOTA)
+            {
+                bool isTabItemSearch = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
+                if (bOTAContent.TabItemSearch.IsSelected)
+                {
+                    SearchContentViewModel viewModel = GetSearchContentVM(bOTAContentViewModel, out searchContent);
+                    if (viewModel.SearchItemList.Count > 0)
+                    {
+                        PDFViewer.ClearPageSelectText();
+                        viewModel.SearchItemList.Clear();
+                    }
+                }
+            }
+            return searchContent;
+        }
+
+        private SearchContentViewModel GetSearchContentVM(BOTAContentViewModel bOTAContentViewModel, out SearchContent searchContent)
+        {
+            SearchContentViewModel viewModel = null;
+            searchContent = 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 SearchContent search)
+                        {
+                            searchContent = search;
+                            viewModel = search.DataContext as SearchContentViewModel;
+                            break;
+                        }
+                    }
+                }
+            }
+            return viewModel;
+        }
+
         /// <summary>
         /// 选项卡切换事件埋点
         /// </summary>
         /// <param name="e"></param>
         private void TabControlSelectonDataTracking(string currentBar)
         {
-            switch (currentBar) {
+            switch (currentBar)
+            {
                 case "TabItemAnnotation":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Annotation");
                     break;
@@ -2217,24 +2282,26 @@ namespace PDF_Master.ViewModels
                 case "TabItemEdit":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_EditPDF");
                     break;
+
                 case "TabItemPageEdit":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_PageEdit");
                     break;
+
                 case "TabItemConvert":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Converter");
                     break;
+
                 case "TabItemTool":
                     DataTrackingHelper.SendEvent(DataTrackingHelper.EventType.Tbr, "Tbr_Btn", "Btn_Tbr_Tools");
                     break;
             }
-        
         }
 
-            /// <summary>
-            /// 进入页面编辑模式
-            /// </summary>
-            //工具栏添加功能应注意自处
-            public void EnterPageEdit()
+        /// <summary>
+        /// 进入页面编辑模式
+        /// </summary>
+        //工具栏添加功能应注意自处
+        public void EnterPageEdit()
         {
             if (TabSelectedIndex != 2)
             {
@@ -2602,6 +2669,7 @@ namespace PDF_Master.ViewModels
                 events.GetEvent<PageEditNotifyEvent>().Publish(new PageEditNotifyEventArgs(unicode));
             }
         }
+
         private void Redo()
         {
             PDFViewer.UndoManager.Redo();
@@ -2826,9 +2894,9 @@ namespace PDF_Master.ViewModels
                 //是否取消了水印保存步骤
                 bool flg = false;
                 //删掉Settings.Default.UserDate.isInFreeUseTime == false,没有试用期策略了
-                if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true||PDFViewer.UndoManager.PDFEditChanged==true))
+                if ((!App.IsLogin || Settings.Default.UserDate.subscribestatus != 1) && ((App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).IsUsedVIP == true || PDFViewer.UndoManager.PDFEditChanged == true))
                 {
-                       DialogParameters value = new DialogParameters();
+                    DialogParameters value = new DialogParameters();
                     value.Add(ParameterNames.ViewContentViewModel, this);
                     if (autosave)
                     {
@@ -3189,7 +3257,7 @@ namespace PDF_Master.ViewModels
                             DoAfterSaveAs(dlg.FileName);
                         }
                         else
-                        {   //提示文件被其他软件占用 无法保存          
+                        {   //提示文件被其他软件占用 无法保存
                             AlertsMessage alertsMessage = new AlertsMessage();
                             alertsMessage.ShowDialog(App.MainPageLoader.GetString("Main_SaveFailed"), App.MainPageLoader.GetString("Main_TheFileOccupiedWarning"), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_ok"));
                         }
@@ -3334,15 +3402,14 @@ namespace PDF_Master.ViewModels
         /// <summary>
         /// 转档、压缩、合并、分享前自动保存
         /// </summary>
-        public async Task<bool> SaveBeforeOption(bool NoIAP=false)
+        public async Task<bool> SaveBeforeOption(bool NoIAP = false)
         {
-            if(NoIAP == false)
+            if (NoIAP == false)
             {            //添加付费拦截锁
                 if (!ServiceHelper.IAPBeforeFunction())
                 {
                     return false;
                 }
-
             }
             bool result = true;
             //因配合权益弹窗弹出,暂时移除可保存条件判断
@@ -3391,7 +3458,7 @@ namespace PDF_Master.ViewModels
 
                 if (flg == false)
                 {
-                    return ;
+                    return;
                 }
             }
             var dlg = new SaveFileDialog();
@@ -3563,7 +3630,6 @@ namespace PDF_Master.ViewModels
 
         private void EnterSelectedBar(string currentBar)
         {
-
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.PDFViewer, PDFViewer);
             param.Add(ParameterNames.ViewContentViewModel, this);
@@ -3596,6 +3662,7 @@ namespace PDF_Master.ViewModels
         {
             ServiceHelper.GetUser();
         }
+
         #endregion 方法
 
         #region Navigate

+ 6 - 3
PDF Office/Views/BOTA/AnnotationContent.xaml.cs

@@ -71,7 +71,7 @@ namespace PDF_Master.Views.BOTA
             else
             {
                 //需要时间加载完 listbox所有的控件模板
-                await Task.Delay(500);
+                await Task.Delay(200);
                 ExpandOneGroupHeader(obj);
             }
         }
@@ -90,10 +90,13 @@ namespace PDF_Master.Views.BOTA
                         {
                             if (group.Items.Contains(item))
                             {
-                                await Task.Delay(5);
                                 var scroller = GetScrollHost(AnnotationList);
                                 var stackpanel = CommonHelper.FindVisualChild<StackPanel>(scroller);
-                                if (stackpanel != null)
+                                if (stackpanel == null)
+                                {
+                                    await Task.Delay(1);
+                                }
+                                else
                                 {
                                     GroupItemExpanded(stackpanel, i);
                                 }