diff --git a/source/helpers.pas b/source/helpers.pas index 78a44863..1ea637b4 100644 --- a/source/helpers.pas +++ b/source/helpers.pas @@ -16,6 +16,7 @@ uses Classes, SysUtils, Graphics, db, clipbrd, dialogs, type TListNodeType = (lntNone, lntDb, lntTable, lntCrashedTable, lntView, lntFunction, lntProcedure, lntColumn); + TListNodeTypes = Set of TListNodeType; TListNode = record Text: WideString; NodeType: TListNodeType; @@ -162,7 +163,7 @@ type function FormatByteNumber( Bytes: String; Decimals: Byte = 1 ): String; Overload; function FormatTimeNumber( Seconds: Cardinal ): String; function TColorToHex( Color : TColor ): string; - function GetVTCaptions( VT: TVirtualStringTree; OnlySelected: Boolean = False; Column: Integer = 0; OnlyNodeType: TListNodeType = lntNone ): TWideStringList; + function GetVTCaptions( VT: TVirtualStringTree; OnlySelected: Boolean = False; Column: Integer = 0; OnlyNodeTypes: TListNodeTypes = [lntNone] ): TWideStringList; procedure SetVTSelection( VT: TVirtualStringTree; Selected: TWideStringList ); function Pos2(const Needle, HayStack: string; const StartPos: Integer) : Integer; function GetTempDir: String; @@ -2238,7 +2239,7 @@ end; Return a TStringList with captions from all selected nodes in a VirtualTree Especially helpful when toMultiSelect is True } -function GetVTCaptions( VT: TVirtualStringTree; OnlySelected: Boolean = False; Column: Integer = 0; OnlyNodeType: TListNodeType = lntNone ): TWideStringList; +function GetVTCaptions( VT: TVirtualStringTree; OnlySelected: Boolean = False; Column: Integer = 0; OnlyNodeTypes: TListNodeTypes = [lntNone] ): TWideStringList; var Node: PVirtualNode; NodeData: PVTreeData; @@ -2247,11 +2248,11 @@ begin if OnlySelected then Node := VT.GetFirstSelected else Node := VT.GetFirst; while Assigned(Node) do begin - if OnlyNodeType = lntNone then // Add all nodes, regardless of their types + if OnlyNodeTypes = [lntNone] then // Add all nodes, regardless of their types Result.Add( VT.Text[Node, Column] ) else begin NodeData := VT.GetNodeData(Node); - if (NodeData.NodeType = OnlyNodeType) then // Node in loop is of specified type + if (NodeData.NodeType in OnlyNodeTypes) then // Node in loop is of specified type Result.Add(NodeData.Captions[Column]); end; if OnlySelected then Node := VT.GetNextSelected(Node) diff --git a/source/main.pas b/source/main.pas index 42a76225..06f34e2b 100644 --- a/source/main.pas +++ b/source/main.pas @@ -473,7 +473,7 @@ type procedure actAboutBoxExecute(Sender: TObject); procedure actApplyFilterExecute(Sender: TObject); procedure actClearEditorExecute(Sender: TObject); - procedure actMaintenanceExecute(Sender: TObject); + procedure actTableToolsExecute(Sender: TObject); procedure actCopyAsHTMLExecute(Sender: TObject); procedure actCopyAsCSVExecute(Sender: TObject); procedure actPrintListExecute(Sender: TObject); @@ -735,7 +735,6 @@ type procedure comboOnlyDBsKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure actFilterPanelExecute(Sender: TObject); procedure TimerFilterVTTimer(Sender: TObject); - procedure actFindTextOnServerExecute(Sender: TObject); private ReachedEOT : Boolean; FDelimiter: String; @@ -1964,21 +1963,28 @@ begin m.SelEnd := 0; end; -procedure TMainForm.actMaintenanceExecute(Sender: TObject); +procedure TMainForm.actTableToolsExecute(Sender: TObject); +var + Act: TAction; + InDBTree: Boolean; begin - // optimize / repair... tables + // Show table tools dialog if TableToolsDialog = nil then TableToolsDialog := TfrmTableTools.Create(Self); - TableToolsDialog.PageControlTools.ActivePage := TableToolsDialog.tabMaintenance; - TableToolsDialog.ShowModal; -end; - -procedure TMainForm.actFindTextOnServerExecute(Sender: TObject); -begin - // Find text on server - if TableToolsDialog = nil then - TableToolsDialog := TfrmTableTools.Create(Self); - TableToolsDialog.PageControlTools.ActivePage := TableToolsDialog.tabFind; + Act := Sender as TAction; + InDBTree := (Act.ActionComponent is TMenuItem) + and (TPopupMenu((Act.ActionComponent as TMenuItem).GetParentMenu).PopupComponent = DBTree); + if InDBTree and (SelectedTable.NodeType in [lntTable, lntCrashedTable, lntView]) then + TableToolsDialog.SelectedTables.Text := SelectedTable.Text + else if not InDBTree then + TableToolsDialog.SelectedTables := GetVTCaptions(ListTables, True, 0, [lntTable, lntCrashedTable, lntView]) + else + TableToolsDialog.SelectedTables.Clear; + logsql(TableToolsDialog.SelectedTables.CommaText); + if Sender = actMaintenance then + TableToolsDialog.PageControlTools.ActivePage := TableToolsDialog.tabMaintenance + else + TableToolsDialog.PageControlTools.ActivePage := TableToolsDialog.tabFind; TableToolsDialog.ShowModal; end; @@ -2464,11 +2470,11 @@ begin end; end else begin // Invoked from database tab - Tables := GetVTCaptions(ListTables, True, 0, lntTable); - Tables.AddStrings(GetVTCaptions(ListTables, True, 0, lntCrashedTable)); - Views := GetVTCaptions(ListTables, True, 0, lntView); - Procedures := GetVTCaptions(ListTables, True, 0, lntProcedure); - Functions := GetVTCaptions(ListTables, True, 0, lntFunction); + Tables := GetVTCaptions(ListTables, True, 0, [lntTable]); + Tables.AddStrings(GetVTCaptions(ListTables, True, 0, [lntCrashedTable])); + Views := GetVTCaptions(ListTables, True, 0, [lntView]); + Procedures := GetVTCaptions(ListTables, True, 0, [lntProcedure]); + Functions := GetVTCaptions(ListTables, True, 0, [lntFunction]); end; // Fix actions temporarily enabled for popup menu. diff --git a/source/tabletools.pas b/source/tabletools.pas index e6d796c3..6b4bf50f 100644 --- a/source/tabletools.pas +++ b/source/tabletools.pas @@ -80,6 +80,7 @@ type procedure UpdateResultGrid; public { Public declarations } + SelectedTables: TWideStringList; end; @@ -111,8 +112,8 @@ begin InheritFont(Font); FixVT(TreeObjects); FixVT(ResultGrid); - TreeObjects.RootNodeCount := Mainform.DBtree.RootNodeCount; FResults := TObjectList.Create; + SelectedTables := TWideStringList.Create; end; @@ -131,8 +132,10 @@ end; procedure TfrmTableTools.FormShow(Sender: TObject); begin - // When this form is displayed the second time, databases may be deleted or filtered - treeObjects.ReinitChildren(treeObjects.GetFirst, False); + // When this form is displayed the second time, databases may be deleted or filtered. + // Also, checked nodes must be unchecked and unchecked nodes may need to be checked. + TreeObjects.Clear; + TreeObjects.RootNodeCount := Mainform.DBtree.RootNodeCount; // CHECKSUM available since MySQL 4.1.1 if Mainform.mysql_version < 40101 then comboOperation.Items[comboOperation.Items.IndexOf('Checksum')] := 'Checksum ('+STR_NOTSUPPORTED+')'; @@ -209,23 +212,38 @@ begin Node.CheckState := csUncheckedNormal; case Sender.GetNodeLevel(Node) of 1: begin - // Preselect active database if Mainform.Databases[Node.Index] = Mainform.ActiveDatabase then begin - Node.CheckState := csCheckedNormal; - TreeObjects.ReinitChildren(Node, False); + if SelectedTables.Count = 0 then begin + // Preselect active database + Node.CheckState := csCheckedNormal; + TreeObjects.ReinitChildren(Node, False); + end else begin + // Expand db node so checked table nodes are visible + Include(InitialStates, ivsExpanded); + end; end; - ValidateControls(Sender); end; 2: begin - // Disable stored routines ds := Mainform.FetchDbTableList(Mainform.Databases[ParentNode.Index]); ds.RecNo := Node.Index+1; + // No checkbox for stored routines if not (GetDBObjectType(ds.Fields) in [lntTable, lntCrashedTable, lntView]) then Node.CheckType := ctNone - else if Node.Parent.CheckState in [csCheckedNormal, csCheckedPressed] then - Node.CheckState := csCheckedNormal; + else begin + if Node.Parent.CheckState in [csCheckedNormal, csCheckedPressed] then begin + // Check table node if either parent db is checked ... + Node.CheckState := csCheckedNormal + end else if (Mainform.Databases[Node.Parent.Index] = Mainform.ActiveDatabase) + // ... or table name is in SelectedTables + and (SelectedTables.Count > 0) + and (SelectedTables.IndexOf(ds.FieldByName(DBO_NAME).AsWideString) > -1) then begin + Node.CheckState := csCheckedNormal; + Node.Parent.CheckState := csMixedNormal; + end; + end; end; end; + ValidateControls(Sender); end;