CPDFPageInsertWindow.xaml.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. }
  43. private void CPDFPageInsertUI_Unloaded(object sender, RoutedEventArgs e)
  44. {
  45. CPDFPageInsertUI.InsertTypeChanged -= CPDFPageInsertUI_InsertTypeChanged;
  46. CPDFPageInsertUI.SelectedFileChanged -= CPDFPageInsertUI_SelectedFileChanged;
  47. CPDFPageInsertUI.InsertIndexChanged -= CPDFPageInsertUI_InsertIndexChanged;
  48. CPDFPageInsertUI.TextChanged -= CPDFPageInsertUI_TextChanged;
  49. CPDFPageInsertUI.CancelEvent -= CPDFPageInsertUI_CancelEvent;
  50. CPDFPageInsertUI.InsertEvent -= CPDFPageInsertUI_InsertEvent;
  51. CPDFPageInsertUI.PageSizeChanged -= CPDFPageInsertUI_PageSizeChanged;
  52. CPDFPageInsertUI.PasswordChanged -= CPDFPageInsertUI_PasswordChanged;
  53. }
  54. private void CPDFPageInsertUI_PasswordChanged(object sender, string e)
  55. {
  56. Result.Password = e;
  57. }
  58. private void CPDFPageInsertUI_InsertEvent(object sender, EventArgs e)
  59. {
  60. if (Result.InsertType == InsertType.FromOtherPDF && Result.FilePath == string.Empty)
  61. {
  62. MessageBox.Show(LanguageHelper.DocEditorManager.GetString("Warn_NoFile"),LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.OK, MessageBoxImage.Warning);
  63. return;
  64. }
  65. List<int> pageRangeList = new List<int>();
  66. if (Result.InsertType == InsertType.FromOtherPDF && !CommonHelper.GetPagesInRange(ref pageRangeList, Result.PageRange, CPDFPageInsertUI.MaxIndex, new char[] { ',' }, new char[] { '-' }))
  67. {
  68. MessageBox.Show(LanguageHelper.DocEditorManager.GetString("Warn_PageRange"), LanguageHelper.CommonManager.GetString("Caption_Warning"), MessageBoxButton.OK, MessageBoxImage.Warning);
  69. return;
  70. }
  71. CloseWindow(Result);
  72. }
  73. private void CPDFPageInsertUI_CancelEvent(object sender, EventArgs e)
  74. {
  75. CloseWindow(null);
  76. }
  77. private void CPDFPageInsertUI_TextChanged(object sender, string e)
  78. {
  79. Result.PageRange = e;
  80. }
  81. private void CPDFPageInsertUI_SelectedFileChanged(object sender, string e)
  82. {
  83. Result.FilePath = e;
  84. }
  85. private void CPDFPageInsertUI_InsertTypeChanged(object sender, string e)
  86. {
  87. if (e == "BlankPages")
  88. {
  89. Result.InsertType = InsertType.BlankPages;
  90. }
  91. else if (e == "CustomBlankPages")
  92. {
  93. Result.InsertType = InsertType.CustomBlankPages;
  94. }
  95. else
  96. {
  97. Result.InsertType = InsertType.FromOtherPDF;
  98. }
  99. }
  100. private void CPDFPageInsertUI_InsertIndexChanged(object sender, int e)
  101. {
  102. Result.InsertIndex = e;
  103. }
  104. private void CloseWindow(InsertEventClass dialogResult)
  105. {
  106. DialogClosed?.Invoke(this, new InsertDialogCloseEventArgs(dialogResult));
  107. Close();
  108. }
  109. private void CPDFPageInsertUI_PageSizeChanged(object sender, double[] e)
  110. {
  111. Result.PageWidth = e[0];
  112. Result.PageHeight = e[1];
  113. }
  114. }
  115. public class InsertDialogCloseEventArgs : EventArgs
  116. {
  117. public InsertEventClass DialogResult { get; set; }
  118. public InsertDialogCloseEventArgs(InsertEventClass dialogResult)
  119. {
  120. DialogResult = dialogResult;
  121. }
  122. }
  123. }