Skip to content

Commit 8befce3

Browse files
committed
fix: context menu does not appear at right-click on a tree node text
Refs #2069
1 parent 83c4947 commit 8befce3

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

source/apphelpers.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ procedure FixVT(VT: TVirtualStringTree; IsResultGrid: Boolean=False);
15281528
VT.OnEndOperation := Mainform.AnyGridEndOperation;
15291529
VT.BorderStyle := bsNone; // Cosmetic
15301530
// Some trees have their own OnContextMenu logic set at design time:
1531-
if not Assigned(VT.OnContextPopup) then
1531+
if (not Assigned(VT.OnContextPopup)) and Assigned(VT.Header.PopupMenu) then
15321532
VT.OnContextPopup := MainForm.AnyGridContextPopup;
15331533
end;
15341534

source/main.lfm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,6 @@ object MainForm: TMainForm
951951
Constraints.MinHeight = 32
952952
Constraints.MinWidth = 32
953953
DefaultText = 'Node'
954-
DragMode = dmAutomatic
955954
DragType = dtVCL
956955
Header.AutoSizeIndex = 0
957956
Header.Columns = <
@@ -993,6 +992,7 @@ object MainForm: TMainForm
993992
OnGetNodeDataSize = DBtreeGetNodeDataSize
994993
OnInitChildren = DBtreeInitChildren
995994
OnInitNode = DBtreeInitNode
995+
OnMouseMove = DBtreeMouseMove
996996
OnMouseUp = DBtreeMouseUp
997997
end
998998
end

source/main.pas

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,8 @@ TMainForm = class(TExtForm)
841841
var Handled: Boolean);
842842
procedure DataGridContextPopup(Sender: TObject; MousePos: TPoint;
843843
var Handled: Boolean);
844+
procedure DBtreeMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
845+
);
844846
procedure FormActivate(Sender: TObject);
845847
procedure ImageListGetWidthForPPI(Sender: TCustomImageList;
846848
AImageWidth, APPI: Integer; var AResultWidth: Integer);
@@ -4599,6 +4601,16 @@ procedure TMainForm.DataGridContextPopup(Sender: TObject; MousePos: TPoint;
45994601
Handled := Tree.Header.InHeader(MousePos);
46004602
end;
46014603

4604+
procedure TMainForm.DBtreeMouseMove(Sender: TObject; Shift: TShiftState; X,
4605+
Y: Integer);
4606+
begin
4607+
// Required step with DragMode=dmManual
4608+
// We use dmManual to fix a non appearing context menu in conjunction with DragType=dtVCL
4609+
// This reserves left-clicks for dragging, leaving right-clicks for context menu
4610+
if (ssLeft in Shift) and (not DBtree.Dragging) then
4611+
DBtree.BeginDrag(False);
4612+
end;
4613+
46024614
procedure TMainForm.FormActivate(Sender: TObject);
46034615
begin
46044616
// Work around non-working wsMaxmized in OnCreate and OnShow

0 commit comments

Comments
 (0)