ViewContent.xaml.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.PdfViewer;
  3. using PDF_Office.EventAggregators;
  4. using PDF_Office.Helper;
  5. using PDF_Office.Model;
  6. using PDF_Office.ViewModels;
  7. using PDF_Office.ViewModels.Tools;
  8. using PDF_Office.Views.Dialog;
  9. using PDF_Office.Views.PropertyPanel.ViewModular;
  10. using PDF_Office.Views.Tools;
  11. using Prism.Events;
  12. using Prism.Regions;
  13. using System;
  14. using System.Linq;
  15. using System.Threading;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Input;
  20. using System.Windows.Media;
  21. using System.Windows.Threading;
  22. namespace PDF_Office.Views
  23. {
  24. /// <summary>
  25. /// Interaction logic for ViewContent
  26. /// </summary>
  27. public partial class ViewContent : UserControl
  28. {
  29. private ViewContentViewModel viewModel = null;
  30. private string unicode = "";
  31. public ViewContent()
  32. {
  33. InitializeComponent();
  34. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  35. viewModel = (ViewContentViewModel)this.DataContext;
  36. viewModel.PropertyChanged += ViewModel_PropertyChanged;
  37. }
  38. private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  39. {
  40. if (e.PropertyName == "OpenBOTA")
  41. {
  42. if (!viewModel.OpenBOTA)
  43. {
  44. //动态改变BOTA的最小宽度只能在这里设置,VM里绑定会有异常
  45. BOTACloumn.MinWidth = 48;
  46. viewModel.BOTAWidth = new GridLength(48);
  47. BOTASplitter.Visibility = Visibility.Collapsed;
  48. }
  49. else
  50. {
  51. BOTACloumn.MinWidth = 260;
  52. BOTASplitter.Visibility = Visibility.Visible;
  53. }
  54. }
  55. }
  56. public ViewContent(IEventAggregator eventAggregator) : this()
  57. {
  58. eventAggregator.GetEvent<SplitEvent>().Subscribe(ChangeSplitModeUI, e => e.Unicode == unicode);
  59. }
  60. /// <summary>
  61. /// 根据Vm事件通知处理分屏布局的事件
  62. /// </summary>
  63. /// <param name="e"></param>
  64. private void ChangeSplitModeUI(SplitEventArgs e)
  65. {
  66. switch (e.Mode)
  67. {
  68. case EventAggregators.SplitMode.Horizontal:
  69. //水平分屏 上下
  70. HorizontalSplitter.Visibility = Visibility.Visible;
  71. VerticalSplitter.Visibility = Visibility.Collapsed;
  72. RowRight.Height = new GridLength(1, GridUnitType.Star);
  73. ColumnBottom.Width = new GridLength(0);
  74. Grid.SetColumn(SplitPDFViewer, 0);
  75. Grid.SetRow(SplitPDFViewer, 2);
  76. break;
  77. case EventAggregators.SplitMode.Vertical:
  78. HorizontalSplitter.Visibility = Visibility.Collapsed;
  79. VerticalSplitter.Visibility = Visibility.Visible;
  80. RowRight.Height = new GridLength(0);
  81. ColumnBottom.Width = new GridLength(1, GridUnitType.Star);
  82. Grid.SetColumn(SplitPDFViewer, 2);
  83. Grid.SetRow(SplitPDFViewer, 0);
  84. break;
  85. case EventAggregators.SplitMode.Single:
  86. default:
  87. //退出分屏模式
  88. HorizontalSplitter.Visibility = Visibility.Collapsed;
  89. VerticalSplitter.Visibility = Visibility.Collapsed;
  90. RowRight.Height = new GridLength(0, GridUnitType.Star);
  91. ColumnBottom.Width = new GridLength(0, GridUnitType.Star);
  92. break;
  93. }
  94. GridViewer.UpdateLayout();
  95. }
  96. /// <summary>
  97. /// 退出阅读模式
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. private void UserControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  102. {
  103. if (Key.Escape == e.Key)
  104. {
  105. if (viewModel != null)
  106. {
  107. if (viewModel.PDFViewer.MouseMode != MouseModes.PanTool)
  108. {
  109. if (this.ContentToolsBar.Content is AnnotToolContent annotTool)
  110. {
  111. if (annotTool.BtnSelecttool.IsChecked == true)
  112. {
  113. AnnotToolContentViewModel model = (AnnotToolContentViewModel)annotTool.DataContext;
  114. if (model != null)
  115. {
  116. if (model.SnapshotEditMenuViewModel.SnapToolArgs != null)
  117. {
  118. model.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  119. }
  120. }
  121. }
  122. }
  123. if (viewModel.mainViewModel.IsBookMode == true)
  124. {
  125. viewModel.UnReadModel();
  126. }
  127. }
  128. else
  129. {
  130. if (viewModel.mainViewModel.IsBookMode == true)
  131. {
  132. viewModel.UnReadModel();
  133. }
  134. }
  135. }
  136. }
  137. }
  138. private void BtnFile_Initialized(object sender, EventArgs e)
  139. {
  140. BtnFile.ContextMenu = null;
  141. }
  142. private void BtnFile_Click(object sender, RoutedEventArgs e)
  143. {
  144. FileMenu.PlacementTarget = BtnFile;
  145. FileMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  146. FileMenu.IsOpen = true;
  147. }
  148. private void ContentControl_SizeChanged(object sender, SizeChangedEventArgs e)
  149. {
  150. }
  151. private void MenuRecent_Loaded(object sender, RoutedEventArgs e)
  152. {
  153. int count = 0;
  154. MenuRecent.Items.Clear();
  155. foreach (var file in Properties.Settings.Default.RecentOpenFiles)
  156. {
  157. MenuItem item = new MenuItem();
  158. item.Height = 32;
  159. item.Header = file.FileName;
  160. item.Tag = file.FilePath;
  161. item.ToolTip = file.FilePath;
  162. item.Click += RecentItem_Click;
  163. MenuRecent.Items.Insert(MenuRecent.Items.Count, item);
  164. count++;
  165. if (count >= 20)
  166. break;
  167. }
  168. if (Properties.Settings.Default.RecentOpenFiles.Count > 0)
  169. {
  170. MenuRecent.Items.Add(Menu_Separator);
  171. MenuRecent.Items.Add(MenuDeleteAll);
  172. MenuDeleteAll.IsEnabled = true;
  173. MenuDeleteAll.Opacity = 1;
  174. }
  175. else
  176. {
  177. MenuRecent.Items.Add(MenuDeleteAll);
  178. MenuDeleteAll.IsEnabled = false;
  179. MenuDeleteAll.Opacity = 0.5;
  180. }
  181. }
  182. private void RecentItem_Click(object sender, RoutedEventArgs e)
  183. {
  184. var item = sender as MenuItem;
  185. string[] filePath = new string[1];
  186. filePath[0] = item.Tag.ToString();
  187. if (App.OpenedFileList.Contains(filePath[0]))
  188. {
  189. (this.DataContext as ViewContentViewModel).mainViewModel.mainWindowViewModel.SelectItem(filePath[0]);
  190. }
  191. else
  192. {
  193. (this.DataContext as ViewContentViewModel).mainViewModel.mainWindowViewModel.AddTabItem(filePath[0]);
  194. }
  195. }
  196. private void MenuDeleteAll_Click(object sender, RoutedEventArgs e)
  197. {
  198. SettingHelper.RemoveAllRecentOpenFiles();
  199. }
  200. private void UserControl_DragEnter(object sender, DragEventArgs e)
  201. {
  202. DragDropHelper.DragEnter(this, e);
  203. }
  204. private void UserControl_DragOver(object sender, DragEventArgs e)
  205. {
  206. DragDropHelper.DragOver(this, e);
  207. }
  208. private void UserControl_DragLeave(object sender, DragEventArgs e)
  209. {
  210. DragDropHelper.DragLeave();
  211. }
  212. private void UserControl_Drop(object sender, DragEventArgs e)
  213. {
  214. try
  215. {
  216. DragDropHelper.Drop(this, e);
  217. string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
  218. //页面编辑模式下 不响应拖拽打开文件
  219. if (file!=null &&file.Length > 0&&!(this.DataContext as ViewContentViewModel).isInPageEdit)
  220. {
  221. App.mainWindowViewModel.AddTab.Execute();
  222. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).homeContentViewModel.AddFileFromDrag(file.ToList());
  223. }
  224. }
  225. catch { }
  226. }
  227. private void CloseLeftCommand_Executed(object sender, ExecutedRoutedEventArgs e)
  228. {
  229. BOTASplitter.Visibility = Visibility.Collapsed;
  230. }
  231. private void CloseRightCommand_Executed(object sender, ExecutedRoutedEventArgs e)
  232. {
  233. viewModel.ClosePropertyCommand.Execute();
  234. }
  235. }
  236. }