diff --git a/source/const.inc b/source/const.inc index 10977b88..a0069c6d 100644 --- a/source/const.inc +++ b/source/const.inc @@ -39,6 +39,9 @@ const REGNAME_DISPLAYEDCOLUMNS = 'DisplayedColumns'; REGNAME_SORTDISPLAYEDCOLUMNS = 'DisplayedColumnsSorted'; REGNAME_LISTTABLESCOLUMNNAMES = 'ListTablesColumnNames'; + REGNAME_TBLPROP_LISTHEIGHT = 'TablePropertiesListHeight'; + REGNAME_TBLPROP_FORMHEIGHT = 'TablePropertiesFormHeight'; + REGNAME_TBLPROP_FORMWIDTH = 'TablePropertiesFormWidth'; // how much memory we're aiming to use for the // data grid and it's automatic limit function diff --git a/source/tbl_properties.dfm b/source/tbl_properties.dfm index a6f9f49f..7db7e4b5 100644 --- a/source/tbl_properties.dfm +++ b/source/tbl_properties.dfm @@ -1,14 +1,11 @@ object tbl_properties_form: Ttbl_properties_form - Left = 611 - Top = 109 + Left = 771 + Top = 113 BorderIcons = [biSystemMenu] - BorderWidth = 5 Caption = 'Table-Properties' - ClientHeight = 339 - ClientWidth = 286 + ClientHeight = 415 + ClientWidth = 334 Color = clBtnFace - Constraints.MaxHeight = 550 - Constraints.MaxWidth = 450 Constraints.MinHeight = 376 Constraints.MinWidth = 304 Font.Charset = DEFAULT_CHARSET @@ -18,34 +15,29 @@ object tbl_properties_form: Ttbl_properties_form Font.Style = [] OldCreateOrder = False Position = poMainFormCenter + OnClose = FormClose OnResize = FormResize OnShow = FormShow PixelsPerInch = 96 TextHeight = 13 - object Bevel: TBevel - Left = 0 - Top = 230 - Width = 286 - Height = 8 - Align = alBottom - Shape = bsSpacer - end object PageControl: TPageControl - Left = 0 - Top = 0 - Width = 286 - Height = 230 + AlignWithMargins = True + Left = 3 + Top = 3 + Width = 328 + Height = 286 + Margins.Bottom = 0 Align = alClient HotTrack = True TabOrder = 0 end object PanelSummary: TPanel Left = 0 - Top = 238 - Width = 286 - Height = 65 + Top = 289 + Width = 334 + Height = 107 Align = alBottom - BevelOuter = bvLowered + BevelOuter = bvNone TabOrder = 1 object LabelSizeOfTableData: TLabel Left = 8 @@ -62,19 +54,17 @@ object tbl_properties_form: Ttbl_properties_form Caption = 'Size of Indexes:' end object LabelSizeOfTableDataValue: TLabel - Left = 144 + Left = 112 Top = 8 Width = 134 Height = 13 - Alignment = taRightJustify Caption = 'LabelSizeOfTableDataValue' end object LabelIndexesValue: TLabel - Left = 188 + Left = 112 Top = 24 Width = 90 Height = 13 - Alignment = taRightJustify Caption = 'LabelIndexesValue' end object LabelSum: TLabel @@ -91,11 +81,10 @@ object tbl_properties_form: Ttbl_properties_form ParentFont = False end object LabelSumValue: TLabel - Left = 191 + Left = 112 Top = 45 Width = 88 Height = 13 - Alignment = taRightJustify Caption = 'LabelSumValue' Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText @@ -104,26 +93,37 @@ object tbl_properties_form: Ttbl_properties_form Font.Style = [fsBold] ParentFont = False end - end - object PanelControl: TPanel - Left = 0 - Top = 303 - Width = 286 - Height = 36 - Align = alBottom - BevelOuter = bvNone - TabOrder = 2 object btnClose: TButton - Left = 96 - Top = 9 - Width = 89 + Left = 112 + Top = 73 + Width = 97 Height = 25 Cancel = True Caption = 'Close' Default = True ModalResult = 1 TabOrder = 0 - OnClick = btnCloseClick + end + end + object StatusBar1: TStatusBar + Left = 0 + Top = 396 + Width = 334 + Height = 19 + Panels = <> + SimplePanel = True + end + object popupSynMemo: TPopupMenu + Images = MainForm.ImageList1 + Left = 16 + Top = 24 + object Copy1: TMenuItem + Action = MainForm.EditCopy1 + end + object menuSelectAll: TMenuItem + Caption = 'Select all' + ShortCut = 16449 + OnClick = menuSelectAllClick end end end diff --git a/source/tbl_properties.pas b/source/tbl_properties.pas index d163a386..787700cc 100644 --- a/source/tbl_properties.pas +++ b/source/tbl_properties.pas @@ -11,7 +11,7 @@ interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, HeidiComp, ExtCtrls, ZDataset, SynMemo, Synedit, - VirtualTrees; + VirtualTrees, Registry, Menus; type Ttbl_properties_form = class(TForm) @@ -23,12 +23,16 @@ type LabelIndexesValue: TLabel; LabelSum: TLabel; LabelSumValue: TLabel; - Bevel: TBevel; - PanelControl: TPanel; + StatusBar1: TStatusBar; btnClose: TButton; + popupSynMemo: TPopupMenu; + Copy1: TMenuItem; + menuSelectAll: TMenuItem; + procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormShow(Sender: TObject); - procedure btnCloseClick(Sender: TObject); procedure FormResize(Sender: TObject); + procedure menuSelectAllClick(Sender: TObject); + procedure SplitterMove(Sender: TObject); end; function tbl_properties_Window(AOwner: TComponent): Boolean; @@ -40,6 +44,9 @@ uses {$R *.DFM} +const + DEFAULT_LISTHEIGHT = 150; + {** Create form on demand @@ -56,9 +63,12 @@ begin end; -{*** - - +{** + Form gets displayed. + - Setup dimensions of components + - create one page + listview + synmemo for each selected table. + - display data and CREATE TABLE statement + - calculate the sum of their size } procedure Ttbl_properties_form.FormShow(Sender: TObject); var @@ -66,36 +76,40 @@ var t: Integer; ts: TTabSheet; list: TSortListView; - ListTables: TVirtualStringTree; datasize: Int64; indexsize: Int64; isSelected: Boolean; - FieldList: TStringList; splitter: TSplitter; synmemo: TSynMemo; query: TDataSet; Selected: TStringList; + reg : TRegistry; + listheight : Integer; begin - ListTables := Mainform.Childwin.ListTables; - - for i := (PageControl.PageCount - 1) downto 0 do - begin - PageControl.Pages[i].Free(); - end; datasize := 0; indexsize := 0; + listheight := DEFAULT_LISTHEIGHT; - query := Mainform.Childwin.GetResults( 'SHOW TABLE STATUS'); - - FieldList := TStringList.Create; - for i := 0 to (query.FieldCount - 1) do - begin - FieldList.add( query.Fields[i].Fieldname ); + reg := TRegistry.Create; + reg.OpenKey( REGPATH, true ); + try + // Read values + if reg.ValueExists( REGNAME_TBLPROP_LISTHEIGHT ) then + listheight := reg.ReadInteger( REGNAME_TBLPROP_LISTHEIGHT ); + if reg.ValueExists( REGNAME_TBLPROP_FORMHEIGHT ) then + Height := reg.ReadInteger( REGNAME_TBLPROP_FORMHEIGHT ); + if reg.ValueExists( REGNAME_TBLPROP_FORMWIDTH ) then + Width := reg.ReadInteger( REGNAME_TBLPROP_FORMWIDTH ); + finally + reg.CloseKey; + reg.Free; end; // Fetch selected nodes - Selected := GetVTCaptions(ListTables, True); + Selected := GetVTCaptions(Mainform.Childwin.ListTables, True); + + query := Mainform.Childwin.GetResults( 'SHOW TABLE STATUS'); // for tables found for t := 0 to (query.RecordCount - 1) do @@ -127,11 +141,13 @@ begin // creates a splitter splitter := TSplitter.Create(self); splitter.Parent := ts; + splitter.ResizeStyle := rsUpdate; + splitter.OnMoved := SplitterMove; // create a detailed properties list list := TSortListView.Create(self); list.Parent := ts; - list.Height := 150; + list.Height := listheight; list.ViewStyle := vsReport; list.ReadOnly := true; list.GridLines := true; @@ -151,11 +167,11 @@ begin inc( datasize, StrToInt64Def(query.FieldByName('Data_length').AsString, 0) ); inc( indexsize, StrToInt64Def(query.FieldByName('Index_length').AsString, 0) ); - for i:=0 to FieldList.count-1 do + for i:=0 to query.FieldCount - 1 do begin with (list.Items.add) do begin - Caption := FieldList[i]; + Caption := query.Fields[i].FieldName; SubItems.Add( query.Fields[i].AsString); end; end; @@ -175,7 +191,7 @@ begin synmemo.Font.Name := Mainform.Childwin.SynMemoQuery.Font.Name; synmemo.Font.Size := Mainform.Childwin.SynMemoQuery.Font.Size; synmemo.Lines.Text := Mainform.Childwin.GetVar( 'SHOW CREATE TABLE ' + Mainform.Childwin.mask(query.Fields[0].AsString), 1 ); - + synmemo.PopupMenu := popupSynMemo; // realign the components to correct position list.Align := alTop; @@ -186,24 +202,87 @@ begin query.Next(); end; - LabelSizeOfTableDataValue.Caption := FormatNumber(datasize div 1024) + ' KB'; - LabelIndexesValue.Caption := FormatNumber(indexsize div 1024) + ' KB'; - LabelSumValue.Caption := FormatNumber(datasize div 1024 + indexsize div 1024) + ' KB'; + LabelSizeOfTableDataValue.Caption := FormatByteNumber(datasize); + LabelIndexesValue.Caption := FormatByteNumber(indexsize); + LabelSumValue.Caption := FormatByteNumber(datasize + indexsize); end; -procedure Ttbl_properties_form.btnCloseClick(Sender: TObject); +{** + Form closes. Store dimensions of relevant components. +} +procedure Ttbl_properties_form.FormClose(Sender: TObject; var Action: + TCloseAction); +var + reg: TRegistry; + i, listheight: Integer; begin - Close(); + // Find height of dynamically created listviews + listheight := DEFAULT_LISTHEIGHT; + for i := 0 to ComponentCount-1 do + begin + if Components[i] is TListView then + begin + listheight := TListView(Components[i]).Height; + break; + end; + end; + + reg := TRegistry.Create; + reg.OpenKey( REGPATH, true ); + try + // Save values + reg.WriteInteger( REGNAME_TBLPROP_LISTHEIGHT, listheight ); + reg.WriteInteger( REGNAME_TBLPROP_FORMHEIGHT, Height ); + reg.WriteInteger( REGNAME_TBLPROP_FORMWIDTH, Width ); + finally + reg.CloseKey; + reg.Free; + end; end; + +{** + Form has been resized. Adjust position of Close-button. +} procedure Ttbl_properties_form.FormResize(Sender: TObject); begin - btnClose.Left := PanelControl.Width div 2 - (btnClose.Width div 2); - - LabelSizeOfTableDataValue.Left := PanelSummary.Width - LabelSizeOfTableDataValue.Width - 8; - LabelIndexesValue.Left := PanelSummary.Width - LabelIndexesValue.Width - 8; - LabelSumValue.Left := PanelSummary.Width - LabelSumValue.Width - 8; + btnClose.Left := PanelSummary.Width div 2 - (btnClose.Width div 2); end; + +{** + Select all text in a synmemo +} +procedure Ttbl_properties_form.menuSelectAllClick(Sender: TObject); +var + i: Integer; +begin + for i := 0 to ComponentCount - 1 do + begin + if (Components[i] is TSynMemo) and (TSynMemo(Components[i]).Parent = PageControl.ActivePage) then + begin + TSynMemo(Components[i]).SelectAll; + break; + end; + end; +end; + + +{** + Splitter between list and synmemo was moved. + Move all other splitters to the same position +} +procedure Ttbl_properties_form.SplitterMove(Sender: TObject); +var + i: Integer; +begin + for i := 0 to ComponentCount-1 do + begin + if Components[i] is TListView then + TSortListView(Components[i]).Height := TSplitter(Sender).Top; + end; +end; + + end.