AnnotToolContentViewModel.cs 30 KB

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