Browse Source

其他-文件菜单补充从文件创建逻辑

ZhouJieSheng 2 years ago
parent
commit
12d79243f8
1 changed files with 43 additions and 0 deletions
  1. 43 0
      PDF Office/ViewModels/ViewContentViewModel.cs

+ 43 - 0
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -738,6 +738,8 @@ namespace PDF_Master.ViewModels
 
         public DelegateCommand CreateBlankFileCommand { get; set; }
 
+        public DelegateCommand CreateFromFile { get; set; }
+
         public DelegateCommand ClosePropertyCommand { get; set; }
 
         #endregion 命令
@@ -769,6 +771,7 @@ namespace PDF_Master.ViewModels
             OpenFileCommand = new DelegateCommand(openfile);
             HelpCommand = new DelegateCommand<string>(help);
             CreateBlankFileCommand = new DelegateCommand(createBlankFile);
+            CreateFromFile = new DelegateCommand(createfromFile);
 
             ViwerRegionName = RegionNames.ViwerRegionName;
             SplitViewerRegionName = RegionNames.Viewer_SplitRegionName;
@@ -837,6 +840,46 @@ namespace PDF_Master.ViewModels
             }
         }
 
+        private async void createfromFile()
+        {
+            string txt = Properties.Resources.txtex;
+            string word = Properties.Resources.wordex;
+            string ppt = Properties.Resources.pptex;
+            string excel = Properties.Resources.excelex;
+            string html = Properties.Resources.htmlex;
+            string image = Properties.Resources.imageex;
+            string allfiles = txt + word + excel + ppt + image + html;
+            OpenFileDialog dialog = new OpenFileDialog();
+            dialog.Multiselect = true;
+            dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
+           $"Microsoft Office Word({word})|{word}|" +
+           $"Microsoft Office Excel({excel})|{excel}|" +
+           $"Microsoft Office PowerPoint({ppt})|{ppt}|" +
+           $"Txt({txt})|{txt}|" +
+           $"Picture({image})|{image}|" +
+           $"Html({html})|{html}");
+
+            if ((bool)dialog.ShowDialog())
+            {
+                for(int i=0;i<dialog.FileNames.Length;i++)
+                {
+                    if(App.OpenedFileList.Contains(dialog.FileNames[i]))
+                    {
+                        App.mainWindowViewModel.SelectItem(dialog.FileNames[i]);
+                    }
+                    else
+                    {
+                        System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
+                        {
+                            App.mainWindowViewModel.AddTabItem(dialog.FileNames[i]);
+                        }));
+                        await Task.Delay(20);
+                        ToolMethod.SetFileThumbImg(dialog.FileNames[i]);
+                    }
+                }
+            }
+        }
+
         /// <summary>
         ///创建空白文档
         /// </summary>