Skip to content

Commit

Permalink
Closes Issue #91: ENH: horizontal scrolling for long items.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjdescy committed Aug 11, 2016
1 parent 4298691 commit 262883c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
2 changes: 1 addition & 1 deletion TodoTxtMac/Base.lproj/TTMDocument.xib
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" white="0.33333298560000002" alpha="1" colorSpace="calibratedWhite"/>
</tableHeaderCell>
<textFieldCell key="dataCell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="B31-jc-X0I">
<textFieldCell key="dataCell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" alignment="left" title="Text Cell" id="B31-jc-X0I">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
Expand Down
2 changes: 2 additions & 0 deletions TodoTxtMac/TTMDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,6 @@ typedef enum : NSUInteger {
*/
- (IBAction)toggleStatusBarVisability:(id)sender;

- (void)setTableWidthToWidthOfContents;

@end
32 changes: 30 additions & 2 deletions TodoTxtMac/TTMDocument.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -533,7 +535,8 @@ - (void)refreshTaskListWithSave:(BOOL)saveToFile {
[self.arrayController rearrangeObjects];
// Reload table.
[self.tableView reloadData];

[self setTableWidthToWidthOfContents];

// re-set selected items
[self setTaskListSelections:taskListSelectedItemsList];

Expand All @@ -555,6 +558,7 @@ - (IBAction)visualRefreshOnly:(id)sender {
[self setTaskListFont];
[self reapplyActiveFilterPredicate];
[self.tableView reloadData];
[self setTableWidthToWidthOfContents];
[self updateTaskListMetadata];
}

Expand Down Expand Up @@ -1561,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
10 changes: 10 additions & 0 deletions TodoTxtMac/TTMTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ - (void)translateKeyDownEvent:(NSEvent*)theEvent

#pragma mark - Respond to Changes Methods

- (void)editColumn:(NSInteger)column row:(NSInteger)row withEvent:(NSEvent *)theEvent select:(BOOL)select {
[self.tableColumns.lastObject setMinWidth:0];
[self.tableColumns.lastObject setMaxWidth:self.parentDocument.windowForSheet.frame.size.width];
[self.tableColumns.lastObject setWidth:self.parentDocument.windowForSheet.frame.size.width];


[super editColumn:column row:row withEvent:theEvent select:select];
}

- (void)textDidBeginEditing:(NSNotification*)notification {
[self.parentDocument initializeUpdateSelectedTask];
[super textDidBeginEditing:notification];
Expand All @@ -190,6 +199,7 @@ - (void)textDidEndEditing:(NSNotification*)notification {
// Handle no change.
if (self.selectedRawText == nil ||
[self.selectedRawText isEqualToString:newValue]) {
[self.parentDocument setTableWidthToWidthOfContents];
return;
}

Expand Down
2 changes: 1 addition & 1 deletion TodoTxtMac/TodoTxtMac-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2027</string>
<string>2028</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.productivity</string>
<key>LSMinimumSystemVersion</key>
Expand Down

0 comments on commit 262883c

Please sign in to comment.