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