MainWindow.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using PDF_Office.ViewModels;
  2. using Prism.Regions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using Prism.Events;
  18. using PDF_Office.EventAggregators;
  19. using PDF_Office.CustomControl;
  20. using Prism.Ioc;
  21. using PDF_Office.Helper;
  22. using System.IO;
  23. using ComPDFKit.PDFDocument;
  24. using PDFSettings.Settings;
  25. using PDF_Office.Properties;
  26. namespace PDF_Office.Views
  27. {
  28. /// <summary>
  29. /// MainWindow.xaml 的交互逻辑
  30. /// </summary>
  31. public partial class MainWindow : Window
  32. {
  33. public IEventAggregator aggregator;
  34. public IRegionManager region;
  35. public MainWindow()
  36. {
  37. InitializeComponent();
  38. }
  39. /// <summary>
  40. /// 此类因为Dragablz控件的原因需要特殊处理
  41. /// </summary>
  42. /// <param name="eventAggregator"></param>
  43. public MainWindow(IEventAggregator eventAggregator, IContainerProvider container) :this()
  44. {
  45. aggregator = eventAggregator;
  46. eventAggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Opened });
  47. }
  48. private void BtnMiniSize_Click(object sender, RoutedEventArgs e)
  49. {
  50. System.Windows.SystemCommands.MinimizeWindow(this);
  51. }
  52. private void BtnClose_Click(object sender, RoutedEventArgs e)
  53. {
  54. System.Windows.SystemCommands.CloseWindow(this);
  55. }
  56. private void BtnReStore_Click(object sender, RoutedEventArgs e)
  57. {
  58. if (this.WindowState == WindowState.Maximized)
  59. System.Windows.SystemCommands.RestoreWindow(this);
  60. else
  61. System.Windows.SystemCommands.MaximizeWindow(this);
  62. }
  63. private void Window_Activated(object sender, EventArgs e)
  64. {
  65. App.Current.MainWindow = this;
  66. aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Activated });
  67. }
  68. private void Window_Closed(object sender, EventArgs e)
  69. {
  70. aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Closed });
  71. }
  72. private bool isNewDocument = false;
  73. public void LoadPdfViewer(string[] filePaths)
  74. {
  75. var content = App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel;
  76. if (filePaths.Count() == 1)
  77. {
  78. if (App.OpenedFileList.Contains(filePaths[0]))
  79. {
  80. App.mainWindowViewModel.SelectItem(filePaths[0]);
  81. }
  82. else
  83. {
  84. content.OpenFile(filePaths[0]);
  85. }
  86. ToolMethod.SetFileThumbImg(filePaths[0]);
  87. }
  88. else
  89. {
  90. var fileList = filePaths.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  91. if (fileList.Count <= 0)
  92. return;
  93. content.OpenFile(filePaths[0]);
  94. for (int i = 1; i < fileList.Count(); i++)
  95. {
  96. if (!App.OpenedFileList.Contains(fileList[i]))
  97. {
  98. App.mainWindowViewModel.AddTabItem(fileList[i]);
  99. }
  100. ToolMethod.SetFileThumbImg(fileList[i]);
  101. }
  102. }
  103. Settings.Default.Save();
  104. }
  105. }
  106. }