FileGridListWithPageRangeControl.xaml.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using ComPDFKit.PDFDocument;
  2. using Compdfkit_Tools.Common;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.Linq;
  8. using System.Runtime.CompilerServices;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Forms;
  16. using System.Windows.Input;
  17. using System.Windows.Media;
  18. using System.Windows.Media.Imaging;
  19. using System.Windows.Navigation;
  20. using System.Windows.Shapes;
  21. using UserControl = System.Windows.Controls.UserControl;
  22. namespace Compdfkit_Tools.PDFControl
  23. {
  24. /// <summary>
  25. /// Interaction logic for FileGridListWithPageRangeControl.xaml
  26. /// </summary>
  27. public partial class FileGridListWithPageRangeControl : UserControl, INotifyPropertyChanged
  28. {
  29. public static readonly DependencyProperty IsEnsureProperty =
  30. DependencyProperty.Register(nameof(IsEnsure), typeof(bool), typeof(FileGridListWithPageRangeControl), new PropertyMetadata(false));
  31. public bool IsEnsure
  32. {
  33. get => (bool)GetValue(IsEnsureProperty);
  34. private set
  35. {
  36. SetValue(IsEnsureProperty, value);
  37. }
  38. }
  39. private int _fileNumText;
  40. public int FileNumText
  41. {
  42. get => _fileNumText;
  43. set
  44. {
  45. if (UpdateProper(ref _fileNumText, value))
  46. IsEnsure = _fileNumText > 0;
  47. }
  48. }
  49. private ObservableCollection<CPDFDocument> _fileInfoDataList;
  50. public ObservableCollection<CPDFDocument> FileInfoDataList
  51. {
  52. get { return _fileInfoDataList; }
  53. set
  54. {
  55. _fileInfoDataList = value;
  56. _fileInfoDataList.CollectionChanged += (sender, args) =>
  57. {
  58. FileNumText = _fileInfoDataList.Count;
  59. };
  60. }
  61. }
  62. public FileGridListWithPageRangeControl()
  63. {
  64. InitializeComponent();
  65. }
  66. public event PropertyChangedEventHandler PropertyChanged;
  67. protected virtual void OnPropertyChanged(string propertyName = null)
  68. {
  69. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  70. }
  71. protected bool UpdateProper<T>(ref T properValue,
  72. T newValue,
  73. [CallerMemberName] string properName = "")
  74. {
  75. if (object.Equals(properValue, newValue))
  76. return false;
  77. properValue = newValue;
  78. OnPropertyChanged(properName);
  79. return true;
  80. }
  81. private void AddFilesBtn_Click(object sender, RoutedEventArgs e)
  82. {
  83. var dialog = new OpenFileDialog();
  84. dialog.Multiselect = true;
  85. dialog.Filter = "PDF Files (*.pdf)|*.pdf";
  86. dialog.ShowDialog();
  87. foreach (string filePath in dialog.FileNames)
  88. {
  89. CPDFDocument document = CPDFDocument.InitWithFilePath(filePath);
  90. if (document.IsLocked)
  91. {
  92. PasswordWindow passwordWindow = new PasswordWindow();
  93. passwordWindow.InitWithDocument(document);
  94. passwordWindow.Owner = Window.GetWindow(this);
  95. passwordWindow.PasswordDialog.SetShowText(filePath + " is encrypted.");
  96. passwordWindow.PasswordDialog.SetShowText("Password error");
  97. }
  98. }
  99. }
  100. private void RemoveBtn_Click(object sender, RoutedEventArgs e)
  101. {
  102. }
  103. private void PageRangeBtn_Click(object sender, RoutedEventArgs e)
  104. {
  105. }
  106. }
  107. }