mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-04 17:00:17 +02:00
LCL: Implement method TreeView.Items.AddNode. Issue #15807
git-svn-id: trunk@33618 -
This commit is contained in:
parent
31e6b3ee9a
commit
78b6a2d026
@ -2341,8 +2341,7 @@ type
|
||||
|
||||
TAddMode = (taAddFirst, taAdd, taInsert);
|
||||
|
||||
TMultiSelectStyles = (msControlSelect, msShiftSelect,
|
||||
msVisibleOnly, msSiblingOnly);
|
||||
TMultiSelectStyles = (msControlSelect, msShiftSelect, msVisibleOnly, msSiblingOnly);
|
||||
TMultiSelectStyle = set of TMultiSelectStyles;
|
||||
|
||||
TTreeNodeArray = ^TTreeNode;
|
||||
@ -2626,6 +2625,7 @@ type
|
||||
FTopLvlCount: integer;
|
||||
FTopLvlItems: TTreeNodeArray; // root and root siblings
|
||||
FUpdateCount: Integer;
|
||||
fNewNodeToBeAdded: TTreeNode;
|
||||
procedure ClearCache;
|
||||
function GetHandle: THandle;
|
||||
function GetNodeFromIndex(Index: Integer): TTreeNode;
|
||||
@ -2665,6 +2665,8 @@ type
|
||||
Data: Pointer): TTreeNode;
|
||||
function AddObjectFirst(SiblingNode: TTreeNode; const S: string;
|
||||
Data: Pointer): TTreeNode;
|
||||
function AddNode(Node: TTreeNode; Relative: TTreeNode; const S: string;
|
||||
Ptr: Pointer; Method: TNodeAttachMode): TTreeNode;
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
procedure BeginUpdate;
|
||||
procedure Clear;
|
||||
|
@ -1393,14 +1393,12 @@ var
|
||||
OldOnChanging: TTVChangingEvent;
|
||||
OldOnChange: TTVChangedEvent;
|
||||
begin
|
||||
if (Destination=nil)
|
||||
and not(Mode in [naAdd,naAddFirst]) then
|
||||
if (Destination=nil) and not(Mode in [naAdd,naAddFirst]) then
|
||||
TreeNodeError('TTreeNode.MoveTo Destination=nil');
|
||||
if Mode=naInsertBehind then begin
|
||||
// convert naInsertBehind
|
||||
if Destination.GetNextSibling=nil then begin
|
||||
Mode:=naAdd;
|
||||
end else begin
|
||||
if Mode=naInsertBehind then begin // convert naInsertBehind
|
||||
if Destination.GetNextSibling=nil then
|
||||
Mode:=naAdd
|
||||
else begin
|
||||
Mode:=naInsert;
|
||||
Destination:=Destination.GetNextSibling;
|
||||
end;
|
||||
@ -1414,11 +1412,9 @@ begin
|
||||
if (Destination <> nil) and (Mode in [naAdd, naAddFirst]) then
|
||||
Destination := Destination.Parent;
|
||||
case Mode of
|
||||
naAdd,
|
||||
naAddChild: AddMode := taAdd;
|
||||
naAddFirst,
|
||||
naAddChildFirst: AddMode := taAddFirst;
|
||||
naInsert: AddMode := taInsert;
|
||||
naInsert: AddMode := taInsert;
|
||||
else
|
||||
AddMode:=taAdd;
|
||||
end;
|
||||
@ -2006,6 +2002,34 @@ begin
|
||||
Result := InternalAddObject(ParentNode, S, Data, taAddFirst);
|
||||
end;
|
||||
|
||||
function TTreeNodes.AddNode(Node: TTreeNode; Relative: TTreeNode;
|
||||
const S: string; Ptr: Pointer; Method: TNodeAttachMode): TTreeNode;
|
||||
var
|
||||
AddMode: TAddMode;
|
||||
begin
|
||||
if (Relative=nil) and not (Method in [naAdd,naAddFirst]) then
|
||||
TreeNodeError('TTreeNode.AddNode Relative=nil');
|
||||
if Method=naInsertBehind then begin // convert naInsertBehind
|
||||
if Relative.GetNextSibling=nil then
|
||||
Method:=naAdd
|
||||
else begin
|
||||
Method:=naInsert;
|
||||
Relative:=Relative.GetNextSibling;
|
||||
end;
|
||||
end;
|
||||
if (Relative <> nil) and (Method in [naAdd, naAddFirst]) then
|
||||
Relative := Relative.Parent;
|
||||
// Convert TNodeAttachMode to TAddMode
|
||||
case Method of
|
||||
naAddFirst,naAddChildFirst: AddMode := taAddFirst;
|
||||
naInsert: AddMode := taInsert;
|
||||
else
|
||||
AddMode:=taAdd;
|
||||
end;
|
||||
fNewNodeToBeAdded := Node;
|
||||
Result := InternalAddObject(Relative, S, Ptr, AddMode);
|
||||
end;
|
||||
|
||||
procedure TTreeNodes.SelectionsChanged(ANode: TTreeNode; const AIsSelected: Boolean);
|
||||
begin
|
||||
if ANode <> nil then
|
||||
@ -2067,8 +2091,7 @@ begin
|
||||
Result:=InternalAddObject(NextNode,S,Data,taInsert);
|
||||
end;
|
||||
|
||||
function TTreeNodes.InsertBehind(PrevNode: TTreeNode; const S: string
|
||||
): TTreeNode;
|
||||
function TTreeNodes.InsertBehind(PrevNode: TTreeNode; const S: string): TTreeNode;
|
||||
begin
|
||||
Result := InsertObjectBehind(PrevNode, S, nil);
|
||||
end;
|
||||
@ -2110,7 +2133,10 @@ begin
|
||||
DbgOut(' Node.Text=',Node.Text);
|
||||
DebugLn('');
|
||||
{$ENDIF}
|
||||
Result := Owner.CreateNode;
|
||||
Result := fNewNodeToBeAdded; // Used by AddNode to pass an existing node.
|
||||
if Result = Nil then
|
||||
Result := Owner.CreateNode;
|
||||
fNewNodeToBeAdded := nil;
|
||||
ok:=false;
|
||||
try
|
||||
Result.Data := Data;
|
||||
|
Loading…
Reference in New Issue
Block a user