MainWindow.xaml.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. }
  62. else
  63. {
  64. System.Windows.SystemCommands.MaximizeWindow(this);
  65. }
  66. }
  67. private void Window_Activated(object sender, EventArgs e)
  68. {
  69. App.Current.MainWindow = this;
  70. App.mainWindowViewModel = this.DataContext as MainWindowViewModel;
  71. aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Activated });
  72. }
  73. private void Window_Closed(object sender, EventArgs e)
  74. {
  75. aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Closed });
  76. }
  77. private bool isNewDocument = false;
  78. public void LoadPdfViewer(string[] filePaths)
  79. {
  80. var content = App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel;
  81. if (filePaths.Count() == 1)
  82. {
  83. if (App.OpenedFileList.Contains(filePaths[0]))
  84. {
  85. App.mainWindowViewModel.SelectItem(filePaths[0]);
  86. }
  87. else
  88. {
  89. content.OpenFile(filePaths[0]);
  90. }
  91. ToolMethod.SetFileThumbImg(filePaths[0]);
  92. }
  93. else
  94. {
  95. var fileList = filePaths.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  96. if (fileList.Count <= 0)
  97. return;
  98. content.OpenFile(filePaths[0]);
  99. for (int i = 1; i < fileList.Count(); i++)
  100. {
  101. if (!App.OpenedFileList.Contains(fileList[i]))
  102. {
  103. App.mainWindowViewModel.AddTabItem(fileList[i]);
  104. }
  105. ToolMethod.SetFileThumbImg(fileList[i]);
  106. }
  107. }
  108. Settings.Default.Save();
  109. }
  110. private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
  111. {
  112. var width = StkPnlRight.ActualWidth;
  113. BtnAdd.Margin = new Thickness(8,13,width,7);
  114. if (this.WindowState == WindowState.Maximized)
  115. {
  116. ico_max.Visibility = Visibility.Visible;
  117. }
  118. else
  119. {
  120. ico_max.Visibility = Visibility.Collapsed;
  121. }
  122. }
  123. private void TxtRename_PreviewKeyDown(object sender, KeyEventArgs e)
  124. {
  125. if(e.Key == Key.Enter)
  126. {
  127. TabablzControl.Focus();
  128. }
  129. }
  130. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  131. {
  132. if (!(DataContext as MainWindowViewModel).closeAllTabItem())
  133. {
  134. e.Cancel = true;
  135. }
  136. }
  137. }
  138. }