Browse Source

其他-修复页面编辑缩小页面不刷新问题、调整关闭页签逻辑

ZhouJieSheng 1 year ago
parent
commit
7a8e03798d

+ 22 - 8
PDF Office/App.xaml.cs

@@ -172,6 +172,13 @@ namespace PDF_Master
         var countryCode = RegionInfo.CurrentRegion.TwoLetterISORegionName;//上传国家信息
         AppCenter.SetCountryCode(countryCode);
 #endif
+            //增加全局异常捕获
+            //UI线程异常
+            this.DispatcherUnhandledException += App_DispatcherUnhandledException;
+            //非UI线程异常
+            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
+            //Task线程内
+            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
         }
 
         private void InitSettings()
@@ -288,13 +295,6 @@ namespace PDF_Master
             }
 
 
-            //增加全局异常捕获
-            //UI线程异常
-            this.DispatcherUnhandledException += App_DispatcherUnhandledException;
-            //非UI线程异常
-            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
-            //Task线程内
-            TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
 
             if (!LicenseVerify())
             {
@@ -395,6 +395,7 @@ namespace PDF_Master
             base.OnStartup(e);
         }
 
+
         private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
         {
 #if DEBUG
@@ -403,6 +404,11 @@ namespace PDF_Master
             {
                 MessageBox.Show("发生Task未处理异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
             }
+#else
+            if (e.Exception is System.Exception)
+            {
+                Crashes.TrackError(e.Exception as Exception);
+            }
 #endif
         }
 
@@ -414,6 +420,12 @@ namespace PDF_Master
                 Exception ex = (System.Exception)e.ExceptionObject;
                 MessageBox.Show("发生非UI线程异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
             }
+
+#else
+            if (e.ExceptionObject is System.Exception)
+            {
+                Crashes.TrackError(e.ExceptionObject as Exception);
+            }
 #endif
         }
 
@@ -422,9 +434,11 @@ namespace PDF_Master
 #if DEBUG
             e.Handled = true;
             MessageBox.Show("发生UI线程异常:" + e.Exception.Message + "\n" + e.Exception.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
+#else
+            e.Handled = true;
+            Crashes.TrackError(e.Exception);
 #endif
         }
-
         /// <summary>
         /// 创建启动窗口
         /// </summary>

+ 27 - 23
PDF Office/ViewModels/MainWindowViewModel.cs

@@ -30,7 +30,7 @@ namespace PDF_Master.ViewModels
     public class MainWindowViewModel : BindableBase
     {
         private MainContent selectedItem;
-        private LoginDialogViewModel LoginDialogViewModel ;
+        private LoginDialogViewModel LoginDialogViewModel;
 
         #region 文案
 
@@ -60,7 +60,7 @@ namespace PDF_Master.ViewModels
         {
 
             Msgtologin = App.ServiceLoader.GetString("Msgtologin");
-          
+
         }
 
 
@@ -298,7 +298,9 @@ namespace PDF_Master.ViewModels
             OpenRegisterCommand = new DelegateCommand(OpenRegister);
             OpenLoginCommand = new DelegateCommand(OpenLogin);
             OpenUserCommand = new DelegateCommand(OpenUser);
-            CloseAllTabCommand = new DelegateCommand(() => { if (closeAllTabItem())
+            CloseAllTabCommand = new DelegateCommand(() =>
+            {
+                if (closeAllTabItem())
                 {
                     App.Current.MainWindow.Close();
                 }
@@ -328,7 +330,7 @@ namespace PDF_Master.ViewModels
                     else
                     {
                         //如果有拖拽文件到图标或者设为默认阅读器的情况,双击文件打开软件时,不加载首页
-                        if ((App.Current.MainWindow as MainWindow)!=null&&(App.Current.MainWindow as MainWindow).TabablzControl.Items.Count <= 0)
+                        if ((App.Current.MainWindow as MainWindow) != null && (App.Current.MainWindow as MainWindow).TabablzControl.Items.Count <= 0)
                         {
                             region.RequestNavigate(RegionNames.MainRegion, "MainContent");
                         }
@@ -369,14 +371,14 @@ namespace PDF_Master.ViewModels
 
                 if (ServiceHelper.GetUser() == "401")
                 {
-                   
+
                     LoginVis = Visibility.Visible;
                     OphVis = Visibility.Visible;
                 }
                 else
                 {
                     App.IsLogin = true;
-                    Useremailchar= Settings.Default.UserDate.Email.Substring(0, 1);
+                    Useremailchar = Settings.Default.UserDate.Email.Substring(0, 1);
                     UserVis = Visibility.Visible;
                 }
             }
@@ -395,7 +397,7 @@ namespace PDF_Master.ViewModels
             bool result = true;
             dialogs.ShowDialog(DialogNames.GuidDialog, null, r =>
             {
-                if(r.Result == ButtonResult.Ignore)
+                if (r.Result == ButtonResult.Ignore)
                 {
                     result = false;
                 }
@@ -428,7 +430,7 @@ namespace PDF_Master.ViewModels
                 if (ServiceHelper.GetUser() == "401")
                 {
 
-                   UserVis = Visibility.Collapsed;
+                    UserVis = Visibility.Collapsed;
                     LoginVis = Visibility.Visible;
                     OphVis = Visibility.Visible;
                     OpenLogin();
@@ -450,7 +452,7 @@ namespace PDF_Master.ViewModels
                 OphVis = Visibility.Visible;
                 OpenLogin();
             }
-           
+
         }
 
         /// <summary>
@@ -458,7 +460,7 @@ namespace PDF_Master.ViewModels
         /// </summary>
         private void closeocr()
         {
-            
+
             if (ProcessCloseAction != null)
             {
                 ProcessCloseAction.Invoke();
@@ -538,10 +540,10 @@ namespace PDF_Master.ViewModels
         /// 设置value值小于MaxValue值时 自动显示
         /// Value值 大于等于MaxValue值时,自动隐藏
         /// </summary>
-        public async void SetProcessValue(string title,double value,double maxvalue,bool showClose = true)
+        public async void SetProcessValue(string title, double value, double maxvalue, bool showClose = true)
         {
             ProgressTitle = title;
-            if(value<0)
+            if (value < 0)
             {
                 //异常处理
                 this.Value = 0;
@@ -553,11 +555,11 @@ namespace PDF_Master.ViewModels
                 this.MaxValue = 0;
             }
 
-            if(value<maxvalue)
+            if (value < maxvalue)
             {
                 this.Value = value;
                 this.MaxValue = maxvalue;
-                if(IsProcessVisible!=Visibility.Visible)
+                if (IsProcessVisible != Visibility.Visible)
                 {
                     IsProcessVisible = Visibility.Visible;
                 }
@@ -580,49 +582,51 @@ namespace PDF_Master.ViewModels
             //获取x号所在的maincontentviewmodel对象
             var maincontentViewModel = (item as MainContent).DataContext as MainContentViewModel;
             //如果已经有打开文档,先切换到目标页签
-            if (maincontentViewModel.PDFViewer != null)
+            if (maincontentViewModel.PDFViewer != null && maincontentViewModel.PDFViewer.Document != null)
             {
                 SelectItem(maincontentViewModel.PDFViewer.Document.FilePath);
             }
+
+            //可以保存时,弹窗询问提示弹窗
             if (maincontentViewModel.PDFViewer != null && maincontentViewModel.PDFViewer.UndoManager.CanSave)
             {
                 ContentResult result = ShowSaveDialog(maincontentViewModel.viewContentViewModel);
                 //此处要加上第二个判断,如果去除第二个判断,则新建文件后,点击关闭按钮,不选择保存路径时,无法关闭页签
-                if (result == ContentResult.Cancel&& !Settings.Default.AppProperties.Description.NotShowSaveWhenClose)
+                if (result == ContentResult.Cancel && !Settings.Default.AppProperties.Description.NotShowSaveWhenClose)
                 {
                     //非自动保存且取消了另存为时
                     return;
                 }
             }
-
-            //不要保存 可以直接关闭页签时
+            //这里不能加Else 需要分开写If 否则会出现无法关闭页签的情况
+            //不要保存 可以直接关闭页签时(有多个页签时)
             if (region.Regions[RegionNames.MainRegion].Views.Count() > 1)
             {
                 region.Regions[RegionNames.MainRegion].Remove(item);
                 CheckViewsCount();
 
                 //关闭子窗体的最后一个页签时,子窗体关闭(不显示首页),参考福昕逻辑
-                if ((App.Current.MainWindow as MainWindow).TabablzControl.Items.Count==0)
+                if ((App.Current.MainWindow as MainWindow).TabablzControl.Items.Count == 0)
                 {
                     App.Current.MainWindow.Close();
                 }
             }
             else
             {
+                //只剩一个页签的情况
                 if (maincontentViewModel.PDFViewer != null)
                 {
-                    //如果是关闭文档的页签 则回到首页
+                    // 如果是关闭文档的页签 则回到首页
                     region.Regions[RegionNames.MainRegion].Remove(item);
                     region.RequestNavigate(RegionNames.MainRegion, "MainContent");
                 }
                 else
                 {
-                    //如果是关闭首页则关闭软件
+                    // 如果是关闭首页则关闭软件
                     region.Regions[RegionNames.MainRegion].Remove(item);
                     App.Current.MainWindow.Close();
                 }
             }
-            return;
         }
 
         /// <summary>
@@ -666,7 +670,7 @@ namespace PDF_Master.ViewModels
             {
                 //偏好设置里未设置直接保存时,需要弹窗提示
                 AlertsMessage alertsMessage = new AlertsMessage();
-                alertsMessage.ShowDialog("",string.Format(App.MainPageLoader.GetString("Main_ModifiedFileWarning"),System.IO.Path.GetFileName(CurrentPDFViewer.Document.FilePath)), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_no"), App.ServiceLoader.GetString("Text_ok"));
+                alertsMessage.ShowDialog("", string.Format(App.MainPageLoader.GetString("Main_ModifiedFileWarning"), System.IO.Path.GetFileName(CurrentPDFViewer.Document.FilePath)), App.ServiceLoader.GetString("Text_cancel"), App.ServiceLoader.GetString("Text_no"), App.ServiceLoader.GetString("Text_ok"));
                 result = alertsMessage.result;
             }
 

+ 3 - 1
PDF Office/ViewModels/PageEdit/PageEditContentViewModel.cs

@@ -906,10 +906,12 @@ namespace PDF_Master.ViewModels.PageEdit
         /// <summary>
         /// 缩小页面
         /// </summary>
-        private void ZoomOutCommandEvent()
+        private async void ZoomOutCommandEvent()
         {
             ZoomIndex--;
             ChangeItemSize(ItemSizes[ZoomIndex + 1]);
+            //增加一定延时,计算页面显示范围时,用新的尺寸进行计算
+            await Task.Delay(3);
             NotifyUIToRefresh();
         }