KMPDFMergeFileNameTabelViewCell.m 7.3 KB

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