View Issue Details

IDProjectCategoryView StatusLast Update
0036281LazarusWidgetsetpublic2019-11-07 21:22
ReporterChris RordenAssigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
PlatformMacBook 2012 Retina 13"OSDarwinOS Version10.11.6
Product Version2.0.7 (SVN)Product Build62218 
Target VersionFixed in Version 
Summary0036281: Cocoa: Feature request for ListView SortIndicator
DescriptionThis 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 Informationtype
  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;
TagsNo tags attached.
Fixed in Revision
LazTarget
WidgetsetCocoa
Attached Files

Activities

Chris Rorden

2019-11-07 21:22

reporter  

sort.png (5,218 bytes)
sort.png (5,218 bytes)

Issue History

Date Modified Username Field Change
2019-11-07 21:22 Chris Rorden New Issue
2019-11-07 21:22 Chris Rorden File Added: sort.png