unit Aurelius.Design.SourceCreator;

interface

uses
  SysUtils, ToolsApi;

type
  TAureliusPluginSourceCreator = class(TInterfacedObject, IOTACreator, IOTAModuleCreator)
  strict private
    FOwner: IOTAModule;
    FSourceCode: string;
    FUnitIdent: string;
    FFileName: string;
  strict protected
    function GetAncestorName: string;
    function GetImplFileName: string;
    function GetIntfFileName: string;
    function GetFormName: string;
    function GetMainForm: Boolean;
    function GetShowForm: Boolean;
    function GetShowSource: Boolean;
    function NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
    function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
    function NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
    procedure FormCreated(const FormEditor: IOTAFormEditor);
    function GetCreatorType: string;
    function GetExisting: Boolean;
    function GetFileSystem: string;
    function GetOwner: IOTAModule;
    function GetUnnamed: Boolean;
  public
    constructor Create(AOwner: IOTAModule; const AUnitIdent, AFileName, ASourceCode: string);
  end;

  TAureliusPluginSourceFile = class(TInterfacedObject, IOTAFile)
  strict private
    FSourceCode: string;
    FModuleIdent: string;
  strict protected
    function GetSource: string;
    function GetAge: TDateTime;
  public
    constructor Create(const AModuleIdent, ASourceCode: string);
  end;

implementation

{ TAureliusPluginSourceCreator }

constructor TAureliusPluginSourceCreator.Create(AOwner: IOTAModule;
  const AUnitIdent, AFileName, ASourceCode: string);
begin
  FOwner := AOwner;
  FSourceCode := ASourceCode;
  FUnitIdent := AUnitIdent;
  FFileName := AFileName;
end;

procedure TAureliusPluginSourceCreator.FormCreated(
  const FormEditor: IOTAFormEditor);
begin
end;

function TAureliusPluginSourceCreator.GetAncestorName: string;
begin
  Result := '';
end;

function TAureliusPluginSourceCreator.GetCreatorType: string;
begin
  Result := sUnit;
end;

function TAureliusPluginSourceCreator.GetExisting: Boolean;
begin
  Result := False;
end;

function TAureliusPluginSourceCreator.GetFileSystem: string;
begin
  Result := '';
end;

function TAureliusPluginSourceCreator.GetFormName: string;
begin
  Result := '';
end;

function TAureliusPluginSourceCreator.GetImplFileName: string;
begin
  Result := FFileName;
end;

function TAureliusPluginSourceCreator.GetIntfFileName: string;
begin
  Result := '';
end;

function TAureliusPluginSourceCreator.GetMainForm: Boolean;
begin
  Result := False;
end;

function TAureliusPluginSourceCreator.GetOwner: IOTAModule;
begin
  Result := FOwner;
end;

function TAureliusPluginSourceCreator.GetShowForm: Boolean;
begin
  Result := False;
end;

function TAureliusPluginSourceCreator.GetShowSource: Boolean;
begin
  Result := True;
end;

function TAureliusPluginSourceCreator.GetUnnamed: Boolean;
begin
  Result := True;
end;

function TAureliusPluginSourceCreator.NewFormFile(const FormIdent,
  AncestorIdent: string): IOTAFile;
begin
  Result := nil;
end;

function TAureliusPluginSourceCreator.NewImplSource(const ModuleIdent,
  FormIdent, AncestorIdent: string): IOTAFile;
begin
  Result := TAureliusPluginSourceFile.Create(ModuleIdent, FSourceCode);
end;

function TAureliusPluginSourceCreator.NewIntfSource(const ModuleIdent,
  FormIdent, AncestorIdent: string): IOTAFile;
begin
  Result := nil;
end;

{ TAureliusPluginSourceFile }

constructor TAureliusPluginSourceFile.Create(const AModuleIdent, ASourceCode: string);
begin
  FSourceCode := ASourceCode;
  FModuleIdent := AModuleIdent;
end;

function TAureliusPluginSourceFile.GetAge: TDateTime;
begin
  Result := -1;
end;

function TAureliusPluginSourceFile.GetSource: string;
begin
  Result := StringReplace(FSourceCode, '%UnitName%', FModuleIdent, [rfReplaceAll, rfIgnoreCase]);
end;

end.
