From 8679b371e3c7215a8379bf00754d5f4bae180f41 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Fri, 29 Feb 2008 22:32:53 +0000 Subject: [PATCH] New feature: Introduce a dialog for editing a server variable which is called on ListVariables (DblClick or Enter). --- packages/delphi10/heidisql.dpr | 3 +- packages/delphi11/heidisql.dpr | 3 +- packages/delphi11/heidisql.dproj | 3 ++ source/childwin.dfm | 7 +++ source/childwin.pas | 30 +++++++++++- source/editvar.dfm | 76 +++++++++++++++++++++++++++++ source/editvar.pas | 82 ++++++++++++++++++++++++++++++++ 7 files changed, 201 insertions(+), 3 deletions(-) create mode 100644 source/editvar.dfm create mode 100644 source/editvar.pas diff --git a/packages/delphi10/heidisql.dpr b/packages/delphi10/heidisql.dpr index c43edcfc..cb920c04 100644 --- a/packages/delphi10/heidisql.dpr +++ b/packages/delphi10/heidisql.dpr @@ -35,7 +35,8 @@ uses data_sorting in '..\..\source\data_sorting.pas' {DataSortingForm}, runsqlfile in '..\..\source\runsqlfile.pas' {RunSQLFileForm}, createdatabase in '..\..\source\createdatabase.pas' {CreateDatabaseForm}, - updatecheck in '..\..\source\updatecheck.pas' {frmUpdateCheck}; + updatecheck in '..\..\source\updatecheck.pas' {frmUpdateCheck}, + editvar in '..\..\source\editvar.pas' {frmEditVariable}; {$R *.RES} diff --git a/packages/delphi11/heidisql.dpr b/packages/delphi11/heidisql.dpr index c43edcfc..cb920c04 100644 --- a/packages/delphi11/heidisql.dpr +++ b/packages/delphi11/heidisql.dpr @@ -35,7 +35,8 @@ uses data_sorting in '..\..\source\data_sorting.pas' {DataSortingForm}, runsqlfile in '..\..\source\runsqlfile.pas' {RunSQLFileForm}, createdatabase in '..\..\source\createdatabase.pas' {CreateDatabaseForm}, - updatecheck in '..\..\source\updatecheck.pas' {frmUpdateCheck}; + updatecheck in '..\..\source\updatecheck.pas' {frmUpdateCheck}, + editvar in '..\..\source\editvar.pas' {frmEditVariable}; {$R *.RES} diff --git a/packages/delphi11/heidisql.dproj b/packages/delphi11/heidisql.dproj index f8f323f1..c62e694f 100644 --- a/packages/delphi11/heidisql.dproj +++ b/packages/delphi11/heidisql.dproj @@ -88,6 +88,9 @@
FormEditUser
+ +
frmEditVariable
+
ExportSQLForm
diff --git a/source/childwin.dfm b/source/childwin.dfm index 50e5b272..f1c6536c 100644 --- a/source/childwin.dfm +++ b/source/childwin.dfm @@ -138,6 +138,7 @@ object MDIChild: TMDIChild TreeOptions.SelectionOptions = [toFullRowSelect, toRightClickSelect] OnBeforePaint = vstBeforePaint OnCompareNodes = vstCompareNodes + OnDblClick = ListVariablesDblClick OnFreeNode = vstFreeNode OnGetText = vstGetText OnGetImageIndex = vstGetImageIndex @@ -1950,6 +1951,12 @@ object MDIChild: TMDIChild OnClick = DisableAutoRefreshClick end end + object menuEditVariable: TMenuItem + Caption = 'Edit ...' + ImageIndex = 32 + ShortCut = 13 + OnClick = menuEditVariableClick + end object N1: TMenuItem Caption = '-' end diff --git a/source/childwin.pas b/source/childwin.pas index 686c7cc3..55f422f9 100644 --- a/source/childwin.pas +++ b/source/childwin.pas @@ -24,7 +24,7 @@ uses SynCompletionProposal, HeidiComp, SynEditMiscClasses, MysqlQuery, MysqlQueryThread, queryprogress, communication, MysqlConn, Tabs, VirtualTrees, createdatabase, tbl_properties, createtable, TntDBGrids, TntClasses, - SynUnicode, SynRegExpr; + SynUnicode, SynRegExpr, EditVar; type TOrderCol = class(TObject) @@ -330,6 +330,7 @@ type pnlFilterProcesses: TPanel; lblFilterProcesses: TLabel; editFilterProcesses: TEdit; + menuEditVariable: TMenuItem; procedure DBtreeContextPopup(Sender: TObject; MousePos: TPoint; var Handled: Boolean); procedure DBtreeChanging(Sender: TObject; Node: TTreeNode; @@ -542,6 +543,8 @@ type TRect); procedure ListProcessesChange(Sender: TBaseVirtualTree; Node: PVirtualNode); procedure editFilterVTChange(Sender: TObject); + procedure ListVariablesDblClick(Sender: TObject); + procedure menuEditVariableClick(Sender: TObject); private methodStack : TStack; @@ -566,6 +569,7 @@ type CreateDatabaseForm : TCreateDatabaseForm; TablePropertiesForm : Ttbl_properties_form; CreateTableForm : TCreateTableForm; + EditVariableForm : TfrmEditVariable; FileNameSessionLog : String; FileHandleSessionLog : Textfile; SqlMessages : TStringList; @@ -4398,6 +4402,7 @@ end; procedure TMDIChild.popupHostPopup(Sender: TObject); begin Kill1.Enabled := (PageControlHost.ActivePage = tabProcessList) and Assigned(ListProcesses.FocusedNode); + menuEditVariable.Enabled := (PageControlHost.ActivePage = tabVariables) and Assigned(ListVariables.FocusedNode); end; procedure TMDIChild.Saveastextfile1Click(Sender: TObject); @@ -6924,4 +6929,27 @@ begin end; +procedure TMDIChild.ListVariablesDblClick(Sender: TObject); +begin + menuEditVariableClick(Sender); +end; + + +{** + Edit a server variable +} +procedure TMDIChild.menuEditVariableClick(Sender: TObject); +var + NodeData: PVTreeData; +begin + if EditVariableForm = nil then + EditVariableForm := TfrmEditVariable.Create(Self); + NodeData := ListVariables.GetNodeData(ListVariables.FocusedNode); + EditVariableForm.VarName := NodeData.Captions[0]; + EditVariableForm.VarValue := NodeData.Captions[1]; + if EditVariableForm.ShowModal = mrOK then + ShowVariablesAndProcesses(Sender); +end; + + end. diff --git a/source/editvar.dfm b/source/editvar.dfm new file mode 100644 index 00000000..0f6d588c --- /dev/null +++ b/source/editvar.dfm @@ -0,0 +1,76 @@ +object frmEditVariable: TfrmEditVariable + Left = 0 + Top = 0 + BorderStyle = bsDialog + Caption = 'Edit server variable' + ClientHeight = 142 + ClientWidth = 301 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'Tahoma' + Font.Style = [] + OldCreateOrder = False + Position = poMainFormCenter + OnShow = FormShow + DesignSize = ( + 301 + 142) + PixelsPerInch = 96 + TextHeight = 13 + object lblValue: TLabel + Left = 8 + Top = 11 + Width = 54 + Height = 13 + Caption = 'New value:' + end + object editValue: TEdit + Left = 8 + Top = 29 + Width = 285 + Height = 21 + Anchors = [akLeft, akTop, akRight] + TabOrder = 0 + Text = 'editValue' + OnChange = editValueChange + end + object rgScope: TRadioGroup + Left = 8 + Top = 56 + Width = 285 + Height = 45 + Anchors = [akLeft, akTop, akRight, akBottom] + Caption = 'Scope' + Columns = 2 + ItemIndex = 0 + Items.Strings = ( + 'This session' + 'Global') + TabOrder = 1 + end + object btnOK: TButton + Left = 154 + Top = 109 + Width = 75 + Height = 25 + Anchors = [akRight, akBottom] + Caption = 'OK' + Default = True + ModalResult = 1 + TabOrder = 2 + OnClick = btnOKClick + end + object btnCancel: TButton + Left = 73 + Top = 109 + Width = 75 + Height = 25 + Anchors = [akRight, akBottom] + Cancel = True + Caption = 'Cancel' + ModalResult = 2 + TabOrder = 3 + end +end diff --git a/source/editvar.pas b/source/editvar.pas new file mode 100644 index 00000000..91aa15eb --- /dev/null +++ b/source/editvar.pas @@ -0,0 +1,82 @@ +unit editvar; + +interface + +uses + Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, + Dialogs, StdCtrls, ExtCtrls; + +type + TfrmEditVariable = class(TForm) + editValue: TEdit; + rgScope: TRadioGroup; + lblValue: TLabel; + btnOK: TButton; + btnCancel: TButton; + procedure btnOKClick(Sender: TObject); + procedure editValueChange(Sender: TObject); + procedure FormShow(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + VarName, VarValue: String; + end; + +implementation + +uses main, helpers; + +{$R *.dfm} + + +procedure TfrmEditVariable.FormShow(Sender: TObject); +begin + lblValue.Caption := 'New value for "'+VarName+'":'; + editValue.Text := VarValue; + editValue.SelectAll; + editValue.SetFocus; +end; + + +{** + Compose SQL query and set the new variable value +} +procedure TfrmEditVariable.btnOKClick(Sender: TObject); +var + sql: String; +begin + // Syntax taken from http://dev.mysql.com/doc/refman/4.1/en/using-system-variables.html + sql := 'SET @@'; + if rgScope.ItemIndex = 0 then + sql := sql + 'session' + else + sql := sql + 'global'; + sql := sql + '.' + VarName + ' = '; + + // Test if the original value is numerical and should be passed without quotes + // Avoids SQL error "Wrong argument type to variable" + if IntToStr(MakeInt(VarValue)) = VarValue then + sql := sql + IntToStr(MakeInt(editValue.Text)) + else + sql := sql + esc(editValue.Text); + + // Set the value and keep the form open in any error case + try + Mainform.Childwin.ExecUpdateQuery(sql, False, True); + except + ModalResult := mrNone; + end; +end; + + +{** + Enable the OK button only if the value is different from the initial one +} +procedure TfrmEditVariable.editValueChange(Sender: TObject); +begin + btnOK.Enabled := editValue.Text <> VarValue; +end; + + +end.