unit ProjectCreator;

interface

procedure Register;

implementation

uses Windows, ToolsApi;

type
  TProjectWizard = class(TNotifierObject, IOTAMenuWizard, IOTAWizard)
  public
    procedure Execute;
    function GetIDString: string;
    function GetMenuText: string;
    function GetName: string;
    function GetState: TWizardState;
  end;

  TGxProjectCreator = class(TInterfacedObject, IOTACreator, IOTAProjectCreator)
  public
    // IOTACreator
    function GetCreatorType: string;
    function GetExisting: Boolean;
    function GetFileSystem: string;
    function GetOwner: IOTAModule;
    function GetUnnamed: Boolean;
    // IOTAProjectCreator
    function GetFileName: string;
    function GetOptionFileName: string;
    function GetShowSource: Boolean;
    procedure NewDefaultModule;
    function NewOptionSource(const ProjectName: string): IOTAFile;
    procedure NewProjectResource(const Project: IOTAProject);
    function NewProjectSource(const ProjectName: string): IOTAFile;
  end;

procedure Register;
begin
  RegisterPackageWizard(TProjectWizard.Create);
end;

procedure TProjectWizard.Execute;
begin
  (BorlandIDEServices as IOTAModuleServices).CreateModule(TGxProjectCreator.Create);
end;

function TProjectWizard.GetIDString: string;
begin
  Result := 'GX.ProjectCreator';
end;

function TProjectWizard.GetMenuText: string;
begin
  Result := '&GX Project Creator';
end;

function TProjectWizard.GetName: string;
begin
  Result := 'GX Project Creator';
end;

function TProjectWizard.GetState: TWizardState;
begin
  Result := [wsEnabled];
end;

{ TGxProjectCreator }

function TGxProjectCreator.GetCreatorType: string;
begin
  Result := sApplication; // Create an application project
end;

function TGxProjectCreator.GetExisting: Boolean;
begin
  Result := False; // Create a new project
end;

function TGxProjectCreator.GetFileName: string;
begin
  Result := ''; // Default
end;

function TGxProjectCreator.GetFileSystem: string;
begin
  Result := ''; // Default
end;

function TGxProjectCreator.GetOptionFileName: string;
begin
  Result := ''; // Default
end;

function GetCurrentProjectGroup: IOTAProjectGroup;
var
  IModuleServices: IOTAModuleServices;
  IModule: IOTAModule;
  IProjectGroup: IOTAProjectGroup;
  i: Integer;
begin
  Result := nil;
  IModuleServices := BorlandIDEServices as IOTAModuleServices;
  for i := 0 to IModuleServices.ModuleCount - 1 do
  begin
    IModule := IModuleServices.Modules[i];
    if IModule.QueryInterface(IOTAProjectGroup, IProjectGroup) = S_OK then
    begin
      Result := IProjectGroup;
      Break;
    end;
  end;
end;

function TGxProjectCreator.GetOwner: IOTAModule;
begin
  Result := GetCurrentProjectGroup;  // Owned by current project group
end;

function TGxProjectCreator.GetShowSource: Boolean;
begin
  Result := True; // Show the source in the editor
end;

function TGxProjectCreator.GetUnnamed: Boolean;
begin
  Result := True; // Project needs to be named/saved
end;

procedure TGxProjectCreator.NewDefaultModule;
begin
  // No default modules are created
end;

function TGxProjectCreator.NewOptionSource(const ProjectName: string): IOTAFile;
begin
  Result := nil; // For BCB only
end;

procedure TGxProjectCreator.NewProjectResource(const Project: IOTAProject);
begin
  // No resources needed
end;

function TGxProjectCreator.NewProjectSource(const ProjectName: string): IOTAFile;
begin
  // Create the default source code for a new application
  Result := nil;
end;

end.
