From 28de728f76bfbc8db3a2f77c86e105f6b5df2bc3 Mon Sep 17 00:00:00 2001 From: Damiano Galassi Date: Tue, 24 Nov 2015 16:29:08 +0100 Subject: [PATCH] Use a monospace font variant for the time column, and change the text color when the row is selected. --- .../PropertyView/SBChapterViewController.m | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/Classes/PropertyView/SBChapterViewController.m b/Classes/PropertyView/SBChapterViewController.m index 53beed2..2c91fa2 100755 --- a/Classes/PropertyView/SBChapterViewController.m +++ b/Classes/PropertyView/SBChapterViewController.m @@ -17,15 +17,13 @@ { [super loadView]; - NSMutableParagraphStyle * ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease]; + NSMutableParagraphStyle *ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease]; [ps setHeadIndent: -10.0]; [ps setAlignment:NSRightTextAlignment]; - detailBoldAttr = [[NSDictionary dictionaryWithObjectsAndKeys: - [NSFont boldSystemFontOfSize:11.0], NSFontAttributeName, - ps, NSParagraphStyleAttributeName, - [NSColor grayColor], NSForegroundColorAttributeName, - nil] retain]; + detailBoldAttr = [@{ NSFontAttributeName: [NSFont monospacedDigitSystemFontOfSize:[NSFont smallSystemFontSize] weight:NSFontWeightBold], + NSParagraphStyleAttributeName: ps, + NSForegroundColorAttributeName: [NSColor grayColor] } retain]; chapterTableView.defaultEditingColumn = 1; } @@ -97,6 +95,25 @@ } } +- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex +{ + if ([tableColumn.identifier isEqualToString:@"time"]) { + if ([[tableView selectedRowIndexes] containsIndex:rowIndex]) { + // Without this, the color won't change because + // we are using a attributed string. + NSMutableAttributedString *highlightedString = [[NSMutableAttributedString alloc] initWithAttributedString:[cell attributedStringValue]]; + [highlightedString addAttribute:NSForegroundColorAttributeName value:[NSColor blackColor] range:NSMakeRange(0, [highlightedString length])]; + [cell setAttributedStringValue:highlightedString]; + [highlightedString release]; + + [cell setTextColor:[NSColor blackColor]]; + } + else { + [cell setTextColor:[NSColor grayColor]]; + } + } +} + - (IBAction)removeChapter:(id)sender { NSInteger current_index = [chapterTableView selectedRow]; if (current_index < [track chapterCount]) {