Cocoa: Feature request for ListView SortIndicator
Original Reporter info from Mantis: crlab @neurolabusc1
-
Reporter name: Chris Rorden
Original Reporter info from Mantis: crlab @neurolabusc1
- Reporter name: Chris Rorden
Description:
This is a want not need, as this feature does not exist with Lazarus on Windows or Linux. However, it would make Tables in MacOS look more native. It would be great if the Cocoa ListViews could show a SortIndicator at the top of the column used for a sort. Ryan Joseph wrote a skeleton code to implement this (see attached screenshot), and it would be great if this indicated the column that was sorted and the sort direction.
Additional information:
type
TCustomTableHeaderCell = objcclass (NSTableHeaderCell)
listView: TListView;
procedure drawSortIndicatorWithFrame_inView_ascending_priority (cellFrame: NSRect; controlView_: NSView; ascending: boolean; priority: NSInteger); override;
end;
procedure TCustomTableHeaderCell.drawSortIndicatorWithFrame_inView_ascending_priority (cellFrame: NSRect; controlView_: NSView; ascending: boolean; priority: NSInteger);
begin
// manually set the ascending flag to match the current sorting order in the TListView
inherited drawSortIndicatorWithFrame_inView_ascending_priority(cellFrame, controlView_, false{listView.SortDirection=sdAscending}, priority);
end;
class procedure TCocoaWSCustomListView.ColumnInsert(const ALV: TCustomListView;
const AIndex: Integer; const AColumn: TListColumn);
var
lTableLV: TCocoaTableListView;
lNSColumn: NSTableColumn;
lTitle: NSString;
sc: TCocoaListView;
begin
{$IFDEF COCOA_DEBUG_LISTVIEW}
WriteLn(Format('[TCocoaWSCustomListView.ColumnInsert] ALV=%x AIndex=%d', [PtrInt(ALV), AIndex]));
{$ENDIF}
ALV.HandleNeeded();
//if not Assigned(ALV) or not ALV.HandleAllocated then Exit;
//lTableLV := TCocoaTableListView(TCocoaListView(ALV.Handle).documentView);
if not CheckParams(sc, lTableLV, ALV) then Exit;
{$IFDEF COCOA_DEBUG_LISTVIEW}
WriteLn(Format('[TCocoaWSCustomListView.ColumnInsert]=> tableColumns.count=%d', [lTableLV.tableColumns.count()]));
{$ENDIF}
if (AIndex < 0) or (AIndex >= lTableLV.tableColumns.count()+1) then Exit;
lTitle := NSStringUTF8(AColumn.Caption);
lNSColumn := NSTableColumn.alloc.initWithIdentifier(lTitle);
// set custom header cell
lNSColumn.setHeaderCell(TCustomTableHeaderCell.alloc.init);
lNSColumn.headerCell.setStringValue(lTitle);
// set a reference to the TListView but I'm not sure how
TCustomTableHeaderCell(lNSColumn.headerCell).listView := nil;
// set the NSSortDescriptor so NSTableView draws the arrows
lNSColumn.setSortDescriptorPrototype(NSSortDescriptor.sortDescriptorWithKey_ascending(lNSColumn.identifier, true));
lNSColumn.setResizingMask(NSTableColumnUserResizingMask);
lTableLV.addTableColumn(lNSColumn);
lTitle.release;
end;
Mantis conversion info:
- Mantis ID: 36281
- OS: Darwin
- OS Build: 10.11.6
- Build: 62218
- Platform: MacBook 2012 Retina 13"
- Version: 2.0.7 (SVN)
- Fixed in revision: 62567 (#556c5562)