TextEditToolContentViewModel.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Media;
  9. using System.Windows;
  10. using PDF_Master.Model.PropertyPanel.AnnotPanel;
  11. using System.Windows.Controls;
  12. using Prism.Regions;
  13. using ComPDFKitViewer.PdfViewer;
  14. using PDF_Master.Model;
  15. using Microsoft.Win32;
  16. using PDF_Master.CustomControl;
  17. using ComPDFKitViewer;
  18. using System.Windows.Input;
  19. using PDF_Master.Helper;
  20. using ComPDFKitViewer.AnnotEvent;
  21. namespace PDF_Master.ViewModels.Tools
  22. {
  23. public class TextEditToolContentViewModel: BindableBase, INavigationAware
  24. {
  25. #region 属性与变量
  26. public ViewContentViewModel viewContentViewModel;
  27. private CPDFViewer PDFViewer;
  28. private IRegionManager regions;
  29. private Dictionary<string, string> btnToProperty = new Dictionary<string, string>();
  30. private bool _isTextEdit = false;
  31. public bool IsTextEdit
  32. {
  33. get { return _isTextEdit; }
  34. set { SetProperty(ref _isTextEdit, value);
  35. }
  36. }
  37. private bool _isImgEdit = false;
  38. public bool IsImgEdit
  39. {
  40. get { return _isImgEdit; }
  41. set
  42. {
  43. SetProperty(ref _isImgEdit, value);
  44. }
  45. }
  46. private bool _flg=false;
  47. public bool flg
  48. {
  49. get { return _flg; }
  50. set { SetProperty(ref _flg, value); }
  51. }
  52. #endregion
  53. #region Command
  54. // 添加文本、图像
  55. public DelegateCommand<object> AddContentCommand { get; set; }
  56. public DelegateCommand AddTextCommand { get; set; }
  57. public DelegateCommand AddImgCommand { get; set; }
  58. public DelegateCommand EditTextModeCommand { get; set; }
  59. #endregion
  60. #region 初始化
  61. public TextEditToolContentViewModel(IRegionManager regionManager)
  62. {
  63. regions = regionManager;
  64. InitCommand();
  65. InitBtnToProperty();
  66. }
  67. private void InitCommand()
  68. {
  69. AddContentCommand = new DelegateCommand<object>(AddContent);
  70. AddTextCommand = new DelegateCommand(AddText);
  71. AddImgCommand = new DelegateCommand(AddImg);
  72. EditTextModeCommand = new DelegateCommand(EditTextMode);
  73. }
  74. private void InitBtnToProperty()
  75. {
  76. btnToProperty.Add("Text", "TextEditProperty");
  77. btnToProperty.Add("Image", "ImageEditProperty");
  78. btnToProperty.Add("TextAndImage", "ImageTextEditProperty");
  79. btnToProperty.Add("PropertyPanelContent", "PropertyPanelContent");
  80. }
  81. #endregion
  82. #region 右键菜单
  83. //点击空白处时
  84. private ContextMenu EmptyStateMenu(object sender)
  85. {
  86. var popMenu = App.Current.FindResource("NoneMenu") as ContextMenu;
  87. CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
  88. //粘贴
  89. customMenu.SetMenuBinding(0, ApplicationCommands.Paste);
  90. //添加文本
  91. customMenu.SetMenuBinding(1, AddTextCommand);
  92. //添加图像
  93. customMenu.SetMenuBinding(2, AddImgCommand);
  94. return popMenu;
  95. }
  96. //选中文字的框
  97. private ContextMenu SelectTextBorder(object sender)
  98. {
  99. var popMenu = App.Current.FindResource("SelectTextMenu") as ContextMenu;
  100. CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
  101. //复制
  102. customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
  103. //剪切
  104. customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
  105. //粘贴
  106. customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
  107. //删除
  108. customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
  109. customMenu.SetVisibilityProperty(6, false);
  110. return popMenu;
  111. }
  112. //选中文字内容
  113. private ContextMenu SelectTextContent(object sender)
  114. {
  115. var popMenu = App.Current.FindResource("SelectContentMenu") as ContextMenu;
  116. CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
  117. //复制
  118. customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
  119. //剪切
  120. customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
  121. //粘贴
  122. customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
  123. //粘贴并匹配样式
  124. customMenu.SetVisibilityProperty(3, false);
  125. //删除
  126. customMenu.SetMenuBinding(4, ApplicationCommands.Delete);
  127. //全部选定
  128. customMenu.SetMenuBinding(5, ApplicationCommands.SelectAll);
  129. return popMenu;
  130. }
  131. //编辑中右键
  132. private ContextMenu EditTextContent(object sender)
  133. {
  134. var popMenu = App.Current.FindResource("NoneSelectContentMenu") as ContextMenu;
  135. CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
  136. ////复制
  137. //customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
  138. ////剪切
  139. //customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
  140. //全部选定
  141. customMenu.SetMenuBinding(0, ApplicationCommands.SelectAll);
  142. //粘贴
  143. customMenu.SetMenuBinding(1, ApplicationCommands.Paste);
  144. //粘贴并匹配样式
  145. customMenu.SetVisibilityProperty(2, false);
  146. ////删除
  147. //customMenu.SetMenuBinding(4, ApplicationCommands.Delete);
  148. return popMenu;
  149. }
  150. #endregion
  151. #region 图片右键菜单
  152. //选中图像时
  153. private ContextMenu SelectImgPDFEdit(object sender)
  154. {
  155. var popMenu = App.Current.FindResource("SelectImgMenu") as ContextMenu;
  156. CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
  157. //复制
  158. customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
  159. //剪切
  160. customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
  161. //粘贴
  162. customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
  163. //删除
  164. customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
  165. //裁剪
  166. customMenu.SetMenuBinding(4, new DelegateCommand(CropMode));
  167. //替换
  168. customMenu.SetMenuBinding(5, new DelegateCommand(ReplaceImg));
  169. //导出
  170. customMenu.SetMenuBinding(6, new DelegateCommand(ExportImg));
  171. return popMenu;
  172. }
  173. //选中裁剪图像时
  174. private ContextMenu CropImgPDFEdit(object sender)
  175. {
  176. var popMenu = App.Current.FindResource("CropImgMenu") as ContextMenu;
  177. CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
  178. //确认裁剪
  179. customMenu.SetMenuBinding(0, new DelegateCommand(CropImg));
  180. //取消裁剪
  181. customMenu.SetMenuBinding(1, new DelegateCommand(CancelCropImg));
  182. //还原裁剪
  183. customMenu.SetMenuBinding(2, new DelegateCommand(RestoreCropImg));
  184. return popMenu;
  185. }
  186. //多选图片右键
  187. private ContextMenu SelectMoreImage(object sender)
  188. {
  189. var popMenu = App.Current.FindResource("SelectMoreImageMenu") as ContextMenu;
  190. CustomPopMenu customMenu = new CustomPopMenu(popMenu, sender);
  191. //复制
  192. customMenu.SetMenuBinding(0, ApplicationCommands.Copy);
  193. //剪切
  194. customMenu.SetMenuBinding(1, ApplicationCommands.Cut);
  195. //粘贴
  196. customMenu.SetMenuBinding(2, ApplicationCommands.Paste);
  197. //删除
  198. customMenu.SetMenuBinding(3, ApplicationCommands.Delete);
  199. //导出
  200. customMenu.SetMenuBinding(4, new DelegateCommand(ExportImg));
  201. return popMenu;
  202. }
  203. #endregion
  204. #region 快捷键
  205. private void ShortCut_KeyDown(object sender, KeyEventArgs e)
  206. {
  207. try
  208. {
  209. if (e.Key == Key.Escape)
  210. {
  211. if (PDFViewer != null)
  212. {
  213. //缩小esc的操作范围
  214. if (PDFViewer.ToolManager != null && PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.EditText)
  215. {
  216. PDFViewer.RemovePDFEditEmptyText();
  217. //只有在有画框的时候才进行
  218. if (PDFViewer.MouseMode == MouseModes.PDFEdit&& PDFViewer.ToolManager.HasTool == true)
  219. {
  220. PDFViewer.RemoveTool(false);
  221. }
  222. else if (IsTextEdit == true || IsImgEdit == true)
  223. {
  224. IsImgEdit = false;
  225. IsTextEdit = false;
  226. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
  227. //文本和图像都框选
  228. PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
  229. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  230. PDFViewer.ReloadDocument();
  231. ShowPropertyPanel(false);
  232. }
  233. }
  234. else if (PDFViewer.ToolManager != null && PDFViewer.GetPDFEditCreateType() == ComPDFKit.PDFPage.CPDFEditType.EditImage)
  235. {
  236. PDFViewer.RemovePDFEditEmptyText();
  237. if (PDFViewer.MouseMode == MouseModes.PDFEdit&&PDFViewer.ToolManager.HasTool == true)
  238. {
  239. PDFViewer.RemoveTool(false);
  240. }
  241. else if (IsTextEdit == true || IsImgEdit == true)
  242. {
  243. IsImgEdit = false;
  244. IsTextEdit = false;
  245. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
  246. //文本和图像都框选
  247. PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
  248. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  249. PDFViewer.ReloadDocument();
  250. ShowPropertyPanel(false);
  251. }
  252. }
  253. }
  254. }
  255. }
  256. catch
  257. {
  258. }
  259. }
  260. #endregion
  261. //模式选择进入
  262. public void AddContent(object obj)
  263. {
  264. if (PDFViewer == null || obj == null || obj as CustomIconToggleBtn == null) return;
  265. var btn = obj as CustomIconToggleBtn;
  266. EnterEditMode((bool)btn.IsChecked, btn.Tag.ToString());
  267. }
  268. //编辑按钮逻辑,暂时保留
  269. private void EditTextMode()
  270. {
  271. }
  272. //对应模式的逻辑
  273. private void EnterEditMode(bool isCheckMode,string modeType)
  274. {
  275. if (isCheckMode)
  276. {
  277. if (modeType == "Text")
  278. {
  279. IsImgEdit = false;
  280. IsTextEdit = true;
  281. //只框选文本
  282. PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText);
  283. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  284. PDFViewer.ReloadDocument();
  285. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditText);
  286. List<PDFEditEvent> pDFEditEvents = new List<PDFEditEvent>();
  287. AddToPropertyPanel("Text", null);
  288. ShowPropertyPanel(true);
  289. }
  290. else
  291. {
  292. IsImgEdit = true;
  293. IsTextEdit = false;
  294. //只框选图像
  295. PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
  296. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.EditImage);
  297. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  298. PDFViewer.ReloadDocument();
  299. }
  300. }
  301. else
  302. {
  303. IsImgEdit = false;
  304. IsTextEdit = false;
  305. PDFViewer.SetPDFEditCreateType(ComPDFKit.PDFPage.CPDFEditType.None);
  306. //文本和图像都框选
  307. PDFViewer.SetPDFEditType(ComPDFKit.PDFPage.CPDFEditType.EditText | ComPDFKit.PDFPage.CPDFEditType.EditImage);
  308. PDFViewer.SetMouseMode(MouseModes.PDFEdit);
  309. PDFViewer.ReloadDocument();
  310. ShowPropertyPanel(false);
  311. }
  312. }
  313. #region Command功能
  314. private void AddText()
  315. {
  316. EnterEditMode(true, "Text");
  317. }
  318. private void AddImg()
  319. {
  320. EnterEditMode(true, "Image");
  321. }
  322. //进入裁剪模式
  323. private void CropMode()
  324. {
  325. if (TextEditEvent != null)
  326. {
  327. TextEditEvent.ClipImage = true;
  328. TextEditEvent.UpdatePDFEditByEventArgs();
  329. flg = true;
  330. }
  331. }
  332. //取消裁剪
  333. private void CancelCropImg()
  334. {
  335. if (TextEditEvent != null)
  336. {
  337. TextEditEvent.ClipImage = false;
  338. TextEditEvent.CancelClip();
  339. flg = false;
  340. TextEditEvent.UpdatePDFEditByEventArgs();
  341. }
  342. }
  343. //还原裁剪
  344. private void RestoreCropImg()
  345. {
  346. if (TextEditEvent != null)
  347. {
  348. TextEditEvent.RestoreClip();
  349. }
  350. }
  351. //完成裁剪
  352. private void CropImg()
  353. {
  354. if (TextEditEvent != null)
  355. {
  356. TextEditEvent.SaveClip();
  357. TextEditEvent.ClipImage = false;
  358. flg = false;
  359. TextEditEvent.UpdatePDFEditByEventArgs();
  360. GetImagePreView();
  361. }
  362. }
  363. //导出图片
  364. private void ExportImg()
  365. {
  366. if (PDFViewer == null || TextEditEvent == null || TextEditEvent.EditType != ComPDFKit.PDFPage.CPDFEditType.EditImage) return;
  367. System.Windows.Forms.FolderBrowserDialog folder = new System.Windows.Forms.FolderBrowserDialog();
  368. folder.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
  369. if (folder.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  370. {
  371. if (string.IsNullOrEmpty(folder.SelectedPath))
  372. return;
  373. var keyValueList = PDFViewer.GetSelectedImages();
  374. int i = 0;
  375. foreach (var bitmap in keyValueList)
  376. {
  377. foreach (var bitmapItem in bitmap.Value)
  378. {
  379. bitmapItem.Save(folder.SelectedPath + "\\" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
  380. i++;
  381. }
  382. }
  383. var strFilePath = folder.SelectedPath + "\\0.png";
  384. CommonHelper.ShowFileBrowser(strFilePath);
  385. }
  386. }
  387. //替换图片
  388. private void ReplaceImg()
  389. {
  390. OpenFileDialog openFileDialog = new OpenFileDialog();
  391. openFileDialog.Filter = "png|*.png;|Image|*.gif;*.jpg;*.jpeg;*.bmp;*.jfif;*.png;";
  392. openFileDialog.Multiselect = true;
  393. if ((bool)openFileDialog.ShowDialog())
  394. {
  395. if (string.IsNullOrEmpty(openFileDialog.FileName) == false)
  396. {
  397. TextEditEvent.ReplaceImagePath = openFileDialog.FileName;
  398. TextEditEvent.UpdatePDFEditByEventArgs();
  399. ReplaceimgTask();
  400. }
  401. }
  402. }
  403. //此处只有异步 ReplaceimgTask()才有作用
  404. async Task ReplaceimgTask()
  405. {
  406. await Task.Delay(100);
  407. GetImagePreView();
  408. }
  409. //选中的图像
  410. private System.Windows.Media.Imaging.BitmapSource _currentImg;
  411. public System.Windows.Media.Imaging.BitmapSource CurrentImg { get { return _currentImg; } set { SetProperty(ref _currentImg, value); } }
  412. private void GetImagePreView()
  413. {
  414. try
  415. {
  416. var list = PDFViewer.GetSelectedImages();
  417. if (list != null && list.Count > 0)
  418. {
  419. System.Drawing.Bitmap bitmap = null;
  420. foreach (var item in list)
  421. {
  422. if (item.Value.Count > 0)
  423. {
  424. bitmap = item.Value[0];
  425. break;
  426. }
  427. }
  428. if (bitmap != null)
  429. {
  430. IntPtr ip = bitmap.GetHbitmap();
  431. System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(ip, IntPtr.Zero, Int32Rect.Empty,
  432. System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
  433. CurrentImg = bitmapSource;
  434. }
  435. }
  436. }
  437. catch
  438. {
  439. }
  440. }
  441. #endregion
  442. //传参数给属性面板
  443. private void AddToPropertyPanel(string type, List<PDFEditEvent> e)
  444. {
  445. if (btnToProperty.ContainsKey(type))
  446. {
  447. NavigationParameters parameters = new NavigationParameters();
  448. parameters.Add(ParameterNames.PDFViewer, PDFViewer);
  449. parameters.Add(ParameterNames.AnnotEvent, e);
  450. parameters.Add(ParameterNames.TextEditToolContentViewModel, this);
  451. System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
  452. {
  453. regions.RequestNavigate(RegionNames.PropertyRegionName, btnToProperty[type], parameters);
  454. }));
  455. if(e!=null)
  456. {
  457. ShowPropertyPanel(true);
  458. }
  459. }
  460. }
  461. //控制属性面板是否展示
  462. private void ShowPropertyPanel(bool show = true)
  463. {
  464. viewContentViewModel.IsPropertyOpen = show;
  465. }
  466. public void OnNavigatedTo(NavigationContext navigationContext)
  467. {
  468. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  469. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  470. if (PDFViewer != null)
  471. {
  472. if(viewContentViewModel.TabSelectedIndex==2)
  473. {
  474. IsImgEdit = false;
  475. IsTextEdit = false;
  476. }
  477. //左键激活
  478. PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
  479. PDFViewer.PDFEditActiveHandler += PDFViewer_PDFEditActiveHandler;
  480. //右键
  481. PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
  482. PDFViewer.PDFEditCommandHandler += PDFViewer_PDFEditCommandHandler;
  483. //图片添加
  484. PDFViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
  485. PDFViewer.CustomNotifyHandler += PDFViewer_CustomNotifyHandler;
  486. //粘贴后选中
  487. PDFViewer.PDFEditHandler -= PDFViewer_PDFEditHandler;
  488. PDFViewer.PDFEditHandler += PDFViewer_PDFEditHandler;
  489. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  490. KeyEventsHelper.KeyDown += ShortCut_KeyDown;
  491. }
  492. }
  493. private void PDFViewer_PDFEditHandler(object sender, List<PDFEditSelectionData> e)
  494. {
  495. PDFViewer.SelectPDFEdit(e,true);
  496. }
  497. protected PDFEditEvent TextEditEvent;
  498. //左键激活逻辑
  499. private void PDFViewer_PDFEditActiveHandler(object sender, List<PDFEditEvent> e)
  500. {
  501. if (e != null && e.Count > 0)
  502. {
  503. TextEditEvent=e[0];
  504. bool isText = false;
  505. bool isImg = false;
  506. foreach (var item in e)
  507. {
  508. if (item.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
  509. {
  510. isImg = true;
  511. }
  512. if (item.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
  513. {
  514. isText = true;
  515. }
  516. }
  517. if (isText == true && isImg == false)
  518. {
  519. AddToPropertyPanel("Text", e);
  520. }
  521. if (isText == false && isImg == true)
  522. {
  523. AddToPropertyPanel("Image", e);
  524. }
  525. if (isText == true && isImg == true)
  526. {
  527. AddToPropertyPanel("TextAndImage", e);
  528. }
  529. }
  530. else
  531. {
  532. AddToPropertyPanel("PropertyPanelContent", null);
  533. }
  534. }
  535. //右键点击逻辑
  536. private void PDFViewer_PDFEditCommandHandler(object sender, PDFEditCommand e)
  537. {
  538. if (e == null)
  539. return;
  540. switch (e.CommandType)
  541. {
  542. case CommandType.Context:
  543. if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.None)//点击空白区域
  544. {
  545. e.PopupMenu = EmptyStateMenu(sender);
  546. }
  547. else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditText)
  548. {
  549. //文字编辑
  550. if (e.PressOnBorder == true)
  551. {
  552. e.PopupMenu = SelectTextBorder(sender);
  553. }
  554. else if(e.PressOnSelectedText == true)
  555. {
  556. e.PopupMenu = SelectTextContent(sender);
  557. }
  558. else if(e.SelectText=="")
  559. {
  560. e.PopupMenu= EditTextContent(sender);
  561. }
  562. else
  563. {
  564. e.PopupMenu = SelectTextContent(sender);
  565. }
  566. }
  567. else if (e.EditType == ComPDFKit.PDFPage.CPDFEditType.EditImage)
  568. {
  569. if (e.IsClipState == true)
  570. {
  571. e.PopupMenu = CropImgPDFEdit(sender);
  572. }
  573. else
  574. {
  575. e.PopupMenu = SelectImgPDFEdit(sender);
  576. }
  577. }
  578. break;
  579. default:
  580. e.DoCommand();
  581. break;
  582. }
  583. if (e.PopupMenu != null)
  584. {
  585. e.Handle = true;
  586. }
  587. flg = e.IsClipState;
  588. }
  589. //图片添加逻辑
  590. private void PDFViewer_CustomNotifyHandler(object sender, CustomNotityData e)
  591. {
  592. if (e.NotifyType == CustomNotifyType.PDFEditImage)
  593. {
  594. OpenFileDialog openFileDialog = new OpenFileDialog();
  595. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  596. if (openFileDialog.ShowDialog() == true)
  597. {
  598. PDFViewer.AddPDFEditImage(openFileDialog.FileName,500,500);
  599. }
  600. }
  601. }
  602. public bool IsNavigationTarget(NavigationContext navigationContext)
  603. {
  604. return true;
  605. }
  606. public void OnNavigatedFrom(NavigationContext navigationContext)
  607. {
  608. IsImgEdit = false;
  609. IsTextEdit = false;
  610. PDFViewer.PDFEditActiveHandler -= PDFViewer_PDFEditActiveHandler;
  611. PDFViewer.PDFEditCommandHandler -= PDFViewer_PDFEditCommandHandler;
  612. PDFViewer.CustomNotifyHandler -= PDFViewer_CustomNotifyHandler;
  613. PDFViewer.PDFEditHandler -= PDFViewer_PDFEditHandler;
  614. KeyEventsHelper.KeyDown -= ShortCut_KeyDown;
  615. ShowPropertyPanel(false);
  616. }
  617. }
  618. }