diff --git a/AppKit/CPTableColumn.j b/AppKit/CPTableColumn.j index b0349993d..6a1765cad 100644 --- a/AppKit/CPTableColumn.j +++ b/AppKit/CPTableColumn.j @@ -494,7 +494,13 @@ CPTableColumnUserResizingMask = 1 << 1; */ - (CPSortDescriptor)sortDescriptorPrototype { - return _sortDescriptorPrototype; + if (_sortDescriptorPrototype) + return _sortDescriptorPrototype; + + var binderClass = [[self class] _binderClassForBinding:CPValueBinding], + binding = [binderClass getBinding:CPValueBinding forObject:self]; + + return [binding _defaultSortDescriptorPrototype]; } /*! @@ -570,6 +576,30 @@ CPTableColumnUserResizingMask = 1 << 1; [tableView reloadDataForRowIndexes:rowIndexes columnIndexes:columnIndexes]; } +- (CPSortDescriptor)_defaultSortDescriptorPrototype +{ + if (![self createsSortDescriptor]) + return nil; + + var keyPath = [_info objectForKey:CPObservedKeyPathKey], + dotIndex = keyPath.lastIndexOf("."); + + if (dotIndex === CPNotFound) + return nil; + + var firstPart = keyPath.substring(0, dotIndex), + key = keyPath.substring(dotIndex + 1); + + return [CPSortDescriptor sortDescriptorWithKey:key ascending:YES]; +} + +- (BOOL)createsSortDescriptor +{ + var options = [_info objectForKey:CPOptionsKey], + optionValue = [options objectForKey:CPCreatesSortDescriptorBindingOption]; + return optionValue === nil ? YES : [optionValue boolValue]; +} + @end @implementation CPTableColumn (Bindings)