KMPDFMergeFileNameTabelViewCell.m 7.4 KB

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