CPDFBookmarkAddUI.xaml.cs 3.3 KB

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