New feature: Introduce a dialog for editing a server variable which is called on ListVariables (DblClick or Enter).

This commit is contained in:
Ansgar Becker
2008-02-29 22:32:53 +00:00
parent 7e4bfafbe1
commit 8679b371e3
7 changed files with 201 additions and 3 deletions

View File

@ -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}

View File

@ -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}

View File

@ -88,6 +88,9 @@
<DCCReference Include="..\..\source\edituser.pas">
<Form>FormEditUser</Form>
</DCCReference>
<DCCReference Include="..\..\source\editvar.pas">
<Form>frmEditVariable</Form>
</DCCReference>
<DCCReference Include="..\..\source\exportsql.pas">
<Form>ExportSQLForm</Form>
</DCCReference>

View File

@ -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

View File

@ -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.

76
source/editvar.dfm Normal file
View File

@ -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

82
source/editvar.pas Normal file
View File

@ -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.