@@ -98,7 +98,9 @@ - (void)awakeFromNib {
9898 [self .tableView registerForDraggedTypes: [NSArray arrayWithObject: NSStringPboardType ]];
9999
100100 [self setTaskListFont ];
101-
101+
102+ [self setTableWidthToWidthOfContents ];
103+
102104 // Observe array controller selection to update "selected tasks" count in status bar
103105 [self .arrayController addObserver: self forKeyPath: @" selection" options: NSKeyValueObservingOptionNew context: nil ];
104106
@@ -110,6 +112,44 @@ - (void)awakeFromNib {
110112 forKeyPath: @" levelsOfUndo"
111113 options: NSKeyValueObservingOptionNew
112114 context: nil ];
115+
116+ // Observe NSUserDefaults to update filter-related preferences
117+ [[NSUserDefaults standardUserDefaults ] addObserver: self
118+ forKeyPath: @" filterPredicate1"
119+ options: NSKeyValueObservingOptionNew
120+ context: nil ];
121+ [[NSUserDefaults standardUserDefaults ] addObserver: self
122+ forKeyPath: @" filterPredicate2"
123+ options: NSKeyValueObservingOptionNew
124+ context: nil ];
125+ [[NSUserDefaults standardUserDefaults ] addObserver: self
126+ forKeyPath: @" filterPredicate3"
127+ options: NSKeyValueObservingOptionNew
128+ context: nil ];
129+ [[NSUserDefaults standardUserDefaults ] addObserver: self
130+ forKeyPath: @" filterPredicate4"
131+ options: NSKeyValueObservingOptionNew
132+ context: nil ];
133+ [[NSUserDefaults standardUserDefaults ] addObserver: self
134+ forKeyPath: @" filterPredicate5"
135+ options: NSKeyValueObservingOptionNew
136+ context: nil ];
137+ [[NSUserDefaults standardUserDefaults ] addObserver: self
138+ forKeyPath: @" filterPredicate6"
139+ options: NSKeyValueObservingOptionNew
140+ context: nil ];
141+ [[NSUserDefaults standardUserDefaults ] addObserver: self
142+ forKeyPath: @" filterPredicate7"
143+ options: NSKeyValueObservingOptionNew
144+ context: nil ];
145+ [[NSUserDefaults standardUserDefaults ] addObserver: self
146+ forKeyPath: @" filterPredicate8"
147+ options: NSKeyValueObservingOptionNew
148+ context: nil ];
149+ [[NSUserDefaults standardUserDefaults ] addObserver: self
150+ forKeyPath: @" filterPredicate9"
151+ options: NSKeyValueObservingOptionNew
152+ context: nil ];
113153}
114154
115155- (NSString *)windowNibName {
@@ -495,7 +535,8 @@ - (void)refreshTaskListWithSave:(BOOL)saveToFile {
495535 [self .arrayController rearrangeObjects ];
496536 // Reload table.
497537 [self .tableView reloadData ];
498-
538+ [self setTableWidthToWidthOfContents ];
539+
499540 // re-set selected items
500541 [self setTaskListSelections: taskListSelectedItemsList];
501542
@@ -517,6 +558,7 @@ - (IBAction)visualRefreshOnly:(id)sender {
517558 [self setTaskListFont ];
518559 [self reapplyActiveFilterPredicate ];
519560 [self .tableView reloadData ];
561+ [self setTableWidthToWidthOfContents ];
520562 [self updateTaskListMetadata ];
521563}
522564
@@ -1442,14 +1484,60 @@ - (IBAction)hideTasklistMetadata:(id)sender {
14421484- (void )observeValueForKeyPath : (NSString *)keyPath ofObject : (id )object change : (NSDictionary *)change context : (void *)context {
14431485 if ([keyPath isEqualToString: @" selection" ]) {
14441486 [self updateStatusBarText ];
1487+ return ;
14451488 }
14461489
14471490 if ([keyPath isEqualToString: @" searchFieldPredicate" ]) {
14481491 [self reapplyActiveFilterPredicate ];
1492+ return ;
14491493 }
14501494
14511495 if ([keyPath isEqualToString: @" levelsOfUndo" ]) {
14521496 [self .undoManager setLevelsOfUndo: [[NSUserDefaults standardUserDefaults ] integerForKey: @" levelsOfUndo" ]];
1497+ return ;
1498+ }
1499+
1500+ if ([keyPath isEqualToString: @" filterPredicate1" ]) {
1501+ [self visualRefreshIfFilterChangedAtPreset: 1 ];
1502+ return ;
1503+ }
1504+ if ([keyPath isEqualToString: @" filterPredicate2" ]) {
1505+ [self visualRefreshIfFilterChangedAtPreset: 2 ];
1506+ return ;
1507+ }
1508+ if ([keyPath isEqualToString: @" filterPredicate3" ]) {
1509+ [self visualRefreshIfFilterChangedAtPreset: 3 ];
1510+ return ;
1511+ }
1512+ if ([keyPath isEqualToString: @" filterPredicate4" ]) {
1513+ [self visualRefreshIfFilterChangedAtPreset: 4 ];
1514+ return ;
1515+ }
1516+ if ([keyPath isEqualToString: @" filterPredicate5" ]) {
1517+ [self visualRefreshIfFilterChangedAtPreset: 5 ];
1518+ return ;
1519+ }
1520+ if ([keyPath isEqualToString: @" filterPredicate6" ]) {
1521+ [self visualRefreshIfFilterChangedAtPreset: 6 ];
1522+ return ;
1523+ }
1524+ if ([keyPath isEqualToString: @" filterPredicate7" ]) {
1525+ [self visualRefreshIfFilterChangedAtPreset: 7 ];
1526+ return ;
1527+ }
1528+ if ([keyPath isEqualToString: @" filterPredicate8" ]) {
1529+ [self visualRefreshIfFilterChangedAtPreset: 8 ];
1530+ return ;
1531+ }
1532+ if ([keyPath isEqualToString: @" filterPredicate9" ]) {
1533+ [self visualRefreshIfFilterChangedAtPreset: 9 ];
1534+
1535+ }
1536+ }
1537+
1538+ - (void )visualRefreshIfFilterChangedAtPreset : (int )presentNumber {
1539+ if (self.activeFilterPredicateNumber == presentNumber) {
1540+ [self visualRefreshOnly: self ];
14531541 }
14541542}
14551543
@@ -1477,4 +1565,28 @@ - (IBAction)toggleStatusBarVisability:(id)sender {
14771565 [self setStatusBarVisable: !self .statusBarVisable];
14781566}
14791567
1568+ // MARK - Column resizing methods
1569+
1570+ - (void )setTableWidthToWidthOfContents {
1571+ CGFloat currentWidth = self.tableView .tableColumns .lastObject .width ;
1572+ CGFloat tableContentWidth = [self tableViewContentWidth ];
1573+ [self .tableView.tableColumns.lastObject setMinWidth: tableContentWidth];
1574+ if (currentWidth > tableContentWidth) {
1575+ [self .tableView.tableColumns.lastObject setWidth: tableContentWidth];
1576+ }
1577+ }
1578+
1579+ - (CGFloat)tableViewContentWidth {
1580+ NSTableView * tableView = self.tableView ;
1581+ NSRect rect = NSMakeRect (0 ,0 , INFINITY, tableView.rowHeight );
1582+ NSInteger columnIndex = 0 ;
1583+ CGFloat maxSize = 0 ;
1584+ for (NSInteger i = 0 ; i < tableView.numberOfRows ; i++) {
1585+ NSCell *cell = [tableView preparedCellAtColumn: columnIndex row: i];
1586+ NSSize size = [cell cellSizeForBounds: rect];
1587+ maxSize = MAX (maxSize, size.width );
1588+ }
1589+ return maxSize;
1590+ }
1591+
14801592@end
0 commit comments