LCL: Select a single TreeView node with RightClick also when MultiSelect is enabled. Issue #28193, patch from Ondrej Pokorny.

git-svn-id: trunk@49227 -
This commit is contained in:
juha 2015-05-31 11:06:08 +00:00
parent c6b6503cf2
commit ff08bf968d

View File

@ -5192,18 +5192,56 @@ var
CursorNode: TTreeNode;
LogicalX: Integer;
CursorNodeSelected: Boolean;
begin
{$IFDEF VerboseDrag}
DebugLn('TCustomTreeView.MouseDown A ',DbgSName(Self),' ');
{$ENDIF}
fMouseDownPos := Point(X,Y);
FStates:=FStates-[tvsEditOnMouseUp,tvsSingleSelectOnMouseUp];
procedure ChangeSelection;
CursorNode := GetNodeAt(X, Y);
CursorNodeSelected := (CursorNode<>nil)
and (CursorNode.Selected
or ((tvoAllowMultiselect in Options) and CursorNode.MultiSelected));
LogicalX:=X;
//change selection on right click
if (Button = mbRight) and RightClickSelect and//right click
(([ssDouble, ssTriple, ssQuad] * Shift) = []) and//single or first of a multi click
not(ssCtrl in Shift) and//only when CTRL is not pressed
(CursorNode <> nil) and
(LogicalX >= CursorNode.DisplayStateIconLeft)//only after expand sign
then
begin
if (CursorNode <> nil) then
if not (tvoAllowMultiselect in Options) then
Selected := CursorNode
else
if not CursorNodeSelected then
Items.SelectOnlyThis(CursorNode);
end;
if not Focused and CanFocus then
SetFocus;
inherited MouseDown(Button, Shift, X, Y);
//CursorNode must be reassigned again - e.g. in OnMouseDown the node can be deleted or moved.
CursorNode := GetNodeAt(X, Y);
CursorNodeSelected := (CursorNode<>nil)
and (CursorNode.Selected
or ((tvoAllowMultiselect in Options) and CursorNode.MultiSelected));
//change selection on left click
if (Button = mbLeft) and//left click
(([ssDouble, ssTriple, ssQuad] * Shift) = []) and//single or first of a multi click
(CursorNode <> nil) then
begin
if CursorNode.HasChildren and ShowButtons and
(LogicalX >= CursorNode.DisplayExpandSignLeft) and
(LogicalX < CursorNode.DisplayExpandSignRight) then
begin
// mousedown occured on expand sign -> expand/collapse only on left button
if (Button = mbLeft) then
CursorNode.Expanded:=not CursorNode.Expanded;
// mousedown occured on expand sign -> expand/collapse
CursorNode.Expanded := not CursorNode.Expanded;
end
else if LogicalX >= CursorNode.DisplayStateIconLeft then
begin
@ -5229,8 +5267,7 @@ var
UnlockSelectionChangeEvent;
end;
end
else
if (ssCtrl in Shift) then
else if (ssCtrl in Shift) then
begin
Exclude(FStates,tvsEditOnMouseUp);
CursorNode.MultiSelected:=not CursorNode.MultiSelected;
@ -5239,43 +5276,13 @@ var
begin
if not CursorNodeSelected then
Items.SelectOnlyThis(CursorNode)
else if Button = mbLeft then
else
Include(FStates, tvsSingleSelectOnMouseUp);
end;
end;
end;
end;
end;//ChangeSelection
begin
{$IFDEF VerboseDrag}
DebugLn('TCustomTreeView.MouseDown A ',DbgSName(Self),' ');
{$ENDIF}
fMouseDownPos := Point(X,Y);
FStates:=FStates-[tvsEditOnMouseUp,tvsSingleSelectOnMouseUp];
if not Focused and CanFocus then
SetFocus;
CursorNode := GetNodeAt(X, Y);
CursorNodeSelected := (CursorNode<>nil)
and (CursorNode.Selected
or ((tvoAllowMultiselect in Options) and CursorNode.MultiSelected));
LogicalX:=X;
if (Button = mbRight) and RightClickSelect and
(([ssDouble, ssTriple, ssQuad] * Shift) = [])//single right click or first of a multi click
then
ChangeSelection;
inherited MouseDown(Button, Shift, X, Y);
if (Button = mbLeft) and
(([ssDouble, ssTriple, ssQuad] * Shift) = [])//single left click or first of a multi click
then
ChangeSelection;
// multi click
end
else// multi click
if not (tvoNoDoubleClickExpand in Options) and (ssDouble in Shift)
and (Button = mbLeft) and (CursorNode<>nil) then
CursorNode.Expanded := not CursorNode.Expanded;