ViewContent.xaml.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. using ComPDFKitViewer;
  2. using ComPDFKitViewer.AnnotEvent;
  3. using ComPDFKitViewer.PdfViewer;
  4. using PDF_Master.CustomControl;
  5. using PDF_Master.EventAggregators;
  6. using PDF_Master.Helper;
  7. using PDF_Master.Model;
  8. using PDF_Master.ViewModels;
  9. using PDF_Master.ViewModels.BOTA;
  10. using PDF_Master.ViewModels.PropertyPanel.ViewModular;
  11. using PDF_Master.ViewModels.Tools;
  12. using PDF_Master.Views.BOTA;
  13. using PDF_Master.Views.Dialog;
  14. using PDF_Master.Views.PageEdit;
  15. using PDF_Master.Views.PropertyPanel.ViewModular;
  16. using PDF_Master.Views.Tools;
  17. using Prism.Events;
  18. using Prism.Regions;
  19. using System;
  20. using System.Linq;
  21. using System.Threading;
  22. using System.Threading.Tasks;
  23. using System.Windows;
  24. using System.Windows.Controls;
  25. using System.Windows.Input;
  26. using System.Windows.Media;
  27. using System.Windows.Threading;
  28. namespace PDF_Master.Views
  29. {
  30. /// <summary>
  31. /// Interaction logic for ViewContent
  32. /// </summary>
  33. public partial class ViewContent : UserControl
  34. {
  35. private ViewContentViewModel viewModel = null;
  36. private string unicode = "";
  37. /// <summary>
  38. /// 是否是展开工具栏
  39. /// </summary>
  40. private bool expandToolRow = true;
  41. private bool DelayIsEnable = true;
  42. public ViewContent()
  43. {
  44. InitializeComponent();
  45. unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  46. viewModel = (ViewContentViewModel)this.DataContext;
  47. ScrViewTab.Margin = new Thickness(CalculateStackPanelWidth(Leftpanel)+16, 0, CalculateStackPanelWidth(Rightpanel)+16,0);
  48. viewModel.PropertyChanged += ViewModel_PropertyChanged;
  49. }
  50. /// <summary>
  51. /// 计算StackPane的宽度
  52. /// </summary>
  53. /// <param name="stackPanel"></param>
  54. /// <returns></returns>
  55. public double CalculateStackPanelWidth(StackPanel stackPanel)
  56. {
  57. double totalWidth = 0;
  58. foreach (UIElement child in stackPanel.Children)
  59. {
  60. child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
  61. totalWidth += child.DesiredSize.Width;
  62. }
  63. return totalWidth;
  64. }
  65. private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
  66. {
  67. if (e.PropertyName == "OpenBOTA")
  68. {
  69. if (!viewModel.OpenBOTA)
  70. {
  71. //动态改变BOTA的最小宽度只能在这里设置,VM里绑定会有异常
  72. BOTACloumn.MinWidth = 48;
  73. viewModel.BOTAWidth = new GridLength(48);
  74. BOTASplitter.Visibility = Visibility.Collapsed;
  75. }
  76. else
  77. {
  78. BOTACloumn.MinWidth = viewModel.BOTAMiniWidth;
  79. BOTASplitter.Visibility = Visibility.Visible;
  80. }
  81. }
  82. }
  83. public ViewContent(IEventAggregator eventAggregator) : this()
  84. {
  85. eventAggregator.GetEvent<SplitEvent>().Subscribe(ChangeSplitModeUI, e => e.Unicode == unicode);
  86. eventAggregator.GetEvent<ReadModeEvent>().Subscribe(ChangeReadModeUI, e => e.Unicode == unicode);
  87. eventAggregator.GetEvent<ReadModePropertyOpenEvent>().Subscribe(ChangeReadModePropertyOpenUI, e => e.Unicode == unicode);
  88. }
  89. private void ChangeReadModePropertyOpenUI(ReadModePropertyOpenArgs obj)
  90. {
  91. viewModel.ReadModeIsShowProperty = true;
  92. Grid.SetColumnSpan(GridViewer, 3);
  93. Grid.SetColumn(GridViewer, 0);
  94. Grid.SetColumn(Scroller, 4);
  95. }
  96. private void ChangeReadModeUI(ReadModeArgs obj)
  97. {
  98. if (obj.IsReadMode)
  99. {
  100. ReadModeContent.Visibility = Visibility.Visible;
  101. RectangleReadMode.Visibility = Visibility.Collapsed;
  102. // 是否悬停显示阅读模式翻页控件,防止在其他区域遮挡部分功能
  103. RectangleReadMode.IsHitTestVisible = true;
  104. //因为ispropertyOpen 属性改成了单向控制 因此这里的语句不再适用
  105. //this.TbtnProperty.IsChecked = false;
  106. Grid.SetRowSpan(DocumentView, 4);
  107. Grid.SetRow(DocumentView, 0);
  108. Grid.SetColumn(GridViewer, 0);
  109. Grid.SetColumnSpan(GridViewer, 4);
  110. //var annotArgs = new SelectToolArgs();
  111. //viewModel.PDFViewer.SetToolParam(annotArgs);
  112. #region to do
  113. //Grid.SetRowSpan(RectangleBota, 4);
  114. //Grid.SetRow(RectangleBota, 0);
  115. //RectangleBota.Visibility = Visibility.Visible;
  116. #endregion to do
  117. }
  118. else
  119. {
  120. ReadModeContent.Visibility = Visibility.Collapsed;
  121. RectangleReadMode.Visibility = Visibility.Collapsed;
  122. RectangleReadMode.IsHitTestVisible = false;
  123. //this.TbtnProperty.IsChecked=true;
  124. Grid.SetRowSpan(DocumentView, 1);
  125. Grid.SetRow(DocumentView, 2);
  126. Grid.SetColumn(GridViewer, 2);
  127. Grid.SetColumnSpan(GridViewer, 1);
  128. //var annotArgs = new SelectToolArgs();
  129. //viewModel.PDFViewer.SetToolParam(annotArgs);
  130. #region to do
  131. //Grid.SetRowSpan(RectangleBota, 1);
  132. //Grid.SetRow(RectangleBota, 2);
  133. //RectangleBota.Visibility = Visibility.Visible;
  134. //Panel.SetZIndex(BOTAContent, 0);
  135. //Panel.SetZIndex(BOTASplitter, 0);
  136. #endregion to do
  137. }
  138. }
  139. private void RectangleBota_MouseEnter(object sender, MouseEventArgs e)
  140. {
  141. if (viewModel.mainViewModel.IsBookMode)
  142. {
  143. RectangleBota.Visibility = Visibility.Collapsed;
  144. BOTAContent.Visibility = Visibility.Visible;
  145. Panel.SetZIndex(BOTAContent, 2);
  146. Panel.SetZIndex(BOTASplitter, 2);
  147. ReadModeContent.Visibility = Visibility.Visible;
  148. RectangleReadMode.Visibility = Visibility.Collapsed;
  149. //因为ispropertyOpen 属性改成了单向控制 因此这里的语句不再适用
  150. //this.TbtnProperty.IsChecked = false;
  151. Grid.SetRowSpan(DocumentView, 4);
  152. Grid.SetRow(DocumentView, 0);
  153. Grid.SetColumnSpan(GridViewer, 1);
  154. Grid.SetColumn(GridViewer, 2);
  155. Grid.SetColumnSpan(BOTAContent, 1);
  156. Grid.SetColumn(BOTAContent, 0);
  157. Grid.SetColumnSpan(BOTASplitter, 1);
  158. Grid.SetColumn(BOTASplitter, 1);
  159. Grid.SetRowSpan(RectangleBota, 4);
  160. Grid.SetRow(RectangleBota, 0);
  161. }
  162. else
  163. {
  164. }
  165. }
  166. private void GridViewer_MouseEnter(object sender, MouseEventArgs e)
  167. {
  168. if (viewModel.mainViewModel.IsBookMode)
  169. {
  170. ReadModeContent.Visibility = Visibility.Visible;
  171. RectangleReadMode.Visibility = Visibility.Collapsed;
  172. //因为ispropertyOpen 属性改成了单向控制 因此这里的语句不再适用
  173. //this.TbtnProperty.IsChecked = false;
  174. Grid.SetRowSpan(DocumentView, 4);
  175. Grid.SetRow(DocumentView, 0);
  176. Grid.SetRowSpan(RectangleBota, 4);
  177. Grid.SetRow(RectangleBota, 0);
  178. Panel.SetZIndex(BOTAContent, 0);
  179. Panel.SetZIndex(BOTASplitter, 0);
  180. RectangleBota.Visibility = Visibility.Visible;
  181. if (viewModel.ReadModeIsShowProperty)
  182. {
  183. Grid.SetColumnSpan(GridViewer, 3);
  184. Grid.SetColumn(GridViewer, 0);
  185. Grid.SetColumn(Scroller, 4);
  186. }
  187. else
  188. {
  189. Grid.SetColumnSpan(GridViewer, 4);
  190. Grid.SetColumn(GridViewer, 0);
  191. }
  192. }
  193. }
  194. /// <summary>
  195. /// 鼠标移动到控件范围时显示控件
  196. /// </summary>
  197. /// <param name="sender"></param>
  198. /// <param name="e"></param>
  199. private void RectangleReadMode_MouseEnter(object sender, MouseEventArgs e)
  200. {
  201. //Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(delegate
  202. //{
  203. if (viewModel.mainViewModel.IsBookMode)
  204. {
  205. DelayIsEnable = false;
  206. this.ReadModeContent.Visibility = Visibility.Visible;
  207. this.RectangleReadMode.Visibility = Visibility.Collapsed;
  208. }
  209. //}));
  210. }
  211. /// <summary>
  212. /// 鼠标移开页面控件,三秒后隐藏该控件
  213. /// </summary>
  214. /// <param name="sender"></param>
  215. /// <param name="e"></param>
  216. private async void ReadModeContent_MouseLeave(object sender, MouseEventArgs e)
  217. {
  218. DelayIsEnable = true;
  219. await System.Threading.Tasks.Task.Delay(3000);
  220. //Thread.Sleep(3000);
  221. if (DelayIsEnable)
  222. {
  223. this.ReadModeContent.Visibility = Visibility.Collapsed;
  224. this.RectangleReadMode.Visibility = Visibility.Visible;
  225. }
  226. }
  227. /// <summary>
  228. /// 根据Vm事件通知处理分屏布局的事件
  229. /// </summary>
  230. /// <param name="e"></param>
  231. private void ChangeSplitModeUI(SplitEventArgs e)
  232. {
  233. switch (e.Mode)
  234. {
  235. case EventAggregators.SplitMode.Horizontal:
  236. //水平分屏 上下
  237. HorizontalSplitter.Visibility = Visibility.Visible;
  238. VerticalSplitter.Visibility = Visibility.Collapsed;
  239. RowRight.Height = new GridLength(1, GridUnitType.Star);
  240. ColumnBottom.Width = new GridLength(0);
  241. Grid.SetColumn(SplitPDFViewer, 0);
  242. Grid.SetRow(SplitPDFViewer, 2);
  243. break;
  244. case EventAggregators.SplitMode.Vertical:
  245. HorizontalSplitter.Visibility = Visibility.Collapsed;
  246. VerticalSplitter.Visibility = Visibility.Visible;
  247. RowRight.Height = new GridLength(0);
  248. ColumnBottom.Width = new GridLength(1, GridUnitType.Star);
  249. Grid.SetColumn(SplitPDFViewer, 2);
  250. Grid.SetRow(SplitPDFViewer, 0);
  251. break;
  252. case EventAggregators.SplitMode.Single:
  253. default:
  254. //退出分屏模式
  255. HorizontalSplitter.Visibility = Visibility.Collapsed;
  256. VerticalSplitter.Visibility = Visibility.Collapsed;
  257. RowRight.Height = new GridLength(0, GridUnitType.Star);
  258. ColumnBottom.Width = new GridLength(0, GridUnitType.Star);
  259. break;
  260. }
  261. GridViewer.UpdateLayout();
  262. }
  263. /// <summary>
  264. /// 退出阅读模式
  265. /// </summary>
  266. /// <param name="sender"></param>
  267. /// <param name="e"></param>
  268. private void UserControl_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
  269. {
  270. if (Key.Escape == e.Key)
  271. {
  272. if (viewModel != null)
  273. {
  274. if (viewModel.PDFViewer.MouseMode != MouseModes.PanTool)
  275. {
  276. if (this.ContentToolsBar.Content is AnnotToolContent annotTool)
  277. {
  278. if (annotTool.BtnSelecttool.IsChecked == true)
  279. {
  280. AnnotToolContentViewModel model = (AnnotToolContentViewModel)annotTool.DataContext;
  281. if (model != null)
  282. {
  283. if (model.SnapshotEditMenuViewModel.SnapToolArgs != null)
  284. {
  285. model.SnapshotEditMenuViewModel.SnapToolArgs.ReSnapshot();
  286. }
  287. }
  288. }
  289. }
  290. if (viewModel.mainViewModel.IsBookMode == true)
  291. {
  292. viewModel.Off_ReadModel();
  293. }
  294. }
  295. else
  296. {
  297. if (viewModel.mainViewModel.IsBookMode == true)
  298. {
  299. viewModel.Off_ReadModel();
  300. }
  301. }
  302. }
  303. }
  304. }
  305. private void BtnFile_Initialized(object sender, EventArgs e)
  306. {
  307. BtnFile.ContextMenu = null;
  308. }
  309. private void BtnFile_Click(object sender, RoutedEventArgs e)
  310. {
  311. FileMenu.PlacementTarget = BtnFile;
  312. FileMenu.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  313. FileMenu.IsOpen = true;
  314. }
  315. private void BtnMore_Initialized(object sender, EventArgs e)
  316. {
  317. BtnMore.ContextMenu = null;
  318. }
  319. private void BtnMore_Click(object sender, RoutedEventArgs e)
  320. {
  321. MenuMore.PlacementTarget = BtnMore;
  322. MenuMore.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  323. MenuMore.IsOpen = true;
  324. }
  325. private void ContentControl_SizeChanged(object sender, SizeChangedEventArgs e)
  326. {
  327. }
  328. private void MenuRecent_Loaded(object sender, RoutedEventArgs e)
  329. {
  330. int count = 0;
  331. MenuRecent.Items.Clear();
  332. foreach (var file in Properties.Settings.Default.RecentOpenFiles)
  333. {
  334. MenuItem item = new MenuItem();
  335. item.Height = 32;
  336. item.Header = file.FileName;
  337. item.Tag = file.FilePath;
  338. item.ToolTip = file.FilePath;
  339. item.Click += RecentItem_Click;
  340. MenuRecent.Items.Insert(MenuRecent.Items.Count, item);
  341. count++;
  342. if (count >= 20)
  343. break;
  344. }
  345. if (Properties.Settings.Default.RecentOpenFiles.Count > 0)
  346. {
  347. MenuRecent.Items.Add(Menu_Separator);
  348. MenuRecent.Items.Add(MenuDeleteAll);
  349. MenuDeleteAll.IsEnabled = true;
  350. MenuDeleteAll.Opacity = 1;
  351. }
  352. else
  353. {
  354. MenuRecent.Items.Add(MenuDeleteAll);
  355. MenuDeleteAll.IsEnabled = false;
  356. MenuDeleteAll.Opacity = 0.5;
  357. }
  358. }
  359. private void RecentItem_Click(object sender, RoutedEventArgs e)
  360. {
  361. var item = sender as MenuItem;
  362. string[] filePath = new string[1];
  363. filePath[0] = item.Tag.ToString();
  364. if (App.OpenedFileList.Contains(filePath[0]))
  365. {
  366. (this.DataContext as ViewContentViewModel).mainViewModel.mainWindowViewModel.SelectItem(filePath[0]);
  367. }
  368. else
  369. {
  370. (this.DataContext as ViewContentViewModel).mainViewModel.mainWindowViewModel.AddTabItem(filePath[0]);
  371. }
  372. }
  373. private void MenuDeleteAll_Click(object sender, RoutedEventArgs e)
  374. {
  375. SettingHelper.RemoveAllRecentOpenFiles();
  376. }
  377. private void UserControl_DragEnter(object sender, DragEventArgs e)
  378. {
  379. DragDropHelper.DragEnter(this, e);
  380. }
  381. private void UserControl_DragOver(object sender, DragEventArgs e)
  382. {
  383. DragDropHelper.DragOver(this, e);
  384. }
  385. private void UserControl_DragLeave(object sender, DragEventArgs e)
  386. {
  387. DragDropHelper.DragLeave();
  388. }
  389. private void UserControl_Drop(object sender, DragEventArgs e)
  390. {
  391. try
  392. {
  393. DragDropHelper.Drop(this, e);
  394. //页面编辑模式下,拖动文件到页面编辑的Listbox时,不运行打开文件的逻辑
  395. //拖动到页面编辑的Listbox上方空白处时,打开文件
  396. if (viewModel.isInPageEdit)
  397. {
  398. var pos2 = e.GetPosition(this);
  399. var result2 = VisualTreeHelper.HitTest(this, pos2);
  400. if (result2 != null)
  401. {
  402. var pageEdite = CommonHelper.FindVisualParent<PageEditContent>(result2.VisualHit);
  403. var pageEdite1 = CommonHelper.FindVisualChild<PageEditContent>(result2.VisualHit);
  404. }
  405. // 暂时 用遍历 的方法,找PageEditContent,缺点=》有点耗时,非最优方案,后续有较好的方案可补充修改
  406. viewModel.FindPageEditContent(out PageEditContent pageEditContent);
  407. if (pageEditContent != null)
  408. {
  409. var pos1 = e.GetPosition(pageEditContent);
  410. var result1 = VisualTreeHelper.HitTest(pageEditContent, pos1);
  411. if (result1 == null)
  412. {
  413. OpenDocument(e);
  414. }
  415. else
  416. {
  417. pos1 = e.GetPosition(pageEditContent.GridHeader);
  418. result1 = VisualTreeHelper.HitTest(pageEditContent.GridHeader, pos1);
  419. if (result1 != null)
  420. {
  421. OpenDocument(e);
  422. }
  423. }
  424. }
  425. }
  426. else
  427. {
  428. bool isTabItemThumbnail = viewModel.IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemThumbnail");
  429. //BOTA缩略图和页面编辑拖动中时,不响应拖拽打开文件
  430. //因为目前页面编辑支持拖拽到桌面生成文件,也会是FileDrop类型,所以通过鼠标坐标点判断是否在缩略图区域
  431. if (isTabItemThumbnail)
  432. {
  433. var pos = e.GetPosition(BOTAContent);
  434. var result = VisualTreeHelper.HitTest(BOTAContent, pos);
  435. if (result == null)
  436. {
  437. //BOTA缩略图和页面编辑拖动中时,不响应拖拽打开文件
  438. //因为目前页面编辑支持拖拽到桌面生成文件,也会是FileDrop类型,暂时只能通过DragDropEffects来区分app内的拖拽和外部文件拖入(外部文件拖入是多个操作类型)
  439. //if (file != null && file.Length > 0 && flag == false && e.AllowedEffects != DragDropEffects.Copy)
  440. //{
  441. // if (!App.OpenedFileList.Contains(file[0]))
  442. // {
  443. // App.mainWindowViewModel.AddTab.Execute();
  444. // }
  445. // (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).homeContentViewModel.AddFileFromDrag(file.ToList());
  446. //}
  447. OpenDocument(e);
  448. }
  449. }
  450. else
  451. {
  452. OpenDocument(e);
  453. }
  454. }
  455. //var pos = e.GetPosition(this);
  456. //var result = VisualTreeHelper.HitTest(this, pos);
  457. //var listbox = CommonHelper.FindVisualParent<ListBox>(result.VisualHit);
  458. //if (listbox != null)
  459. //{
  460. // return;
  461. //}
  462. ////BOTA缩略图和页面编辑拖动中时,不响应拖拽打开文件
  463. ////因为目前页面编辑支持拖拽到桌面生成文件,也会是FileDrop类型,暂时只能通过DragDropEffects来区分app内的拖拽和外部文件拖入(外部文件拖入是多个操作类型)
  464. //OpenDocument(e);
  465. }
  466. catch { }
  467. }
  468. private void OpenDocument(DragEventArgs e)
  469. {
  470. string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
  471. if (file != null && file.Length > 0 && e.AllowedEffects != DragDropEffects.Copy)
  472. {
  473. if (!App.OpenedFileList.Contains(file[0]))
  474. {
  475. App.mainWindowViewModel.AddTab.Execute();
  476. }
  477. (App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel).homeContentViewModel.AddFileFromDrag(file.ToList());
  478. }
  479. }
  480. private void CloseLeftCommand_Executed(object sender, ExecutedRoutedEventArgs e)
  481. {
  482. viewModel.OpenBOTA = false;
  483. }
  484. private void CloseRightCommand_Executed(object sender, ExecutedRoutedEventArgs e)
  485. {
  486. viewModel.ClosePropertyCommand.Execute();
  487. }
  488. private void UserControl_Unloaded(object sender, RoutedEventArgs e)
  489. {
  490. viewModel.CloseAutoSave();
  491. }
  492. private void ToolTabControl_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  493. {
  494. var visual = VisualTreeHelper.HitTest(ToolTabControl, e.GetPosition(ToolTabControl));
  495. if (visual == null)
  496. {
  497. return;
  498. }
  499. var item = CommonHelper.FindVisualParent<TabItem>(visual.VisualHit);
  500. if (item == null)
  501. {
  502. return;
  503. }
  504. //默认展开子工具栏
  505. //单击工具栏工具展开子工具栏;再次单击工具栏工具则收起子工具栏
  506. if (item.IsSelected && item.Name != "TabItemPageEdit")
  507. {
  508. expandToolRow = !expandToolRow;
  509. ToolRow.Height = expandToolRow ? new GridLength(40) : new GridLength(0);
  510. //取消选中
  511. item.IsSelected = false;
  512. //修复第一次打开文档后,第一次点击收起工具栏异常问题
  513. e.Handled = true;
  514. }
  515. else
  516. {
  517. if (ToolRow.Height == new GridLength(0))
  518. {
  519. //点击其他菜单栏时,之前为折叠状态时,自动展开
  520. expandToolRow = !expandToolRow;
  521. ToolRow.Height = new GridLength(40);
  522. }
  523. //取消选中
  524. item.IsSelected = true;
  525. }
  526. }
  527. private void AddTabCommand_Executed(object sender, ExecutedRoutedEventArgs e)
  528. {
  529. viewModel.mainViewModel.mainWindowViewModel.AddTab.Execute();
  530. }
  531. private void CloseTabCommand_Executed(object sender, ExecutedRoutedEventArgs e)
  532. {
  533. viewModel.mainViewModel.CloseTab.Execute(null);
  534. }
  535. private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
  536. {
  537. //鼠标侧键无法在Xaml里绑定 因此写在后台代码里
  538. if (e.ChangedButton == MouseButton.XButton2)
  539. {
  540. viewModel.bottom?.NextViewCommnad.Execute();
  541. }
  542. else if (e.ChangedButton == MouseButton.XButton1)
  543. {
  544. viewModel.bottom?.PreViewCommand.Execute();
  545. }
  546. }
  547. private void ButLeft_Click(object sender, RoutedEventArgs e)
  548. {
  549. ScrViewTab.LineLeft();
  550. }
  551. private void ButRight_Click(object sender, RoutedEventArgs e)
  552. {
  553. ScrViewTab.LineRight();
  554. }
  555. private void ScrViewTab_ScrollChanged(object sender, ScrollChangedEventArgs e)
  556. {
  557. if (e.ViewportWidth < 384)
  558. {
  559. ButLeft.Visibility = Visibility.Visible;
  560. ButRight.Visibility = Visibility.Visible;
  561. }
  562. else
  563. {
  564. ButLeft.Visibility = Visibility.Collapsed;
  565. ButRight.Visibility = Visibility.Collapsed;
  566. }
  567. }
  568. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  569. {
  570. //自动聚焦,修复快捷键无响应的问题
  571. this.Focusable = true;
  572. this.Focus();
  573. }
  574. private void ToolTabControl_PreviewKeyDown(object sender, KeyEventArgs e)
  575. {
  576. //禁用控件的左右按键,避免和左右翻页快捷键冲突
  577. if (e.Key == Key.Left || e.Key == Key.Right || e.Key == Key.Tab)
  578. {
  579. e.Handled = true;
  580. }
  581. }
  582. private void MenuItem_Click(object sender, RoutedEventArgs e)
  583. {
  584. //检查更新
  585. if (App.SparkleUpdateDetector != null)
  586. App.SparkleUpdateDetector?.CheckForUpdatesAtUserRequest();
  587. }
  588. private void BOTASplitter_PreviewMouseUp(object sender, MouseButtonEventArgs e)
  589. {
  590. if(e.GetPosition(this).X<viewModel.BOTAMiniWidth)
  591. {
  592. //需要拦截控件本身关于拖拽事件后的操作,才能响应关闭BOTA的逻辑
  593. e.Handled = true;
  594. viewModel.OpenBOTA = false;
  595. }
  596. }
  597. }
  598. }