ContentEditControl.xaml.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. using ComPDFKit.PDFDocument;
  2. using ComPDFKit.PDFPage;
  3. using ComPDFKit.PDFPage.Edit;
  4. using Compdfkit_Tools.Edit;
  5. using ComPDFKitViewer;
  6. using ComPDFKitViewer.PdfViewer;
  7. using Microsoft.Win32;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Diagnostics;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Runtime.CompilerServices;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Controls.Primitives;
  20. using System.Windows.Data;
  21. using System.Windows.Documents;
  22. using System.Windows.Input;
  23. using System.Windows.Media;
  24. using System.Windows.Media.Imaging;
  25. using System.Windows.Navigation;
  26. using System.Windows.Shapes;
  27. using Compdfkit_Tools.Helper;
  28. namespace Compdfkit_Tools.PDFControl
  29. {
  30. public partial class ContentEditControl : UserControl, INotifyPropertyChanged
  31. {
  32. #region Property
  33. public PDFViewControl PdfViewControl = new PDFViewControl();
  34. public PDFContentEditControl pdfContentEditControl = new PDFContentEditControl();
  35. private CPDFDisplaySettingsControl displaySettingsControl = null;
  36. private bool _isActive = false;
  37. public bool IsActive
  38. {
  39. get => _isActive;
  40. set
  41. {
  42. _isActive = value;
  43. OnPropertyChanged();
  44. }
  45. }
  46. private double[] zoomLevelList = { 1f, 8f, 12f, 25, 33f, 50, 66f, 75, 100, 125, 150, 200, 300, 400, 600, 800, 1000 };
  47. private PDFEditEvent pdfTextCreateParam;
  48. private PDFEditEvent lastPDFEditEvent = null;
  49. private PanelState panelState = PanelState.GetInstance();
  50. private KeyEventHandler KeyDownHandler;
  51. public event PropertyChangedEventHandler PropertyChanged;
  52. public ICommand CloseTabCommand;
  53. public ICommand ExpandPropertyPanelCommand;
  54. public bool CanUndo
  55. {
  56. get
  57. {
  58. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  59. {
  60. return PdfViewControl.PDFView.UndoManager.CanUndo;
  61. }
  62. return false;
  63. }
  64. }
  65. public bool CanRedo
  66. {
  67. get
  68. {
  69. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  70. {
  71. return PdfViewControl.PDFView.UndoManager.CanRedo;
  72. }
  73. return false;
  74. }
  75. }
  76. private bool CanSave
  77. {
  78. get
  79. {
  80. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  81. {
  82. return PdfViewControl.PDFView.UndoManager.CanSave;
  83. }
  84. return false;
  85. }
  86. }
  87. public event EventHandler<bool> OnCanSaveChanged;
  88. public event EventHandler OnAnnotEditHandler;
  89. #endregion
  90. public ContentEditControl()
  91. {
  92. InitializeComponent();
  93. panelState.PropertyChanged += PanelState_PropertyChanged;
  94. }
  95. private void PanelState_PropertyChanged(object sender, PropertyChangedEventArgs e)
  96. {
  97. if (e.PropertyName == nameof(PanelState.IsLeftPanelExpand))
  98. {
  99. ExpandLeftPanel(panelState.IsLeftPanelExpand);
  100. }
  101. else if (e.PropertyName == nameof(PanelState.RightPanel))
  102. {
  103. if (panelState.RightPanel == PanelState.RightPanelState.PropertyPanel)
  104. {
  105. ExpandRightPropertyPanel(pdfContentEditControl, Visibility.Visible);
  106. }
  107. else if (panelState.RightPanel == PanelState.RightPanelState.ViewSettings)
  108. {
  109. ExpandRightPropertyPanel((IsActive)?displaySettingsControl:null, Visibility.Visible);
  110. }
  111. else
  112. {
  113. ExpandRightPropertyPanel(null, Visibility.Collapsed);
  114. }
  115. }
  116. }
  117. private void ClearPDFEditState(ToggleButton ignoreBtn = null)
  118. {
  119. List<ToggleButton> clearBtnList = new List<ToggleButton>()
  120. {
  121. PDFTextEditButton,
  122. PDFImageEditButton
  123. };
  124. foreach (ToggleButton item in clearBtnList)
  125. {
  126. if (ignoreBtn == item)
  127. {
  128. continue;
  129. }
  130. item.IsChecked = false;
  131. }
  132. }
  133. private void PDFTextEditButton_Click(object sender, RoutedEventArgs e)
  134. {
  135. ToggleButton senderBtn = sender as ToggleButton;
  136. if (senderBtn != null && PdfViewControl != null)
  137. {
  138. ClearPDFEditState(senderBtn);
  139. if (senderBtn.IsChecked == true)
  140. {
  141. PDFEditEvent createParam = new PDFEditEvent();
  142. createParam.EditType = CPDFEditType.EditText;
  143. createParam.IsBold = false;
  144. createParam.IsItalic = false;
  145. createParam.FontSize = 14;
  146. createParam.FontName = "Helvetica";
  147. createParam.FontColor = Colors.Black;
  148. createParam.TextAlign = TextAlignType.AlignLeft;
  149. createParam.Transparency = 255;
  150. if (PdfViewControl.PDFView != null && PdfViewControl.PDFView.Document != null)
  151. {
  152. CPDFDocument pdfDoc = PdfViewControl.PDFView.Document;
  153. if (pdfDoc.PageCount > 0)
  154. {
  155. CPDFPage pdfPage = pdfDoc.PageAtIndex(0);
  156. CPDFEditPage editPage = pdfPage.GetEditPage();
  157. editPage.BeginEdit(CPDFEditType.EditText);
  158. createParam.SystemFontNameList.AddRange(editPage.GetFontList());
  159. editPage.EndEdit();
  160. }
  161. }
  162. PdfViewControl.PDFView?.SetMouseMode(MouseModes.PanTool);
  163. PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditText);
  164. PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditText);
  165. PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  166. PdfViewControl.PDFView?.ReloadDocument();
  167. PdfViewControl.PDFView?.SetPDFEditParam(createParam);
  168. pdfContentEditControl.SetPDFTextEditData(createParam);
  169. panelState.RightPanel = PanelState.RightPanelState.PropertyPanel;
  170. pdfTextCreateParam = createParam;
  171. }
  172. else
  173. {
  174. PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.None);
  175. PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  176. PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  177. PdfViewControl.PDFView?.ReloadDocument();
  178. pdfContentEditControl.ClearContentControl();
  179. panelState.RightPanel = PanelState.RightPanelState.None;
  180. }
  181. }
  182. }
  183. private void PDFImageEditButton_Click(object sender, RoutedEventArgs e)
  184. {
  185. ToggleButton senderBtn = sender as ToggleButton;
  186. if (senderBtn != null && PdfViewControl != null)
  187. {
  188. panelState.RightPanel = PanelState.RightPanelState.None;
  189. senderBtn.IsChecked = false;
  190. OpenFileDialog openFileDialog = new OpenFileDialog();
  191. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  192. if (openFileDialog.ShowDialog() == true)
  193. {
  194. ClearPDFEditState(senderBtn);
  195. PdfViewControl.PDFView?.ClearSelectPDFEdit();
  196. PdfViewControl.PDFView?.SetPDFEditType(CPDFEditType.EditImage | CPDFEditType.EditText);
  197. PdfViewControl.PDFView?.SetMouseMode(MouseModes.PDFEdit);
  198. PdfViewControl.PDFView?.ReloadDocument();
  199. PdfViewControl.PDFView?.SetPDFEditCreateType(CPDFEditType.EditImage);
  200. PdfViewControl.PDFView?.AddPDFEditImage(openFileDialog.FileName);
  201. }
  202. }
  203. }
  204. public void ExpandLeftPanel(bool isExpand)
  205. {
  206. BotaContainer.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  207. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  208. if (isExpand)
  209. {
  210. BodyGrid.ColumnDefinitions[0].Width = new GridLength(320);
  211. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  212. }
  213. else
  214. {
  215. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  216. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  217. }
  218. }
  219. private void UndoBtn_Click(object sender, RoutedEventArgs e)
  220. {
  221. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  222. {
  223. PdfViewControl.PDFView.UndoManager?.Undo();
  224. }
  225. }
  226. private void RedoBtn_Click(object sender, RoutedEventArgs e)
  227. {
  228. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  229. {
  230. PdfViewControl.PDFView.UndoManager?.Redo();
  231. }
  232. }
  233. public void SetViewSettings(Visibility visibility, CPDFDisplaySettingsControl displaySettingsControl = null)
  234. {
  235. this.PropertyContainer.Child = displaySettingsControl;
  236. this.PropertyContainer.Visibility = visibility;
  237. }
  238. public void SetBOTAContainer(CPDFBOTABarControl botaControl)
  239. {
  240. this.BotaContainer.Child = botaControl;
  241. }
  242. public void SetDisplaySettingsControl(CPDFDisplaySettingsControl displaySettingsControl)
  243. {
  244. this.displaySettingsControl = displaySettingsControl;
  245. }
  246. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  247. {
  248. PdfViewControl.PDFView.PDFEditCommandHandler += PDFView_PDFEditCommandHandler;
  249. }
  250. private void UserControl_UnLoaded(object sender, RoutedEventArgs e)
  251. {
  252. PdfViewControl.PDFView.PDFEditCommandHandler -= PDFView_PDFEditCommandHandler;
  253. }
  254. public void ExpandRightPropertyPanel(UIElement propertytPanel, Visibility visible)
  255. {
  256. PropertyContainer.Width = 260;
  257. PropertyContainer.Child = propertytPanel;
  258. PropertyContainer.Visibility = visible;
  259. }
  260. public void InitWithPDFViewer(CPDFViewer pdfViewer)
  261. {
  262. PdfViewControl.PDFView = pdfViewer;
  263. PDFGrid.Child = PdfViewControl;
  264. FloatPageTool.InitWithPDFViewer(pdfViewer);
  265. pdfContentEditControl.InitWithPDFViewer(pdfViewer);
  266. PdfViewControl.PDFView.PDFEditActiveHandler -= PDFView_PDFEditActiveHandler;
  267. PdfViewControl.PDFView.PDFEditActiveHandler += PDFView_PDFEditActiveHandler;
  268. PdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  269. PdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  270. DataContext = this;
  271. }
  272. /// <summary>
  273. /// Text and Image Selected Event
  274. /// </summary>
  275. private void PDFView_PDFEditActiveHandler(object sender, ComPDFKitViewer.PDFEditEvent e)
  276. {
  277. lastPDFEditEvent = e;
  278. if (e == null)
  279. {
  280. PropertyContainer.Child = pdfContentEditControl;
  281. if (pdfTextCreateParam != null && PdfViewControl != null && PdfViewControl.PDFView != null)
  282. {
  283. if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.EditText)
  284. {
  285. pdfContentEditControl.SetPDFTextEditData(pdfTextCreateParam);
  286. }
  287. else if (PdfViewControl.PDFView.GetPDFEditCreateType() == CPDFEditType.None)
  288. {
  289. pdfContentEditControl.ClearContentControl();
  290. }
  291. }
  292. else
  293. {
  294. pdfContentEditControl.ClearContentControl();
  295. }
  296. return;
  297. }
  298. if (e.EditType == CPDFEditType.EditText)
  299. {
  300. pdfContentEditControl.SetPDFTextEditData(e, true);
  301. return;
  302. }
  303. if (e.EditType == CPDFEditType.EditImage && PdfViewControl != null)
  304. {
  305. UIElement pageView = sender as UIElement;
  306. if (pageView != null)
  307. {
  308. pageView.MouseLeftButtonUp += PageView_MouseLeftButtonUp;
  309. }
  310. pdfContentEditControl.SetPDFImageEditData(e);
  311. return;
  312. }
  313. }
  314. private void PageView_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  315. {
  316. UIElement pageView = sender as UIElement;
  317. if (pageView != null)
  318. {
  319. pageView.MouseLeftButtonUp -= PageView_MouseLeftButtonUp;
  320. }
  321. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  322. {
  323. pdfContentEditControl.SetPDFImageEditData(lastPDFEditEvent);
  324. }
  325. }
  326. public void ClearViewerControl()
  327. {
  328. PDFGrid.Child = null;
  329. BotaContainer.Child = null;
  330. PropertyContainer.Child = null;
  331. }
  332. #region Property changed
  333. protected void OnPropertyChanged([CallerMemberName] string name = null)
  334. {
  335. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  336. }
  337. public void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  338. {
  339. OnPropertyChanged(e.PropertyName);
  340. if (e.PropertyName == "CanSave")
  341. {
  342. OnCanSaveChanged?.Invoke(this, CanSave);
  343. }
  344. }
  345. #endregion
  346. #region Context menu
  347. private void PDFView_PDFEditCommandHandler(object sender, PDFEditCommand e)
  348. {
  349. if (e == null)
  350. {
  351. return;
  352. }
  353. if (e.EditType == CPDFEditType.EditText)
  354. {
  355. e.Handle = true;
  356. PDFEditTextContextMenu(sender, e);
  357. }
  358. if (e.EditType == CPDFEditType.EditImage)
  359. {
  360. e.Handle = true;
  361. PDFEditImageContextMenu(sender, e);
  362. }
  363. }
  364. private void PDFEditTextContextMenu(object sender, PDFEditCommand editCommand)
  365. {
  366. editCommand.PopupMenu = new ContextMenu();
  367. if (lastPDFEditEvent != null)
  368. {
  369. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  370. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  371. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  372. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  373. }
  374. else
  375. {
  376. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  377. if (editCommand.TextAreaCopied)
  378. {
  379. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  380. }
  381. }
  382. }
  383. private void PDFEditImageContextMenu(object sender, PDFEditCommand editCommand)
  384. {
  385. editCommand.PopupMenu = new ContextMenu();
  386. if (lastPDFEditEvent != null)
  387. {
  388. MenuItem rotateLeftMenu = new MenuItem();
  389. rotateLeftMenu.Header = "Left Rotate";
  390. rotateLeftMenu.Click += (o, p) =>
  391. {
  392. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  393. {
  394. lastPDFEditEvent.Rotate = -90;
  395. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  396. pdfContentEditControl.RefreshThumb();
  397. }
  398. };
  399. editCommand.PopupMenu.Items.Add(rotateLeftMenu);
  400. MenuItem rotateRightMenu = new MenuItem();
  401. rotateRightMenu.Header = "Right Rotate";
  402. rotateRightMenu.Click += (o, p) =>
  403. {
  404. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  405. {
  406. lastPDFEditEvent.Rotate = 90;
  407. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  408. pdfContentEditControl.RefreshThumb();
  409. }
  410. };
  411. editCommand.PopupMenu.Items.Add(rotateRightMenu);
  412. MenuItem replaceMenu = new MenuItem();
  413. replaceMenu.Header = "Replace";
  414. replaceMenu.Click += (o, p) =>
  415. {
  416. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  417. {
  418. OpenFileDialog openFileDialog = new OpenFileDialog();
  419. openFileDialog.Filter = "Image Files(*.jpg;*.jpeg;*.png;*.bmp)|*.jpg;*.jpeg;*.png;*.bmp;";
  420. if (openFileDialog.ShowDialog() == true)
  421. {
  422. lastPDFEditEvent.ReplaceImagePath = openFileDialog.FileName;
  423. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  424. PdfViewControl.PDFView?.ClearSelectPDFEdit();
  425. pdfContentEditControl.RefreshThumb();
  426. }
  427. }
  428. };
  429. editCommand.PopupMenu.Items.Add(replaceMenu);
  430. MenuItem exportMenu = new MenuItem();
  431. exportMenu.Header = "Export";
  432. exportMenu.Click += (o, p) =>
  433. {
  434. if (PdfViewControl != null && PdfViewControl.PDFView != null)
  435. {
  436. Dictionary<int, List<Bitmap>> imageDict = PdfViewControl.PDFView.GetSelectedImages();
  437. if (imageDict != null && imageDict.Count > 0)
  438. {
  439. System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
  440. if (folderBrowser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  441. {
  442. string choosePath = folderBrowser.SelectedPath;
  443. string openPath = choosePath;
  444. foreach (int pageIndex in imageDict.Keys)
  445. {
  446. List<Bitmap> imageList = imageDict[pageIndex];
  447. foreach (Bitmap image in imageList)
  448. {
  449. string savePath = System.IO.Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  450. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  451. openPath = savePath;
  452. }
  453. }
  454. Process.Start("explorer", "/select,\"" + openPath + "\"");
  455. }
  456. }
  457. }
  458. };
  459. editCommand.PopupMenu.Items.Add(exportMenu);
  460. MenuItem opacityMenu = new MenuItem();
  461. opacityMenu.Header = "Opacity";
  462. editCommand.PopupMenu.Items.Add(opacityMenu);
  463. AppendOpacityMenu(opacityMenu);
  464. MenuItem horizonMirror = new MenuItem();
  465. horizonMirror.Header = "HMirror";
  466. horizonMirror.Click += (o, p) =>
  467. {
  468. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  469. {
  470. lastPDFEditEvent.HorizontalMirror = true;
  471. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  472. }
  473. };
  474. editCommand.PopupMenu.Items.Add(horizonMirror);
  475. MenuItem verticalMirror = new MenuItem();
  476. verticalMirror.Header = "VMirror";
  477. verticalMirror.Click += (o, p) =>
  478. {
  479. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  480. {
  481. lastPDFEditEvent.VerticalMirror = true;
  482. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  483. }
  484. };
  485. editCommand.PopupMenu.Items.Add(verticalMirror);
  486. MenuItem cropMenu = new MenuItem();
  487. cropMenu.Header = "Crop";
  488. cropMenu.Click += (o, p) =>
  489. {
  490. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  491. {
  492. lastPDFEditEvent.ClipImage = true;
  493. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  494. }
  495. };
  496. editCommand.PopupMenu.Items.Add(cropMenu);
  497. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Copy", Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  498. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Cut", Command = ApplicationCommands.Cut, CommandTarget = (UIElement)sender });
  499. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Delete", Command = ApplicationCommands.Delete, CommandTarget = (UIElement)sender });
  500. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  501. if (editCommand.TextAreaCopied)
  502. {
  503. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste And Match Style", Command = CustomCommands.PasteMatchStyle, CommandTarget = (UIElement)sender });
  504. }
  505. }
  506. else
  507. {
  508. editCommand.PopupMenu.Items.Add(new MenuItem() { Header = "Paste", Command = ApplicationCommands.Paste, CommandTarget = (UIElement)sender });
  509. }
  510. }
  511. private void AppendOpacityMenu(MenuItem parentMenu)
  512. {
  513. List<int> opacityList = new List<int>()
  514. {
  515. 25,50,75,100
  516. };
  517. foreach (int opacity in opacityList)
  518. {
  519. MenuItem opacityMenu = new MenuItem();
  520. opacityMenu.Header = string.Format("{0}%", opacity);
  521. opacityMenu.Click += (o, p) =>
  522. {
  523. if (lastPDFEditEvent != null && lastPDFEditEvent.EditType == CPDFEditType.EditImage)
  524. {
  525. lastPDFEditEvent.Transparency = (int)Math.Ceiling(opacity * 255 / 100D);
  526. lastPDFEditEvent.UpdatePDFEditByEventArgs();
  527. }
  528. };
  529. parentMenu.Items.Add(opacityMenu);
  530. }
  531. }
  532. #endregion
  533. private void CommandBinding_Executed_Undo(object sender, ExecutedRoutedEventArgs e)
  534. {
  535. if (PdfViewControl != null && PdfViewControl.PDFView != null && CanUndo)
  536. {
  537. PdfViewControl.PDFView.UndoManager?.Undo();
  538. }
  539. }
  540. private void CommandBinding_Executed_Redo(object sender, ExecutedRoutedEventArgs e)
  541. {
  542. if (PdfViewControl != null && PdfViewControl.PDFView != null && CanRedo)
  543. {
  544. PdfViewControl.PDFView.UndoManager?.Redo();
  545. }
  546. }
  547. }
  548. }