Cocoa: Fixed the issue of calling reloadData in NSTableView triggering OnChange

TListView / TListBox / TCheckListBox
This commit is contained in:
rich2014 2024-11-08 00:37:49 +08:00
parent 2e21040755
commit 253c6b1be6
2 changed files with 15 additions and 0 deletions

View File

@ -80,6 +80,7 @@ type
iconSize: NSSize;
callback: TLCLListControlCallback;
selectingByProgram: Boolean;
dontSendOnChangeMessage: Boolean;
readOnly: Boolean;
isOwnerDraw : Boolean;
isDynamicRowHeight: Boolean;
@ -672,8 +673,10 @@ begin
if NOT Assigned(self.callback) then
Exit;
self.dontSendOnChangeMessage:= True;
selection:= self.callback.selectionIndexSet;
self.selectRowIndexesByProgram( selection );
self.dontSendOnChangeMessage:= False;
end;
procedure TCocoaTableListView.reloadData;
@ -685,6 +688,12 @@ begin
inherited reloadData;
_processor.onReloadData( self );
// 1. the first step is here
// synchronously restore the selection immediately after calling reloadData()
// 2. the second step is elsewhere
// the selection will be restored asynchronously after reloadData actually takes effect.
self.restoreFromStableSelection;
end;
procedure TCocoaTableListView.reloadDataForRow_column(ARow, ACol: NSInteger);
@ -2030,6 +2039,9 @@ begin
selectionIndexSet.addIndexes( tv.selectedRowIndexes );
end;
if cocoaTLV.dontSendOnChangeMessage then
Exit;
NewSel := cocoaTLV.selectedRow();
sendSelectionChangedMsgToLCL( lclListView, NewSel, ad, rm );
end;

View File

@ -2500,6 +2500,9 @@ begin
lclcb.selectionIndexSet.addIndexes( tv.selectedRowIndexes );
end;
if cocoaTLV.dontSendOnChangeMessage then
Exit;
// do not notify about selection changes while clearing
if Assigned(lclcb.strings) and (lclcb.strings.isClearing) then Exit;
SendSimpleMessage(lclListBox, LM_SELCHANGE);