AnnotToolContentViewModel.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. using ComPDFKit.PDFAnnotation;
  2. using ComPDFKit.PDFDocument;
  3. using ComPDFKitViewer;
  4. using ComPDFKitViewer.AnnotEvent;
  5. using ComPDFKitViewer.PdfViewer;
  6. using Microsoft.Office.Interop.Excel;
  7. using Microsoft.Office.Interop.Word;
  8. using Microsoft.Win32;
  9. using PDF_Office.CustomControl;
  10. using PDF_Office.EventAggregators;
  11. using PDF_Office.Helper;
  12. using PDF_Office.Model;
  13. using PDF_Office.Properties;
  14. using PDF_Office.ViewModels.BOTA;
  15. using PDF_Office.ViewModels.PropertyPanel;
  16. using PDF_Office.ViewModels.PropertyPanel.AnnotPanel;
  17. using PDF_Office.Views.BOTA;
  18. using PDF_Office.Views.PropertyPanel.AnnotPanel;
  19. using PDFSettings;
  20. using PDFSettings.Settings;
  21. using Prism.Commands;
  22. using Prism.Events;
  23. using Prism.Mvvm;
  24. using Prism.Regions;
  25. using Prism.Services.Dialogs;
  26. using System;
  27. using System.Collections.Generic;
  28. using System.Linq;
  29. using System.Reflection;
  30. using System.Text;
  31. using System.Threading.Tasks;
  32. using System.Windows;
  33. using System.Windows.Controls;
  34. using System.Windows.Controls.Primitives;
  35. using System.Windows.Forms;
  36. using System.Windows.Input;
  37. using System.Windows.Media;
  38. using ContextMenu = System.Windows.Controls.ContextMenu;
  39. using KeyEventArgs = System.Windows.Input.KeyEventArgs;
  40. using MenuItem = System.Windows.Controls.MenuItem;
  41. namespace PDF_Office.ViewModels.Tools
  42. {
  43. public sealed partial class AnnotToolContentViewModel : BindableBase, INavigationAware
  44. {
  45. #region 初始化
  46. public AnnotToolContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, IDialogService dialogService)
  47. {
  48. region = regionManager;
  49. events = eventAggregator;
  50. dialogs = dialogService;
  51. InitCommand();
  52. InitDefaultValue();
  53. InitToolDict();
  54. InitToolTipDict();
  55. InitPopMenu();
  56. SubscribeEvent();
  57. }
  58. //事件聚合器
  59. private void SubscribeEvent()
  60. {
  61. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  62. events.GetEvent<FillAndSignEvent>().Subscribe(FromFillAndSign, e => e.AppUnicode == Unicode);
  63. }
  64. private void InitPopMenu()
  65. {
  66. InitSelectHightAnnotMenu();
  67. InitSelectFreeHandAnnotMenu();
  68. InitSelectFreeTextAnnotMenu();
  69. InitSelectStrickNoteAnnotMenu();
  70. InitSelectShapeAnnotMenu();
  71. InitSelectLinkAnnotMenu();
  72. InitSelectStampAnnotMenu();
  73. InitSelectMultiAnnotMenu();
  74. }
  75. private void InitCommand()
  76. {
  77. MyToolsCommand = new DelegateCommand<CustomIconToggleBtn>(BtnMyTools_Click);
  78. SetAddAnnotationCommand = new DelegateCommand<object>(AddAnnotation_Click);
  79. AddBookMarkCommand = new DelegateCommand(AddBookMark_Click);
  80. PropertyRegionName = Guid.NewGuid().ToString();
  81. HandCommand = new DelegateCommand(Hand_Click);
  82. #region 注释 - 右键菜单
  83. //公共command
  84. AnnotDefaultValue_MenuCommand = new DelegateCommand<object>(AnnotDefaultValues_Menu);
  85. AnnotColorPalette_MenuCommand = new DelegateCommand<object>(AnnotColorPalette_Menu);
  86. AnnotAddNoteText_MenuCommand = new DelegateCommand<object>(AnnotAddNoteText_Menu);
  87. //高亮、下划线、删除
  88. HightAnnotCopyText_MenuCommand = new DelegateCommand<object>(HightAnnotCopyText_Menu);
  89. //手绘
  90. FreeHandLineStyle_MenuCommand = new DelegateCommand<object>(FreeHandLineStyle_Menu);
  91. //文本
  92. FreeTextFontFamily_MenuCommand = new DelegateCommand<object>(FreeTextFontFamily_Menu);
  93. FreeTextAglin_MenuCommand = new DelegateCommand<object>(FreeTextAglin_Menu);
  94. //便签
  95. StrikeNoteEditStrike_MenuCommand = new DelegateCommand<object>(StrikeNoteEditStrike_Menu);
  96. //形状
  97. ShapeLineStyle_MenuCommand = new DelegateCommand<object>(ShapeLineStyle_Menu);
  98. ShapeLineDirect_MenuCommand = new DelegateCommand<object>(ShapeLineDirect_Menu);
  99. //图章
  100. StampExportPicture_MenuCommand = new DelegateCommand<object>(StampExportPicture_Menu);
  101. //链接
  102. Link_MenuCommand = new DelegateCommand<object>(Link_Menu);
  103. #endregion 注释 - 右键菜单
  104. }
  105. #endregion 初始化
  106. #region 注释工具栏 -》Command实现
  107. //手型工具
  108. private void Hand_Click()
  109. {
  110. HandToolIsCheckedEvent(BtnHandIsChecked);
  111. if (BtnHandIsChecked)
  112. {
  113. //其余注释工具 取消选中
  114. StrAnnotToolChecked = "";
  115. BtnLinkIsChecked = false;
  116. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  117. }
  118. }
  119. //手型工具按钮选中或取消
  120. private void HandToolIsCheckedEvent(bool isChecked)
  121. {
  122. if (isChecked == false)
  123. {
  124. //鼠标框选多选注释
  125. if (PDFViewer.MouseMode != MouseModes.AnnotCreate)
  126. {
  127. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  128. var annotArgs = new SelectToolArgs();
  129. PDFViewer.SetToolParam(annotArgs);
  130. }
  131. else
  132. {
  133. PDFViewer.SetMouseMode(MouseModes.PanTool);
  134. }
  135. }
  136. else
  137. {
  138. //鼠标滚动页面
  139. PDFViewer.SetMouseMode(MouseModes.Scroll);
  140. PDFViewer.SetToolParam(new AnnotHandlerEventArgs());
  141. }
  142. }
  143. //点击注释工具
  144. private void BtnMyTools_Click(CustomIconToggleBtn annotBtn)
  145. {
  146. if (annotBtn == null || annotBtn.Tag == null) return;
  147. //不创建注释,属于注释模板
  148. Dictionary<string,bool> dictVar = new Dictionary<string,bool>();
  149. dictVar.Add("isTemplateAnnot", false);
  150. dictVar.Add("isSnapshotEdit", false);
  151. AnnotHandlerEventArgs annotArgs = null;
  152. var tag = annotBtn.Tag.ToString();
  153. if (annotBtn.Name == "BtnShowAnnot")
  154. {
  155. //显示/隐藏注释
  156. PDFViewer.SetDrawAnnot((bool)annotBtn.IsChecked);
  157. return;
  158. }
  159. if (annotBtn.IsChecked == true)
  160. {
  161. MyToolCheckedDoing(dictVar, tag);
  162. FindAnnotTypeKey(tag, ref annotArgs);
  163. if (annotArgs != null)
  164. {
  165. //设置点击页面会创建对应选中注释工具的注释
  166. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  167. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  168. PDFViewer.SetToolParam(annotArgs);
  169. #region 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  170. //isRightMenuAddAnnot = false;
  171. #endregion 设计重新调整,阅读页空白处,右键菜单,添加链接需要显示,其他和pro mac一样的效果,不显示属性栏
  172. }
  173. }
  174. else
  175. {
  176. //取消选中注释工具按钮后,恢复到未编辑注释的状态
  177. propertyPanel.IsAddLink = false;
  178. propertyPanel.IsLocationLink = false;
  179. PDFViewer.ToolManager.EnableClickCreate = false;
  180. }
  181. if (dictVar["isTemplateAnnot"] == false && annotArgs == null)
  182. {
  183. //当不是注释模板,且无创建注释时,属性面板显示为空内容
  184. PDFViewer.SetMouseMode(MouseModes.PanTool);
  185. viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
  186. }
  187. else
  188. {
  189. if (dictVar["isSnapshotEdit"] == true)
  190. {
  191. ShowPropertyPanel(false);
  192. }
  193. else
  194. {
  195. ShowPropertyPanel((bool)annotBtn.IsChecked);
  196. }
  197. }
  198. }
  199. //选中注释工具按钮时,处理的一些系列事情
  200. private void MyToolCheckedDoing(Dictionary<string, bool> dict,string tag)
  201. {
  202. if (BtnHandIsChecked)
  203. BtnHandIsChecked = false;
  204. PDFViewer.ClearSelectAnnots();
  205. //选中内容选择工具按钮
  206. if (tag == "SnapshotEdit")
  207. {
  208. dict["isSnapshotEdit"] = true;
  209. }
  210. else if (tag == "Signature" || tag == "Stamp")
  211. {
  212. //选中签名、图章工具按钮
  213. dict["isTemplateAnnot"] = true;
  214. }
  215. //超链接工具
  216. if (tag != "Link")
  217. BtnLinkIsChecked = false;
  218. else
  219. StrAnnotToolChecked = "Link";
  220. if (tag == "Rect" || tag == "Circle" || tag == "Arrow" || tag == "Line")
  221. {
  222. //新建形状注释,设置默认大小
  223. PDFViewer.ToolManager.EnableClickCreate = true;
  224. PDFViewer.ToolManager.ClickCreateWidth = 140;
  225. PDFViewer.ToolManager.ClickCreateHeight = 140;
  226. }
  227. else
  228. {
  229. PDFViewer.ToolManager.EnableClickCreate = false;
  230. }
  231. }
  232. #endregion 注释工具栏 -》Command实现
  233. #region BOTA
  234. private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel, out AnnotationContent annotation)
  235. {
  236. AnnotationContentViewModel viewModel = null;
  237. annotation = null;
  238. if (bOTAContentViewModel != null)
  239. {
  240. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  241. {
  242. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  243. foreach (var item in views)
  244. {
  245. if (item is AnnotationContent annotation1)
  246. {
  247. annotation = annotation1;
  248. viewModel = annotation1.DataContext as AnnotationContentViewModel;
  249. break;
  250. }
  251. }
  252. }
  253. }
  254. return viewModel;
  255. }
  256. /// <summary>
  257. /// 判断Bota的TabItem是否已显示
  258. /// </summary>
  259. /// <param name="bOTAContentViewModel"></param>
  260. /// <param name="bOTAContent"></param>
  261. /// <param name="tabItemText"></param>
  262. /// <returns></returns>
  263. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  264. {
  265. bool isTabItem = false;
  266. bOTAContentViewModel = null;
  267. bOTAContent = null;
  268. if (region.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  269. {
  270. var views = region.Regions[viewContentViewModel.BOTARegionName].Views;
  271. var model = views.FirstOrDefault(q => q is BOTAContent);
  272. if (model is BOTAContent bOTAContent1)
  273. {
  274. bOTAContent = bOTAContent1;
  275. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  276. if (bOTAContentViewModel.CurrentBar == tabItemText)
  277. {
  278. isTabItem = true;
  279. }
  280. }
  281. }
  282. return isTabItem;
  283. }
  284. private void Select_Click(object sender, RoutedEventArgs e)
  285. {
  286. if (viewContentViewModel.OpenBOTA == false)
  287. {
  288. viewContentViewModel.OpenBOTA = true;
  289. }
  290. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  291. if (isBook == false)
  292. {
  293. bOTAContent.TabItemSearch.IsSelected = true;
  294. }
  295. }
  296. #endregion BOTA
  297. #region 阅读页右键菜单
  298. private void PageDisplay(ItemCollection items)
  299. {
  300. foreach (var item in items)
  301. {
  302. if (item is MenuItem menuItem)
  303. {
  304. menuItem.IsCheckable = false;
  305. menuItem.Click -= PageDisplay_Click;
  306. menuItem.Click += PageDisplay_Click;
  307. }
  308. }
  309. }
  310. private void PageDisplay_Click(object sender, RoutedEventArgs e)
  311. {
  312. if (sender is MenuItem menuItem)
  313. {
  314. switch (menuItem.Tag.ToString())
  315. {
  316. case "SingleView":
  317. PDFViewer.ChangeViewMode(ViewMode.Single);
  318. break;
  319. case "SingleContinueView":
  320. PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  321. break;
  322. case "DoubleView":
  323. PDFViewer.ChangeViewMode(ViewMode.Double);
  324. break;
  325. case "DoubleContinueView":
  326. PDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
  327. break;
  328. case "BookMode":
  329. PDFViewer.ChangeViewMode(ViewMode.Book);
  330. break;
  331. }
  332. }
  333. }
  334. private void ViewZoom(ItemCollection items)
  335. {
  336. foreach (var item in items)
  337. {
  338. if (item is MenuItem menuItem)
  339. {
  340. //switch (PDFViewer.ModeFit)
  341. //{
  342. // case FitMode.FitWidth:
  343. // break;
  344. // case FitMode.FitHeight:
  345. // break;
  346. // case FitMode.FitSize:
  347. // break;
  348. // case FitMode.FitFree:
  349. // break;
  350. // default:
  351. // break;
  352. //}
  353. menuItem.IsCheckable = false;
  354. menuItem.Click -= ViewZoom_Click;
  355. menuItem.Click += ViewZoom_Click;
  356. }
  357. }
  358. }
  359. private void ViewZoom_Click(object sender, RoutedEventArgs e)
  360. {
  361. if (sender is MenuItem menuItem)
  362. {
  363. switch (menuItem.Tag.ToString())
  364. {
  365. case "FitWidth":
  366. PDFViewer.ChangeFitMode(FitMode.FitWidth);
  367. break;
  368. case "FitHeight":
  369. PDFViewer.ChangeFitMode(FitMode.FitHeight);
  370. break;
  371. case "FitSize":
  372. PDFViewer.ChangeFitMode(FitMode.FitSize);
  373. break;
  374. case "enlarge":
  375. double newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + 0.01), true);
  376. PDFViewer.Zoom(newZoom);
  377. break;
  378. case "narrow":
  379. newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + -0.01), false);
  380. PDFViewer.Zoom(newZoom);
  381. break;
  382. }
  383. }
  384. }
  385. private void UnReadModel_Click(object sender, RoutedEventArgs e)
  386. {
  387. viewContentViewModel.Off_ReadModel();
  388. }
  389. private void ReadModel_Click(object sender, RoutedEventArgs e)
  390. {
  391. viewContentViewModel.On_ReadMode();
  392. }
  393. private void SetToolMode(ItemCollection items)
  394. {
  395. foreach (var item in items)
  396. {
  397. if (item is MenuItem menuItem)
  398. {
  399. menuItem.IsCheckable = false;
  400. menuItem.Click -= ToolMode_Click;
  401. menuItem.Click += ToolMode_Click;
  402. }
  403. }
  404. }
  405. private void ToolMode_Click(object sender, RoutedEventArgs e)
  406. {
  407. if (sender is MenuItem menuItem)
  408. {
  409. switch (menuItem.Tag.ToString())
  410. {
  411. case "default":
  412. HandToolIsCheckedEvent(false);
  413. BtnHandIsChecked = false;
  414. ShowPropertyPanel(false);
  415. break;
  416. case "roll":
  417. HandToolIsCheckedEvent(true);
  418. BtnHandIsChecked = true;
  419. ShowPropertyPanel(false);
  420. break;
  421. case "content":
  422. AnnotHandlerEventArgs annotHandler = GetSnapshotEdit();
  423. BtnSelecttoolIsChecked = true;
  424. if (annotHandler != null)
  425. {
  426. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  427. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  428. PDFViewer.SetToolParam(annotHandler);
  429. ShowPropertyPanel(false);
  430. }
  431. break;
  432. default:
  433. break;
  434. }
  435. }
  436. }
  437. private void DelBookMark_Click(object sender, RoutedEventArgs e)
  438. {
  439. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  440. if (bOTAContentVM != null && bOTA != null)
  441. {
  442. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  443. int index = PDFViewer.CurrentIndex;
  444. //检测是否已存在相同数据
  445. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  446. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null && list != null)
  447. {
  448. bookmarkContentViewModel.DeleteCommand.Execute(list);
  449. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  450. }
  451. }
  452. }
  453. private void CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA)
  454. {
  455. if (viewContentViewModel.OpenBOTA == false)
  456. {
  457. viewContentViewModel.OpenBOTA = true;
  458. }
  459. bool isBook = IsBOTATabItemShow(out bOTAContentVM, out bOTA, "TabItemBookMark");
  460. if (isBook == false)
  461. {
  462. bOTA.TabItemBookMark.IsSelected = true;
  463. }
  464. }
  465. private void AddBookMark_Click()
  466. {
  467. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  468. //if (viewContentViewModel.mainViewModel.IsBookMode)
  469. //{
  470. // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
  471. //}
  472. if (bOTAContentVM != null && bOTA != null)
  473. {
  474. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  475. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null)
  476. {
  477. //bookmarkContentViewModel.AddBookmarkCommand.Execute(bookmark.BookMarkListView);
  478. bookmark.BtnAddBookmark_Click(null, null);
  479. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  480. return;
  481. }
  482. }
  483. }
  484. private BookmarkContentViewModel GetBookmarkContentViewModel(BOTAContentViewModel bOTAContentViewModel, out BookmarkContent bookmark)
  485. {
  486. BookmarkContentViewModel viewModel = null;
  487. bookmark = null;
  488. if (bOTAContentViewModel != null)
  489. {
  490. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  491. {
  492. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  493. foreach (var item in views)
  494. {
  495. if (item is BookmarkContent bookmark1)
  496. {
  497. bookmark = bookmark1;
  498. viewModel = bookmark1.DataContext as BookmarkContentViewModel;
  499. break;
  500. }
  501. }
  502. }
  503. }
  504. return viewModel;
  505. }
  506. private OutLineControlViewModel GetOutLineControlViewModel(BOTAContentViewModel bOTAContentViewModel, out OutLineControl outLineControl)
  507. {
  508. OutLineControlViewModel viewModel = null;
  509. outLineControl = null;
  510. if (bOTAContentViewModel != null)
  511. {
  512. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  513. {
  514. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  515. foreach (var item in views)
  516. {
  517. if (item is OutLineControl outLineControl1)
  518. {
  519. outLineControl = outLineControl1;
  520. viewModel = outLineControl1.DataContext as OutLineControlViewModel;
  521. break;
  522. }
  523. }
  524. }
  525. }
  526. return viewModel;
  527. }
  528. private void DisplayAnnot_Click(object sender, RoutedEventArgs e)
  529. {
  530. PDFViewer.SetDrawAnnot(true);
  531. BtnShowAnnotIsChecked = true;
  532. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  533. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  534. {
  535. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  536. viewModel.DisplayAnnot();
  537. }
  538. }
  539. private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
  540. {
  541. PDFViewer.SetDrawAnnot(false);
  542. BtnShowAnnotIsChecked = false;
  543. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  544. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  545. {
  546. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  547. viewModel.HiddenAnnot();
  548. }
  549. }
  550. private void SetAddAnnotation(ItemCollection items)
  551. {
  552. foreach (var item in items)
  553. {
  554. if (item is MenuItem menuItem)
  555. {
  556. string str = menuItem.Tag.ToString();
  557. //if (str == AddAnnotType.AnnotLink.ToString()
  558. //|| str == AddAnnotType.AnnotStamp.ToString()
  559. //|| str == AddAnnotType.AnnotAutograph.ToString()
  560. //)
  561. //{
  562. // InBookModeSetIsEnabled(menuItem);
  563. //}
  564. menuItem.CommandParameter = item;
  565. menuItem.Command = SetAddAnnotationCommand;
  566. }
  567. }
  568. }
  569. private void AddLink_Click(object sender, RoutedEventArgs e)
  570. {
  571. var args = PDFViewer.ToolManager.CurrentAnnotArgs;
  572. BtnLinkIsChecked = true;
  573. }
  574. #endregion 阅读页右键菜单
  575. #region 快捷键
  576. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  577. {
  578. if (KeyEventsHelper.IsSingleKey(Key.Escape))
  579. {
  580. BtnHandIsChecked = true;
  581. PDFViewer.SetMouseMode(MouseModes.Scroll);
  582. PDFViewer.ClearSelectAnnots();
  583. StrAnnotToolChecked = "";
  584. ShowPropertyPanel(false);
  585. }
  586. else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
  587. {
  588. //按住Shift等比缩放
  589. }
  590. AnnotToolCtrlAltKey();
  591. }
  592. /// <summary>
  593. /// 按下Ctrl + Alt + 序列键,响应注释工具
  594. /// </summary>
  595. private void AnnotToolCtrlAltKey()
  596. {
  597. var tuple = GetCtrlAltKey();
  598. if (tuple != null)
  599. {
  600. if (tuple.Item1 == Key.L)
  601. BtnLinkIsChecked = false;
  602. AnnotHandlerEventArgs annotArgs = null;
  603. StrAnnotToolChecked = tuple.Item2;
  604. FindAnnotTypeKey(tuple.Item2, ref annotArgs);
  605. if (annotArgs != null)
  606. {
  607. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  608. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  609. PDFViewer.SetToolParam(annotArgs);
  610. PDFViewer.ToolManager.EnableClickCreate = false;
  611. }
  612. }
  613. }
  614. private Tuple<Key, string> GetCtrlAltKey()
  615. {
  616. Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
  617. AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
  618. AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
  619. AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
  620. AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
  621. AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
  622. AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
  623. AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
  624. AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
  625. AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
  626. AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
  627. AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
  628. Key key = Key.None;
  629. foreach (var item in AnnotToolDir.Keys)
  630. {
  631. if (AnnotToolDir[item] == true)
  632. {
  633. key = item;
  634. break;
  635. }
  636. }
  637. if (key == Key.None)
  638. return null;
  639. var tag = "";
  640. if (key == Key.H || key == Key.U || key == Key.S)
  641. {
  642. var str = PDFViewer.GetSelectedText();
  643. if (string.IsNullOrEmpty(str) == false)
  644. {
  645. if (key == Key.H)
  646. tag = "HighLight";
  647. else if (key == Key.U)
  648. tag = "UnderLine";
  649. else if (key == Key.S)
  650. tag = "Strikeout";
  651. }
  652. else
  653. {
  654. return null;
  655. }
  656. }
  657. else
  658. {
  659. if (AnnotToolDir[Key.P])
  660. tag = "Freehand";
  661. else if (AnnotToolDir[Key.T])
  662. tag = "Freetext";
  663. else if (AnnotToolDir[Key.N])
  664. tag = "StickyNote";
  665. else if (AnnotToolDir[Key.R])
  666. tag = "Rect";
  667. else if (AnnotToolDir[Key.O])
  668. tag = "Circle";
  669. else if (AnnotToolDir[Key.A])
  670. tag = "Arrow";
  671. else if (AnnotToolDir[Key.L])
  672. tag = "Line";
  673. }
  674. if (tag == "")
  675. return null;
  676. return new Tuple<Key, string>(key, tag);
  677. }
  678. #endregion 快捷键
  679. #region Navigation
  680. public bool IsNavigationTarget(NavigationContext navigationContext)
  681. {
  682. return true;
  683. }
  684. public void OnNavigatedFrom(NavigationContext navigationContext)
  685. {
  686. StrAnnotToolChecked = "";
  687. UnBindingPDFViewerHandler();
  688. UnBindingEvent();
  689. }
  690. public void OnNavigatedTo(NavigationContext navigationContext)
  691. {
  692. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  693. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  694. if (viewContentViewModel != null)
  695. {
  696. OpenFileInfo = viewContentViewModel.OpenFileInfo;
  697. }
  698. BindingPDFViewerHandler();
  699. BindingEvent();
  700. LoaedStickyNotePopup();
  701. BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
  702. }
  703. #endregion Navigation
  704. }
  705. }