CPDFBookmarkAddUI.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Globalization;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Data;
  6. using System.Windows.Input;
  7. namespace Compdfkit_Tools.PDFControlUI
  8. {
  9. public partial class CPDFBookmarkAddUI : UserControl
  10. {
  11. public event EventHandler<BookmarkChangeData> BookmarkAddEvent;
  12. public event EventHandler BookmarkInputExpandEvent;
  13. private bool toggleState;
  14. private BookmarkChangeData bookmarkData=new BookmarkChangeData();
  15. public CPDFBookmarkAddUI()
  16. {
  17. InitializeComponent();
  18. }
  19. private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  20. {
  21. toggleState = !toggleState;
  22. BookmarkInputPanel.Visibility=toggleState?Visibility.Visible:Visibility.Collapsed;
  23. if(toggleState)
  24. {
  25. BookmarkInputExpandEvent?.Invoke(this, EventArgs.Empty);
  26. }
  27. }
  28. private void ButtonCancel_Click(object sender, MouseButtonEventArgs e)
  29. {
  30. HideInputUI(true);
  31. }
  32. private void ButtonAdd_Click(object sender, RoutedEventArgs e)
  33. {
  34. if(!string.IsNullOrEmpty(BookmarkText.Text) && bookmarkData!=null)
  35. {
  36. bookmarkData.NewTitle = BookmarkText.Text;
  37. BookmarkAddEvent?.Invoke(this, bookmarkData);
  38. bookmarkData = null;
  39. BookmarkText.Text = string.Empty;
  40. HideInputUI(true);
  41. }
  42. }
  43. public void SetBookmarkChangeData(BookmarkChangeData newChangeData)
  44. {
  45. if(newChangeData!=null)
  46. {
  47. PageNumText.Text = string.Format("Page {0}", newChangeData.PageIndex + 1);
  48. BookmarkText.Text = newChangeData.BookmarkTitle;
  49. BookmarkText.Focus();
  50. BookmarkText.SelectAll();
  51. }
  52. bookmarkData=newChangeData;
  53. }
  54. public void HideInputUI(bool isHide)
  55. {
  56. toggleState = !isHide;
  57. BookmarkInputPanel.Visibility = isHide? Visibility.Collapsed:Visibility.Visible;
  58. }
  59. private void DeleteBorder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  60. {
  61. BookmarkText.Text = string.Empty;
  62. }
  63. }
  64. internal class BoolEnableConvert : IValueConverter
  65. {
  66. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  67. {
  68. if (value == null)
  69. {
  70. return false;
  71. }
  72. else
  73. {
  74. try
  75. {
  76. if (value is string)
  77. {
  78. string checkValue=value as string;
  79. if(checkValue.Length>0)
  80. {
  81. return true;
  82. }
  83. }
  84. }
  85. catch(Exception ex)
  86. {
  87. }
  88. return false;
  89. }
  90. }
  91. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. }
  96. }