KMPDFMergeFileNameTabelViewCell.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //
  2. // KMPDFMergeFileNameTabelViewCell.m
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2023/2/23.
  6. //
  7. #import "KMPDFMergeFileNameTabelViewCell.h"
  8. #import <PDF_Master-Swift.h>
  9. @interface KMPDFMergeFileNameTabelViewCell ()
  10. @property (nonatomic, strong) NSTextField *numberLabel;
  11. @property (nonatomic, strong) NSImageView *iconImageView;
  12. @property (nonatomic, strong) NSTextField *fileNameLabel;
  13. @property (nonatomic, strong) NSTextField *pageNumberLabel;
  14. @end
  15. @implementation KMPDFMergeFileNameTabelViewCell
  16. - (instancetype)initWithFrame:(NSRect)frameRect {
  17. if (self = [super initWithFrame:frameRect]) {
  18. [self addSubview:self.numberLabel];
  19. [self addSubview:self.iconImageView];
  20. [self addSubview:self.fileNameLabel];
  21. [self addSubview:self.pageNumberLabel];
  22. }
  23. return self;
  24. }
  25. - (BOOL)isFlipped {
  26. return YES;
  27. }
  28. - (void)layout {
  29. [super layout];
  30. CGFloat width = NSWidth(self.bounds);
  31. CGFloat height = NSHeight(self.bounds);
  32. CGFloat labelH = 22;
  33. self.numberLabel.frame = NSMakeRect(16+16, (height-labelH)*0.5, 30, labelH);
  34. CGFloat iconSize = 60;
  35. self.iconImageView.frame = NSMakeRect(NSMaxX(self.numberLabel.frame)+6, (height-iconSize)*0.5, iconSize, iconSize);
  36. CGFloat fileNameX = NSMaxX(self.iconImageView.frame)+8;
  37. self.fileNameLabel.frame = NSMakeRect(fileNameX, 13, width-fileNameX, labelH);
  38. self.pageNumberLabel.frame = NSMakeRect(fileNameX, NSMaxY(self.fileNameLabel.frame)+8, width-fileNameX, labelH);
  39. }
  40. #pragma mark - Getting
  41. - (NSTextField *)numberLabel {
  42. if (!_numberLabel) {
  43. _numberLabel = [NSTextField labelWithString:@""];
  44. _numberLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
  45. _numberLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14];
  46. }
  47. return _numberLabel;
  48. }
  49. - (NSImageView *)iconImageView {
  50. if (!_iconImageView) {
  51. _iconImageView = [[NSImageView alloc] init];
  52. }
  53. return _iconImageView;
  54. }
  55. - (NSTextField *)fileNameLabel {
  56. if (!_fileNameLabel) {
  57. _fileNameLabel = [NSTextField labelWithString:@""];
  58. _fileNameLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
  59. _fileNameLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14];
  60. _fileNameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  61. }
  62. return _fileNameLabel;
  63. }
  64. - (NSTextField *)pageNumberLabel {
  65. if (!_pageNumberLabel) {
  66. _pageNumberLabel = [NSTextField labelWithString:@""];
  67. _pageNumberLabel.textColor = [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f];
  68. _pageNumberLabel.font = [NSFont fontWithName:@"SFProText-Regular" size:14];
  69. }
  70. return _pageNumberLabel;
  71. }
  72. @end
  73. @interface KMPDFMergePageRangeTabelViewCell ()<KMSelectPopButtonDelegate>
  74. @property (nonatomic, strong) KMMergeSelect *comboBox;
  75. @end
  76. @implementation KMPDFMergePageRangeTabelViewCell
  77. - (instancetype)initWithFrame:(NSRect)frameRect {
  78. if (self = [super initWithFrame:frameRect]) {
  79. [self addSubview:self.comboBox.view];
  80. [self.comboBox removeAllItems];
  81. [self.comboBox addItemsWithObjectValues:@[NSLocalizedString(@"All Pages", nil),NSLocalizedString(@"Odd Pages", nil),NSLocalizedString(@"Even Pages", nil),NSLocalizedString(@"Customized", nil)]];
  82. self.comboBox.stringValue = NSLocalizedString(@"All Pages", nil);
  83. self.comboBox.editable = false;
  84. self.comboBox.delete = self;
  85. self.comboBox.placeholderString = NSLocalizedString(@"eg .1,3-5,10", nil);
  86. }
  87. return self;
  88. }
  89. - (BOOL)isFlipped {
  90. return YES;
  91. }
  92. - (void)updatePageRange:(KMPDFSelectPageStringType)pageRange pageStrings:(nonnull NSString *)pageStrings {
  93. if (pageRange == KMPDFSeleectPageType_AllPages) {
  94. self.comboBox.stringValue = NSLocalizedString(@"All Pages", nil);
  95. } else if (pageRange == KMPDFSeleectPageType_OnlyOdd) {
  96. self.comboBox.stringValue = NSLocalizedString(@"Odd Pages", nil);
  97. } else if (pageRange == KMPDFSeleectPageType_OnlyEven) {
  98. self.comboBox.stringValue = NSLocalizedString(@"Even Pages", nil);
  99. } else {
  100. self.comboBox.stringValue = pageStrings;
  101. }
  102. }
  103. - (void)layout {
  104. [super layout];
  105. CGFloat width = NSWidth(self.bounds);
  106. CGFloat height = NSHeight(self.bounds);
  107. CGFloat comboBoxH = 24;
  108. self.comboBox.view.frame = NSMakeRect(10, (height-comboBoxH)*0.5, width-10, comboBoxH);
  109. }
  110. #pragma mark - KMSelectPopButtonDelegate
  111. - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {
  112. if (self.callback) {
  113. NSInteger index = obj.indexOfSelectedItem;
  114. if (index < 0) {
  115. index = 0;
  116. }
  117. if (index == self.comboBox.numberOfItems-1) {
  118. self.comboBox.editable = true;
  119. dispatch_async(dispatch_get_main_queue(), ^{
  120. self.comboBox.stringValue = @"";
  121. });
  122. [self.window makeFirstResponder:self.comboBox.textField];
  123. } else {
  124. self.comboBox.editable = false;
  125. }
  126. self.callback(index);
  127. }
  128. }
  129. - (void)km_controlTextDidChange:(KMDesignSelect *)obj {
  130. if (self.textDidChange) {
  131. self.textDidChange(obj.stringValue);
  132. }
  133. }
  134. - (void)km_controlTextDidEndEditing:(KMDesignSelect *)obj {
  135. }
  136. - (void)km_SelectPopoverWillShow:(KMDesignSelect *)obj {
  137. if ([self.comboBox isEqual:obj]) {
  138. NSMutableArray *disableItems = [NSMutableArray array];
  139. if (self.pageCount <= 1) {
  140. [disableItems addObject:NSLocalizedString(@"Even Pages", nil)];
  141. }
  142. self.comboBox.disItems = disableItems.copy;
  143. }
  144. }
  145. #pragma mark - Getting
  146. - (KMDesignSelect *)comboBox {
  147. if (!_comboBox) {
  148. _comboBox = [[KMMergeSelect alloc] initWithType:1];
  149. }
  150. return _comboBox;
  151. }
  152. @end
  153. @interface KMPDFMergeSizeTabelViewCell ()
  154. @property (nonatomic, strong) NSTextField *label;
  155. @property (nonatomic, strong) NSButton *button;
  156. @end
  157. @implementation KMPDFMergeSizeTabelViewCell
  158. - (instancetype)initWithFrame:(NSRect)frameRect {
  159. if (self = [super initWithFrame:frameRect]) {
  160. [self addSubview:self.label];
  161. [self addSubview:self.button];
  162. self.button.target = self;
  163. self.button.action = @selector(buttonAction);
  164. }
  165. return self;
  166. }
  167. - (BOOL)isFlipped {
  168. return YES;
  169. }
  170. - (void)layout {
  171. [super layout];
  172. CGFloat height = NSHeight(self.bounds);
  173. CGFloat labelH = 22;
  174. self.label.frame = NSMakeRect(16, (height-labelH)*0.5, 70, labelH);
  175. CGFloat buttonSize = 20;
  176. self.button.frame = NSMakeRect(NSMaxX(self.label.frame)+5, (height-buttonSize)*0.5, buttonSize, buttonSize);
  177. }
  178. - (void)buttonAction {
  179. if (self.callback) {
  180. self.callback();
  181. }
  182. }
  183. #pragma mark - Getting
  184. - (NSTextField *)label {
  185. if (!_label) {
  186. _label = [NSTextField labelWithString:@""];
  187. _label.textColor = [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f];
  188. _label.font = [NSFont fontWithName:@"SFProText-Regular" size:14];
  189. }
  190. return _label;
  191. }
  192. - (NSButton *)button {
  193. if (!_button) {
  194. _button = [[NSButton alloc] init];
  195. _button.bordered = false;
  196. _button.image = [NSImage imageNamed:@"KMImageNameSecureClearIcon"];
  197. }
  198. return _button;
  199. }
  200. @end