Disallow to drag a session folder somewhere below itself, which would end up in an infinite folder structure, theoretically. Fixes issue #3086.

This commit is contained in:
Ansgar Becker
2013-01-15 09:09:44 +00:00
parent 7ddfa83ace
commit d16f19da91

View File

@@ -666,16 +666,33 @@ procedure Tconnform.ListSessionsDragOver(Sender: TBaseVirtualTree;
Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint;
Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
var
TargetNode: PVirtualNode;
TargetNode, ParentNode: PVirtualNode;
TargetSess: PConnectionParameters;
begin
// Allow node dragging everywhere except within the current folder
TargetNode := Sender.GetNodeAt(Pt.X, Pt.Y);
TargetSess := Sender.GetNodeData(TargetNode);
Accept := (Source = Sender)
and ((TargetNode.Parent <> ListSessions.FocusedNode.Parent) or TargetSess.IsFolder)
and (TargetNode <> ListSessions.FocusedNode.Parent)
and (Mode <> dmNowhere);
and Assigned(TargetSess)
and (Mode <> dmNowhere)
and (TargetNode <> ListSessions.FocusedNode.Parent);
// Moving a folder into itself would create an infinite folder structure
if Accept and TargetSess.IsFolder then
Accept := Accept and (TargetNode <> ListSessions.FocusedNode);
if Accept and (not TargetSess.IsFolder) then
Accept := Accept and (TargetNode.Parent <> ListSessions.FocusedNode.Parent);
if Accept then begin
// Do not allow focused node to be moved somewhere below itself
ParentNode := TargetNode.Parent;
while Assigned(ParentNode) do begin
Accept := Accept and (ParentNode <> ListSessions.FocusedNode);
if not Accept then
Break;
ParentNode := ParentNode.Parent;
end;
end;
end;