CPDFPageInsertWindow.xaml.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using Compdfkit_Tools.Helper;
  2. using Compdfkit_Tools.PDFControlUI;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Windows;
  6. namespace Compdfkit_Tools.PDFControl
  7. {
  8. public partial class CPDFPageInsertWindow : Window
  9. {
  10. public InsertEventClass Result = new InsertEventClass();
  11. public delegate void DialogCloseEventHandler(object sender, InsertDialogCloseEventArgs e);
  12. public event DialogCloseEventHandler DialogClosed;
  13. public CPDFPageInsertWindow()
  14. {
  15. InitializeComponent();
  16. Title = LanguageHelper.DocEditorManager.GetString("Title_Insert");
  17. }
  18. public void InitPageInsertWindow(int index, int maxPage)
  19. {
  20. if (index == -1)
  21. {
  22. CPDFPageInsertUI.PageInsertLocation = PageInsertLocation.HomePage;
  23. }
  24. else
  25. {
  26. CPDFPageInsertUI.PageInsertLocation = PageInsertLocation.CustomPage;
  27. CPDFPageInsertUI.CustomPageIndex = index + 1;
  28. Result.InsertIndex = index + 1;
  29. }
  30. CPDFPageInsertUI.MaxIndex = maxPage;
  31. }
  32. private void CPDFPageInsertUI_Loaded(object sender, RoutedEventArgs e)
  33. {
  34. CPDFPageInsertUI.InsertTypeChanged -= CPDFPageInsertUI_InsertTypeChanged;
  35. CPDFPageInsertUI.SelectedFileChanged -= CPDFPageInsertUI_SelectedFileChanged;
  36. CPDFPageInsertUI.InsertIndexChanged -= CPDFPageInsertUI_InsertIndexChanged;
  37. CPDFPageInsertUI.TextChanged -= CPDFPageInsertUI_TextChanged;
  38. CPDFPageInsertUI.CancelEvent -= CPDFPageInsertUI_CancelEvent;
  39. CPDFPageInsertUI.InsertEvent -= CPDFPageInsertUI_InsertEvent;
  40. CPDFPageInsertUI.PageSizeChanged -= CPDFPageInsertUI_PageSizeChanged;
  41. CPDFPageInsertUI.PasswordChanged -= CPDFPageInsertUI_PasswordChanged;
  42. CPDFPageInsertUI.InsertTypeChanged += CPDFPageInsertUI_InsertTypeChanged;
  43. CPDFPageInsertUI.SelectedFileChanged += CPDFPageInsertUI_SelectedFileChanged;
  44. CPDFPageInsertUI.InsertIndexChanged += CPDFPageInsertUI_InsertIndexChanged;
  45. CPDFPageInsertUI.TextChanged += CPDFPageInsertUI_TextChanged;
  46. CPDFPageInsertUI.CancelEvent += CPDFPageInsertUI_CancelEvent;
  47. CPDFPageInsertUI.InsertEvent += CPDFPageInsertUI_InsertEvent;
  48. CPDFPageInsertUI.PageSizeChanged += CPDFPageInsertUI_PageSizeChanged;
  49. CPDFPageInsertUI.PasswordChanged += CPDFPageInsertUI_PasswordChanged;
  50. }
  51. private void CPDFPageInsertUI_Unloaded(object sender, RoutedEventArgs e)
  52. {
  53. CPDFPageInsertUI.InsertTypeChanged -= CPDFPageInsertUI_InsertTypeChanged;
  54. CPDFPageInsertUI.SelectedFileChanged -= CPDFPageInsertUI_SelectedFileChanged;
  55. CPDFPageInsertUI.InsertIndexChanged -= CPDFPageInsertUI_InsertIndexChanged;
  56. CPDFPageInsertUI.TextChanged -= CPDFPageInsertUI_TextChanged;
  57. CPDFPageInsertUI.CancelEvent -= CPDFPageInsertUI_CancelEvent;
  58. CPDFPageInsertUI.InsertEvent -= CPDFPageInsertUI_InsertEvent;
  59. CPDFPageInsertUI.PageSizeChanged -= CPDFPageInsertUI_PageSizeChanged;
  60. CPDFPageInsertUI.PasswordChanged -= CPDFPageInsertUI_PasswordChanged;
  61. }
  62. private void CPDFPageInsertUI_PasswordChanged(object sender, string e)
  63. {
  64. Result.Password = e;
  65. }
  66. private void CPDFPageInsertUI_InsertEvent(object sender, EventArgs e)
  67. {
  68. if (Result.InsertType == InsertType.FromOtherPDF && Result.FilePath == string.Empty)
  69. {
  70. MessageBox.Show(LanguageHelper.DocEditorManager.GetString("Warn_NoFile"),LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.OK, MessageBoxImage.Warning);
  71. return;
  72. }
  73. List<int> pageRangeList = new List<int>();
  74. if (Result.InsertType == InsertType.FromOtherPDF && !CommonHelper.GetPagesInRange(ref pageRangeList, Result.PageRange, CPDFPageInsertUI.MaxIndex, new char[] { ',' }, new char[] { '-' }))
  75. {
  76. MessageBox.Show(LanguageHelper.DocEditorManager.GetString("Warn_PageRange"), LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.OK, MessageBoxImage.Warning);
  77. return;
  78. }
  79. CloseWindow(Result);
  80. }
  81. private void CPDFPageInsertUI_CancelEvent(object sender, EventArgs e)
  82. {
  83. CloseWindow(null);
  84. }
  85. private void CPDFPageInsertUI_TextChanged(object sender, string e)
  86. {
  87. Result.PageRange = e;
  88. }
  89. private void CPDFPageInsertUI_SelectedFileChanged(object sender, string e)
  90. {
  91. Result.FilePath = e;
  92. }
  93. private void CPDFPageInsertUI_InsertTypeChanged(object sender, string e)
  94. {
  95. if (e == "BlankPages")
  96. {
  97. Result.InsertType = InsertType.BlankPages;
  98. }
  99. else if (e == "CustomBlankPages")
  100. {
  101. Result.InsertType = InsertType.CustomBlankPages;
  102. }
  103. else
  104. {
  105. Result.InsertType = InsertType.FromOtherPDF;
  106. }
  107. }
  108. private void CPDFPageInsertUI_InsertIndexChanged(object sender, int e)
  109. {
  110. Result.InsertIndex = e;
  111. }
  112. private void CloseWindow(InsertEventClass dialogResult)
  113. {
  114. DialogClosed?.Invoke(this, new InsertDialogCloseEventArgs(dialogResult));
  115. Close();
  116. }
  117. private void CPDFPageInsertUI_PageSizeChanged(object sender, double[] e)
  118. {
  119. Result.PageWidth = e[0];
  120. Result.PageHeight = e[1];
  121. }
  122. }
  123. public class InsertDialogCloseEventArgs : EventArgs
  124. {
  125. public InsertEventClass DialogResult { get; set; }
  126. public InsertDialogCloseEventArgs(InsertEventClass dialogResult)
  127. {
  128. DialogResult = dialogResult;
  129. }
  130. }
  131. }