Fix wxDataViewColumn::SetSortOrder() under macOS

Don't check if we already sort by the column in SetSortOrder() as this
meant the sort order couldn't be changed programmatically at all.

Closes #15405.
This commit is contained in:
Hartwig Wiesmann 2018-02-03 21:03:49 +01:00 committed by Vadim Zeitlin
parent 6c9ced9be2
commit 43c1baf1bd
2 changed files with 19 additions and 14 deletions

View File

@ -282,6 +282,7 @@ wxOSX:
- Fix selecting RGB bitmaps (with no alpha channel) into wxMemoryDC.
- Fix updating radio groups when menu item is inserted/removed from wxMenu.
- Allow changing alignment styles after wxTextCtrl creation (Andreas Falkenhahn).
- Fix wxDataViewColumn::SetSortOrder() (hartwigw).
wxQt

View File

@ -3513,23 +3513,27 @@ void wxDataViewColumn::SetSortable(bool sortable)
void wxDataViewColumn::SetSortOrder(bool ascending)
{
if (m_ascending != ascending)
NSTableColumn* const tableColumn = m_NativeDataPtr->GetNativeColumnPtr();
NSTableView* tableView = [tableColumn tableView];
wxCHECK_RET( tableView, wxS("Column has to be associated with a table view when the sorting order is set") );
if ( (m_ascending != ascending) || ([tableColumn sortDescriptorPrototype] == nil) )
{
m_ascending = ascending;
if (IsSortKey())
{
// change sorting order:
NSArray* sortDescriptors;
NSSortDescriptor* sortDescriptor;
NSTableColumn* tableColumn;
tableColumn = m_NativeDataPtr->GetNativeColumnPtr();
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[[tableColumn sortDescriptorPrototype] key] ascending:m_ascending];
sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[tableColumn setSortDescriptorPrototype:sortDescriptor];
[[tableColumn tableView] setSortDescriptors:sortDescriptors];
[sortDescriptor release];
}
// change sorting order for the native implementation (this will
// trigger a call to outlineView:sortDescriptorsDidChange: where the
// wxWidget's sort descriptors are going to be set):
NSSortDescriptor* const
sortDescriptor = [[NSSortDescriptor alloc]
initWithKey:[NSString stringWithFormat:@"%ld",(long)[tableView columnWithIdentifier:[tableColumn identifier]]]
ascending:m_ascending];
NSArray* sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[tableColumn setSortDescriptorPrototype:sortDescriptor];
[tableView setSortDescriptors:sortDescriptors];
[sortDescriptor release];
}
}