Question

The truncation can be easily set for the main text area but the popup does not do any truncation, with similar paths, users cannot tell which path is which.

or is the a way to change the width of the popup list to match the longest string so that truncation is not needed?

Was it helpful?

Solution

There is no official way to do this, unfortunately.

There is a way to do it which, though it doesn’t use any private methods, relies on the way NSComboBoxes are implemented internally, and that could change at any time. This would probably would not be acceptable in the App Store.

If you subclass NSComboBoxCell and implement the NSTableViewDelegate method tableView:willDisplayCell:forTableColumn:row:, you can modify the text cell before it is displayed in the combo box’s popup window.

- (void)tableView:(NSTableView *)tableView
        willDisplayCell:(NSCell *)cell
        forTableColumn:(NSTableColumn *)tableColumn
        row:(NSInteger)rowIndex
{
   [cell setTruncatesLastVisibleLine:YES];
   [cell setLineBreakMode:NSLineBreakByTruncatingMiddle];
}

This works because the popup list is implemented internally with an NSTableView, and the table view’s delegate is set to the popup cell.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top