mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-26 03:01:07 +08:00
Issue #1577: make apphelpers.SelectNode more intelligent, returning true/false to indicate whether it successful went through OnFocusChanging event
This commit is contained in:
@ -332,8 +332,8 @@ type
|
||||
function ComposeOrderClause(Cols: TOrderColArray): String;
|
||||
procedure DeInitializeVTNodes(Sender: TBaseVirtualTree);
|
||||
function FindNode(VT: TVirtualStringTree; idx: Int64; ParentNode: PVirtualNode): PVirtualNode;
|
||||
procedure SelectNode(VT: TVirtualStringTree; idx: Int64; ParentNode: PVirtualNode=nil); overload;
|
||||
procedure SelectNode(VT: TVirtualStringTree; Node: PVirtualNode; ClearSelection: Boolean=True); overload;
|
||||
function SelectNode(VT: TVirtualStringTree; idx: Int64; ParentNode: PVirtualNode=nil): Boolean; overload;
|
||||
function SelectNode(VT: TVirtualStringTree; Node: PVirtualNode; ClearSelection: Boolean=True): Boolean; overload;
|
||||
procedure GetVTSelection(VT: TVirtualStringTree; var SelectedCaptions: TStringList; var FocusedCaption: String);
|
||||
procedure SetVTSelection(VT: TVirtualStringTree; SelectedCaptions: TStringList; FocusedCaption: String);
|
||||
function GetNextNode(Tree: TVirtualStringTree; CurrentNode: PVirtualNode; Selected: Boolean=False): PVirtualNode;
|
||||
@ -1455,31 +1455,39 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
procedure SelectNode(VT: TVirtualStringTree; idx: Int64; ParentNode: PVirtualNode=nil); overload;
|
||||
function SelectNode(VT: TVirtualStringTree; idx: Int64; ParentNode: PVirtualNode=nil): Boolean; overload;
|
||||
var
|
||||
Node: PVirtualNode;
|
||||
begin
|
||||
// Helper to focus and highlight a node by its index
|
||||
Node := FindNode(VT, idx, ParentNode);
|
||||
if Assigned(Node) then
|
||||
SelectNode(VT, Node);
|
||||
Result := SelectNode(VT, Node)
|
||||
else
|
||||
Result := False;
|
||||
end;
|
||||
|
||||
|
||||
procedure SelectNode(VT: TVirtualStringTree; Node: PVirtualNode; ClearSelection: Boolean=True); overload;
|
||||
function SelectNode(VT: TVirtualStringTree; Node: PVirtualNode; ClearSelection: Boolean=True): Boolean; overload;
|
||||
var
|
||||
OldFocus: PVirtualNode;
|
||||
begin
|
||||
if Node = VT.RootNode then
|
||||
Node := nil;
|
||||
OldFocus := VT.FocusedNode;
|
||||
if ClearSelection then
|
||||
VT.ClearSelection;
|
||||
VT.FocusedNode := Node;
|
||||
VT.Selected[Node] := True;
|
||||
VT.ScrollIntoView(Node, False);
|
||||
if (OldFocus = Node) and Assigned(VT.OnFocusChanged) then
|
||||
VT.OnFocusChanged(VT, Node, VT.Header.MainColumn);
|
||||
Result := True;
|
||||
if (Node <> OldFocus) and Assigned(VT.OnFocusChanging) then begin
|
||||
VT.OnFocusChanging(VT, OldFocus, Node, VT.FocusedColumn, VT.FocusedColumn, Result);
|
||||
end;
|
||||
if Result then begin
|
||||
if ClearSelection then
|
||||
VT.ClearSelection;
|
||||
VT.FocusedNode := Node;
|
||||
VT.Selected[Node] := True;
|
||||
VT.ScrollIntoView(Node, False);
|
||||
if (OldFocus = Node) and Assigned(VT.OnFocusChanged) then
|
||||
VT.OnFocusChanged(VT, Node, VT.Header.MainColumn);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -367,7 +367,7 @@ var
|
||||
rx: TRegExpr;
|
||||
Prompt: TModalResult;
|
||||
ReplaceFlags: TReplaceFlags;
|
||||
FocusChangeAllowed: Boolean;
|
||||
NodeSelected: Boolean;
|
||||
begin
|
||||
// Data grid version of DoSearchReplaceText
|
||||
MainForm.ShowStatusMsg(_('Searching ...'));
|
||||
@ -388,7 +388,7 @@ begin
|
||||
ReplaceFlags := [rfReplaceAll];
|
||||
if not (ssoMatchCase in Options) then
|
||||
Include(ReplaceFlags, rfIgnoreCase);
|
||||
FocusChangeAllowed := True;
|
||||
NodeSelected := True;
|
||||
|
||||
// Init regular expression
|
||||
rx := TRegExpr.Create;
|
||||
@ -451,12 +451,9 @@ begin
|
||||
Inc(MatchCount);
|
||||
|
||||
// Set focus on node and column
|
||||
if (Node <> Grid.FocusedNode) and Assigned(Grid.OnFocusChanging) then begin
|
||||
Grid.OnFocusChanging(Grid, Grid.FocusedNode, Node, Grid.FocusedColumn, Column, FocusChangeAllowed);
|
||||
if not FocusChangeAllowed then
|
||||
Break;
|
||||
end;
|
||||
SelectNode(Grid, Node, False);
|
||||
NodeSelected := SelectNode(Grid, Node, False);
|
||||
if not NodeSelected then
|
||||
Break;
|
||||
Grid.FocusedColumn := Column;
|
||||
|
||||
// Replace logic
|
||||
@ -497,7 +494,7 @@ begin
|
||||
|
||||
if Match and (not (ssoReplaceAll in Options)) then
|
||||
Break;
|
||||
if not FocusChangeAllowed then
|
||||
if not NodeSelected then
|
||||
Break;
|
||||
|
||||
if Backwards then
|
||||
|
Reference in New Issue
Block a user