KMPDFMergeFileNameTabelViewCell.m 7.4 KB

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