mirror of
https://github.com/HeidiSQL/HeidiSQL.git
synced 2025-08-14 01:56:36 +08:00
Implement a parent class for all database object editors (table, view, routine, trigger) and let these editors derive from this class. Could simplify code in the future.
This commit is contained in:
@ -143,6 +143,14 @@ type
|
|||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
TDBObjectEditor = class(TFrame)
|
||||||
|
private
|
||||||
|
FModified: Boolean;
|
||||||
|
procedure SetModified(Value: Boolean);
|
||||||
|
public
|
||||||
|
property Modified: Boolean read FModified write SetModified;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{$I const.inc}
|
{$I const.inc}
|
||||||
|
|
||||||
@ -3225,6 +3233,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
{ *** TDBObjectEditor }
|
||||||
|
|
||||||
|
procedure TDBObjectEditor.SetModified(Value: Boolean);
|
||||||
|
begin
|
||||||
|
FModified := Value;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@ interface
|
|||||||
uses
|
uses
|
||||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||||
Dialogs, SynEdit, SynMemo, StdCtrls, TntStdCtrls, ComCtrls, ToolWin,
|
Dialogs, SynEdit, SynMemo, StdCtrls, TntStdCtrls, ComCtrls, ToolWin,
|
||||||
VirtualTrees, WideStrings, mysql_connection, SynRegExpr, WideStrUtils;
|
VirtualTrees, WideStrings, mysql_connection, SynRegExpr, WideStrUtils, helpers;
|
||||||
|
|
||||||
type
|
type
|
||||||
TfrmRoutineEditor = class(TFrame)
|
TfrmRoutineEditor = class(TDBObjectEditor)
|
||||||
btnSave: TButton;
|
btnSave: TButton;
|
||||||
btnDiscard: TButton;
|
btnDiscard: TButton;
|
||||||
btnHelp: TButton;
|
btnHelp: TButton;
|
||||||
@ -67,11 +67,8 @@ type
|
|||||||
private
|
private
|
||||||
{ Private declarations }
|
{ Private declarations }
|
||||||
Parameters: TWideStringList;
|
Parameters: TWideStringList;
|
||||||
FModified: Boolean;
|
|
||||||
FAlterRoutineName: WideString;
|
FAlterRoutineName: WideString;
|
||||||
FAlterRoutineType: String;
|
FAlterRoutineType: String;
|
||||||
procedure SetModified(Value: Boolean);
|
|
||||||
property Modified: Boolean read FModified write SetModified;
|
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
constructor Create(AOwner: TComponent); override;
|
constructor Create(AOwner: TComponent); override;
|
||||||
@ -81,7 +78,7 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses main, helpers, mysql_structures, grideditlinks;
|
uses main, mysql_structures, grideditlinks;
|
||||||
|
|
||||||
{$R *.dfm}
|
{$R *.dfm}
|
||||||
|
|
||||||
@ -188,6 +185,8 @@ begin
|
|||||||
comboTypeSelect(comboType);
|
comboTypeSelect(comboType);
|
||||||
btnRemoveParam.Enabled := Assigned(listParameters.FocusedNode);
|
btnRemoveParam.Enabled := Assigned(listParameters.FocusedNode);
|
||||||
Modified := False;
|
Modified := False;
|
||||||
|
btnSave.Enabled := Modified;
|
||||||
|
btnDiscard.Enabled := Modified;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -204,13 +203,15 @@ begin
|
|||||||
editName.Color := clYellow;
|
editName.Color := clYellow;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
Modified := True;
|
Modification(Sender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmRoutineEditor.Modification(Sender: TObject);
|
procedure TfrmRoutineEditor.Modification(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Modified := True;
|
Modified := True;
|
||||||
|
btnSave.Enabled := Modified;
|
||||||
|
btnDiscard.Enabled := Modified;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -221,7 +222,7 @@ begin
|
|||||||
isfunc := (Sender as TTNTComboBox).ItemIndex = 1;
|
isfunc := (Sender as TTNTComboBox).ItemIndex = 1;
|
||||||
lblReturns.Enabled := isfunc;
|
lblReturns.Enabled := isfunc;
|
||||||
comboReturns.Enabled := isfunc;
|
comboReturns.Enabled := isfunc;
|
||||||
Modified := True;
|
Modification(Sender);
|
||||||
listParameters.Repaint;
|
listParameters.Repaint;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -231,7 +232,7 @@ begin
|
|||||||
Parameters.Add('Param'+IntToStr(Parameters.Count+1)+DELIM+'INT'+DELIM+'IN');
|
Parameters.Add('Param'+IntToStr(Parameters.Count+1)+DELIM+'INT'+DELIM+'IN');
|
||||||
// See List.OnPaint:
|
// See List.OnPaint:
|
||||||
listParameters.Repaint;
|
listParameters.Repaint;
|
||||||
Modified := True;
|
Modification(Sender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -239,7 +240,7 @@ procedure TfrmRoutineEditor.btnRemoveParamClick(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
Parameters.Delete(ListParameters.FocusedNode.Index);
|
Parameters.Delete(ListParameters.FocusedNode.Index);
|
||||||
listParameters.Repaint;
|
listParameters.Repaint;
|
||||||
Modified := True;
|
Modification(Sender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -247,7 +248,7 @@ procedure TfrmRoutineEditor.btnClearParamsClick(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
Parameters.Clear;
|
Parameters.Clear;
|
||||||
listParameters.Repaint;
|
listParameters.Repaint;
|
||||||
Modified := True;
|
Modification(Sender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -327,7 +328,7 @@ begin
|
|||||||
3: new := OldValues[0] + DELIM + OldValues[1] + DELIM + NewText;
|
3: new := OldValues[0] + DELIM + OldValues[1] + DELIM + NewText;
|
||||||
end;
|
end;
|
||||||
Parameters[Node.Index] := new;
|
Parameters[Node.Index] := new;
|
||||||
Modified := True;
|
Modification(Sender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -481,6 +482,8 @@ begin
|
|||||||
Mainform.SetEditorTabCaption(Self, FAlterRoutineName);
|
Mainform.SetEditorTabCaption(Self, FAlterRoutineName);
|
||||||
Mainform.actRefresh.Execute;
|
Mainform.actRefresh.Execute;
|
||||||
Modified := False;
|
Modified := False;
|
||||||
|
btnSave.Enabled := Modified;
|
||||||
|
btnDiscard.Enabled := Modified;
|
||||||
except
|
except
|
||||||
on E:Exception do
|
on E:Exception do
|
||||||
MessageDlg(E.Message, mtError, [mbOk], 0);
|
MessageDlg(E.Message, mtError, [mbOk], 0);
|
||||||
@ -488,14 +491,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmRoutineEditor.SetModified(Value: Boolean);
|
|
||||||
begin
|
|
||||||
FModified := Value;
|
|
||||||
btnSave.Enabled := FModified;
|
|
||||||
btnDiscard.Enabled := FModified;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmRoutineEditor.btnDiscardClick(Sender: TObject);
|
procedure TfrmRoutineEditor.btnDiscardClick(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Init(FAlterRoutineName, FAlterRoutineType);
|
Init(FAlterRoutineName, FAlterRoutineType);
|
||||||
|
@ -9,7 +9,7 @@ uses
|
|||||||
Contnrs, grideditlinks, mysql_structures, mysql_connection, helpers;
|
Contnrs, grideditlinks, mysql_structures, mysql_connection, helpers;
|
||||||
|
|
||||||
type
|
type
|
||||||
TfrmTableEditor = class(TFrame)
|
TfrmTableEditor = class(TDBObjectEditor)
|
||||||
btnSave: TButton;
|
btnSave: TButton;
|
||||||
btnDiscard: TButton;
|
btnDiscard: TButton;
|
||||||
btnHelp: TButton;
|
btnHelp: TButton;
|
||||||
@ -168,7 +168,6 @@ type
|
|||||||
procedure listColumnsNodeMoved(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
procedure listColumnsNodeMoved(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
||||||
private
|
private
|
||||||
{ Private declarations }
|
{ Private declarations }
|
||||||
FModified: Boolean;
|
|
||||||
FLoaded: Boolean;
|
FLoaded: Boolean;
|
||||||
FAlterTableName: WideString;
|
FAlterTableName: WideString;
|
||||||
CreateCodeValid, AlterCodeValid: Boolean;
|
CreateCodeValid, AlterCodeValid: Boolean;
|
||||||
@ -177,13 +176,11 @@ type
|
|||||||
procedure ValidateColumnControls;
|
procedure ValidateColumnControls;
|
||||||
procedure ValidateIndexControls;
|
procedure ValidateIndexControls;
|
||||||
procedure MoveFocusedIndexPart(NewIdx: Cardinal);
|
procedure MoveFocusedIndexPart(NewIdx: Cardinal);
|
||||||
procedure SetModified(Value: Boolean);
|
|
||||||
procedure ResetModificationFlags;
|
procedure ResetModificationFlags;
|
||||||
function ComposeCreateStatement: WideString;
|
function ComposeCreateStatement: WideString;
|
||||||
function ComposeAlterStatement: WideString;
|
function ComposeAlterStatement: WideString;
|
||||||
function GetIndexSQL(idx: Integer): WideString;
|
function GetIndexSQL(idx: Integer): WideString;
|
||||||
function GetForeignKeySQL(idx: Integer): WideString;
|
function GetForeignKeySQL(idx: Integer): WideString;
|
||||||
property Modified: Boolean read FModified write SetModified;
|
|
||||||
procedure UpdateSQLcode;
|
procedure UpdateSQLcode;
|
||||||
function CellEditingAllowed(Node: PVirtualNode; Column: TColumnIndex): Boolean;
|
function CellEditingAllowed(Node: PVirtualNode; Column: TColumnIndex): Boolean;
|
||||||
function GetIndexIcon(idx: Integer): Integer;
|
function GetIndexIcon(idx: Integer): Integer;
|
||||||
@ -446,6 +443,8 @@ begin
|
|||||||
ForeignKey.Modified := False;
|
ForeignKey.Modified := False;
|
||||||
end;
|
end;
|
||||||
Modified := False;
|
Modified := False;
|
||||||
|
btnSave.Enabled := Modified;
|
||||||
|
btnDiscard.Enabled := Modified;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -757,6 +756,11 @@ begin
|
|||||||
if Sender is TComponent then
|
if Sender is TComponent then
|
||||||
TComponent(Sender).Tag := ModifiedFlag;
|
TComponent(Sender).Tag := ModifiedFlag;
|
||||||
Modified := True;
|
Modified := True;
|
||||||
|
btnSave.Enabled := Modified;
|
||||||
|
btnDiscard.Enabled := Modified;
|
||||||
|
CreateCodeValid := False;
|
||||||
|
AlterCodeValid := False;
|
||||||
|
UpdateSQLcode;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1215,18 +1219,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmTableEditor.SetModified(Value: Boolean);
|
|
||||||
begin
|
|
||||||
// Some value has changed
|
|
||||||
FModified := Value;
|
|
||||||
btnSave.Enabled := FModified;
|
|
||||||
btnDiscard.Enabled := FModified;
|
|
||||||
CreateCodeValid := False;
|
|
||||||
AlterCodeValid := False;
|
|
||||||
UpdateSQLcode;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TfrmTableEditor.editNumEditChange(Sender: TObject);
|
procedure TfrmTableEditor.editNumEditChange(Sender: TObject);
|
||||||
var
|
var
|
||||||
ed: TEdit;
|
ed: TEdit;
|
||||||
|
@ -5,10 +5,10 @@ interface
|
|||||||
uses
|
uses
|
||||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||||
Dialogs, StdCtrls, TntStdCtrls, SynEdit, SynMemo, ExtCtrls, mysql_connection, mysql_api,
|
Dialogs, StdCtrls, TntStdCtrls, SynEdit, SynMemo, ExtCtrls, mysql_connection, mysql_api,
|
||||||
SynCompletionProposal, VirtualTrees;
|
SynCompletionProposal, VirtualTrees, helpers;
|
||||||
|
|
||||||
type
|
type
|
||||||
TfrmTriggerEditor = class(TFrame)
|
TfrmTriggerEditor = class(TDBObjectEditor)
|
||||||
lblName: TLabel;
|
lblName: TLabel;
|
||||||
editName: TTntEdit;
|
editName: TTntEdit;
|
||||||
SynMemoStatement: TSynMemo;
|
SynMemoStatement: TSynMemo;
|
||||||
@ -39,7 +39,7 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses main, helpers;
|
uses main;
|
||||||
|
|
||||||
{$R *.dfm}
|
{$R *.dfm}
|
||||||
|
|
||||||
@ -108,8 +108,9 @@ begin
|
|||||||
Mainform.SetEditorTabCaption(Self, '');
|
Mainform.SetEditorTabCaption(Self, '');
|
||||||
editName.Text := 'Enter trigger name';
|
editName.Text := 'Enter trigger name';
|
||||||
end;
|
end;
|
||||||
btnSave.Enabled := False;
|
Modified := False;
|
||||||
btnDiscard.Enabled := False;
|
btnSave.Enabled := Modified;
|
||||||
|
btnDiscard.Enabled := Modified;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -120,6 +121,7 @@ begin
|
|||||||
and (comboTiming.ItemIndex > -1) and (comboEvent.ItemIndex > -1)
|
and (comboTiming.ItemIndex > -1) and (comboEvent.ItemIndex > -1)
|
||||||
and (SynMemoStatement.Text <> '');
|
and (SynMemoStatement.Text <> '');
|
||||||
btnDiscard.Enabled := True;
|
btnDiscard.Enabled := True;
|
||||||
|
Modified := True;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ object frmView: TfrmView
|
|||||||
'Merge'
|
'Merge'
|
||||||
'Temptable')
|
'Temptable')
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
|
OnClick = Modification
|
||||||
end
|
end
|
||||||
object SynMemoSelect: TSynMemo
|
object SynMemoSelect: TSynMemo
|
||||||
Left = 3
|
Left = 3
|
||||||
@ -76,6 +77,7 @@ object frmView: TfrmView
|
|||||||
Options = [eoAutoIndent, eoDropFiles, eoGroupUndo, eoShowScrollHint]
|
Options = [eoAutoIndent, eoDropFiles, eoGroupUndo, eoShowScrollHint]
|
||||||
RightEdge = 0
|
RightEdge = 0
|
||||||
WantTabs = True
|
WantTabs = True
|
||||||
|
OnChange = Modification
|
||||||
RemovedKeystrokes = <
|
RemovedKeystrokes = <
|
||||||
item
|
item
|
||||||
Command = ecDeleteLine
|
Command = ecDeleteLine
|
||||||
@ -122,6 +124,7 @@ object frmView: TfrmView
|
|||||||
'Cascaded'
|
'Cascaded'
|
||||||
'Local')
|
'Local')
|
||||||
TabOrder = 5
|
TabOrder = 5
|
||||||
|
OnClick = Modification
|
||||||
end
|
end
|
||||||
object btnHelp: TButton
|
object btnHelp: TButton
|
||||||
Left = 3
|
Left = 3
|
||||||
|
@ -4,10 +4,11 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||||
Dialogs, StdCtrls, ComCtrls, SynEdit, SynMemo, ExtCtrls, mysql_connection, SynRegExpr;
|
Dialogs, StdCtrls, ComCtrls, SynEdit, SynMemo, ExtCtrls, mysql_connection, SynRegExpr,
|
||||||
|
helpers;
|
||||||
|
|
||||||
type
|
type
|
||||||
TfrmView = class(TFrame)
|
TfrmView = class(TDBObjectEditor)
|
||||||
editName: TEdit;
|
editName: TEdit;
|
||||||
lblName: TLabel;
|
lblName: TLabel;
|
||||||
rgAlgorithm: TRadioGroup;
|
rgAlgorithm: TRadioGroup;
|
||||||
@ -21,6 +22,7 @@ type
|
|||||||
procedure btnSaveClick(Sender: TObject);
|
procedure btnSaveClick(Sender: TObject);
|
||||||
procedure editNameChange(Sender: TObject);
|
procedure editNameChange(Sender: TObject);
|
||||||
procedure btnDiscardClick(Sender: TObject);
|
procedure btnDiscardClick(Sender: TObject);
|
||||||
|
procedure Modification(Sender: TObject);
|
||||||
private
|
private
|
||||||
{ Private declarations }
|
{ Private declarations }
|
||||||
FEditViewName: WideString;
|
FEditViewName: WideString;
|
||||||
@ -33,7 +35,7 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses main, helpers;
|
uses main;
|
||||||
|
|
||||||
{$R *.dfm}
|
{$R *.dfm}
|
||||||
|
|
||||||
@ -95,6 +97,9 @@ begin
|
|||||||
// Ensure name is validated
|
// Ensure name is validated
|
||||||
editNameChange(Self);
|
editNameChange(Self);
|
||||||
MainForm.SetupSynEditors;
|
MainForm.SetupSynEditors;
|
||||||
|
Modified := False;
|
||||||
|
btnSave.Enabled := Modified;
|
||||||
|
btnDiscard.Enabled := Modified;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -103,16 +108,15 @@ end;
|
|||||||
}
|
}
|
||||||
procedure TfrmView.editNameChange(Sender: TObject);
|
procedure TfrmView.editNameChange(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
btnSave.Enabled := False;
|
|
||||||
try
|
try
|
||||||
ensureValidIdentifier( editName.Text );
|
ensureValidIdentifier( editName.Text );
|
||||||
editName.Font.Color := clWindowText;
|
editName.Font.Color := clWindowText;
|
||||||
editName.Color := clWindow;
|
editName.Color := clWindow;
|
||||||
btnSave.Enabled := True;
|
|
||||||
except
|
except
|
||||||
editName.Font.Color := clRed;
|
editName.Font.Color := clRed;
|
||||||
editName.Color := clYellow;
|
editName.Color := clYellow;
|
||||||
end;
|
end;
|
||||||
|
Modification(Sender);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -175,4 +179,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TfrmView.Modification(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Modified := True;
|
||||||
|
btnSave.Enabled := Modified;
|
||||||
|
btnDiscard.Enabled := Modified;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
Reference in New Issue
Block a user