* Factor more code out of each database object editors into parent TDBObjectEditor.

* Use this chance to add a confirmation dialog when leaving the editors, to ask the user if he wants to save modifications. Fixes issue #1524.
* Also, enhance Mainform.RefreshTreeDB in a way that it does not trigger the OnFocusChange event. Important for the editors when saving changes.
This commit is contained in:
Ansgar Becker
2009-12-14 23:55:36 +00:00
parent cbedf0d163
commit dd398bb101
7 changed files with 213 additions and 147 deletions

View File

@ -147,9 +147,15 @@ type
private
FModified: Boolean;
procedure SetModified(Value: Boolean);
protected
FEditObjectName: WideString;
public
procedure Init(ObjectName: WideString=''; ObjectType: TListNodeType=lntNone); Virtual; Abstract;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Init(ObjectName: WideString=''; ObjectType: TListNodeType=lntNone); virtual;
procedure DeInit;
property Modified: Boolean read FModified write SetModified;
procedure ApplyModifications; virtual; abstract;
end;
@ -245,7 +251,7 @@ var
implementation
uses main, uVistaFuncs;
uses main, uVistaFuncs, table_editor, view, routine_editor, trigger_editor;
type
CharacterSet = record
@ -3236,11 +3242,56 @@ end;
{ *** TDBObjectEditor }
constructor TDBObjectEditor.Create(AOwner: TComponent);
begin
inherited;
// Do not set alClient via DFM! In conjunction with ExplicitXXX properties that
// repeatedly breaks the GUI layout when you reload the project
Align := alClient;
InheritFont(Font);
end;
destructor TDBObjectEditor.Destroy;
begin
DeInit;
inherited;
end;
procedure TDBObjectEditor.SetModified(Value: Boolean);
begin
FModified := Value;
end;
procedure TDBObjectEditor.Init(ObjectName: WideString=''; ObjectType: TListNodeType=lntNone);
begin
DeInit;
Mainform.showstatus('Initializing editor ...');
FEditObjectName := ObjectName;
Mainform.SetEditorTabCaption(Self, FEditObjectName);
Screen.Cursor := crHourglass;
MainForm.SetupSynEditors;
end;
procedure TDBObjectEditor.DeInit;
var
Msg, ObjType: WideString;
begin
// Ask for saving modifications
if Modified then begin
if Self is TfrmTableEditor then ObjType := 'table'
else if Self is TfrmView then ObjType := 'view'
else if Self is TfrmRoutineEditor then ObjType := 'routine'
else if Self is TfrmTriggerEditor then ObjType := 'trigger'
else ObjType := '<Unknown Type - should never appear>';
if FEditObjectName <> '' then
Msg := 'Save modified '+ObjType+' "'+FEditObjectName+'"?'
else
Msg := 'Save new '+ObjType+'?';
if MessageDlg(Msg, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
ApplyModifications;
end;
end;
end.