diff --git a/TodoTxtMac.xcodeproj/project.pbxproj b/TodoTxtMac.xcodeproj/project.pbxproj index 5bd8ba5..4a6efa0 100644 --- a/TodoTxtMac.xcodeproj/project.pbxproj +++ b/TodoTxtMac.xcodeproj/project.pbxproj @@ -70,6 +70,7 @@ 00D102B61991ABBE00D30237 /* TTMTasklistMetadata.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D102B51991ABBE00D30237 /* TTMTasklistMetadata.m */; }; 00D531271CACA285007EF487 /* TTMTask_IsHidden_UnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D531261CACA285007EF487 /* TTMTask_IsHidden_UnitTests.m */; }; 00D5312A1CACC3C7007EF487 /* TTMPredicateEditorHiddenRowTemplate.m in Sources */ = {isa = PBXBuildFile; fileRef = 00D531291CACC3C7007EF487 /* TTMPredicateEditorHiddenRowTemplate.m */; }; + 00DA4A1D1D5BBEB600CFF2B1 /* TTMPredicateEditorTextRowTemplate.m in Sources */ = {isa = PBXBuildFile; fileRef = 00DA4A1C1D5BBEB600CFF2B1 /* TTMPredicateEditorTextRowTemplate.m */; }; 00EAAB9718E0C168009CBE8C /* TTMPredicateEditorDateRowTemplate.m in Sources */ = {isa = PBXBuildFile; fileRef = 00EAAB9618E0C168009CBE8C /* TTMPredicateEditorDateRowTemplate.m */; }; 00EAAB9A18E1CF79009CBE8C /* TTMPredicateEditorDueRowTemplate.m in Sources */ = {isa = PBXBuildFile; fileRef = 00EAAB9918E1CF79009CBE8C /* TTMPredicateEditorDueRowTemplate.m */; }; 00EAAB9D18E1CF92009CBE8C /* TTMPredicateEditorCompletedRowTemplate.m in Sources */ = {isa = PBXBuildFile; fileRef = 00EAAB9C18E1CF92009CBE8C /* TTMPredicateEditorCompletedRowTemplate.m */; }; @@ -191,6 +192,8 @@ 00D531261CACA285007EF487 /* TTMTask_IsHidden_UnitTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTMTask_IsHidden_UnitTests.m; sourceTree = ""; }; 00D531281CACC3C7007EF487 /* TTMPredicateEditorHiddenRowTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTMPredicateEditorHiddenRowTemplate.h; sourceTree = ""; }; 00D531291CACC3C7007EF487 /* TTMPredicateEditorHiddenRowTemplate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTMPredicateEditorHiddenRowTemplate.m; sourceTree = ""; }; + 00DA4A1B1D5BBEB600CFF2B1 /* TTMPredicateEditorTextRowTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTMPredicateEditorTextRowTemplate.h; sourceTree = ""; }; + 00DA4A1C1D5BBEB600CFF2B1 /* TTMPredicateEditorTextRowTemplate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTMPredicateEditorTextRowTemplate.m; sourceTree = ""; }; 00EAAB9518E0C168009CBE8C /* TTMPredicateEditorDateRowTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTMPredicateEditorDateRowTemplate.h; sourceTree = ""; }; 00EAAB9618E0C168009CBE8C /* TTMPredicateEditorDateRowTemplate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TTMPredicateEditorDateRowTemplate.m; sourceTree = ""; }; 00EAAB9818E1CF79009CBE8C /* TTMPredicateEditorDueRowTemplate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TTMPredicateEditorDueRowTemplate.h; sourceTree = ""; }; @@ -261,6 +264,8 @@ 007B835E1A5A415300A4D5F7 /* TTMPredicateEditorThresholdRowTemplate.m */, 00D531281CACC3C7007EF487 /* TTMPredicateEditorHiddenRowTemplate.h */, 00D531291CACC3C7007EF487 /* TTMPredicateEditorHiddenRowTemplate.m */, + 00DA4A1B1D5BBEB600CFF2B1 /* TTMPredicateEditorTextRowTemplate.h */, + 00DA4A1C1D5BBEB600CFF2B1 /* TTMPredicateEditorTextRowTemplate.m */, ); name = Filters; sourceTree = ""; @@ -586,6 +591,7 @@ 00930EB118B537C10064D41B /* TTMDateUtility.m in Sources */, 00FA1D2818F1EF340066A437 /* FontNameTransformer.m in Sources */, 00D102B61991ABBE00D30237 /* TTMTasklistMetadata.m in Sources */, + 00DA4A1D1D5BBEB600CFF2B1 /* TTMPredicateEditorTextRowTemplate.m in Sources */, 0086C98518B54F1A00A427AA /* TTMTableViewDelegate.m in Sources */, 007B835F1A5A415300A4D5F7 /* TTMPredicateEditorThresholdRowTemplate.m in Sources */, 00B4CBAF18B43E8400313DAA /* TTMDocument.m in Sources */, diff --git a/TodoTxtMac/Base.lproj/TTMDocument.xib b/TodoTxtMac/Base.lproj/TTMDocument.xib index cc5a1c0..d091270 100644 --- a/TodoTxtMac/Base.lproj/TTMDocument.xib +++ b/TodoTxtMac/Base.lproj/TTMDocument.xib @@ -1,5 +1,5 @@ - + @@ -20,12 +20,12 @@ - + - + @@ -53,7 +53,7 @@ - + diff --git a/TodoTxtMac/TTMDocument.h b/TodoTxtMac/TTMDocument.h index 5553e14..4a66455 100644 --- a/TodoTxtMac/TTMDocument.h +++ b/TodoTxtMac/TTMDocument.h @@ -550,4 +550,6 @@ typedef enum : NSUInteger { */ - (IBAction)toggleStatusBarVisability:(id)sender; +- (void)setTableWidthToWidthOfContents; + @end diff --git a/TodoTxtMac/TTMDocument.m b/TodoTxtMac/TTMDocument.m index f4d1261..5acc927 100644 --- a/TodoTxtMac/TTMDocument.m +++ b/TodoTxtMac/TTMDocument.m @@ -98,7 +98,9 @@ - (void)awakeFromNib { [self.tableView registerForDraggedTypes:[NSArray arrayWithObject:NSStringPboardType]]; [self setTaskListFont]; - + + [self setTableWidthToWidthOfContents]; + // Observe array controller selection to update "selected tasks" count in status bar [self.arrayController addObserver:self forKeyPath:@"selection" options:NSKeyValueObservingOptionNew context:nil]; @@ -110,6 +112,44 @@ - (void)awakeFromNib { forKeyPath:@"levelsOfUndo" options:NSKeyValueObservingOptionNew context:nil]; + + // Observe NSUserDefaults to update filter-related preferences + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate1" + options:NSKeyValueObservingOptionNew + context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate2" + options:NSKeyValueObservingOptionNew + context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate3" + options:NSKeyValueObservingOptionNew + context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate4" + options:NSKeyValueObservingOptionNew + context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate5" + options:NSKeyValueObservingOptionNew + context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate6" + options:NSKeyValueObservingOptionNew + context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate7" + options:NSKeyValueObservingOptionNew + context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate8" + options:NSKeyValueObservingOptionNew + context:nil]; + [[NSUserDefaults standardUserDefaults] addObserver:self + forKeyPath:@"filterPredicate9" + options:NSKeyValueObservingOptionNew + context:nil]; } - (NSString *)windowNibName { @@ -495,7 +535,8 @@ - (void)refreshTaskListWithSave:(BOOL)saveToFile { [self.arrayController rearrangeObjects]; // Reload table. [self.tableView reloadData]; - + [self setTableWidthToWidthOfContents]; + // re-set selected items [self setTaskListSelections:taskListSelectedItemsList]; @@ -517,6 +558,7 @@ - (IBAction)visualRefreshOnly:(id)sender { [self setTaskListFont]; [self reapplyActiveFilterPredicate]; [self.tableView reloadData]; + [self setTableWidthToWidthOfContents]; [self updateTaskListMetadata]; } @@ -1442,14 +1484,60 @@ - (IBAction)hideTasklistMetadata:(id)sender { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([keyPath isEqualToString:@"selection"]) { [self updateStatusBarText]; + return; } if ([keyPath isEqualToString:@"searchFieldPredicate"]) { [self reapplyActiveFilterPredicate]; + return; } if ([keyPath isEqualToString:@"levelsOfUndo"]) { [self.undoManager setLevelsOfUndo:[[NSUserDefaults standardUserDefaults] integerForKey:@"levelsOfUndo"]]; + return; + } + + if ([keyPath isEqualToString:@"filterPredicate1"]) { + [self visualRefreshIfFilterChangedAtPreset:1]; + return; + } + if ([keyPath isEqualToString:@"filterPredicate2"]) { + [self visualRefreshIfFilterChangedAtPreset:2]; + return; + } + if ([keyPath isEqualToString:@"filterPredicate3"]) { + [self visualRefreshIfFilterChangedAtPreset:3]; + return; + } + if ([keyPath isEqualToString:@"filterPredicate4"]) { + [self visualRefreshIfFilterChangedAtPreset:4]; + return; + } + if ([keyPath isEqualToString:@"filterPredicate5"]) { + [self visualRefreshIfFilterChangedAtPreset:5]; + return; + } + if ([keyPath isEqualToString:@"filterPredicate6"]) { + [self visualRefreshIfFilterChangedAtPreset:6]; + return; + } + if ([keyPath isEqualToString:@"filterPredicate7"]) { + [self visualRefreshIfFilterChangedAtPreset:7]; + return; + } + if ([keyPath isEqualToString:@"filterPredicate8"]) { + [self visualRefreshIfFilterChangedAtPreset:8]; + return; + } + if ([keyPath isEqualToString:@"filterPredicate9"]) { + [self visualRefreshIfFilterChangedAtPreset:9]; + + } +} + +- (void)visualRefreshIfFilterChangedAtPreset:(int)presentNumber { + if (self.activeFilterPredicateNumber == presentNumber) { + [self visualRefreshOnly:self]; } } @@ -1477,4 +1565,28 @@ - (IBAction)toggleStatusBarVisability:(id)sender { [self setStatusBarVisable:!self.statusBarVisable]; } +// MARK - Column resizing methods + +- (void)setTableWidthToWidthOfContents { + CGFloat currentWidth = self.tableView.tableColumns.lastObject.width; + CGFloat tableContentWidth = [self tableViewContentWidth]; + [self.tableView.tableColumns.lastObject setMinWidth:tableContentWidth]; + if (currentWidth > tableContentWidth) { + [self.tableView.tableColumns.lastObject setWidth:tableContentWidth]; + } +} + +- (CGFloat)tableViewContentWidth { + NSTableView * tableView = self.tableView; + NSRect rect = NSMakeRect(0,0, INFINITY, tableView.rowHeight); + NSInteger columnIndex = 0; + CGFloat maxSize = 0; + for (NSInteger i = 0; i < tableView.numberOfRows; i++) { + NSCell *cell = [tableView preparedCellAtColumn:columnIndex row:i]; + NSSize size = [cell cellSizeForBounds:rect]; + maxSize = MAX(maxSize, size.width); + } + return maxSize; +} + @end diff --git a/TodoTxtMac/TTMFilters.xib b/TodoTxtMac/TTMFilters.xib index 0f72473..2420f1a 100644 --- a/TodoTxtMac/TTMFilters.xib +++ b/TodoTxtMac/TTMFilters.xib @@ -1,32 +1,33 @@ - + - + - - - - - - - - + + + + + + + + + - + - + @@ -49,11 +50,11 @@ - + - - + + @@ -78,7 +79,7 @@ - + rawText @@ -101,6 +102,9 @@ + + + @@ -209,6 +213,9 @@ + + + @@ -546,7 +553,7 @@ - + @@ -560,43 +567,43 @@ - - + + - - - - + + + + - - + + - + - + - + - + - + - + - + - + rawText @@ -605,43 +612,46 @@ - + - + rawText - + - + - + + + + - + - + - + - + - + - + projects @@ -650,43 +660,43 @@ - + - + projects - + - + - + - + - + - + - + - + - + contexts @@ -695,43 +705,43 @@ - + - + contexts - + - + - + - + - + - + - + - + - + priorityText @@ -740,40 +750,40 @@ - + - + priorityText - + - + - + - + - + - + - + - + dueDate @@ -781,40 +791,40 @@ - + - + dueDate - + - + - + - + - + - + - + - + completionDate @@ -822,40 +832,40 @@ - + - + completionDate - + - + - + - + - + - + - + - + creationDate @@ -863,40 +873,40 @@ - + - + creationDate - + - + - + - + - + - + - + - + thresholdDate @@ -904,40 +914,40 @@ - + - + thresholdDate - + - + - + - + - + - + - + - + completed @@ -945,25 +955,25 @@ - + - + completed - + - + - + dueState @@ -971,28 +981,28 @@ - + - + dueState - + - + - + - + thresholdState @@ -1000,28 +1010,28 @@ - + - + thresholdState - + - + - + - + isHidden @@ -1029,18 +1039,18 @@ - + - + isHidden - + - + @@ -1049,7 +1059,7 @@ - + NSKeyedUnarchiveFromData @@ -1059,62 +1069,62 @@ -