KMPDFMergeFileNameTabelViewCell.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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. [self updatePageRange:pageRange pageStrings:pageStrings isFirstResponser:YES];
  100. }
  101. - (void)updatePageRange:(KMPDFSelectPageStringType)pageRange pageStrings:(NSString *)pageStrings isFirstResponser:(BOOL)isFirstResponser {
  102. if (pageRange == KMPDFSeleectPageType_AllPages) {
  103. self.comboBox.stringValue = NSLocalizedString(@"All Pages", nil);
  104. self.comboBox.editable = false;
  105. } else if (pageRange == KMPDFSeleectPageType_OnlyOdd) {
  106. self.comboBox.stringValue = NSLocalizedString(@"Odd Pages", nil);
  107. self.comboBox.editable = false;
  108. } else if (pageRange == KMPDFSeleectPageType_OnlyEven) {
  109. self.comboBox.stringValue = NSLocalizedString(@"Even Pages", nil);
  110. self.comboBox.editable = false;
  111. } else {
  112. self.comboBox.stringValue = pageStrings;
  113. self.comboBox.editable = YES;
  114. if (isFirstResponser) {
  115. if (![self.window.firstResponder isEqual:self.comboBox.textField]) {
  116. if ([NSThread isMainThread]) {
  117. [self.window makeFirstResponder:self.comboBox.textField];
  118. } else {
  119. dispatch_async(dispatch_get_main_queue(), ^{
  120. [self.window makeFirstResponder:self.comboBox.textField];
  121. });
  122. }
  123. }
  124. }
  125. }
  126. }
  127. - (void)updateRageRangeState:(NSInteger)state {
  128. if (state == 9) {
  129. self.comboBox.state = KMDesignTokenStateError_def;
  130. } else if (state == 10) {
  131. self.comboBox.state = KMDesignTokenStateError_focus;
  132. }
  133. }
  134. - (void)layout {
  135. [super layout];
  136. CGFloat width = NSWidth(self.bounds);
  137. CGFloat height = NSHeight(self.bounds);
  138. CGFloat comboBoxH = 26;
  139. self.comboBox.view.frame = NSMakeRect(10, (height-comboBoxH)*0.5, width-10, comboBoxH);
  140. }
  141. #pragma mark - KMSelectPopButtonDelegate
  142. - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {
  143. if (self.callback) {
  144. NSInteger index = obj.indexOfSelectedItem;
  145. if (index < 0) {
  146. index = 0;
  147. }
  148. if (index == self.comboBox.numberOfItems-1) {
  149. self.comboBox.editable = true;
  150. dispatch_async(dispatch_get_main_queue(), ^{
  151. self.comboBox.stringValue = @"";
  152. });
  153. [self.window makeFirstResponder:self.comboBox.textField];
  154. } else {
  155. self.comboBox.editable = false;
  156. }
  157. self.callback(index);
  158. }
  159. }
  160. - (void)km_controlTextDidChange:(KMDesignSelect *)obj {
  161. if (self.textDidChange) {
  162. self.textDidChange(obj.stringValue);
  163. }
  164. }
  165. - (void)km_controlTextDidEndEditing:(KMDesignSelect *)obj {
  166. if (self.textDidEndEdit) {
  167. self.textDidEndEdit(obj.stringValue, self);
  168. }
  169. }
  170. - (void)km_SelectPopoverWillShow:(KMDesignSelect *)obj {
  171. if ([self.comboBox isEqual:obj]) {
  172. NSMutableArray *disableItems = [NSMutableArray array];
  173. if (self.pageCount <= 1) {
  174. [disableItems addObject:NSLocalizedString(@"Even Pages", nil)];
  175. }
  176. self.comboBox.disItems = disableItems.copy;
  177. }
  178. }
  179. #pragma mark - Getting
  180. - (KMDesignSelect *)comboBox {
  181. if (!_comboBox) {
  182. _comboBox = [[KMMergeSelect alloc] initWithType:1];
  183. }
  184. return _comboBox;
  185. }
  186. @end
  187. @interface KMPDFMergeSizeTabelViewCell ()
  188. @property (nonatomic, strong) NSTextField *label;
  189. @property (nonatomic, strong) NSButton *button;
  190. @end
  191. @implementation KMPDFMergeSizeTabelViewCell
  192. - (instancetype)initWithFrame:(NSRect)frameRect {
  193. if (self = [super initWithFrame:frameRect]) {
  194. [self addSubview:self.label];
  195. [self addSubview:self.button];
  196. self.button.target = self;
  197. self.button.action = @selector(buttonAction);
  198. }
  199. return self;
  200. }
  201. - (BOOL)isFlipped {
  202. return YES;
  203. }
  204. - (void)layout {
  205. [super layout];
  206. CGFloat height = NSHeight(self.bounds);
  207. CGFloat labelH = 22;
  208. self.label.frame = NSMakeRect(16, (height-labelH)*0.5, 70, labelH);
  209. CGFloat buttonSize = 20;
  210. self.button.frame = NSMakeRect(NSMaxX(self.label.frame)+5, (height-buttonSize)*0.5, buttonSize, buttonSize);
  211. }
  212. - (void)buttonAction {
  213. if (self.callback) {
  214. self.callback();
  215. }
  216. }
  217. #pragma mark - Getting
  218. - (NSTextField *)label {
  219. if (!_label) {
  220. _label = [NSTextField labelWithString:@""];
  221. _label.textColor = [NSColor colorWithRed:148/255.f green:152/255.f blue:156/255.f alpha:1.f];
  222. _label.font = [NSFont fontWithName:@"SFProText-Regular" size:14];
  223. }
  224. return _label;
  225. }
  226. - (NSButton *)button {
  227. if (!_button) {
  228. _button = [[NSButton alloc] init];
  229. _button.bordered = false;
  230. _button.image = [NSImage imageNamed:@"KMImageNameSecureClearIcon"];
  231. }
  232. return _button;
  233. }
  234. @end