Skip to content

Commit 37b811c

Browse files
committed
Implemented #856: Always select next node upon deletion of the selected node
1 parent 7392bcb commit 37b811c

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

Source/VirtualTrees.BaseTree.pas

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ TBaseVirtualTree = class abstract(TVTBaseAncestor)
14231423
function EndEditNode: Boolean;
14241424
procedure EndSynch;
14251425
procedure EndUpdate; virtual;
1426-
procedure EnsureNodeSelected(); virtual;
1426+
procedure EnsureNodeSelected(pAfterDeletion: Boolean); virtual;
14271427
function ExecuteAction(Action: TBasicAction): Boolean; override;
14281428
procedure FinishCutOrCopy;
14291429
procedure FlushClipboard;
@@ -10205,7 +10205,7 @@ procedure TBaseVirtualTree.DoCollapsed(Node: PVirtualNode);
1020510205
end;//if
1020610206
//if there is (still) no selected node, then use FNextNodeToSelect to select one
1020710207
if SelectedCount = 0 then
10208-
EnsureNodeSelected();
10208+
EnsureNodeSelected(False);
1020910209
end;//if
1021010210
end;
1021110211

@@ -10550,7 +10550,7 @@ procedure TBaseVirtualTree.DoEndOperation(OperationKind: TVTOperationKind);
1055010550
procedure TBaseVirtualTree.DoEnter();
1055110551
begin
1055210552
inherited;
10553-
EnsureNodeSelected();
10553+
EnsureNodeSelected(False);
1055410554
end;
1055510555

1055610556
//----------------------------------------------------------------------------------------------------------------------
@@ -10672,7 +10672,7 @@ procedure TBaseVirtualTree.DoFreeNode(Node: PVirtualNode);
1067210672

1067310673
FreeMem(Node);
1067410674
if Self.UpdateCount = 0 then
10675-
EnsureNodeSelected();
10675+
EnsureNodeSelected(True);
1067610676
end;
1067710677

1067810678
//----------------------------------------------------------------------------------------------------------------------
@@ -12083,9 +12083,11 @@ procedure TBaseVirtualTree.EnsureNodeFocused();
1208312083

1208412084
//----------------------------------------------------------------------------------------------------------------------
1208512085

12086-
procedure TBaseVirtualTree.EnsureNodeSelected();
12086+
procedure TBaseVirtualTree.EnsureNodeSelected(pAfterDeletion: Boolean);
1208712087
begin
12088-
if (toAlwaysSelectNode in TreeOptions.SelectionOptions) and not IsEmpty then
12088+
if IsEmpty then
12089+
exit; // Nothing to do
12090+
if (toAlwaysSelectNode in TreeOptions.SelectionOptions) or (pAfterDeletion and (toSelectNextNodeOnRemoval in TreeOptions.SelectionOptions)) then
1208912091
begin
1209012092
if (SelectedCount = 0) and not SelectionLocked then
1209112093
begin
@@ -15259,7 +15261,7 @@ procedure TBaseVirtualTree.UpdateNextNodeToSelect(Node: PVirtualNode);
1525915261
// selected one gets deleted.
1526015262

1526115263
begin
15262-
if not (toAlwaysSelectNode in TreeOptions.SelectionOptions) then
15264+
if ([toAlwaysSelectNode, toSelectNextNodeOnRemoval] * TreeOptions.SelectionOptions) = [] then
1526315265
Exit;
1526415266
if GetNextSibling(Node) <> nil then
1526515267
FNextNodeToSelect := GetNextSibling(Node)
@@ -16938,7 +16940,7 @@ procedure TBaseVirtualTree.DeleteChildren(Node: PVirtualNode; ResetHasChildren:
1693816940
InvalidateToBottom(Node);
1693916941
if tsChangePending in FStates then begin
1694016942
DoChange(FLastChangedNode);
16941-
EnsureNodeSelected();
16943+
EnsureNodeSelected(True);
1694216944
end;
1694316945
end;
1694416946
StructureChange(Node, crChildDeleted);
@@ -17205,7 +17207,7 @@ procedure TBaseVirtualTree.EndUpdate;
1720517207
NotifyAccessibilityCollapsed(); // See issue #1174
1720617208

1720717209
DoUpdating(usEnd);
17208-
EnsureNodeSelected();
17210+
EnsureNodeSelected(False);
1720917211
end
1721017212
else
1721117213
DoUpdating(usUpdate);

Source/VirtualTrees.Types.pas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,10 @@ TSortDirectionHelper = record helper for VirtualTrees.Types.TSortDirection
359359
toRestoreSelection, // Set to true if upon refill the previously selected nodes should be selected again.
360360
// The nodes will be identified by its caption (text in MainColumn)
361361
// You may use TVTHeader.RestoreSelectiuonColumnIndex to define an other column that should be used for indentification.
362-
toSyncCheckboxesWithSelection // If checkboxes are shown, they follow the change in selections. When checkboxes are
362+
toSyncCheckboxesWithSelection, // If checkboxes are shown, they follow the change in selections. When checkboxes are
363363
// changed, the selections follow them and vice-versa.
364364
// **Only supported for ctCheckBox type checkboxes.
365+
toSelectNextNodeOnRemoval // If the selected node gets deleted, automatically select the next node.
365366
);
366367
TVTSelectionOptions = set of TVTSelectionOption;
367368

@@ -768,7 +769,7 @@ TChunkHeader = record
768769
DefaultPaintOptions = [toShowButtons, toShowDropmark, toShowTreeLines, toShowRoot, toThemeAware, toUseBlendedImages];
769770
DefaultAnimationOptions = [];
770771
DefaultAutoOptions = [toAutoDropExpand, toAutoTristateTracking, toAutoScrollOnExpand, toAutoDeleteMovedNodes, toAutoChangeScale, toAutoSort, toAutoHideButtons];
771-
DefaultSelectionOptions = [];
772+
DefaultSelectionOptions = [toSelectNextNodeOnRemoval];
772773
DefaultMiscOptions = [toAcceptOLEDrop, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning, toEditOnClick];
773774

774775
DefaultStringOptions = [toSaveCaptions, toAutoAcceptEditChange];

0 commit comments

Comments
 (0)