mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-06 18:24:26 +08:00
Enhancement for all VirtualTrees: Remember previously selected nodes and restore them after any refresh. Using existing helpers:GetVTCaptions plus new helpers:SetVTSelection
This commit is contained in:
@ -2086,13 +2086,17 @@ var
|
|||||||
i : Integer;
|
i : Integer;
|
||||||
bytes : Extended;
|
bytes : Extended;
|
||||||
ds : TDataSet;
|
ds : TDataSet;
|
||||||
ListCaptions : TStringList;
|
ListCaptions,
|
||||||
|
SelectedCaptions: TStringList;
|
||||||
begin
|
begin
|
||||||
// DB-Properties
|
// DB-Properties
|
||||||
Screen.Cursor := crHourGlass;
|
Screen.Cursor := crHourGlass;
|
||||||
MainForm.ShowStatus( 'Reading from database ' + db + '...', 2, true );
|
MainForm.ShowStatus( 'Reading from database ' + db + '...', 2, true );
|
||||||
Mainform.ButtonDropDatabase.Hint := 'Drop Database...|Drop Database ' + db + '...';
|
Mainform.ButtonDropDatabase.Hint := 'Drop Database...|Drop Database ' + db + '...';
|
||||||
|
|
||||||
|
// Remember selected nodes
|
||||||
|
SelectedCaptions := GetVTCaptions(ListTables, True);
|
||||||
|
|
||||||
try
|
try
|
||||||
ds := FetchDbTableList(db);
|
ds := FetchDbTableList(db);
|
||||||
|
|
||||||
@ -2210,6 +2214,7 @@ begin
|
|||||||
finally
|
finally
|
||||||
ListTables.RootNodeCount := Length(VTRowDataListTables);
|
ListTables.RootNodeCount := Length(VTRowDataListTables);
|
||||||
ListTables.EndUpdate;
|
ListTables.EndUpdate;
|
||||||
|
SetVTSelection(ListTables, SelectedCaptions);
|
||||||
Mainform.showstatus(db + ': ' + IntToStr(ListTables.RootNodeCount) +' table(s)');
|
Mainform.showstatus(db + ': ' + IntToStr(ListTables.RootNodeCount) +' table(s)');
|
||||||
Screen.Cursor := crDefault;
|
Screen.Cursor := crDefault;
|
||||||
end;
|
end;
|
||||||
@ -2241,6 +2246,7 @@ var
|
|||||||
ds : TDataSet;
|
ds : TDataSet;
|
||||||
dummy: Boolean;
|
dummy: Boolean;
|
||||||
hasCommentColumn: Boolean;
|
hasCommentColumn: Boolean;
|
||||||
|
SelectedCaptions: TStringList;
|
||||||
begin
|
begin
|
||||||
// Table-Properties
|
// Table-Properties
|
||||||
dataselected := false;
|
dataselected := false;
|
||||||
@ -2258,6 +2264,8 @@ begin
|
|||||||
pnlTableTop.Caption := 'Table-Properties for ' + ActiveDatabase + ': ' + table;
|
pnlTableTop.Caption := 'Table-Properties for ' + ActiveDatabase + ': ' + table;
|
||||||
|
|
||||||
MainForm.ShowStatus( 'Reading table properties...', 2, true );
|
MainForm.ShowStatus( 'Reading table properties...', 2, true );
|
||||||
|
// Remember selected nodes
|
||||||
|
SelectedCaptions := GetVTCaptions(ListColumns, True);
|
||||||
ListColumns.BeginUpdate;
|
ListColumns.BeginUpdate;
|
||||||
ListColumns.Clear;
|
ListColumns.Clear;
|
||||||
Try
|
Try
|
||||||
@ -2371,6 +2379,8 @@ begin
|
|||||||
finally
|
finally
|
||||||
|
|
||||||
ListColumns.EndUpdate;
|
ListColumns.EndUpdate;
|
||||||
|
// Reselect previous selected nodes
|
||||||
|
SetVTSelection(ListColumns, SelectedCaptions);
|
||||||
Screen.Cursor := crDefault;
|
Screen.Cursor := crDefault;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2661,10 +2671,14 @@ var
|
|||||||
i : Integer;
|
i : Integer;
|
||||||
questions : Int64;
|
questions : Int64;
|
||||||
ds : TDataSet;
|
ds : TDataSet;
|
||||||
|
SelectedCaptions: TStringList;
|
||||||
begin
|
begin
|
||||||
// Refresh variables and process-list
|
// Refresh variables and process-list
|
||||||
Screen.Cursor := crSQLWait;
|
Screen.Cursor := crSQLWait;
|
||||||
|
|
||||||
|
// Remember selected nodes
|
||||||
|
SelectedCaptions := GetVTCaptions(ListVariables, True);
|
||||||
|
|
||||||
// VARIABLES
|
// VARIABLES
|
||||||
ListVariables.BeginUpdate;
|
ListVariables.BeginUpdate;
|
||||||
ListVariables.Clear;
|
ListVariables.Clear;
|
||||||
@ -2683,6 +2697,7 @@ begin
|
|||||||
// Tell VirtualTree the number of nodes it will display
|
// Tell VirtualTree the number of nodes it will display
|
||||||
ListVariables.RootNodeCount := Length(VTRowDataListVariables);
|
ListVariables.RootNodeCount := Length(VTRowDataListVariables);
|
||||||
ListVariables.EndUpdate;
|
ListVariables.EndUpdate;
|
||||||
|
SetVTSelection( ListVariables, SelectedCaptions );
|
||||||
// Apply filter
|
// Apply filter
|
||||||
if editFilterVariables.Text <> '' then
|
if editFilterVariables.Text <> '' then
|
||||||
editFilterVTChange(editFilterVariables);
|
editFilterVTChange(editFilterVariables);
|
||||||
@ -2692,6 +2707,8 @@ begin
|
|||||||
// STATUS
|
// STATUS
|
||||||
uptime := 1; // avoids division by zero :)
|
uptime := 1; // avoids division by zero :)
|
||||||
questions := 1;
|
questions := 1;
|
||||||
|
// Remember selected nodes
|
||||||
|
SelectedCaptions := GetVTCaptions(ListStatus, True);
|
||||||
ListStatus.BeginUpdate;
|
ListStatus.BeginUpdate;
|
||||||
ListStatus.Clear;
|
ListStatus.Clear;
|
||||||
ds := GetResults( 'SHOW /*!50002 GLOBAL */ STATUS' );
|
ds := GetResults( 'SHOW /*!50002 GLOBAL */ STATUS' );
|
||||||
@ -2711,6 +2728,7 @@ begin
|
|||||||
// Tell VirtualTree the number of nodes it will display
|
// Tell VirtualTree the number of nodes it will display
|
||||||
ListStatus.RootNodeCount := Length(VTRowDataListStatus);
|
ListStatus.RootNodeCount := Length(VTRowDataListStatus);
|
||||||
ListStatus.EndUpdate;
|
ListStatus.EndUpdate;
|
||||||
|
SetVTSelection( ListStatus, SelectedCaptions );
|
||||||
// Apply filter
|
// Apply filter
|
||||||
if editFilterStatus.Text <> '' then
|
if editFilterStatus.Text <> '' then
|
||||||
editFilterVTChange(editFilterStatus);
|
editFilterVTChange(editFilterStatus);
|
||||||
@ -2718,6 +2736,7 @@ begin
|
|||||||
tabStatus.Caption := 'Status (' + IntToStr(ListStatus.RootNodeCount) + ')';
|
tabStatus.Caption := 'Status (' + IntToStr(ListStatus.RootNodeCount) + ')';
|
||||||
|
|
||||||
// Command-Statistics
|
// Command-Statistics
|
||||||
|
SelectedCaptions := GetVTCaptions(ListCommandStats, True);
|
||||||
ListCommandStats.BeginUpdate;
|
ListCommandStats.BeginUpdate;
|
||||||
ListCommandStats.Clear;
|
ListCommandStats.Clear;
|
||||||
SetLength( VTRowDataListCommandStats, 0 );
|
SetLength( VTRowDataListCommandStats, 0 );
|
||||||
@ -2737,6 +2756,7 @@ begin
|
|||||||
// Tell VirtualTree the number of nodes it will display
|
// Tell VirtualTree the number of nodes it will display
|
||||||
ListCommandStats.RootNodeCount := Length(VTRowDataListCommandStats);
|
ListCommandStats.RootNodeCount := Length(VTRowDataListCommandStats);
|
||||||
ListCommandStats.EndUpdate;
|
ListCommandStats.EndUpdate;
|
||||||
|
SetVTSelection( ListCommandStats, SelectedCaptions );
|
||||||
|
|
||||||
TimerHostUptime.Enabled := true;
|
TimerHostUptime.Enabled := true;
|
||||||
TimerHostUptimeTimer(self);
|
TimerHostUptimeTimer(self);
|
||||||
@ -2753,11 +2773,14 @@ procedure TMDIChild.ShowProcessList(sender: TObject);
|
|||||||
var
|
var
|
||||||
i,j : Integer;
|
i,j : Integer;
|
||||||
ds : TDataSet;
|
ds : TDataSet;
|
||||||
|
SelectedCaptions: TStringList;
|
||||||
begin
|
begin
|
||||||
// No need to update if it's not visible.
|
// No need to update if it's not visible.
|
||||||
if PageControlMain.ActivePage <> tabHost then exit;
|
if PageControlMain.ActivePage <> tabHost then exit;
|
||||||
if PageControlHost.ActivePage <> tabProcesslist then exit;
|
if PageControlHost.ActivePage <> tabProcesslist then exit;
|
||||||
Screen.Cursor := crSQLWait;
|
Screen.Cursor := crSQLWait;
|
||||||
|
// Remember selected nodes
|
||||||
|
SelectedCaptions := GetVTCaptions(ListProcesses, True);
|
||||||
try
|
try
|
||||||
ListProcesses.BeginUpdate;
|
ListProcesses.BeginUpdate;
|
||||||
ListProcesses.Clear;
|
ListProcesses.Clear;
|
||||||
@ -2787,6 +2810,8 @@ begin
|
|||||||
end;
|
end;
|
||||||
ListProcesses.RootNodeCount := Length(VTRowDataListProcesses);
|
ListProcesses.RootNodeCount := Length(VTRowDataListProcesses);
|
||||||
ListProcesses.EndUpdate;
|
ListProcesses.EndUpdate;
|
||||||
|
// Reselect previous selected nodes
|
||||||
|
SetVTSelection( ListProcesses, SelectedCaptions );
|
||||||
// Apply filter
|
// Apply filter
|
||||||
if editFilterProcesses.Text <> '' then
|
if editFilterProcesses.Text <> '' then
|
||||||
editFilterVTChange(editFilterProcesses);
|
editFilterVTChange(editFilterProcesses);
|
||||||
|
@ -84,6 +84,7 @@ type
|
|||||||
function FormatTimeNumber( Seconds: Cardinal ): String;
|
function FormatTimeNumber( Seconds: Cardinal ): String;
|
||||||
function TColorToHex( Color : TColor ): string;
|
function TColorToHex( Color : TColor ): string;
|
||||||
function GetVTCaptions( VT: TVirtualStringTree; OnlySelected: Boolean = False; Column: Integer = 0 ): TStringList;
|
function GetVTCaptions( VT: TVirtualStringTree; OnlySelected: Boolean = False; Column: Integer = 0 ): TStringList;
|
||||||
|
procedure SetVTSelection( VT: TVirtualStringTree; Selected: TStringList );
|
||||||
function Pos2(const Needle, HayStack: string; const StartPos: Integer) : Integer;
|
function Pos2(const Needle, HayStack: string; const StartPos: Integer) : Integer;
|
||||||
function GetTempDir: String;
|
function GetTempDir: String;
|
||||||
|
|
||||||
@ -2125,6 +2126,29 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{**
|
||||||
|
The opposite of GetVTCaptions in "OnlySelected"-Mode:
|
||||||
|
Set selected nodes in a VirtualTree
|
||||||
|
}
|
||||||
|
procedure SetVTSelection( VT: TVirtualStringTree; Selected: TStringList );
|
||||||
|
var
|
||||||
|
Node: PVirtualNode;
|
||||||
|
NodeData: PVTreeData;
|
||||||
|
begin
|
||||||
|
Node := VT.GetFirst;
|
||||||
|
while Assigned(Node) do begin
|
||||||
|
NodeData := VT.GetNodeData(Node);
|
||||||
|
if Selected.IndexOf(NodeData.Captions[0]) > -1 then begin
|
||||||
|
if not Assigned(VT.FocusedNode) then
|
||||||
|
VT.FocusedNode := Node;
|
||||||
|
VT.Selected[Node] := True;
|
||||||
|
end;
|
||||||
|
Node := VT.GetNext(Node);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
function Pos2(const Needle, HayStack: string; const StartPos: Integer) : Integer;
|
function Pos2(const Needle, HayStack: string; const StartPos: Integer) : Integer;
|
||||||
var
|
var
|
||||||
NewHayStack: string;
|
NewHayStack: string;
|
||||||
|
Reference in New Issue
Block a user