瀏覽代碼

其他-补充设为默认阅读器后,双击文件打开软件的逻辑

ZhouJieSheng 1 年之前
父節點
當前提交
f8bc22be77
共有 3 個文件被更改,包括 47 次插入8 次删除
  1. 27 6
      PDF Office/App.xaml.cs
  2. 6 1
      PDF Office/ViewModels/MainWindowViewModel.cs
  3. 14 1
      PDF Office/Views/MainWindow.xaml.cs

+ 27 - 6
PDF Office/App.xaml.cs

@@ -87,6 +87,8 @@ namespace PDF_Master
 
         public static string CurrentPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), Name);
 
+        public static List<string> NeedOpenFilePathList = new List<string>();
+
         /// <summary>
         /// 项目内嵌文档路径  实际打开文档时,会将改文档复制到Document 文件夹下,避免C盘文件无法写入的情况
         /// </summary>
@@ -199,7 +201,7 @@ namespace PDF_Master
                 Settings.Default.UserDate = new PDFSettings.UserDate();
             }
 
-            if(Settings.Default.AppProperties==null)
+            if (Settings.Default.AppProperties == null)
             {
                 Settings.Default.AppProperties = new PDFSettings.APPSettingProperties();
             }
@@ -235,7 +237,7 @@ namespace PDF_Master
                 {
                     foreach (var filePath in e.Args)
                     {
-                        if (filePath.ToLower().Contains(".pdf")&&Path.GetExtension(filePath).ToLower()==".pdf")
+                        if (filePath.ToLower().Contains(".pdf") && Path.GetExtension(filePath).ToLower() == ".pdf")
                         {
                             try
                             {
@@ -332,10 +334,10 @@ namespace PDF_Master
 
                 //复制项目的新手引导文档到Document 目录
                 string guidfilePath = Path.Combine(CachePath.GuidPDFPath, "Quick Start Guide.pdf");
-                if(!File.Exists(guidfilePath)||App.IsGuidPDFUpdated)
+                if (!File.Exists(guidfilePath) || App.IsGuidPDFUpdated)
                 {
                     //Document 路径下没有内嵌文档或者内嵌文档版本更新时
-                    File.Copy(Path.Combine(Environment.CurrentDirectory, "Resources\\GuidPDF\\Quick Start Guide.pdf"), guidfilePath,true);
+                    File.Copy(Path.Combine(Environment.CurrentDirectory, "Resources\\GuidPDF\\Quick Start Guide.pdf"), guidfilePath, true);
                     GuidPDFPath = guidfilePath;
                 }
 
@@ -350,33 +352,52 @@ namespace PDF_Master
             {
             }
 
+            //启动循环检查更新线程
             CheckUpdate();
 
+            //双击文件 打开软件时
+            foreach (var filePath in e.Args)
+            {
+                if (filePath.ToLower().Contains(".pdf"))
+                {
+                    if (filePath.Substring(filePath.LastIndexOf(".")).ToLower() == ".pdf")
+                    {
+                        NeedOpenFilePathList.Add(filePath);
+                    }
+                }
+            }
+
             base.OnStartup(e);
         }
 
         private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
         {
+#if DEBUG
             var ex = e.Exception as Exception;
             if (ex != null)
             {
                 MessageBox.Show("发生Task未处理异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
             }
+#endif
         }
 
         private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
         {
+#if DEBUG
             if (e.ExceptionObject is System.Exception)
             {
                 Exception ex = (System.Exception)e.ExceptionObject;
                 MessageBox.Show("发生非UI线程异常:" + ex.Message + "\n" + ex.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
             }
+#endif
         }
 
         private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
         {
+#if DEBUG
             e.Handled = true;
             MessageBox.Show("发生UI线程异常:" + e.Exception.Message + "\n" + e.Exception.StackTrace, "系统错误", MessageBoxButton.OK, MessageBoxImage.Error);
+#endif
         }
 
         /// <summary>
@@ -640,10 +661,10 @@ namespace PDF_Master
             try
             {
                 LicenseErrorCode verifyResult = CPDFSDKVerifier.LicenseVerify(devKey, devSecret);
-                Trace.WriteLine("CPDFSDK License Code."+ verifyResult+"\n");
+                Trace.WriteLine("CPDFSDK License Code." + verifyResult + "\n");
                 if (verifyResult != LicenseErrorCode.LICENSE_ERR_SUCCESS)
                     return false;
-         
+
             }
             catch { Trace.WriteLine("CPDFSDK License Code Error \n"); }
 

+ 6 - 1
PDF Office/ViewModels/MainWindowViewModel.cs

@@ -305,6 +305,7 @@ namespace PDF_Master.ViewModels
                 System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
                 {
 
+                    //重新打开窗口关闭前 未关闭的页签
                     if (Settings.Default.AppProperties.NeedToOpenFileList != null && Settings.Default.AppProperties.NeedToOpenFileList.Count > 0)
                     {
                         List<string> files = Settings.Default.AppProperties.NeedToOpenFileList;
@@ -321,7 +322,11 @@ namespace PDF_Master.ViewModels
                     }
                     else
                     {
-                        region.RequestNavigate(RegionNames.MainRegion, "MainContent");
+                        //如果有拖拽文件到图标或者设为默认阅读器的情况,双击文件打开软件时,不加载首页
+                        if ((App.Current.MainWindow as MainWindow)!=null&&(App.Current.MainWindow as MainWindow).TabablzControl.Items.Count <= 0)
+                        {
+                            region.RequestNavigate(RegionNames.MainRegion, "MainContent");
+                        }
                     }
 
                     try

+ 14 - 1
PDF Office/Views/MainWindow.xaml.cs

@@ -84,6 +84,7 @@ namespace PDF_Master.Views
                     }
                     if (File.Exists(filePath))
                     {
+
                         //打开传过来的文件路径
                         if (App.OpenedFileList.Contains(App.GuidPDFPath))
                         {
@@ -163,11 +164,22 @@ namespace PDF_Master.Views
             }
         }
 
-        private void Window_Activated(object sender, EventArgs e)
+        private async void Window_Activated(object sender, EventArgs e)
         {
             App.Current.MainWindow = this;
             App.mainWindowViewModel = this.DataContext as MainWindowViewModel;
             aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Activated });
+
+            //设为默认浏览器后,外部点击文档打开
+            if (App.NeedOpenFilePathList.Count != 0)
+            {
+                for(int i=0;i<App.NeedOpenFilePathList.Count;i++)
+                {
+                    (this.DataContext as MainWindowViewModel).AddTabItem(App.NeedOpenFilePathList[i]);
+                    await Task.Delay(50);
+                }
+                App.NeedOpenFilePathList.Clear();
+            }
         }
 
         private void Window_Closed(object sender, EventArgs e)
@@ -230,6 +242,7 @@ namespace PDF_Master.Views
         {
             var width = StkPnlRight.ActualWidth;
             BtnAdd.Margin = new Thickness(8, 13, width, 7);
+            TabablzControl.UpdateLayout();
         }
 
         private void TxtRename_PreviewKeyDown(object sender, KeyEventArgs e)