// // AutoSaveFileItem.m // PDF Reader Pro Edition // // Created by Niehaoyu on 2023/08/15. // #import "AutoSaveFileItem.h" #import @interface AutoSaveFileItem () @property (assign) IBOutlet NSView *contendView; @property (assign) IBOutlet NSTextField *pathLbl; @property (assign) IBOutlet NSTextField *dateLbl; @property (assign) IBOutlet NSButton *checkBtn; @property (assign) IBOutlet NSView *headerLineView1; @property (assign) IBOutlet NSView *headerLineView2; @property (assign) IBOutlet NSView *headerLineView3; @end @implementation AutoSaveFileItem - (void)viewDidLoad { [super viewDidLoad]; // Do view setup here. self.headerLineView1.wantsLayer = self.headerLineView2.wantsLayer = self.headerLineView3.wantsLayer = YES; } - (void)setFilePath:(NSString *)filePath { _filePath = filePath; NSDictionary *attrib = [[NSFileManager defaultManager] attributesOfItemAtPath:_filePath error:nil]; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm"]; self.pathLbl.stringValue = _filePath.lastPathComponent?:@""; self.dateLbl.stringValue = [dateFormatter stringFromDate:[attrib objectForKey:NSFileModificationDate]]?:@""; if ([[AutoSaveManager manager].opendPaths containsObject:_filePath]) { self.checkBtn.state = NSControlStateValueOn; } else { self.checkBtn.state = NSControlStateValueOff; } if ([KMAppearance isDarkMode]) { 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; } else { 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; } self.pathLbl.toolTip = _filePath.lastPathComponent?:@""; } #pragma mark - IBAction - (IBAction)checkBtnAction:(NSButton *)sender { if (self.checkBtn.state == NSControlStateValueOn) { if (![[AutoSaveManager manager].opendPaths containsObject:self.filePath]) { [[AutoSaveManager manager].opendPaths addObject:self.filePath]; } } else { if ([[AutoSaveManager manager].opendPaths containsObject:self.filePath]) { [[AutoSaveManager manager].opendPaths removeObject:self.filePath]; } } if (self.stateHandle) { self.stateHandle(); } self.filePath = self.filePath; } @end