MainWindow.xaml.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. using ComPDFKit.PDFDocument;
  2. using Compdfkit_Tools.Helper;
  3. using Compdfkit_Tools.PDFControl;
  4. using ComPDFKitViewer;
  5. using ComPDFKitViewer.AnnotEvent;
  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.IO;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Runtime.CompilerServices;
  17. using System.Windows;
  18. using System.Windows.Controls;
  19. using System.Windows.Controls.Primitives;
  20. using System.Windows.Input;
  21. using System.Windows.Media.Imaging;
  22. namespace Viewer
  23. {
  24. /// <summary>
  25. /// Interaction logic for MainWindow.xaml
  26. /// </summary>
  27. public partial class MainWindow : Window, INotifyPropertyChanged
  28. {
  29. #region Property
  30. private PDFViewControl passwordViewer;
  31. private PDFViewControl pdfViewControl;
  32. CPDFDisplaySettingsControl displayPanel = new CPDFDisplaySettingsControl();
  33. private int[] zoomLevelList = { 10, 25, 50, 100, 150, 200, 300, 400, 500, 1000 };
  34. public event PropertyChangedEventHandler PropertyChanged;
  35. private KeyEventHandler KeyDownHandler;
  36. public bool CanSave
  37. {
  38. get
  39. {
  40. if (pdfViewControl != null && pdfViewControl.PDFView != null)
  41. {
  42. return pdfViewControl.PDFView.UndoManager.CanSave;
  43. }
  44. return false;
  45. }
  46. }
  47. public string AppInfo
  48. {
  49. get { return Assembly.GetExecutingAssembly().GetName().Name + " " + string.Join(".", Assembly.GetExecutingAssembly().GetName().Version.ToString().Split('.').Take(3)); }
  50. }
  51. #endregion
  52. public MainWindow()
  53. {
  54. InitializeComponent();
  55. Loaded += MainWindow_Loaded;
  56. DataContext = this;
  57. }
  58. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  59. {
  60. BotaSideTool.AddBOTAContent(new[] { BOTATools.Thumbnail, BOTATools.Outline, BOTATools.Bookmark, BOTATools.Search });
  61. LoadDefaultDocument();
  62. }
  63. #region Load Document
  64. private void LoadDocument()
  65. {
  66. if (pdfViewControl.PDFView.Document == null)
  67. {
  68. return;
  69. }
  70. pdfViewControl.PDFView?.SetMouseMode(MouseModes.Viewer);
  71. pdfViewControl.PDFView?.Load();
  72. pdfViewControl.PDFView?.SetShowLink(true);
  73. PDFGrid.Child = pdfViewControl;
  74. pdfViewControl.PDFView.InfoChanged -= PdfViewer_InfoChanged;
  75. pdfViewControl.PDFView.InfoChanged += PdfViewer_InfoChanged;
  76. pdfViewControl.PDFView.AnnotCommandHandler -= PDFView_AnnotCommandHandler;
  77. pdfViewControl.PDFView.AnnotCommandHandler += PDFView_AnnotCommandHandler;
  78. pdfViewControl.PDFView.UndoManager.PropertyChanged -= UndoManager_PropertyChanged;
  79. pdfViewControl.PDFView.UndoManager.PropertyChanged += UndoManager_PropertyChanged;
  80. pdfViewControl.PDFView.SetFormFieldHighlight(true);
  81. PasswordUI.Closed -= PasswordUI_Closed;
  82. PasswordUI.Canceled -= PasswordUI_Canceled;
  83. PasswordUI.Confirmed -= PasswordUI_Confirmed;
  84. PasswordUI.Closed += PasswordUI_Closed;
  85. PasswordUI.Canceled += PasswordUI_Canceled;
  86. PasswordUI.Confirmed += PasswordUI_Confirmed;
  87. pdfViewControl.PDFView.ChangeFitMode(FitMode.FitWidth);
  88. CPDFSaclingControl.InitWithPDFViewer(pdfViewControl.PDFView);
  89. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewControl.PDFView.ZoomFactor * 100)));
  90. FloatPageTool.InitWithPDFViewer(pdfViewControl.PDFView);
  91. BotaSideTool.InitWithPDFViewer(pdfViewControl.PDFView);
  92. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  93. ViewSettingBtn.IsChecked = false;
  94. PropertyContainer.Child = null;
  95. PropertyContainer.Visibility = Visibility.Collapsed;
  96. }
  97. private void LoadDefaultDocument()
  98. {
  99. string defaultFilePath = "ComPDFKit_Sample_File_Windows.pdf";
  100. pdfViewControl = new PDFViewControl();
  101. pdfViewControl.PDFView.InitDocument(defaultFilePath);
  102. LoadDocument();
  103. }
  104. #endregion
  105. #region Password
  106. private void PasswordUI_Confirmed(object sender, string e)
  107. {
  108. if (passwordViewer != null && passwordViewer.PDFView != null && passwordViewer.PDFView.Document != null)
  109. {
  110. passwordViewer.PDFView.Document.UnlockWithPassword(e);
  111. if (passwordViewer.PDFView.Document.IsLocked == false)
  112. {
  113. PasswordUI.SetShowError("", Visibility.Collapsed);
  114. PasswordUI.ClearPassword();
  115. PasswordUI.Visibility = Visibility.Collapsed;
  116. PopupBorder.Visibility = Visibility.Collapsed;
  117. pdfViewControl = passwordViewer;
  118. LoadDocument();
  119. }
  120. else
  121. {
  122. PasswordUI.SetShowError("Wrong Password", Visibility.Visible);
  123. }
  124. }
  125. }
  126. private void PasswordUI_Canceled(object sender, EventArgs e)
  127. {
  128. PopupBorder.Visibility = Visibility.Collapsed;
  129. PasswordUI.Visibility = Visibility.Collapsed;
  130. }
  131. private void PasswordUI_Closed(object sender, EventArgs e)
  132. {
  133. PopupBorder.Visibility = Visibility.Collapsed;
  134. PasswordUI.Visibility = Visibility.Collapsed;
  135. }
  136. #endregion
  137. #region Expand or Hide Panel
  138. private void ControlLeftPanel()
  139. {
  140. if (LeftToolPanelButton != null)
  141. {
  142. bool isExpand = LeftToolPanelButton.IsChecked == true;
  143. ExpandLeftPanel(isExpand);
  144. }
  145. }
  146. private void ExpandLeftPanel(bool isExpand)
  147. {
  148. BotaSideTool.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  149. Splitter.Visibility = isExpand ? Visibility.Visible : Visibility.Collapsed;
  150. if (isExpand)
  151. {
  152. BodyGrid.ColumnDefinitions[0].Width = new GridLength(260);
  153. BodyGrid.ColumnDefinitions[1].Width = new GridLength(15);
  154. }
  155. else
  156. {
  157. BodyGrid.ColumnDefinitions[0].Width = new GridLength(0);
  158. BodyGrid.ColumnDefinitions[1].Width = new GridLength(0);
  159. }
  160. }
  161. private void ExpandSearchBtn_Click(object sender, RoutedEventArgs e)
  162. {
  163. ExpandLeftPanel(true);
  164. BotaSideTool.SelectBotaTool(BOTATools.Search);
  165. }
  166. private void LeftToolPanelButton_Click(object sender, RoutedEventArgs e)
  167. {
  168. ToggleButton expandBtn = sender as ToggleButton;
  169. if (expandBtn != null)
  170. {
  171. bool isExpand = expandBtn.IsChecked == true;
  172. ExpandLeftPanel(isExpand);
  173. }
  174. }
  175. #endregion
  176. #region UI
  177. private double CheckZoomLevel(double zoom, bool IsGrowth)
  178. {
  179. double standardZoom = 100;
  180. if (zoom <= 0.01)
  181. {
  182. return 0.01;
  183. }
  184. if (zoom >= 10)
  185. {
  186. return 10;
  187. }
  188. zoom *= 100;
  189. for (int i = 0; i < zoomLevelList.Length - 1; i++)
  190. {
  191. if (zoom > zoomLevelList[i] && zoom <= zoomLevelList[i + 1] && IsGrowth)
  192. {
  193. standardZoom = zoomLevelList[i + 1];
  194. break;
  195. }
  196. if (zoom >= zoomLevelList[i] && zoom < zoomLevelList[i + 1] && !IsGrowth)
  197. {
  198. standardZoom = zoomLevelList[i];
  199. break;
  200. }
  201. }
  202. return standardZoom / 100;
  203. }
  204. private void ShowViewSettings()
  205. {
  206. if (ViewSettingBtn != null)
  207. {
  208. if (ViewSettingBtn.IsChecked == true)
  209. {
  210. displayPanel.InitWithPDFViewer(pdfViewControl.PDFView);
  211. PropertyContainer.Child = displayPanel;
  212. PropertyContainer.Visibility = Visibility.Visible;
  213. }
  214. else
  215. {
  216. PropertyContainer.Child = null;
  217. PropertyContainer.Visibility = Visibility.Collapsed;
  218. }
  219. }
  220. }
  221. private void ViewSettingBtn_Click(object sender, RoutedEventArgs e)
  222. {
  223. ShowViewSettings();
  224. }
  225. private void ZoomInBtn_Click(object sender, RoutedEventArgs e)
  226. {
  227. if (pdfViewControl != null)
  228. {
  229. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  230. pdfViewControl.PDFView.Zoom(newZoom);
  231. }
  232. }
  233. private void ZoomOutBtn_Click(object sender, RoutedEventArgs e)
  234. {
  235. if (pdfViewControl != null)
  236. {
  237. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  238. pdfViewControl.PDFView.Zoom(newZoom);
  239. }
  240. }
  241. private void NextPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  242. {
  243. pdfViewControl.PDFView?.GoToPage(pdfViewControl.PDFView.CurrentIndex + 1);
  244. }
  245. private void PrevPageBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  246. {
  247. pdfViewControl.PDFView?.GoToPage(pdfViewControl.PDFView.CurrentIndex - 1);
  248. }
  249. private void PageInfoBtn_Click(object sender, RoutedEventArgs e)
  250. {
  251. PasswordUI.Visibility = Visibility.Collapsed;
  252. FileInfoUI.Visibility = Visibility.Visible;
  253. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  254. PopupBorder.Visibility = Visibility.Visible;
  255. }
  256. private void FileInfoCloseBtn_Click(object sender, RoutedEventArgs e)
  257. {
  258. PopupBorder.Visibility = Visibility.Collapsed;
  259. }
  260. #endregion
  261. #region Open and save file
  262. /// <summary>
  263. /// Save the file to another PDF file.
  264. /// </summary>
  265. public void SaveAsFile()
  266. {
  267. {
  268. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  269. {
  270. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  271. SaveFileDialog saveDialog = new SaveFileDialog();
  272. saveDialog.Filter = "(*.pdf)|*.pdf";
  273. saveDialog.DefaultExt = ".pdf";
  274. saveDialog.OverwritePrompt = true;
  275. if (saveDialog.ShowDialog() == true)
  276. {
  277. pdfDoc.WriteToFilePath(saveDialog.FileName);
  278. }
  279. }
  280. }
  281. }
  282. private void SaveFile()
  283. {
  284. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  285. {
  286. CPDFDocument pdfDoc = pdfViewControl.PDFView.Document;
  287. if (pdfDoc.WriteToLoadedPath())
  288. {
  289. pdfViewControl.PDFView.UndoManager.CanSave = false;
  290. return;
  291. }
  292. SaveFileDialog saveDialog = new SaveFileDialog();
  293. saveDialog.Filter = "(*.pdf)|*.pdf";
  294. saveDialog.DefaultExt = ".pdf";
  295. saveDialog.OverwritePrompt = true;
  296. if (saveDialog.ShowDialog() == true)
  297. {
  298. if (pdfDoc.WriteToFilePath(saveDialog.FileName))
  299. {
  300. pdfViewControl.PDFView.UndoManager.CanSave = false;
  301. }
  302. }
  303. }
  304. }
  305. private void OpenFile()
  306. {
  307. string filePath = CommonHelper.GetExistedPathOrEmpty();
  308. if (!string.IsNullOrEmpty(filePath) && pdfViewControl != null)
  309. {
  310. if (pdfViewControl.PDFView != null && pdfViewControl.PDFView.Document != null)
  311. {
  312. string oldFilePath = pdfViewControl.PDFView.Document.FilePath;
  313. if (oldFilePath.ToLower() == filePath.ToLower())
  314. {
  315. return;
  316. }
  317. }
  318. passwordViewer = new PDFViewControl();
  319. passwordViewer.PDFView.InitDocument(filePath);
  320. if (passwordViewer.PDFView.Document == null)
  321. {
  322. MessageBox.Show("Open File Failed");
  323. return;
  324. }
  325. if (passwordViewer.PDFView.Document.IsLocked)
  326. {
  327. PasswordUI.SetShowText(System.IO.Path.GetFileName(filePath) + " " + LanguageHelper.CommonManager.GetString("Tip_Encrypted"));
  328. PasswordUI.ClearPassword();
  329. PopupBorder.Visibility = Visibility.Visible;
  330. PasswordUI.Visibility = Visibility.Visible;
  331. }
  332. else
  333. {
  334. pdfViewControl.PDFView.Document.Release();
  335. pdfViewControl = passwordViewer;
  336. LoadDocument();
  337. }
  338. }
  339. }
  340. private void OpenFile_Click(object sender, RoutedEventArgs e)
  341. {
  342. OpenFile();
  343. }
  344. private void SaveFileBtn_Click(object sender, RoutedEventArgs e)
  345. {
  346. SaveFile();
  347. }
  348. #endregion
  349. #region Context Menu
  350. private void ExtraImage_Click(object sender, RoutedEventArgs e)
  351. {
  352. System.Windows.Forms.FolderBrowserDialog folderDialog = new System.Windows.Forms.FolderBrowserDialog();
  353. if (folderDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  354. {
  355. string choosePath = folderDialog.SelectedPath;
  356. string openPath = choosePath;
  357. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  358. if (imageDict != null && imageDict.Count > 0)
  359. {
  360. foreach (int pageIndex in imageDict.Keys)
  361. {
  362. List<Bitmap> imageList = imageDict[pageIndex];
  363. foreach (Bitmap image in imageList)
  364. {
  365. string savePath = Path.Combine(choosePath, Guid.NewGuid() + ".jpg");
  366. image.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
  367. openPath = savePath;
  368. }
  369. }
  370. }
  371. Process.Start("explorer", "/select,\"" + openPath + "\"");
  372. }
  373. }
  374. private void CopyImage_Click(object sender, RoutedEventArgs e)
  375. {
  376. Dictionary<int, List<Bitmap>> imageDict = pdfViewControl.PDFView?.GetSelectedImages();
  377. if (imageDict != null && imageDict.Count > 0)
  378. {
  379. foreach (int pageIndex in imageDict.Keys)
  380. {
  381. List<Bitmap> imageList = imageDict[pageIndex];
  382. foreach (Bitmap image in imageList)
  383. {
  384. MemoryStream ms = new MemoryStream();
  385. image.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
  386. BitmapImage imageData = new BitmapImage();
  387. imageData.BeginInit();
  388. imageData.StreamSource = ms;
  389. imageData.CacheOption = BitmapCacheOption.OnLoad;
  390. imageData.EndInit();
  391. imageData.Freeze();
  392. Clipboard.SetImage(imageData);
  393. break;
  394. }
  395. }
  396. }
  397. }
  398. private void PDFView_AnnotCommandHandler(object sender, AnnotCommandArgs e)
  399. {
  400. if (e != null && e.CommandType == CommandType.Context)
  401. {
  402. if (e.PressOnSelectedText)
  403. {
  404. e.Handle = true;
  405. e.PopupMenu = new ContextMenu();
  406. e.PopupMenu.Items.Add(new MenuItem() { Header = LanguageHelper.CommonManager.GetString("Menu_Copy"), Command = ApplicationCommands.Copy, CommandTarget = (UIElement)sender });
  407. }
  408. else if (e.CommandTarget == TargetType.ImageSelection)
  409. {
  410. if (pdfViewControl != null && pdfViewControl.PDFView != null && pdfViewControl.PDFView.GetSelectImageCount() > 0)
  411. {
  412. e.Handle = true;
  413. e.PopupMenu = new ContextMenu();
  414. MenuItem imageCopyMenu = new MenuItem();
  415. imageCopyMenu = new MenuItem();
  416. imageCopyMenu.Header = "Copy Images";
  417. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageCopyMenu, "Click", CopyImage_Click);
  418. imageCopyMenu.CommandParameter = e;
  419. e.PopupMenu.Items.Add(imageCopyMenu);
  420. MenuItem imageExtraMenu = new MenuItem();
  421. imageExtraMenu = new MenuItem();
  422. imageExtraMenu.Header = "Extract Images";
  423. WeakEventManager<MenuItem, RoutedEventArgs>.AddHandler(imageExtraMenu, "Click", ExtraImage_Click);
  424. imageExtraMenu.CommandParameter = e;
  425. e.PopupMenu.Items.Add(imageExtraMenu);
  426. }
  427. }
  428. else
  429. {
  430. e.Handle = true;
  431. e.PopupMenu = new ContextMenu();
  432. //if (pdfViewControl.CheckHasForm())
  433. MenuItem fitWidthMenu = new MenuItem();
  434. fitWidthMenu.Header = LanguageHelper.CommonManager.GetString("Menu_AutoSize");
  435. fitWidthMenu.Click += (o, p) =>
  436. {
  437. if (pdfViewControl != null)
  438. {
  439. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitWidth);
  440. }
  441. };
  442. e.PopupMenu.Items.Add(fitWidthMenu);
  443. MenuItem fitSizeMenu = new MenuItem();
  444. fitSizeMenu.Header = LanguageHelper.CommonManager.GetString("Menu_RealSize");
  445. fitSizeMenu.Click += (o, p) =>
  446. {
  447. if (pdfViewControl != null)
  448. {
  449. pdfViewControl.PDFView?.ChangeFitMode(FitMode.FitSize);
  450. }
  451. };
  452. e.PopupMenu.Items.Add(fitSizeMenu);
  453. MenuItem zoomInMenu = new MenuItem();
  454. zoomInMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomIn");
  455. zoomInMenu.Click += (o, p) =>
  456. {
  457. if (pdfViewControl != null)
  458. {
  459. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  460. pdfViewControl.PDFView?.Zoom(newZoom);
  461. }
  462. };
  463. e.PopupMenu.Items.Add(zoomInMenu);
  464. MenuItem zoomOutMenu = new MenuItem();
  465. zoomOutMenu.Header = LanguageHelper.CommonManager.GetString("Menu_ZoomOut");
  466. zoomOutMenu.Click += (o, p) =>
  467. {
  468. if (pdfViewControl != null)
  469. {
  470. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  471. pdfViewControl.PDFView?.Zoom(newZoom);
  472. }
  473. };
  474. e.PopupMenu.Items.Add(zoomOutMenu);
  475. e.PopupMenu.Items.Add(new Separator());
  476. MenuItem singleView = new MenuItem();
  477. singleView.Header = LanguageHelper.CommonManager.GetString("Menu_SinglePage");
  478. singleView.Click += (o, p) =>
  479. {
  480. if (pdfViewControl != null)
  481. {
  482. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Single);
  483. }
  484. };
  485. e.PopupMenu.Items.Add(singleView);
  486. MenuItem singleContinuousView = new MenuItem();
  487. singleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_SingleContinuous");
  488. singleContinuousView.Click += (o, p) =>
  489. {
  490. if (pdfViewControl != null)
  491. {
  492. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.SingleContinuous);
  493. }
  494. };
  495. e.PopupMenu.Items.Add(singleContinuousView);
  496. MenuItem doubleView = new MenuItem();
  497. doubleView.Header = LanguageHelper.CommonManager.GetString("Menu_DoublePage");
  498. doubleView.Click += (o, p) =>
  499. {
  500. if (pdfViewControl != null)
  501. {
  502. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.Double);
  503. }
  504. };
  505. e.PopupMenu.Items.Add(doubleView);
  506. MenuItem doubleContinuousView = new MenuItem();
  507. doubleContinuousView.Header = LanguageHelper.CommonManager.GetString("Menu_DoubleContinuous");
  508. doubleContinuousView.Click += (o, p) =>
  509. {
  510. if (pdfViewControl != null)
  511. {
  512. pdfViewControl.PDFView?.ChangeViewMode(ViewMode.DoubleContinuous);
  513. }
  514. };
  515. e.PopupMenu.Items.Add(doubleContinuousView);
  516. {
  517. MenuItem resetForms = new MenuItem();
  518. resetForms.Header = LanguageHelper.CommonManager.GetString("Menu_Reset");
  519. resetForms.Click += (o, p) =>
  520. {
  521. if (pdfViewControl != null)
  522. {
  523. pdfViewControl.PDFView?.ResetForm(null);
  524. }
  525. };
  526. e.PopupMenu.Items.Add(new Separator());
  527. e.PopupMenu.Items.Add(resetForms);
  528. }
  529. }
  530. }
  531. if (e != null && e.CommandType == CommandType.Copy)
  532. {
  533. e.DoCommand();
  534. }
  535. }
  536. #endregion
  537. #region Close Window
  538. protected override void OnClosing(CancelEventArgs e)
  539. {
  540. if (pdfViewControl.PDFView.UndoManager.CanSave)
  541. {
  542. MessageBoxResult result = MessageBox.Show("Do you want to save your changes before closing the application?", "Message", MessageBoxButton.YesNoCancel);
  543. if (result == MessageBoxResult.Yes)
  544. {
  545. SaveFile();
  546. }
  547. else if (result == MessageBoxResult.No)
  548. {
  549. }
  550. else
  551. {
  552. e.Cancel = true;
  553. }
  554. }
  555. }
  556. #endregion
  557. #region PropertyChanged
  558. /// <summary>
  559. /// Zoom
  560. /// </summary>
  561. private void PdfViewer_InfoChanged(object sender, KeyValuePair<string, object> e)
  562. {
  563. if (e.Key == "Zoom")
  564. {
  565. CPDFSaclingControl.SetZoomTextBoxText(string.Format("{0}", (int)((double)e.Value * 100)));
  566. }
  567. }
  568. /// <summary>
  569. /// Undo Redo Event Noitfy
  570. /// </summary>
  571. private void UndoManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
  572. {
  573. OnPropertyChanged(e.PropertyName);
  574. }
  575. protected void OnPropertyChanged([CallerMemberName] string name = null)
  576. {
  577. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
  578. }
  579. #endregion
  580. #region Shortcut
  581. private void CommandBinding_Executed_Open(object sender, ExecutedRoutedEventArgs e)
  582. {
  583. OpenFile();
  584. }
  585. private void CommandBinding_Executed_Save(object sender, ExecutedRoutedEventArgs e)
  586. {
  587. if (CanSave)
  588. {
  589. SaveFile();
  590. }
  591. }
  592. private void CommandBinding_Executed_SaveAs(object sender, ExecutedRoutedEventArgs e)
  593. {
  594. SaveAsFile();
  595. }
  596. private void CommandBinding_Executed_ControlLeftPanel(object sender, ExecutedRoutedEventArgs e)
  597. {
  598. LeftToolPanelButton.IsChecked = !LeftToolPanelButton.IsChecked;
  599. ControlLeftPanel();
  600. }
  601. private void CommandBinding_Executed_Bookmark(object sender, ExecutedRoutedEventArgs e)
  602. {
  603. ExpandLeftPanel(true);
  604. LeftToolPanelButton.IsChecked = true;
  605. BotaSideTool.SelectBotaTool(BOTATools.Bookmark);
  606. }
  607. private void CommandBinding_Executed_Outline(object sender, ExecutedRoutedEventArgs e)
  608. {
  609. ExpandLeftPanel(true);
  610. LeftToolPanelButton.IsChecked = true;
  611. BotaSideTool.SelectBotaTool(BOTATools.Outline);
  612. }
  613. private void CommandBinding_Executed_Thumbnail(object sender, ExecutedRoutedEventArgs e)
  614. {
  615. ExpandLeftPanel(true);
  616. LeftToolPanelButton.IsChecked = true;
  617. BotaSideTool.SelectBotaTool(BOTATools.Thumbnail);
  618. }
  619. private void CommandBinding_Executed_Search(object sender, ExecutedRoutedEventArgs e)
  620. {
  621. ExpandLeftPanel(true);
  622. LeftToolPanelButton.IsChecked = true;
  623. BotaSideTool.SelectBotaTool(BOTATools.Search);
  624. }
  625. private void CommandBinding_Executed_ScaleAdd(object sender, ExecutedRoutedEventArgs e)
  626. {
  627. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor + 0.01, true);
  628. pdfViewControl.PDFView?.Zoom(newZoom);
  629. }
  630. private void CommandBinding_Executed_ScaleSubtract(object sender, ExecutedRoutedEventArgs e)
  631. {
  632. double newZoom = CheckZoomLevel(pdfViewControl.PDFView.ZoomFactor - 0.01, false);
  633. pdfViewControl.PDFView?.Zoom(newZoom);
  634. }
  635. private void CommandBinding_Executed_DisplaySettings(object sender, ExecutedRoutedEventArgs e)
  636. {
  637. ViewSettingBtn.IsChecked = !ViewSettingBtn.IsChecked;
  638. ShowViewSettings();
  639. }
  640. private void CommandBinding_Executed_DocumentInfo(object sender, ExecutedRoutedEventArgs e)
  641. {
  642. if (PopupBorder.Visibility != Visibility.Visible)
  643. {
  644. PasswordUI.Visibility = Visibility.Collapsed;
  645. FileInfoUI.Visibility = Visibility.Visible;
  646. FileInfoControl.InitWithPDFViewer(pdfViewControl.PDFView);
  647. PopupBorder.Visibility = Visibility.Visible;
  648. }
  649. else
  650. {
  651. FileInfoUI.Visibility = Visibility.Collapsed;
  652. PopupBorder.Visibility = Visibility.Collapsed;
  653. }
  654. }
  655. #endregion
  656. }
  657. }