Refactor Maintenance dialog to fullfill reasonable user wishes in bug #1865477 :

- Rename components with reasonable names
- Use caching mechanism from Childwin.FetchDBTableList to fill tables listbox
- Make form resizable, store and restore customized dimensions
- Keep form instance alive and recycle that instance as long as Mainform lives
- Fix confusion with action item (wasn't really used in both menuitems)
- Add documentation
This commit is contained in:
Ansgar Becker
2008-03-18 20:58:03 +00:00
parent b815b91039
commit de12c10721
7 changed files with 204 additions and 118 deletions

View File

@ -155,6 +155,8 @@ const
REGNAME_UPDATECHECK_INTERVAL = 'UpdatecheckInterval';
DEFAULT_UPDATECHECK_INTERVAL = 3;
REGNAME_LAST_UPDATECHECK = 'UpdatecheckLastrun';
REGNAME_MAINTWINWIDTH = 'Maintenance_WindowWidth';
REGNAME_MAINTWINHEIGHT = 'Maintenance_WindowHeight';
REGPREFIX_COLWIDTHS = 'ColWidths_';
REGPREFIX_COLSVISIBLE = 'ColsVisible_';

View File

@ -1817,9 +1817,7 @@ object MDIChild: TMDIChild
OnClick = MenuRenameTableClick
end
object menuMaintenance: TMenuItem
Caption = 'Maintenance'
ImageIndex = 39
OnClick = menuMaintenanceClick
Action = MainForm.actMaintenance
end
object N18: TMenuItem
Caption = '-'

View File

@ -408,7 +408,6 @@ type
procedure EditQuery1Click(Sender: TObject);
procedure Markall3Click(Sender: TObject);
procedure ReadWindowOptions;
procedure menuMaintenanceClick(Sender: TObject);
procedure ListTablesDblClick(Sender: TObject);
procedure TimerConnectErrorCloseWindowTimer(Sender: TObject);
procedure gridDataTitleClick(Column: TColumn);
@ -664,7 +663,7 @@ implementation
uses
Main, fieldeditor,
optimizetables, copytable, sqlhelp, printlist,
copytable, sqlhelp, printlist,
column_selection, data_sorting, runsqlfile, mysql_structures,
Registry;
@ -2490,7 +2489,7 @@ begin
MenuFlushTableswithreadlock.Enabled := FrmIsFocussed;
MenuFlushStatus.Enabled := FrmIsFocussed;
UserManager.Enabled := FrmIsFocussed;
Diagnostics.Enabled := FrmIsFocussed;
actMaintenance.Enabled := FrmIsFocussed;
InsertFiles.Enabled := FrmIsFocussed;
{***
Activate export-options if we're on Data- or Query-tab
@ -3581,12 +3580,6 @@ begin
end;
procedure TMDIChild.menuMaintenanceClick(Sender: TObject);
begin
TableDiagnosticsWindow(Self);
end;
{**
Clear Query memo
}

View File

@ -482,8 +482,7 @@ object MainForm: TMainForm
Action = UserManager
end
object menuMaintenance: TMenuItem
Action = Diagnostics
Caption = 'Maintenance'
Action = actMaintenance
end
object N7: TMenuItem
Caption = '-'
@ -659,13 +658,13 @@ object MainForm: TMainForm
Hint = 'About MySQL-Front'
OnExecute = ShowAboutBoxExecute
end
object Diagnostics: TAction
object actMaintenance: TAction
Tag = 35
Caption = 'Table-Diagnostics'
Caption = 'Maintenance'
Enabled = False
Hint = 'Optimize, repair and analyse tables'
ImageIndex = 39
OnExecute = DiagnosticsExecute
OnExecute = actMaintenanceExecute
end
object CopyHTMLtable: TAction
Tag = 49

View File

@ -17,7 +17,7 @@ uses
ActnList, ImgList, Registry, ShellApi, ToolWin, Clipbrd, db, DBCtrls,
SynMemo, synedit, SynEditTypes, ZDataSet, ZSqlProcessor,
HeidiComp, sqlhelp, MysqlQueryThread, Childwin, VirtualTrees, TntDBGrids,
StrUtils, DateUtils, PngImageList;
StrUtils, DateUtils, PngImageList, OptimizeTables;
type
TMainForm = class(TForm)
@ -66,7 +66,7 @@ type
menuReadme: TMenuItem;
UserManager: TAction;
ShowAboutBox: TAction;
Diagnostics: TAction;
actMaintenance: TAction;
menuMaintenance: TMenuItem;
ImExport1: TMenuItem;
CopyContentsasHTMLTable1: TMenuItem;
@ -163,7 +163,7 @@ type
procedure FormResize(Sender: TObject);
procedure UserManagerExecute(Sender: TObject);
procedure ShowAboutBoxExecute(Sender: TObject);
procedure DiagnosticsExecute(Sender: TObject);
procedure actMaintenanceExecute(Sender: TObject);
procedure CopyHTMLtableExecute(Sender: TObject);
procedure Copy2CSVExecute(Sender: TObject);
procedure PrintListExecute(Sender: TObject);
@ -203,6 +203,7 @@ type
function GetParamValue(const paramChar: Char; const paramName:
string; var curIdx: Byte; out paramValue: string): Boolean;
public
MaintenanceForm: TOptimize;
procedure OpenRegistry(Session: String = '');
function GetRegValue( valueName: String; defaultValue: Integer; Session: String = '' ) : Integer; Overload;
function GetRegValue( valueName: String; defaultValue: Boolean; Session: String = '' ) : Boolean; Overload;
@ -251,7 +252,6 @@ uses
loaddata,
usermanager,
options,
optimizetables,
printlist,
copytable,
insertfiles,
@ -711,10 +711,12 @@ begin
AboutWindow (Self);
end;
procedure TMainForm.DiagnosticsExecute(Sender: TObject);
procedure TMainForm.actMaintenanceExecute(Sender: TObject);
begin
// optimize / repair... tables
TableDiagnosticsWindow (Self);
if MaintenanceForm = nil then
MaintenanceForm := TOptimize.Create(Self);
MaintenanceForm.ShowModal;
end;

View File

@ -1,10 +1,10 @@
object optimize: Toptimize
Left = 734
Top = 126
BorderStyle = bsDialog
Caption = 'Table-Diagnostics'
ClientHeight = 386
ClientWidth = 433
BorderIcons = [biSystemMenu, biMaximize]
Caption = 'Maintenance'
ClientHeight = 409
ClientWidth = 431
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
@ -13,111 +13,126 @@ object optimize: Toptimize
Font.Style = []
OldCreateOrder = False
Position = poMainFormCenter
OnCreate = FormCreate
OnDestroy = FormDestroy
OnShow = FormShow
DesignSize = (
431
409)
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 16
object lblSelect: TLabel
Left = 8
Top = 8
Width = 145
Height = 13
Caption = 'Select Database and Table(s):'
end
object Label3: TLabel
Left = 16
Top = 224
object lblResults: TLabel
Left = 8
Top = 211
Width = 39
Height = 13
Caption = 'Results:'
end
object TablesCheckListBox: TCheckListBox
Left = 16
Top = 56
Width = 218
Height = 145
Left = 8
Top = 50
Width = 239
Height = 155
OnClickCheck = TablesCheckListBoxClickCheck
Anchors = [akLeft, akTop, akRight]
Columns = 2
ItemHeight = 13
TabOrder = 2
end
object DBComboBox: TComboBox
Left = 62
Top = 32
Width = 171
Left = 54
Top = 26
Width = 193
Height = 21
Style = csDropDownList
Anchors = [akLeft, akTop, akRight]
ItemHeight = 13
TabOrder = 0
OnChange = DBComboBoxChange
end
object Button3: TButton
Left = 328
Top = 360
object btnClose: TButton
Left = 326
Top = 378
Width = 99
Height = 25
Anchors = [akRight, akBottom]
Cancel = True
Caption = 'Close'
Default = True
ModalResult = 2
TabOrder = 12
end
object CheckBoxQuickRepair: TCheckBox
Left = 360
Top = 168
object cbxQuickRepair: TCheckBox
Left = 358
Top = 170
Width = 57
Height = 17
Anchors = [akTop, akRight]
Caption = 'Quick'
TabOrder = 9
end
object CheckBoxQuickCheck: TCheckBox
Left = 360
Top = 88
object cbxQuickCheck: TCheckBox
Left = 358
Top = 90
Width = 57
Height = 17
Anchors = [akTop, akRight]
Caption = 'Quick'
TabOrder = 5
end
object btnOptimize: TButton
Left = 248
Top = 56
Left = 253
Top = 50
Width = 99
Height = 25
Caption = 'Optimze'
Anchors = [akTop, akRight]
Caption = 'Optimize'
TabOrder = 3
OnClick = Optimze
OnClick = Optimize
end
object btnCheck: TButton
Left = 248
Top = 96
Left = 253
Top = 90
Width = 99
Height = 25
Anchors = [akTop, akRight]
Caption = 'Check'
TabOrder = 4
OnClick = Check
end
object btnAnalyze: TButton
Left = 248
Top = 136
Left = 253
Top = 130
Width = 99
Height = 25
Anchors = [akTop, akRight]
Caption = 'Analyze'
TabOrder = 7
OnClick = Analyze
end
object btnRepair: TButton
Left = 248
Top = 176
Left = 253
Top = 170
Width = 99
Height = 25
Anchors = [akTop, akRight]
Caption = 'Repair'
TabOrder = 8
OnClick = Repair
end
object ListViewResults: TListView
Left = 16
Top = 240
Width = 409
Height = 105
object ListResults: TListView
Left = 8
Top = 230
Width = 417
Height = 142
Anchors = [akLeft, akTop, akRight, akBottom]
Columns = <>
ColumnClick = False
MultiSelect = True
@ -126,36 +141,36 @@ object optimize: Toptimize
TabOrder = 11
ViewStyle = vsReport
end
object ToolBar1: TToolBar
Left = 16
Top = 32
object tlbCheckToggle: TToolBar
Left = 8
Top = 26
Width = 46
Height = 22
Align = alNone
AutoSize = True
Caption = 'ToolBar1'
Caption = 'tlbCheckToggle'
EdgeInner = esNone
EdgeOuter = esNone
Images = MainForm.PngImageListMain
ParentShowHint = False
ShowHint = True
TabOrder = 1
object ToolButton1: TToolButton
object tlbCheckNone: TToolButton
Left = 0
Top = 0
Hint = 'Check none'
Caption = 'ToolButton1'
Caption = 'tlbCheckNone'
ImageIndex = 65
ParentShowHint = False
ShowHint = True
OnClick = CheckListToggle
end
object ToolButton2: TToolButton
object tlbCheckAll: TToolButton
Tag = 1
Left = 23
Top = 0
Hint = 'Check all'
Caption = 'ToolButton2'
Caption = 'tlbCheckAll'
ImageIndex = 64
ParentShowHint = False
ShowHint = True
@ -163,18 +178,20 @@ object optimize: Toptimize
end
end
object cbxExtendedCheck: TCheckBox
Left = 360
Top = 111
Left = 358
Top = 108
Width = 70
Height = 17
Anchors = [akTop, akRight]
Caption = 'Extended'
TabOrder = 6
end
object cbxExtendedRepair: TCheckBox
Left = 360
Top = 191
Left = 358
Top = 188
Width = 70
Height = 17
Anchors = [akTop, akRight]
Caption = 'Extended'
TabOrder = 10
end

View File

@ -10,31 +10,33 @@ interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, CheckLst, comctrls, Buttons, ToolWin, Db;
ExtCtrls, StdCtrls, CheckLst, comctrls, Buttons, ToolWin, Db, Registry;
type
Toptimize = class(TForm)
TablesCheckListBox: TCheckListBox;
DBComboBox: TComboBox;
Label1: TLabel;
Button3: TButton;
CheckBoxQuickRepair: TCheckBox;
CheckBoxQuickCheck: TCheckBox;
lblSelect: TLabel;
btnClose: TButton;
cbxQuickRepair: TCheckBox;
cbxQuickCheck: TCheckBox;
btnOptimize: TButton;
btnCheck: TButton;
btnAnalyze: TButton;
btnRepair: TButton;
Label3: TLabel;
ListViewResults: TListView;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
lblResults: TLabel;
ListResults: TListView;
tlbCheckToggle: TToolBar;
tlbCheckNone: TToolButton;
tlbCheckAll: TToolButton;
cbxExtendedCheck: TCheckBox;
cbxExtendedRepair: TCheckBox;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure DBComboBoxChange(Sender: TObject);
procedure CheckListToggle(Sender: TObject);
procedure Optimze(Sender: TObject);
procedure Optimize(Sender: TObject);
procedure Check(Sender: TObject);
procedure Analyze(Sender: TObject);
procedure Repair(Sender: TObject);
@ -49,23 +51,45 @@ type
{ Public declarations }
end;
function TableDiagnosticsWindow (AOwner : TComponent; Flags : String = '') : Boolean;
implementation
uses childwin, helpers, main;
{$R *.DFM}
function TableDiagnosticsWindow (AOwner : TComponent; Flags : String = '') : Boolean;
var
f : Toptimize;
{**
FormCreate: Restore GUI setup
}
procedure Toptimize.FormCreate(Sender: TObject);
begin
f := Toptimize.Create(AOwner);
f.ShowModal;
Result := True;
FreeAndNil (f);
Width := Mainform.GetRegValue(REGNAME_MAINTWINWIDTH, Width);
Height := Mainform.GetRegValue(REGNAME_MAINTWINHEIGHT, Height);
end;
{**
FormDestroy: Save GUI setup
}
procedure Toptimize.FormDestroy(Sender: TObject);
var
reg : TRegistry;
begin
reg := TRegistry.Create;
if reg.OpenKey(REGPATH, False) then begin
reg.WriteInteger( REGNAME_MAINTWINWIDTH, Width );
reg.WriteInteger( REGNAME_MAINTWINHEIGHT, Height );
reg.CloseKey;
end;
reg.Free;
Close;
end;
{**
FormShow: Fill DB combobox and tables list
}
procedure Toptimize.FormShow(Sender: TObject);
var
i : Integer;
@ -98,10 +122,21 @@ begin
ToggleCheckListBox(TablesCheckListBox, True);
end;
{**
DB selected in pulldown
}
procedure Toptimize.DBComboBoxChange(Sender: TObject);
var
ds: TDataset;
begin
// read tables from db
TablesCheckListBox.Items := Mainform.ChildWin.GetCol( 'SHOW TABLES FROM ' + MainForm.mask(DBComboBox.Text) );
ds := Mainform.ChildWin.FetchDbTableList(DBComboBox.Text);
TablesCheckListBox.Items.Clear;
while not ds.Eof do begin
TablesCheckListBox.Items.Add(ds.Fields[0].AsString);
ds.Next;
end;
// Check all
ToggleCheckListBox( TablesCheckListBox, True );
// Enable controls if there are tables in the database.
@ -109,6 +144,9 @@ begin
end;
{**
Check all/none
}
procedure Toptimize.CheckListToggle(Sender: TObject);
begin
// select all/none
@ -116,6 +154,10 @@ begin
TablesCheckListBox.OnClickCheck(self);
end;
{**
Parse and run SQL template for all maintenance actions
}
procedure Toptimize.RunIterated(pseudoSql: string);
var
i: integer;
@ -143,50 +185,74 @@ begin
end;
end;
procedure Toptimize.Optimze(Sender: TObject);
{**
Optimize tables
}
procedure Toptimize.Optimize(Sender: TObject);
begin
RunIterated('OPTIMIZE TABLE $table');
end;
{**
Check tables
}
procedure Toptimize.Check(Sender: TObject);
var
querystr : String;
begin
querystr := 'CHECK TABLE $table';
if CheckBoxQuickCheck.Checked then
if cbxQuickCheck.Checked then
querystr := querystr + ' QUICK';
if cbxExtendedCheck.Checked then
querystr := querystr + ' EXTENDED';
RunIterated(querystr);
end;
{**
Analyze tables
}
procedure Toptimize.Analyze(Sender: TObject);
begin
RunIterated('ANALYZE TABLE $table');
end;
{**
Repair tables
}
procedure Toptimize.Repair(Sender: TObject);
var
querystr : String;
begin
querystr := 'REPAIR TABLE $table';
if CheckBoxQuickRepair.Checked then
if cbxQuickRepair.Checked then
querystr := querystr + ' QUICK';
if cbxExtendedRepair.Checked then
querystr := querystr + ' EXTENDED';
RunIterated(querystr);
end;
{**
Clear ListResults
}
procedure Toptimize.ClearResults;
begin
ListViewResults.Columns.BeginUpdate();
ListViewResults.Columns.Clear;
ListViewResults.Items.BeginUpdate();
ListViewResults.Items.Clear;
ListViewResults.Columns.EndUpdate();
ListViewResults.Items.EndUpdate();
ListResults.Columns.BeginUpdate;
ListResults.Columns.Clear;
ListResults.Items.BeginUpdate;
ListResults.Items.Clear;
ListResults.Columns.EndUpdate;
ListResults.Items.EndUpdate;
end;
{**
Add results from maintenance action
}
procedure Toptimize.AddResults(ds: TDataSet);
var
i,j,fieldcount : Integer;
@ -194,37 +260,45 @@ var
lc : TListColumn;
begin
fieldcount := ds.FieldCount;
if fieldcount > ListViewResults.Columns.Count then begin
ListViewResults.Columns.BeginUpdate();
for i := ListViewResults.Columns.Count to fieldcount - 1 do begin
lc := ListViewResults.Columns.Add;
if fieldcount > ListResults.Columns.Count then begin
ListResults.Columns.BeginUpdate();
for i := ListResults.Columns.Count to fieldcount - 1 do begin
lc := ListResults.Columns.Add;
lc.Caption := ds.Fields[i].Fieldname;
end;
ListViewResults.Columns.EndUpdate();
ListResults.Columns.EndUpdate;
end;
ListViewResults.Items.BeginUpdate();
ListResults.Items.BeginUpdate;
for i:=1 to ds.RecordCount do
begin
li := ListViewResults.Items.Add;
li := ListResults.Items.Add;
li.Caption := ds.Fields[0].AsString;
for j := 1 to fieldcount -1 do // fill cells
li.SubItems.Add(ds.Fields[j].AsString);
ds.Next;
end;
for i := 0 to ListViewResults.Columns.Count-1 do
ListViewResults.Columns[i].Width := -2;
for i := 0 to ListResults.Columns.Count-1 do
ListResults.Columns[i].Width := -2;
ListViewResults.Items[ListViewResults.Items.Count - 1].MakeVisible(false);
ListViewResults.Items.EndUpdate();
ListResults.Items[ListResults.Items.Count - 1].MakeVisible(false);
ListResults.Items.EndUpdate;
end;
{**
Table was (un-)checked: ensure correct state of buttons
}
procedure Toptimize.TablesCheckListBoxClickCheck(Sender: TObject);
begin
ValidateControls;
end;
{**
Check if at least one table is checked and dis/enable the buttons
}
procedure Toptimize.ValidateControls;
var
i : Integer;
@ -244,4 +318,5 @@ begin
btnRepair.Enabled := somechecked;
end;
end.