Skip to content

Commit

Permalink
feat(list): separators should not be auto-sorted #135
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadorbs committed Oct 7, 2024
1 parent 1ea24e2 commit d46407f
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions Library/VirtualTree.Events.pas
Original file line number Diff line number Diff line change
Expand Up @@ -428,21 +428,60 @@ procedure TVirtualTreeEvents.DoCompareNodesList(Sender: TBaseVirtualTree; Node1,
Node2: PVirtualNode; Column: TColumnIndex; var Result: Integer);
var
Data1, Data2: TvBaseNodeData;
NodeIter1, NodeIter2: PVirtualNode;
IsInSameBlock: Boolean;

function FindPreviousSeparator(Node: PVirtualNode): PVirtualNode;
var
Data: TvBaseNodeData;
begin
Result := Node;

while (Assigned(Result)) do
begin
Data := TVirtualTreeMethods.GetNodeItemData(Result, Sender);

Assert(Assigned(Data));

if Data.IsSeparatorItem then
Exit;

Result := Result.PrevSibling;
end;

Result := nil;
end;

begin
Data1 := TVirtualTreeMethods.GetNodeItemData(Node1, Sender);
Data2 := TVirtualTreeMethods.GetNodeItemData(Node2, Sender);
if (Not Assigned(Data1)) or (Not Assigned(Data2)) then

Assert(Assigned(Data1));
Assert(Assigned(Data2));

if Data1.IsSeparatorItem or Data2.IsSeparatorItem then
Result := 0
else
if (Data1.IsCategoryItem) <> (Data2.IsCategoryItem) then
else begin
NodeIter1 := FindPreviousSeparator(Node1);
NodeIter2 := FindPreviousSeparator(Node2);

IsInSameBlock := (NodeIter1 = NodeIter2);

if IsInSameBlock then
begin
if Data1.IsCategoryItem then
Result := -1
if (Data1.IsCategoryItem) <> (Data2.IsCategoryItem) then
begin
if Data1.IsCategoryItem then
Result := -1
else
Result := 1;
end
else
Result := 1
Result := CompareText(Data1.Name, Data2.Name);
end
else
Result := CompareText(Data1.Name, Data2.Name);
Result := 0;
end;
end;

procedure TVirtualTreeEvents.DoDragDrop(Sender: TBaseVirtualTree;
Expand Down

0 comments on commit d46407f

Please sign in to comment.