AnnotToolContentViewModel.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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. BtnHandIsChecked = !BtnHandIsChecked;
  203. PDFViewer.ClearSelectAnnots();
  204. //选中内容选择工具按钮
  205. if (tag == "SnapshotEdit")
  206. {
  207. dict["isSnapshotEdit"] = true;
  208. }
  209. else if (tag == "Signature" || tag == "Stamp")
  210. {
  211. //选中签名、图章工具按钮
  212. dict["isTemplateAnnot"] = true;
  213. }
  214. //超链接工具
  215. if (tag != "Link")
  216. BtnLinkIsChecked = false;
  217. else
  218. StrAnnotToolChecked = "Link";
  219. if (tag == "Rect" || tag == "Circle" || tag == "Arrow" || tag == "Line")
  220. {
  221. //新建形状注释,设置默认大小
  222. PDFViewer.ToolManager.EnableClickCreate = true;
  223. PDFViewer.ToolManager.ClickCreateWidth = 140;
  224. PDFViewer.ToolManager.ClickCreateHeight = 140;
  225. }
  226. else
  227. {
  228. PDFViewer.ToolManager.EnableClickCreate = false;
  229. }
  230. }
  231. #endregion 注释工具栏 -》Command实现
  232. #region BOTA
  233. private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel, out AnnotationContent annotation)
  234. {
  235. AnnotationContentViewModel viewModel = null;
  236. annotation = null;
  237. if (bOTAContentViewModel != null)
  238. {
  239. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  240. {
  241. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  242. foreach (var item in views)
  243. {
  244. if (item is AnnotationContent annotation1)
  245. {
  246. annotation = annotation1;
  247. viewModel = annotation1.DataContext as AnnotationContentViewModel;
  248. break;
  249. }
  250. }
  251. }
  252. }
  253. return viewModel;
  254. }
  255. /// <summary>
  256. /// 判断Bota的TabItem是否已显示
  257. /// </summary>
  258. /// <param name="bOTAContentViewModel"></param>
  259. /// <param name="bOTAContent"></param>
  260. /// <param name="tabItemText"></param>
  261. /// <returns></returns>
  262. private bool IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, string tabItemText)
  263. {
  264. bool isTabItem = false;
  265. bOTAContentViewModel = null;
  266. bOTAContent = null;
  267. if (region.Regions.ContainsRegionWithName(viewContentViewModel.BOTARegionName))
  268. {
  269. var views = region.Regions[viewContentViewModel.BOTARegionName].Views;
  270. var model = views.FirstOrDefault(q => q is BOTAContent);
  271. if (model is BOTAContent bOTAContent1)
  272. {
  273. bOTAContent = bOTAContent1;
  274. bOTAContentViewModel = bOTAContent.DataContext as BOTAContentViewModel;
  275. if (bOTAContentViewModel.CurrentBar == tabItemText)
  276. {
  277. isTabItem = true;
  278. }
  279. }
  280. }
  281. return isTabItem;
  282. }
  283. private void Select_Click(object sender, RoutedEventArgs e)
  284. {
  285. if (viewContentViewModel.OpenBOTA == false)
  286. {
  287. viewContentViewModel.OpenBOTA = true;
  288. }
  289. bool isBook = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemSearch");
  290. if (isBook == false)
  291. {
  292. bOTAContent.TabItemSearch.IsSelected = true;
  293. }
  294. }
  295. #endregion BOTA
  296. #region 阅读页右键菜单
  297. private void PageDisplay(ItemCollection items)
  298. {
  299. foreach (var item in items)
  300. {
  301. if (item is MenuItem menuItem)
  302. {
  303. menuItem.IsCheckable = false;
  304. menuItem.Click -= PageDisplay_Click;
  305. menuItem.Click += PageDisplay_Click;
  306. }
  307. }
  308. }
  309. private void PageDisplay_Click(object sender, RoutedEventArgs e)
  310. {
  311. if (sender is MenuItem menuItem)
  312. {
  313. switch (menuItem.Tag.ToString())
  314. {
  315. case "SingleView":
  316. PDFViewer.ChangeViewMode(ViewMode.Single);
  317. break;
  318. case "SingleContinueView":
  319. PDFViewer.ChangeViewMode(ViewMode.SingleContinuous);
  320. break;
  321. case "DoubleView":
  322. PDFViewer.ChangeViewMode(ViewMode.Double);
  323. break;
  324. case "DoubleContinueView":
  325. PDFViewer.ChangeViewMode(ViewMode.DoubleContinuous);
  326. break;
  327. case "BookMode":
  328. PDFViewer.ChangeViewMode(ViewMode.Book);
  329. break;
  330. }
  331. }
  332. }
  333. private void ViewZoom(ItemCollection items)
  334. {
  335. foreach (var item in items)
  336. {
  337. if (item is MenuItem menuItem)
  338. {
  339. //switch (PDFViewer.ModeFit)
  340. //{
  341. // case FitMode.FitWidth:
  342. // break;
  343. // case FitMode.FitHeight:
  344. // break;
  345. // case FitMode.FitSize:
  346. // break;
  347. // case FitMode.FitFree:
  348. // break;
  349. // default:
  350. // break;
  351. //}
  352. menuItem.IsCheckable = false;
  353. menuItem.Click -= ViewZoom_Click;
  354. menuItem.Click += ViewZoom_Click;
  355. }
  356. }
  357. }
  358. private void ViewZoom_Click(object sender, RoutedEventArgs e)
  359. {
  360. if (sender is MenuItem menuItem)
  361. {
  362. switch (menuItem.Tag.ToString())
  363. {
  364. case "FitWidth":
  365. PDFViewer.ChangeFitMode(FitMode.FitWidth);
  366. break;
  367. case "FitHeight":
  368. PDFViewer.ChangeFitMode(FitMode.FitHeight);
  369. break;
  370. case "FitSize":
  371. PDFViewer.ChangeFitMode(FitMode.FitSize);
  372. break;
  373. case "enlarge":
  374. double newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + 0.01), true);
  375. PDFViewer.Zoom(newZoom);
  376. break;
  377. case "narrow":
  378. newZoom = viewContentViewModel.CheckZoomLevel((PDFViewer.ZoomFactor + -0.01), false);
  379. PDFViewer.Zoom(newZoom);
  380. break;
  381. }
  382. }
  383. }
  384. private void UnReadModel_Click(object sender, RoutedEventArgs e)
  385. {
  386. viewContentViewModel.UnReadModel();
  387. }
  388. private void ReadModel_Click(object sender, RoutedEventArgs e)
  389. {
  390. viewContentViewModel.RbtnReadMode();
  391. }
  392. private void SetToolMode(ItemCollection items)
  393. {
  394. foreach (var item in items)
  395. {
  396. if (item is MenuItem menuItem)
  397. {
  398. menuItem.IsCheckable = false;
  399. menuItem.Click -= ToolMode_Click;
  400. menuItem.Click += ToolMode_Click;
  401. }
  402. }
  403. }
  404. private void ToolMode_Click(object sender, RoutedEventArgs e)
  405. {
  406. if (sender is MenuItem menuItem)
  407. {
  408. switch (menuItem.Tag.ToString())
  409. {
  410. case "default":
  411. HandToolIsCheckedEvent(false);
  412. BtnHandIsChecked = false;
  413. ShowPropertyPanel(false);
  414. break;
  415. case "roll":
  416. HandToolIsCheckedEvent(true);
  417. BtnHandIsChecked = true;
  418. ShowPropertyPanel(false);
  419. break;
  420. case "content":
  421. AnnotHandlerEventArgs annotHandler = GetSnapshotEdit();
  422. BtnSelecttoolIsChecked = true;
  423. if (annotHandler != null)
  424. {
  425. annotHandler.Author = Settings.Default.AppProperties.Description.Author;
  426. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  427. PDFViewer.SetToolParam(annotHandler);
  428. ShowPropertyPanel(false);
  429. }
  430. break;
  431. default:
  432. break;
  433. }
  434. }
  435. }
  436. private void DelBookMark_Click(object sender, RoutedEventArgs e)
  437. {
  438. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  439. if (bOTAContentVM != null && bOTA != null)
  440. {
  441. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  442. int index = PDFViewer.CurrentIndex;
  443. //检测是否已存在相同数据
  444. CPDFBookmark list = PDFViewer.Document.GetBookmarkList().FirstOrDefault(q => q.PageIndex == index);
  445. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null && list != null)
  446. {
  447. bookmarkContentViewModel.DeleteCommand.Execute(list);
  448. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  449. }
  450. }
  451. }
  452. private void CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA)
  453. {
  454. if (viewContentViewModel.OpenBOTA == false)
  455. {
  456. viewContentViewModel.OpenBOTA = true;
  457. }
  458. bool isBook = IsBOTATabItemShow(out bOTAContentVM, out bOTA, "TabItemBookMark");
  459. if (isBook == false)
  460. {
  461. bOTA.TabItemBookMark.IsSelected = true;
  462. }
  463. }
  464. private void AddBookMark_Click()
  465. {
  466. CheckBOTAState(out BOTAContentViewModel bOTAContentVM, out BOTAContent bOTA);
  467. //if (viewContentViewModel.mainViewModel.IsBookMode)
  468. //{
  469. // this.events.GetEvent<ReadModeBOTAShowEvent>().Publish(new ReadModeBOTAShowArgs() { Unicode = App.mainWindowViewModel.SelectedItem.Unicode, IsBOTAShow = true });
  470. //}
  471. if (bOTAContentVM != null && bOTA != null)
  472. {
  473. BookmarkContentViewModel bookmarkContentViewModel = GetBookmarkContentViewModel(bOTAContentVM, out BookmarkContent bookmark);
  474. if (bookmarkContentViewModel != null && bookmark != null && bOTA != null)
  475. {
  476. //bookmarkContentViewModel.AddBookmarkCommand.Execute(bookmark.BookMarkListView);
  477. bookmark.BtnAddBookmark_Click(null, null);
  478. isAddBookMark = bookmarkContentViewModel.isAddBookMark;
  479. return;
  480. }
  481. }
  482. }
  483. private BookmarkContentViewModel GetBookmarkContentViewModel(BOTAContentViewModel bOTAContentViewModel, out BookmarkContent bookmark)
  484. {
  485. BookmarkContentViewModel viewModel = null;
  486. bookmark = null;
  487. if (bOTAContentViewModel != null)
  488. {
  489. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  490. {
  491. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  492. foreach (var item in views)
  493. {
  494. if (item is BookmarkContent bookmark1)
  495. {
  496. bookmark = bookmark1;
  497. viewModel = bookmark1.DataContext as BookmarkContentViewModel;
  498. break;
  499. }
  500. }
  501. }
  502. }
  503. return viewModel;
  504. }
  505. private OutLineControlViewModel GetOutLineControlViewModel(BOTAContentViewModel bOTAContentViewModel, out OutLineControl outLineControl)
  506. {
  507. OutLineControlViewModel viewModel = null;
  508. outLineControl = null;
  509. if (bOTAContentViewModel != null)
  510. {
  511. if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
  512. {
  513. var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
  514. foreach (var item in views)
  515. {
  516. if (item is OutLineControl outLineControl1)
  517. {
  518. outLineControl = outLineControl1;
  519. viewModel = outLineControl1.DataContext as OutLineControlViewModel;
  520. break;
  521. }
  522. }
  523. }
  524. }
  525. return viewModel;
  526. }
  527. private void DisplayAnnot_Click(object sender, RoutedEventArgs e)
  528. {
  529. PDFViewer.SetDrawAnnot(true);
  530. BtnShowAnnotIsChecked = true;
  531. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  532. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  533. {
  534. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  535. viewModel.DisplayAnnot();
  536. }
  537. }
  538. private void HiddenAnnot_Click(object sender, RoutedEventArgs e)
  539. {
  540. PDFViewer.SetDrawAnnot(false);
  541. BtnShowAnnotIsChecked = false;
  542. bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
  543. if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
  544. {
  545. AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
  546. viewModel.HiddenAnnot();
  547. }
  548. }
  549. private void SetAddAnnotation(ItemCollection items)
  550. {
  551. foreach (var item in items)
  552. {
  553. if (item is MenuItem menuItem)
  554. {
  555. string str = menuItem.Tag.ToString();
  556. //if (str == AddAnnotType.AnnotLink.ToString()
  557. //|| str == AddAnnotType.AnnotStamp.ToString()
  558. //|| str == AddAnnotType.AnnotAutograph.ToString()
  559. //)
  560. //{
  561. // InBookModeSetIsEnabled(menuItem);
  562. //}
  563. menuItem.CommandParameter = item;
  564. menuItem.Command = SetAddAnnotationCommand;
  565. }
  566. }
  567. }
  568. private void AddLink_Click(object sender, RoutedEventArgs e)
  569. {
  570. var args = PDFViewer.ToolManager.CurrentAnnotArgs;
  571. BtnLinkIsChecked = true;
  572. }
  573. #endregion 阅读页右键菜单
  574. #region 快捷键
  575. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  576. {
  577. if (KeyEventsHelper.IsSingleKey(Key.Escape))
  578. {
  579. BtnHandIsChecked = true;
  580. PDFViewer.SetMouseMode(MouseModes.Scroll);
  581. PDFViewer.ClearSelectAnnots();
  582. StrAnnotToolChecked = "";
  583. ShowPropertyPanel(false);
  584. }
  585. else if (KeyEventsHelper.IsModifierKey(ModifierKeys.Shift, Key.None))
  586. {
  587. //按住Shift等比缩放
  588. }
  589. AnnotToolCtrlAltKey();
  590. }
  591. /// <summary>
  592. /// 按下Ctrl + Alt + 序列键,响应注释工具
  593. /// </summary>
  594. private void AnnotToolCtrlAltKey()
  595. {
  596. var tuple = GetCtrlAltKey();
  597. if (tuple != null)
  598. {
  599. if (tuple.Item1 == Key.L)
  600. BtnLinkIsChecked = false;
  601. AnnotHandlerEventArgs annotArgs = null;
  602. StrAnnotToolChecked = tuple.Item2;
  603. FindAnnotTypeKey(tuple.Item2, ref annotArgs);
  604. if (annotArgs != null)
  605. {
  606. annotArgs.Author = Settings.Default.AppProperties.Description.Author;
  607. PDFViewer.SetMouseMode(MouseModes.AnnotCreate);
  608. PDFViewer.SetToolParam(annotArgs);
  609. PDFViewer.ToolManager.EnableClickCreate = false;
  610. }
  611. }
  612. }
  613. private Tuple<Key, string> GetCtrlAltKey()
  614. {
  615. Dictionary<Key, bool> AnnotToolDir = new Dictionary<Key, bool>();
  616. AnnotToolDir.Add(Key.H, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.H));
  617. AnnotToolDir.Add(Key.U, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.U));
  618. AnnotToolDir.Add(Key.S, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.S));
  619. AnnotToolDir.Add(Key.P, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.P));
  620. AnnotToolDir.Add(Key.E, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.E));
  621. AnnotToolDir.Add(Key.T, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.T));
  622. AnnotToolDir.Add(Key.N, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.N));
  623. AnnotToolDir.Add(Key.R, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.R));
  624. AnnotToolDir.Add(Key.O, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.O));
  625. AnnotToolDir.Add(Key.A, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.A));
  626. AnnotToolDir.Add(Key.L, KeyEventsHelper.IsModifierKey(ModifierKeys.Control | ModifierKeys.Alt, Key.L));
  627. Key key = Key.None;
  628. foreach (var item in AnnotToolDir.Keys)
  629. {
  630. if (AnnotToolDir[item] == true)
  631. {
  632. key = item;
  633. break;
  634. }
  635. }
  636. if (key == Key.None)
  637. return null;
  638. var tag = "";
  639. if (key == Key.H || key == Key.U || key == Key.S)
  640. {
  641. var str = PDFViewer.GetSelectedText();
  642. if (string.IsNullOrEmpty(str) == false)
  643. {
  644. if (key == Key.H)
  645. tag = "HighLight";
  646. else if (key == Key.U)
  647. tag = "UnderLine";
  648. else if (key == Key.S)
  649. tag = "Strikeout";
  650. }
  651. else
  652. {
  653. return null;
  654. }
  655. }
  656. else
  657. {
  658. if (AnnotToolDir[Key.P])
  659. tag = "Freehand";
  660. else if (AnnotToolDir[Key.T])
  661. tag = "Freetext";
  662. else if (AnnotToolDir[Key.N])
  663. tag = "StickyNote";
  664. else if (AnnotToolDir[Key.R])
  665. tag = "Rect";
  666. else if (AnnotToolDir[Key.O])
  667. tag = "Circle";
  668. else if (AnnotToolDir[Key.A])
  669. tag = "Arrow";
  670. else if (AnnotToolDir[Key.L])
  671. tag = "Line";
  672. }
  673. if (tag == "")
  674. return null;
  675. return new Tuple<Key, string>(key, tag);
  676. }
  677. #endregion 快捷键
  678. #region Navigation
  679. public bool IsNavigationTarget(NavigationContext navigationContext)
  680. {
  681. return true;
  682. }
  683. public void OnNavigatedFrom(NavigationContext navigationContext)
  684. {
  685. StrAnnotToolChecked = "";
  686. UnBindingPDFViewerHandler();
  687. UnBindingEvent();
  688. }
  689. public void OnNavigatedTo(NavigationContext navigationContext)
  690. {
  691. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  692. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  693. if (viewContentViewModel != null)
  694. {
  695. OpenFileInfo = viewContentViewModel.OpenFileInfo;
  696. }
  697. BindingPDFViewerHandler();
  698. BindingEvent();
  699. LoaedStickyNotePopup();
  700. BtnHandIsChecked = (PDFViewer.MouseMode == MouseModes.Scroll ? true : false);
  701. }
  702. #endregion Navigation
  703. }
  704. }