SQLDB: Add 'Edit Script' to the context menu of TSQLScript. Issue , patch by Bruno K.

This commit is contained in:
Juha 2024-06-28 13:33:04 +03:00
parent d328064efb
commit 0ce892437b
2 changed files with 103 additions and 0 deletions

View File

@ -217,6 +217,21 @@ Type
function GetVerbCount: integer; override;
end;
{ TSQLScriptEditor }
TSQLScriptEditor = class(TComponentEditor)
Private
FVOffset: Integer;
Protected
procedure EditScript(aScript: TSQLScript); virtual;
procedure DoEditScript(aScript: TSQLScript); virtual;
public
constructor Create(AComponent: TComponent; ADesigner: TComponentEditorDesigner); override;
procedure ExecuteVerb(Index: integer); override;
function GetVerb(Index: integer): string; override;
function GetVerbCount: integer; override;
end;
procedure Register;
implementation
@ -432,6 +447,92 @@ begin
Result := FVOffset + 3;
end;
{ TSQLScriptEditor }
procedure TSQLScriptEditor.EditScript(aScript: TSQLScript);
var
TheDialog: TSQLStringsPropertyEditorDlg = nil;
begin
try
TheDialog := TSQLStringsPropertyEditorDlg.Create(Application);
TheDialog.IsSQLScript := True;
TheDialog.SQLEditor.Text := aScript.Script.Text;
TheDialog.Caption := Format(SSQLStringsPropertyEditorDlgTitle, ['Script']);
if (TheDialog.ShowModal = mrOk) then begin
aScript.Script.Text := TheDialog.SQLEditor.Text;
Modified;
end;
finally
FreeAndNil(TheDialog);
end;
end;
constructor TSQLScriptEditor.Create(AComponent: TComponent;
ADesigner: TComponentEditorDesigner);
begin
inherited Create(AComponent, ADesigner);
FVOffset := Inherited GetVerbCount;
end;
procedure TSQLScriptEditor.DoEditScript(aScript: TSQLScript);
var
AHook: TPropertyEditorHook;
PEC: TPropertyEditorClass;
PE: TPropertyEditor;
SQLPropInfo: PPropInfo;
begin
PEC := nil;
SQLPropInfo := GetPropInfo(aScript, 'Script');
if Assigned(SQLPropInfo) then
PEC := GetEditorClass(SQLPropInfo, aScript);
if (PEC = nil) or not GetHook(AHook) then
EditScript(aScript)
else
begin
PE := PEC.Create(AHook, 1);
try
PE.SetPropEntry(0, aScript, SQLPropInfo);
PE.Edit;
finally
PE.Free;
end;
end;
end;
procedure TSQLScriptEditor.ExecuteVerb(Index: integer);
var
Q: TSQLScript;
begin
if Index < FVOffset then
inherited
else
begin
Q := Component as TSQLScript;
case Index - FVOffset of
0: DoEditScript(Q);
1: // Separator, do nothing
else
// Do nothing
end;
end;
end;
function TSQLScriptEditor.GetVerb(Index: integer): string;
begin
if Index < FVOffset then
Result := inherited
else
case Index - FVOffset of
0: Result := SSQLEdit;
1: Result := '-';
end;
end;
function TSQLScriptEditor.GetVerbCount: integer;
begin
Result := FVOffset + 2;
end;
{ TSQLDBLibraryLoaderConnectionTypePropertyEditor }
function TSQLDBConnectorTypePropertyEditor.GetAttributes: TPropertyAttributes;
@ -720,6 +821,7 @@ begin
RegisterPropertyEditor(TStrings.ClassInfo, TSQLScript, 'Script' , TSQLStringsPropertyEditor);
RegisterProjectFileDescriptor(TSQLFileDescriptor.Create);
RegisterComponentEditor(TSQLQuery, TSQLQueryEditor);
RegisterComponentEditor(TSQLScript, TSQLScriptEditor);
RegisterUnit('sqldb',@RegisterUnitSQLdb);
AChecker:=TSQLSyntaxChecker.Create(Nil);

View File

@ -10,6 +10,7 @@ resourcestring
lrsSQLDataSetOpen = 'Dataset not open: %s';
lrsSQLGenSelect = 'You must select fields to be updated and key fields.';
SSQLEdit = 'Edit Script ...';
SSQLScript = 'SQL Script file';
SSQLScriptDesc = 'Create a new SQL Script file';
SSQLSource = 'Insert your SQL statements here';