mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 16:38:02 +02:00
ProjectTemplates: Use the template.lpi file for a new project. Issue #38244, patch from Rolf Wetjen.
git-svn-id: trunk@64307 -
This commit is contained in:
parent
9cc893672d
commit
3f43cd260e
@ -9,14 +9,14 @@ object ProjectVariablesForm: TProjectVariablesForm
|
||||
OnCreate = FormCreate
|
||||
OnShow = ProjectVariablesFormShow
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '1.9.0.0'
|
||||
LCLVersion = '2.1.0.0'
|
||||
object ProjNameLabel: TLabel
|
||||
AnchorSideTop.Control = EProjectName
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 8
|
||||
Height = 13
|
||||
Top = 21
|
||||
Width = 124
|
||||
Height = 15
|
||||
Top = 20
|
||||
Width = 118
|
||||
Alignment = taRightJustify
|
||||
Caption = '&Name for new project:'
|
||||
Layout = tlCenter
|
||||
@ -26,9 +26,9 @@ object ProjectVariablesForm: TProjectVariablesForm
|
||||
AnchorSideTop.Control = DEDestDir
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 8
|
||||
Height = 13
|
||||
Top = 53
|
||||
Width = 107
|
||||
Height = 15
|
||||
Top = 52
|
||||
Width = 100
|
||||
Alignment = taRightJustify
|
||||
Caption = 'Create in &directory:'
|
||||
Layout = tlCenter
|
||||
@ -60,7 +60,7 @@ object ProjectVariablesForm: TProjectVariablesForm
|
||||
AnchorSideRight.Side = asrBottom
|
||||
AnchorSideBottom.Control = ButtonPanel1
|
||||
Left = 6
|
||||
Height = 156
|
||||
Height = 158
|
||||
Top = 141
|
||||
Width = 527
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
@ -70,10 +70,11 @@ object ProjectVariablesForm: TProjectVariablesForm
|
||||
DefaultColWidth = 120
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goAlwaysShowEditor, goDblClickAutoSize, goSmoothScroll]
|
||||
TabOrder = 3
|
||||
OnSelectEditor = SGVariablesSelectEditor
|
||||
ColWidths = (
|
||||
120
|
||||
201
|
||||
202
|
||||
203
|
||||
)
|
||||
end
|
||||
object EProjectName: TEdit
|
||||
@ -81,10 +82,10 @@ object ProjectVariablesForm: TProjectVariablesForm
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideRight.Control = Owner
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 138
|
||||
Left = 132
|
||||
Height = 23
|
||||
Top = 16
|
||||
Width = 395
|
||||
Width = 401
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Left = 6
|
||||
BorderSpacing.Right = 6
|
||||
@ -93,10 +94,10 @@ object ProjectVariablesForm: TProjectVariablesForm
|
||||
object DEDestDir: TDirectoryEdit
|
||||
AnchorSideLeft.Control = EProjectName
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 138
|
||||
Left = 132
|
||||
Height = 23
|
||||
Top = 48
|
||||
Width = 393
|
||||
Width = 399
|
||||
ShowHidden = False
|
||||
ButtonWidth = 23
|
||||
NumGlyphs = 1
|
||||
@ -106,8 +107,8 @@ object ProjectVariablesForm: TProjectVariablesForm
|
||||
end
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 36
|
||||
Top = 303
|
||||
Height = 34
|
||||
Top = 305
|
||||
Width = 527
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
|
@ -7,7 +7,7 @@ interface
|
||||
uses
|
||||
Classes,
|
||||
// LCL
|
||||
Forms, ExtCtrls, Grids, StdCtrls, EditBtn, ButtonPanel,
|
||||
Controls, Forms, ExtCtrls, Grids, StdCtrls, EditBtn, ButtonPanel,
|
||||
// ProjectTemplates
|
||||
ProjectTemplates, ptstrconst;
|
||||
|
||||
@ -26,6 +26,8 @@ type
|
||||
procedure BOKClick(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure ProjectVariablesFormShow(Sender: TObject);
|
||||
procedure SGVariablesSelectEditor(Sender: TObject; aCol, aRow: Integer;
|
||||
var Editor: TWinControl);
|
||||
private
|
||||
FSChanged: Boolean;
|
||||
FTemplates: TProjectTemplates;
|
||||
@ -57,6 +59,13 @@ begin
|
||||
SGVariables.Cells[2,0]:=SDescription;
|
||||
end;
|
||||
|
||||
procedure TProjectVariablesForm.SGVariablesSelectEditor(Sender: TObject; aCol,
|
||||
aRow: Integer; var Editor: TWinControl);
|
||||
begin
|
||||
if aCol<>1 then
|
||||
Editor:=nil;
|
||||
end;
|
||||
|
||||
procedure TProjectVariablesForm.BOKClick(Sender: TObject);
|
||||
|
||||
Var
|
||||
|
@ -5,7 +5,7 @@ unit IDETemplateProject;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, ContNrs,
|
||||
Classes, SysUtils, StrUtils, ContNrs,
|
||||
// LCL
|
||||
LResources, Forms, Controls, Graphics, Dialogs,
|
||||
// LazUtils
|
||||
@ -29,13 +29,13 @@ type
|
||||
Function ShowOptionsDialog : TModalResult;
|
||||
public
|
||||
constructor Create(ATemplate : TProjectTemplate); overload;
|
||||
destructor destroy; override;
|
||||
destructor Destroy; override;
|
||||
Function DoInitDescriptor : TModalResult; override;
|
||||
function GetLocalizedName: string; override;
|
||||
function GetLocalizedDescription: string; override;
|
||||
function InitProject(AProject: TLazProject) : TModalResult; override;
|
||||
function CreateStartFiles({%H-}AProject: TLazProject) : TModalResult; override;
|
||||
Property template : TProjectTemplate Read FTemplate Write FTemplate;
|
||||
Property Template : TProjectTemplate Read FTemplate Write FTemplate;
|
||||
end;
|
||||
|
||||
procedure Register;
|
||||
@ -108,11 +108,30 @@ begin
|
||||
NewIDEItems.Add(TNewIDEItemCategory.Create(STemplateCategory));
|
||||
end;
|
||||
|
||||
procedure FileReplaceText(FN, AFrom, ATo: string);
|
||||
var
|
||||
sl: TStringList;
|
||||
i: Integer;
|
||||
begin
|
||||
if not FileExistsUTF8(FN) then
|
||||
exit;
|
||||
sl:=TStringList.Create;
|
||||
try
|
||||
sl.LoadFromFile(FN);
|
||||
for i:=0 to sl.Count-1 do
|
||||
sl[i]:=ReplaceText(sl[i],AFrom,ATo);
|
||||
sl.SaveToFile(fn);
|
||||
finally
|
||||
sl.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
Procedure DoProject(Sender : TObject);
|
||||
|
||||
Var
|
||||
I : Integer;
|
||||
Desc : TTemplateProjectDescriptor;
|
||||
fn: string;
|
||||
|
||||
begin
|
||||
I:=MenuList.count-1;
|
||||
@ -124,8 +143,18 @@ begin
|
||||
Desc:=FProjDesc;
|
||||
Dec(i);
|
||||
end;
|
||||
If Desc<>Nil then
|
||||
LazarusIDE.DoNewProject(Desc);
|
||||
If Desc=Nil then
|
||||
exit;
|
||||
|
||||
If Desc.ShowOptionsDialog<>mrOk then
|
||||
exit;
|
||||
Desc.Template.CreateProject(Desc.FProjectDirectory,Desc.FVariables);
|
||||
fn:=Desc.FProjectDirectory+Desc.FProjectName;
|
||||
FileReplaceText(fn+'.lpi',Desc.FTemplate.ProjectFile,Desc.FProjectName);
|
||||
FileReplaceText(fn+'.lpr',Desc.FTemplate.ProjectFile,Desc.FProjectName);
|
||||
FileReplaceText(fn+'.lps',Desc.FTemplate.ProjectFile,Desc.FProjectName);
|
||||
LazarusIDE.DoOpenProjectFile(Desc.FProjectDirectory+Desc.FProjectName+'.lpi',
|
||||
[ofProjectLoading,ofOnlyIfExists,ofConvertMacros,ofDoLoadResource]);
|
||||
end;
|
||||
|
||||
procedure RegisterKnowntemplates;
|
||||
@ -211,10 +240,16 @@ begin
|
||||
FVariables.Assign(FTemplate.Variables);
|
||||
I:=FVariables.IndexOfName('ProjName');
|
||||
if (I<>-1) then
|
||||
begin
|
||||
EProjectName.Text:=FVariables.Values['ProjName'];
|
||||
FVariables.Delete(I);
|
||||
end;
|
||||
I:=FVariables.IndexOfName('ProjDir');
|
||||
if (I<>-1) then
|
||||
begin
|
||||
DEDestDir.Text:=FVariables.Values['ProjDir'];
|
||||
FVariables.Delete(I);
|
||||
end;
|
||||
Templates:=Templates;
|
||||
Variables:=FVariables;
|
||||
Result:=ShowModal;
|
||||
@ -265,11 +300,23 @@ end;
|
||||
|
||||
|
||||
function TTemplateProjectDescriptor.DoInitDescriptor: TModalResult;
|
||||
|
||||
var
|
||||
I : integer;
|
||||
Desc : TTemplateProjectDescriptor;
|
||||
begin
|
||||
Result:=ShowOptionsDialog;
|
||||
If (Result=mrOK) then
|
||||
FTemplate.CreateProject(FProjectDirectory,FVariables);
|
||||
Result:=mrCancel;
|
||||
I:=MenuList.count-1;
|
||||
Desc:=Nil;
|
||||
While (Desc=Nil) and (I>=0) do
|
||||
begin
|
||||
With TIDEObject(MenuList[i]) do
|
||||
if FProjDesc=self then
|
||||
begin
|
||||
DoProject(FProjMenu);
|
||||
exit;
|
||||
end;
|
||||
Dec(i);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -317,6 +364,9 @@ begin
|
||||
end
|
||||
else
|
||||
Result:=mrCancel;
|
||||
|
||||
Result:=mrCancel;
|
||||
|
||||
end;
|
||||
|
||||
Function TTemplateProjectDescriptor.CreateStartFiles(AProject: TLazProject) : TModalresult;
|
||||
|
@ -136,10 +136,8 @@ begin
|
||||
end;
|
||||
|
||||
Function SimpleFileCopy(Const Source,Dest : String) : Boolean;
|
||||
|
||||
Var
|
||||
F1,F2 : TFileStream;
|
||||
|
||||
begin
|
||||
Result:=False;
|
||||
try
|
||||
@ -307,6 +305,11 @@ begin
|
||||
FExclude:=ReadString(SProject,KeyExclude,'');
|
||||
If (FExclude<>'') then
|
||||
FExclude:=FExclude+',';
|
||||
// Don't change ico and res files
|
||||
If pos('.ico,',FExclude)<=0 then
|
||||
FExclude:=FExclude+'.ico,';
|
||||
If pos('.res,',FExclude)<=0 then
|
||||
FExclude:=FExclude+'.res,';
|
||||
ReadSectionValues(SVariables,FVariables);
|
||||
Finally
|
||||
Free;
|
||||
@ -494,6 +497,4 @@ begin
|
||||
CopyAndSubstituteDir(Directory,ProjectDir,Values);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user