MainWindow.xaml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. {
  60. System.Windows.SystemCommands.RestoreWindow(this);
  61. ico_max.Visibility = Visibility.Visible;
  62. }
  63. else
  64. {
  65. System.Windows.SystemCommands.MaximizeWindow(this);
  66. ico_max.Visibility = Visibility.Collapsed;
  67. }
  68. }
  69. private void Window_Activated(object sender, EventArgs e)
  70. {
  71. App.Current.MainWindow = this;
  72. App.mainWindowViewModel = this.DataContext as MainWindowViewModel;
  73. aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Activated });
  74. }
  75. private void Window_Closed(object sender, EventArgs e)
  76. {
  77. aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Closed });
  78. }
  79. private bool isNewDocument = false;
  80. public void LoadPdfViewer(string[] filePaths)
  81. {
  82. var content = App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel;
  83. if (filePaths.Count() == 1)
  84. {
  85. if (App.OpenedFileList.Contains(filePaths[0]))
  86. {
  87. App.mainWindowViewModel.SelectItem(filePaths[0]);
  88. }
  89. else
  90. {
  91. content.OpenFile(filePaths[0]);
  92. }
  93. ToolMethod.SetFileThumbImg(filePaths[0]);
  94. }
  95. else
  96. {
  97. var fileList = filePaths.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  98. if (fileList.Count <= 0)
  99. return;
  100. content.OpenFile(filePaths[0]);
  101. for (int i = 1; i < fileList.Count(); i++)
  102. {
  103. if (!App.OpenedFileList.Contains(fileList[i]))
  104. {
  105. App.mainWindowViewModel.AddTabItem(fileList[i]);
  106. }
  107. ToolMethod.SetFileThumbImg(fileList[i]);
  108. }
  109. }
  110. Settings.Default.Save();
  111. }
  112. }
  113. }