AutoSaveFileItem.m 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // AutoSaveFileItem.m
  3. // PDF Reader Pro Edition
  4. //
  5. // Created by Niehaoyu on 2023/08/15.
  6. //
  7. #import "AutoSaveFileItem.h"
  8. #import <PDF_Reader_Pro-Swift.h>
  9. @interface AutoSaveFileItem ()
  10. @property (assign) IBOutlet NSView *contendView;
  11. @property (assign) IBOutlet NSTextField *pathLbl;
  12. @property (assign) IBOutlet NSTextField *dateLbl;
  13. @property (assign) IBOutlet NSButton *checkBtn;
  14. @property (assign) IBOutlet NSView *headerLineView1;
  15. @property (assign) IBOutlet NSView *headerLineView2;
  16. @property (assign) IBOutlet NSView *headerLineView3;
  17. @end
  18. @implementation AutoSaveFileItem
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do view setup here.
  22. self.headerLineView1.wantsLayer = self.headerLineView2.wantsLayer = self.headerLineView3.wantsLayer = YES;
  23. }
  24. - (void)setFilePath:(NSString *)filePath {
  25. _filePath = filePath;
  26. NSDictionary *attrib = [[NSFileManager defaultManager] attributesOfItemAtPath:_filePath error:nil];
  27. NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
  28. [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm"];
  29. self.pathLbl.stringValue = _filePath.lastPathComponent?:@"";
  30. self.dateLbl.stringValue = [dateFormatter stringFromDate:[attrib objectForKey:NSFileModificationDate]]?:@"";
  31. if ([[AutoSaveManager manager].opendPaths containsObject:_filePath]) {
  32. self.checkBtn.state = NSControlStateValueOn;
  33. } else {
  34. self.checkBtn.state = NSControlStateValueOff;
  35. }
  36. if ([KMAppearance isDarkMode]) {
  37. self.headerLineView1.layer.backgroundColor = self.headerLineView2.layer.backgroundColor = self.headerLineView3.layer.backgroundColor = [NSColor colorWithRed:62/255. green:62/255. blue:62/255. alpha:1.].CGColor;
  38. } else {
  39. self.headerLineView1.layer.backgroundColor = self.headerLineView2.layer.backgroundColor = self.headerLineView3.layer.backgroundColor = [NSColor colorWithRed:218/255. green:219/255. blue:222/255. alpha:1.].CGColor;
  40. }
  41. self.pathLbl.toolTip = _filePath.lastPathComponent?:@"";
  42. }
  43. #pragma mark - IBAction
  44. - (IBAction)checkBtnAction:(NSButton *)sender {
  45. if (self.checkBtn.state == NSControlStateValueOn) {
  46. if (![[AutoSaveManager manager].opendPaths containsObject:self.filePath]) {
  47. [[AutoSaveManager manager].opendPaths addObject:self.filePath];
  48. }
  49. } else {
  50. if ([[AutoSaveManager manager].opendPaths containsObject:self.filePath]) {
  51. [[AutoSaveManager manager].opendPaths removeObject:self.filePath];
  52. }
  53. }
  54. if (self.stateHandle) {
  55. self.stateHandle();
  56. }
  57. self.filePath = self.filePath;
  58. }
  59. @end