diff --git a/ide/project.pp b/ide/project.pp index 0ccdd2a38c..643a303952 100644 --- a/ide/project.pp +++ b/ide/project.pp @@ -56,7 +56,7 @@ uses // IDEIntf ProjectIntf, MacroIntf, LazIDEIntf, // IDE - CompOptsModes, ProjectResources, LazConf, frmCustomApplicationOptions, + CompOptsModes, ProjectResources, LazConf, LazarusIDEStrConsts, CompilerOptions, TransferMacros, EditorOptions, IDEProcs, RunParamsOpts, ProjectDefs, FileReferenceList, EditDefineTree, PackageDefs, PackageSystem, IDEOptionsIntf, @@ -594,73 +594,6 @@ type end; - //---------------------------------------------------------------------------- - - { TProjectApplicationDescriptor } - - TProjectApplicationDescriptor = class(TProjectDescriptor) - public - constructor Create; override; - function GetLocalizedName: string; override; - function GetLocalizedDescription: string; override; - function InitProject(AProject: TLazProject): TModalResult; override; - function CreateStartFiles(AProject: TLazProject): TModalResult; override; - end; - - { TProjectProgramDescriptor } - - TProjectProgramDescriptor = class(TProjectDescriptor) - public - constructor Create; override; - function GetLocalizedName: string; override; - function GetLocalizedDescription: string; override; - function InitProject(AProject: TLazProject): TModalResult; override; - function CreateStartFiles(AProject: TLazProject): TModalResult; override; - end; - - { TProjectConsoleApplicationDescriptor } - - TProjectConsoleApplicationDescriptor = class(TProjectDescriptor) - public - constructor Create; override; - function GetLocalizedName: string; override; - function GetLocalizedDescription: string; override; - function InitProject(AProject: TLazProject): TModalResult; override; - function CreateStartFiles(AProject: TLazProject): TModalResult; override; - end; - - { TProjectLibraryDescriptor } - - TProjectLibraryDescriptor = class(TProjectDescriptor) - public - constructor Create; override; - function GetLocalizedName: string; override; - function GetLocalizedDescription: string; override; - function InitProject(AProject: TLazProject): TModalResult; override; - function CreateStartFiles(AProject: TLazProject): TModalResult; override; - end; - - { TProjectManualProgramDescriptor } - - TProjectManualProgramDescriptor = class(TProjectDescriptor) - private - FAddMainSource: boolean; - public - constructor Create; override; - function GetLocalizedName: string; override; - function GetLocalizedDescription: string; override; - function InitProject(AProject: TLazProject): TModalResult; override; - function CreateStartFiles(AProject: TLazProject): TModalResult; override; - property AddMainSource: boolean read FAddMainSource write FAddMainSource; - end; - - { TProjectEmptyProgramDescriptor } - - TProjectEmptyProgramDescriptor = class(TProjectManualProgramDescriptor) - public - constructor Create; override; - end; - { TProject } TEndUpdateProjectEvent = @@ -6006,270 +5939,6 @@ begin IncreaseCompilerParseStamp; end; -{ TProjectProgramDescriptor } - -constructor TProjectProgramDescriptor.Create; -begin - inherited Create; - Name:=ProjDescNameProgram; - Flags:=Flags-[pfMainUnitHasCreateFormStatements,pfMainUnitHasTitleStatement] - +[pfUseDefaultCompilerOptions]; -end; - -function TProjectProgramDescriptor.GetLocalizedName: string; -begin - Result:=lisProgram; -end; - -function TProjectProgramDescriptor.GetLocalizedDescription: string; -begin - Result:=Format(lisProgramAFreepascalProgramTheProgramFileIsAutomatic, [#13]); -end; - -function TProjectProgramDescriptor.InitProject(AProject: TLazProject - ): TModalResult; -var - le: String; - NewSource: String; - MainFile: TLazProjectFile; -begin - Result:=inherited InitProject(AProject); - - MainFile:=AProject.CreateProjectFile('project1.lpr'); - MainFile.IsPartOfProject:=true; - AProject.AddFile(MainFile,false); - AProject.MainFileID:=0; - - // create program source - le:=LineEnding; - NewSource:='program Project1;'+le - +le - +'{$mode objfpc}{$H+}'+le - +le - +'uses'+le - +' {$IFDEF UNIX}{$IFDEF UseCThreads}'+le - +' cthreads,'+le - +' {$ENDIF}{$ENDIF}'+le - +' Classes'+le - +' { you can add units after this };'+le - +le - +'begin'+le - +'end.'+le - +le; - AProject.MainFile.SetSourceText(NewSource); - - AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'; - AProject.LazCompilerOptions.TargetFilename:='project1'; -end; - -function TProjectProgramDescriptor.CreateStartFiles(AProject: TLazProject - ): TModalResult; -begin - Result:=LazarusIDE.DoOpenEditorFile(AProject.MainFile.Filename,-1,-1, - [ofProjectLoading,ofRegularFile]); -end; - -{ TProjectApplicationDescriptor } - -constructor TProjectApplicationDescriptor.Create; -begin - inherited Create; - Name:=ProjDescNameApplication; - Flags:=Flags+[pfUseDefaultCompilerOptions]; -end; - -function TProjectApplicationDescriptor.GetLocalizedName: string; -begin - Result:=dlgPOApplication; -end; - -function TProjectApplicationDescriptor.GetLocalizedDescription: string; -begin - Result:=Format(lisApplicationAGraphicalLclFreepascalProgramTheProgra, [#13]); -end; - -function TProjectApplicationDescriptor.InitProject( - AProject: TLazProject): TModalResult; -var - le: string; - NewSource: String; - MainFile: TLazProjectFile; -begin - Result:=inherited InitProject(AProject); - - MainFile:=AProject.CreateProjectFile('project1.lpr'); - MainFile.IsPartOfProject:=true; - AProject.AddFile(MainFile,false); - AProject.MainFileID:=0; - - // create program source - le:=LineEnding; - NewSource:='program Project1;'+le - +le - +'{$mode objfpc}{$H+}'+le - +le - +'uses'+le - +' {$IFDEF UNIX}{$IFDEF UseCThreads}'+le - +' cthreads,'+le - +' {$ENDIF}{$ENDIF}'+le - +' Interfaces, // this includes the LCL widgetset'+le - +' Forms'+le - +' { you can add units after this };'+le - +le - +'begin'+le - +' Application.Initialize;'+le - +' Application.Run;'+le - +'end.'+le - +le; - AProject.MainFile.SetSourceText(NewSource); - - // add lcl pp/pas dirs to source search path - AProject.AddPackageDependency('LCL'); - AProject.LazCompilerOptions.Win32GraphicApp:=true; - AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'; - AProject.LazCompilerOptions.TargetFilename:='project1'; -end; - -function TProjectApplicationDescriptor.CreateStartFiles(AProject: TLazProject - ): TModalResult; -begin - Result:=LazarusIDE.DoNewEditorFile(FileDescriptorForm,'','', - [nfIsPartOfProject,nfOpenInEditor,nfCreateDefaultSrc]); -end; - -{ TProjectManualProgramDescriptor } - -constructor TProjectManualProgramDescriptor.Create; -begin - inherited Create; - VisibleInNewDialog:=false; - Name:=ProjDescNameCustomProgram; - Flags:=Flags-[pfMainUnitHasUsesSectionForAllUnits, - pfMainUnitHasCreateFormStatements, - pfMainUnitHasTitleStatement] - +[pfUseDefaultCompilerOptions]; - FAddMainSource:=true; -end; - -function TProjectManualProgramDescriptor.GetLocalizedName: string; -begin - Result:=lisCustomProgram; -end; - -function TProjectManualProgramDescriptor.GetLocalizedDescription: string; -begin - Result:=Format(lisCustomProgramAFreepascalProgram, [#13]); -end; - -function TProjectManualProgramDescriptor.InitProject(AProject: TLazProject - ): TModalResult; -var - le: string; - NewSource: String; - MainFile: TLazProjectFile; -begin - Result:=inherited InitProject(AProject); - - if AddMainSource then begin - MainFile:=AProject.CreateProjectFile('project1.pas'); - MainFile.IsPartOfProject:=true; - AProject.AddFile(MainFile,false); - AProject.MainFileID:=0; - - // create program source - le:=LineEnding; - NewSource:='program Project1;'+le - +le - +'{$mode objfpc}{$H+}'+le - +le - +'uses'+le - +' Classes, SysUtils'+le - +' { you can add units after this };'+le - +le - +'begin'+le - +'end.'+le - +le; - AProject.MainFile.SetSourceText(NewSource); - end; -end; - -function TProjectManualProgramDescriptor.CreateStartFiles(AProject: TLazProject - ): TModalResult; -begin - if AProject.MainFile<>nil then - Result:=LazarusIDE.DoOpenEditorFile(AProject.MainFile.Filename,-1,-1, - [ofProjectLoading,ofRegularFile]); -end; - -{ TProjectEmptyProgramDescriptor } - -constructor TProjectEmptyProgramDescriptor.Create; -begin - inherited Create; - FAddMainSource:=false; -end; - -{ TProjectLibraryDescriptor } - -constructor TProjectLibraryDescriptor.Create; -begin - inherited Create; - Name:=ProjDescNameLibrary; - Flags:=Flags-[pfMainUnitHasCreateFormStatements,pfMainUnitHasTitleStatement] - +[pfUseDefaultCompilerOptions]; -end; - -function TProjectLibraryDescriptor.GetLocalizedName: string; -begin - Result:=lisPckOptsLibrary; -end; - -function TProjectLibraryDescriptor.GetLocalizedDescription: string; -begin - Result:= Format(lisLibraryAFreepascalLibraryDllUnderWindowsSoUnderLin, [#13]); -end; - -function TProjectLibraryDescriptor.InitProject(AProject: TLazProject - ): TModalResult; -var - le: String; - NewSource: String; - MainFile: TLazProjectFile; -begin - Result:=inherited InitProject(AProject); - - MainFile:=AProject.CreateProjectFile('project1.lpr'); - MainFile.IsPartOfProject:=true; - AProject.AddFile(MainFile,false); - AProject.MainFileID:=0; - AProject.LazCompilerOptions.ExecutableType:=cetLibrary; - - // create program source - le:=LineEnding; - NewSource:='library Project1;'+le - +le - +'{$mode objfpc}{$H+}'+le - +le - +'uses'+le - +' Classes'+le - +' { you can add units after this };'+le - +le - +'begin'+le - +'end.'+le - +le; - AProject.MainFile.SetSourceText(NewSource); - - AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'; - AProject.LazCompilerOptions.TargetFilename:='project1'; -end; - -function TProjectLibraryDescriptor.CreateStartFiles(AProject: TLazProject - ): TModalResult; -begin - Result:=LazarusIDE.DoOpenEditorFile(AProject.MainFile.Filename,-1,-1, - [ofProjectLoading,ofRegularFile]); -end; - { TUnitComponentDependency } procedure TUnitComponentDependency.SetRequiresUnit(const AValue: TUnitInfo); @@ -6432,172 +6101,6 @@ begin end; end; -{ TProjectConsoleApplicationDescriptor } - -constructor TProjectConsoleApplicationDescriptor.Create; -begin - inherited Create; - Name:=ProjDescNameConsoleApplication; - Flags:=Flags-[pfMainUnitHasCreateFormStatements,pfMainUnitHasTitleStatement] - +[pfUseDefaultCompilerOptions]; -end; - -function TProjectConsoleApplicationDescriptor.GetLocalizedName: string; -begin - Result:=lisConsoleApplication; -end; - -function TProjectConsoleApplicationDescriptor.GetLocalizedDescription: string; -begin - Result:=GetLocalizedName+#13 - +lisFreepascalProgramUsingTCustomApplicationToEasilyCh; -end; - -function TProjectConsoleApplicationDescriptor.InitProject(AProject: TLazProject - ): TModalResult; -var - NewSource: TStringList; - MainFile: TLazProjectFile; - C, T : String; - CC,CD,CU,CS, CO : Boolean; - -begin - Result:=inherited InitProject(AProject); - If Result<>mrOk then - Exit; - With TCustomApplicationOptionsForm.Create(Application) do - try - Result:=ShowModal; - If Result<>mrOk then - Exit; - C:=Trim(AppClassName); - T:=StringReplace(Title,'''','''''',[rfReplaceAll]); - CC:=CodeConstructor; - CD:=CodeDestructor; - CU:=CodeUsage; - CS:=CodeStopOnError; - CO:=CodeCheckOptions; - finally - Free; - end; - MainFile:=AProject.CreateProjectFile('project1.lpr'); - MainFile.IsPartOfProject:=true; - AProject.AddFile(MainFile,false); - AProject.MainFileID:=0; - - AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'; - AProject.LazCompilerOptions.TargetFilename:='project1'; - - // create program source - NewSource:=TStringList.Create; - NewSource.Add('program Project1;'); - NewSource.Add(''); - NewSource.Add('{$mode objfpc}{$H+}'); - NewSource.Add(''); - NewSource.Add('uses'); - NewSource.Add(' {$IFDEF UNIX}{$IFDEF UseCThreads}'); - NewSource.Add(' cthreads,'); - NewSource.Add(' {$ENDIF}{$ENDIF}'); - NewSource.Add(' Classes, SysUtils, CustApp'); - NewSource.Add(' { you can add units after this };'); - NewSource.Add(''); - NewSource.Add('type'); - NewSource.Add(''); - NewSource.Add(' { '+C+' }'); - NewSource.Add(''); - NewSource.Add(' '+C+' = class(TCustomApplication)'); - NewSource.Add(' protected'); - NewSource.Add(' procedure DoRun; override;'); - NewSource.Add(' public'); - If CC or CS then - NewSource.Add(' constructor Create(TheOwner: TComponent); override;'); - if CD then - NewSource.Add(' destructor Destroy; override;'); - if CU then - NewSource.Add(' procedure WriteHelp; virtual;'); - NewSource.Add(' end;'); - NewSource.Add(''); - NewSource.Add('{ '+C+' }'); - NewSource.Add(''); - NewSource.Add('procedure '+C+'.DoRun;'); - NewSource.Add('var'); - NewSource.Add(' ErrorMsg: String;'); - NewSource.Add('begin'); - if CO then - begin - NewSource.Add(' // quick check parameters'); - NewSource.Add(' ErrorMsg:=CheckOptions(''h'',''help'');'); - NewSource.Add(' if ErrorMsg<>'''' then begin'); - NewSource.Add(' ShowException(Exception.Create(ErrorMsg));'); - NewSource.Add(' Terminate;'); - NewSource.Add(' Exit;'); - NewSource.Add(' end;'); - NewSource.Add(''); - end; - If CU then - begin - NewSource.Add(' // parse parameters'); - NewSource.Add(' if HasOption(''h'',''help'') then begin'); - NewSource.Add(' WriteHelp;'); - NewSource.Add(' Terminate;'); - NewSource.Add(' Exit;'); - NewSource.Add(' end;'); - end; - NewSource.Add(''); - NewSource.Add(' { add your program here }'); - NewSource.Add(''); - NewSource.Add(' // stop program loop'); - NewSource.Add(' Terminate;'); - NewSource.Add('end;'); - NewSource.Add(''); - If CC or CS then - begin - NewSource.Add('constructor '+C+'.Create(TheOwner: TComponent);'); - NewSource.Add('begin'); - NewSource.Add(' inherited Create(TheOwner);'); - If CS then - NewSource.Add(' StopOnException:=True;'); - NewSource.Add('end;'); - NewSource.Add(''); - end; - If CD then - begin - NewSource.Add('destructor '+C+'.Destroy;'); - NewSource.Add('begin'); - NewSource.Add(' inherited Destroy;'); - NewSource.Add('end;'); - NewSource.Add(''); - end; - If CU then - begin - NewSource.Add('procedure '+C+'.WriteHelp;'); - NewSource.Add('begin'); - NewSource.Add(' { add your help code here }'); - NewSource.Add(' writeln(''Usage: '',ExeName,'' -h'');'); - NewSource.Add('end;'); - NewSource.Add(''); - end; - NewSource.Add('var'); - NewSource.Add(' Application: '+C+';'); - NewSource.Add('begin'); - NewSource.Add(' Application:='+C+'.Create(nil);'); - If (T<>'') then - NewSource.Add(' Application.Title:='''+T+''';'); - NewSource.Add(' Application.Run;'); - NewSource.Add(' Application.Free;'); - NewSource.Add('end.'); - NewSource.Add(''); - AProject.MainFile.SetSourceText(NewSource.Text); - NewSource.Free; -end; - -function TProjectConsoleApplicationDescriptor.CreateStartFiles( - AProject: TLazProject): TModalResult; -begin - Result:=LazarusIDE.DoOpenEditorFile(AProject.MainFile.Filename,-1,-1, - [ofProjectLoading,ofRegularFile]); -end; - { TUCDComponentProperty } constructor TUCDComponentProperty.Create(const SrcPath, DestPath: string); @@ -6609,5 +6112,6 @@ end; initialization RegisterIDEOptionsGroup(GroupProject, TProject); RegisterIDEOptionsGroup(GroupCompiler, TProjectCompilerOptions); + end. diff --git a/ide/projectdefs.pas b/ide/projectdefs.pas index 8ec29e6601..243965c210 100644 --- a/ide/projectdefs.pas +++ b/ide/projectdefs.pas @@ -38,8 +38,9 @@ interface uses Classes, SysUtils, Laz_XMLCfg, - Forms, SynRegExpr, FileUtil, LCLProc, IDEProcs, - ProjectIntf, PublishModule, SrcEditorIntf; + Controls, Forms, SynRegExpr, FileUtil, LCLProc, + ProjectIntf, PublishModule, SrcEditorIntf, LazIDEIntf, + frmCustomApplicationOptions, IDEProcs, LazarusIDEStrConsts; type TOnLoadSaveFilename = procedure(var Filename:string; Load:boolean) of object; @@ -300,6 +301,73 @@ type write SetSaveClosedEditorFilesInfo; end; + //---------------------------------------------------------------------------- + + { TProjectApplicationDescriptor } + + TProjectApplicationDescriptor = class(TProjectDescriptor) + public + constructor Create; override; + function GetLocalizedName: string; override; + function GetLocalizedDescription: string; override; + function InitProject(AProject: TLazProject): TModalResult; override; + function CreateStartFiles(AProject: TLazProject): TModalResult; override; + end; + + { TProjectProgramDescriptor } + + TProjectProgramDescriptor = class(TProjectDescriptor) + public + constructor Create; override; + function GetLocalizedName: string; override; + function GetLocalizedDescription: string; override; + function InitProject(AProject: TLazProject): TModalResult; override; + function CreateStartFiles(AProject: TLazProject): TModalResult; override; + end; + + { TProjectConsoleApplicationDescriptor } + + TProjectConsoleApplicationDescriptor = class(TProjectDescriptor) + public + constructor Create; override; + function GetLocalizedName: string; override; + function GetLocalizedDescription: string; override; + function InitProject(AProject: TLazProject): TModalResult; override; + function CreateStartFiles(AProject: TLazProject): TModalResult; override; + end; + + { TProjectLibraryDescriptor } + + TProjectLibraryDescriptor = class(TProjectDescriptor) + public + constructor Create; override; + function GetLocalizedName: string; override; + function GetLocalizedDescription: string; override; + function InitProject(AProject: TLazProject): TModalResult; override; + function CreateStartFiles(AProject: TLazProject): TModalResult; override; + end; + + { TProjectManualProgramDescriptor } + + TProjectManualProgramDescriptor = class(TProjectDescriptor) + private + FAddMainSource: boolean; + public + constructor Create; override; + function GetLocalizedName: string; override; + function GetLocalizedDescription: string; override; + function InitProject(AProject: TLazProject): TModalResult; override; + function CreateStartFiles(AProject: TLazProject): TModalResult; override; + property AddMainSource: boolean read FAddMainSource write FAddMainSource; + end; + + { TProjectEmptyProgramDescriptor } + + TProjectEmptyProgramDescriptor = class(TProjectManualProgramDescriptor) + public + constructor Create; override; + end; + //--------------------------------------------------------------------------- @@ -1178,6 +1246,436 @@ begin Descriptor.Release; end; +{ TProjectProgramDescriptor } + +constructor TProjectProgramDescriptor.Create; +begin + inherited Create; + Name:=ProjDescNameProgram; + Flags:=Flags-[pfMainUnitHasCreateFormStatements,pfMainUnitHasTitleStatement] + +[pfUseDefaultCompilerOptions]; +end; + +function TProjectProgramDescriptor.GetLocalizedName: string; +begin + Result:=lisProgram; +end; + +function TProjectProgramDescriptor.GetLocalizedDescription: string; +begin + Result:=Format(lisProgramAFreepascalProgramTheProgramFileIsAutomatic, [#13]); +end; + +function TProjectProgramDescriptor.InitProject(AProject: TLazProject + ): TModalResult; +var + le: String; + NewSource: String; + MainFile: TLazProjectFile; +begin + Result:=inherited InitProject(AProject); + + MainFile:=AProject.CreateProjectFile('project1.lpr'); + MainFile.IsPartOfProject:=true; + AProject.AddFile(MainFile,false); + AProject.MainFileID:=0; + + // create program source + le:=LineEnding; + NewSource:='program Project1;'+le + +le + +'{$mode objfpc}{$H+}'+le + +le + +'uses'+le + +' {$IFDEF UNIX}{$IFDEF UseCThreads}'+le + +' cthreads,'+le + +' {$ENDIF}{$ENDIF}'+le + +' Classes'+le + +' { you can add units after this };'+le + +le + +'begin'+le + +'end.'+le + +le; + AProject.MainFile.SetSourceText(NewSource); + + AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'; + AProject.LazCompilerOptions.TargetFilename:='project1'; +end; + +function TProjectProgramDescriptor.CreateStartFiles(AProject: TLazProject + ): TModalResult; +begin + Result:=LazarusIDE.DoOpenEditorFile(AProject.MainFile.Filename,-1,-1, + [ofProjectLoading,ofRegularFile]); +end; + +{ TProjectApplicationDescriptor } + +constructor TProjectApplicationDescriptor.Create; +begin + inherited Create; + Name:=ProjDescNameApplication; + Flags:=Flags+[pfUseDefaultCompilerOptions]; +end; + +function TProjectApplicationDescriptor.GetLocalizedName: string; +begin + Result:=dlgPOApplication; +end; + +function TProjectApplicationDescriptor.GetLocalizedDescription: string; +begin + Result:=Format(lisApplicationAGraphicalLclFreepascalProgramTheProgra, [#13]); +end; + +function TProjectApplicationDescriptor.InitProject( + AProject: TLazProject): TModalResult; +var + le: string; + NewSource: String; + MainFile: TLazProjectFile; +begin + Result:=inherited InitProject(AProject); + + MainFile:=AProject.CreateProjectFile('project1.lpr'); + MainFile.IsPartOfProject:=true; + AProject.AddFile(MainFile,false); + AProject.MainFileID:=0; + + // create program source + le:=LineEnding; + NewSource:='program Project1;'+le + +le + +'{$mode objfpc}{$H+}'+le + +le + +'uses'+le + +' {$IFDEF UNIX}{$IFDEF UseCThreads}'+le + +' cthreads,'+le + +' {$ENDIF}{$ENDIF}'+le + +' Interfaces, // this includes the LCL widgetset'+le + +' Forms'+le + +' { you can add units after this };'+le + +le + +'begin'+le + +' Application.Initialize;'+le + +' Application.Run;'+le + +'end.'+le + +le; + AProject.MainFile.SetSourceText(NewSource); + + // add lcl pp/pas dirs to source search path + AProject.AddPackageDependency('LCL'); + AProject.LazCompilerOptions.Win32GraphicApp:=true; + AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'; + AProject.LazCompilerOptions.TargetFilename:='project1'; +end; + +function TProjectApplicationDescriptor.CreateStartFiles(AProject: TLazProject + ): TModalResult; +begin + Result:=LazarusIDE.DoNewEditorFile(FileDescriptorForm,'','', + [nfIsPartOfProject,nfOpenInEditor,nfCreateDefaultSrc]); +end; + +{ TProjectManualProgramDescriptor } + +constructor TProjectManualProgramDescriptor.Create; +begin + inherited Create; + VisibleInNewDialog:=false; + Name:=ProjDescNameCustomProgram; + Flags:=Flags-[pfMainUnitHasUsesSectionForAllUnits, + pfMainUnitHasCreateFormStatements, + pfMainUnitHasTitleStatement] + +[pfUseDefaultCompilerOptions]; + FAddMainSource:=true; +end; + +function TProjectManualProgramDescriptor.GetLocalizedName: string; +begin + Result:=lisCustomProgram; +end; + +function TProjectManualProgramDescriptor.GetLocalizedDescription: string; +begin + Result:=Format(lisCustomProgramAFreepascalProgram, [#13]); +end; + +function TProjectManualProgramDescriptor.InitProject(AProject: TLazProject + ): TModalResult; +var + le: string; + NewSource: String; + MainFile: TLazProjectFile; +begin + Result:=inherited InitProject(AProject); + + if AddMainSource then begin + MainFile:=AProject.CreateProjectFile('project1.pas'); + MainFile.IsPartOfProject:=true; + AProject.AddFile(MainFile,false); + AProject.MainFileID:=0; + + // create program source + le:=LineEnding; + NewSource:='program Project1;'+le + +le + +'{$mode objfpc}{$H+}'+le + +le + +'uses'+le + +' Classes, SysUtils'+le + +' { you can add units after this };'+le + +le + +'begin'+le + +'end.'+le + +le; + AProject.MainFile.SetSourceText(NewSource); + end; +end; + +function TProjectManualProgramDescriptor.CreateStartFiles(AProject: TLazProject + ): TModalResult; +begin + if AProject.MainFile<>nil then + Result:=LazarusIDE.DoOpenEditorFile(AProject.MainFile.Filename,-1,-1, + [ofProjectLoading,ofRegularFile]); +end; + +{ TProjectEmptyProgramDescriptor } + +constructor TProjectEmptyProgramDescriptor.Create; +begin + inherited Create; + FAddMainSource:=false; +end; + +{ TProjectLibraryDescriptor } + +constructor TProjectLibraryDescriptor.Create; +begin + inherited Create; + Name:=ProjDescNameLibrary; + Flags:=Flags-[pfMainUnitHasCreateFormStatements,pfMainUnitHasTitleStatement] + +[pfUseDefaultCompilerOptions]; +end; + +function TProjectLibraryDescriptor.GetLocalizedName: string; +begin + Result:=lisPckOptsLibrary; +end; + +function TProjectLibraryDescriptor.GetLocalizedDescription: string; +begin + Result:= Format(lisLibraryAFreepascalLibraryDllUnderWindowsSoUnderLin, [#13]); +end; + +function TProjectLibraryDescriptor.InitProject(AProject: TLazProject + ): TModalResult; +var + le: String; + NewSource: String; + MainFile: TLazProjectFile; +begin + Result:=inherited InitProject(AProject); + + MainFile:=AProject.CreateProjectFile('project1.lpr'); + MainFile.IsPartOfProject:=true; + AProject.AddFile(MainFile,false); + AProject.MainFileID:=0; + AProject.LazCompilerOptions.ExecutableType:=cetLibrary; + + // create program source + le:=LineEnding; + NewSource:='library Project1;'+le + +le + +'{$mode objfpc}{$H+}'+le + +le + +'uses'+le + +' Classes'+le + +' { you can add units after this };'+le + +le + +'begin'+le + +'end.'+le + +le; + AProject.MainFile.SetSourceText(NewSource); + + AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'; + AProject.LazCompilerOptions.TargetFilename:='project1'; +end; + +function TProjectLibraryDescriptor.CreateStartFiles(AProject: TLazProject + ): TModalResult; +begin + Result:=LazarusIDE.DoOpenEditorFile(AProject.MainFile.Filename,-1,-1, + [ofProjectLoading,ofRegularFile]); +end; + +{ TProjectConsoleApplicationDescriptor } + +constructor TProjectConsoleApplicationDescriptor.Create; +begin + inherited Create; + Name:=ProjDescNameConsoleApplication; + Flags:=Flags-[pfMainUnitHasCreateFormStatements,pfMainUnitHasTitleStatement] + +[pfUseDefaultCompilerOptions]; +end; + +function TProjectConsoleApplicationDescriptor.GetLocalizedName: string; +begin + Result:=lisConsoleApplication; +end; + +function TProjectConsoleApplicationDescriptor.GetLocalizedDescription: string; +begin + Result:=GetLocalizedName+#13 + +lisFreepascalProgramUsingTCustomApplicationToEasilyCh; +end; + +function TProjectConsoleApplicationDescriptor.InitProject(AProject: TLazProject + ): TModalResult; +var + NewSource: TStringList; + MainFile: TLazProjectFile; + C, T : String; + CC,CD,CU,CS, CO : Boolean; + +begin + Result:=inherited InitProject(AProject); + If Result<>mrOk then + Exit; + With TCustomApplicationOptionsForm.Create(Application) do + try + Result:=ShowModal; + If Result<>mrOk then + Exit; + C:=Trim(AppClassName); + T:=StringReplace(Title,'''','''''',[rfReplaceAll]); + CC:=CodeConstructor; + CD:=CodeDestructor; + CU:=CodeUsage; + CS:=CodeStopOnError; + CO:=CodeCheckOptions; + finally + Free; + end; + MainFile:=AProject.CreateProjectFile('project1.lpr'); + MainFile.IsPartOfProject:=true; + AProject.AddFile(MainFile,false); + AProject.MainFileID:=0; + + AProject.LazCompilerOptions.UnitOutputDirectory:='lib'+PathDelim+'$(TargetCPU)-$(TargetOS)'; + AProject.LazCompilerOptions.TargetFilename:='project1'; + + // create program source + NewSource:=TStringList.Create; + NewSource.Add('program Project1;'); + NewSource.Add(''); + NewSource.Add('{$mode objfpc}{$H+}'); + NewSource.Add(''); + NewSource.Add('uses'); + NewSource.Add(' {$IFDEF UNIX}{$IFDEF UseCThreads}'); + NewSource.Add(' cthreads,'); + NewSource.Add(' {$ENDIF}{$ENDIF}'); + NewSource.Add(' Classes, SysUtils, CustApp'); + NewSource.Add(' { you can add units after this };'); + NewSource.Add(''); + NewSource.Add('type'); + NewSource.Add(''); + NewSource.Add(' { '+C+' }'); + NewSource.Add(''); + NewSource.Add(' '+C+' = class(TCustomApplication)'); + NewSource.Add(' protected'); + NewSource.Add(' procedure DoRun; override;'); + NewSource.Add(' public'); + If CC or CS then + NewSource.Add(' constructor Create(TheOwner: TComponent); override;'); + if CD then + NewSource.Add(' destructor Destroy; override;'); + if CU then + NewSource.Add(' procedure WriteHelp; virtual;'); + NewSource.Add(' end;'); + NewSource.Add(''); + NewSource.Add('{ '+C+' }'); + NewSource.Add(''); + NewSource.Add('procedure '+C+'.DoRun;'); + NewSource.Add('var'); + NewSource.Add(' ErrorMsg: String;'); + NewSource.Add('begin'); + if CO then + begin + NewSource.Add(' // quick check parameters'); + NewSource.Add(' ErrorMsg:=CheckOptions(''h'',''help'');'); + NewSource.Add(' if ErrorMsg<>'''' then begin'); + NewSource.Add(' ShowException(Exception.Create(ErrorMsg));'); + NewSource.Add(' Terminate;'); + NewSource.Add(' Exit;'); + NewSource.Add(' end;'); + NewSource.Add(''); + end; + If CU then + begin + NewSource.Add(' // parse parameters'); + NewSource.Add(' if HasOption(''h'',''help'') then begin'); + NewSource.Add(' WriteHelp;'); + NewSource.Add(' Terminate;'); + NewSource.Add(' Exit;'); + NewSource.Add(' end;'); + end; + NewSource.Add(''); + NewSource.Add(' { add your program here }'); + NewSource.Add(''); + NewSource.Add(' // stop program loop'); + NewSource.Add(' Terminate;'); + NewSource.Add('end;'); + NewSource.Add(''); + If CC or CS then + begin + NewSource.Add('constructor '+C+'.Create(TheOwner: TComponent);'); + NewSource.Add('begin'); + NewSource.Add(' inherited Create(TheOwner);'); + If CS then + NewSource.Add(' StopOnException:=True;'); + NewSource.Add('end;'); + NewSource.Add(''); + end; + If CD then + begin + NewSource.Add('destructor '+C+'.Destroy;'); + NewSource.Add('begin'); + NewSource.Add(' inherited Destroy;'); + NewSource.Add('end;'); + NewSource.Add(''); + end; + If CU then + begin + NewSource.Add('procedure '+C+'.WriteHelp;'); + NewSource.Add('begin'); + NewSource.Add(' { add your help code here }'); + NewSource.Add(' writeln(''Usage: '',ExeName,'' -h'');'); + NewSource.Add('end;'); + NewSource.Add(''); + end; + NewSource.Add('var'); + NewSource.Add(' Application: '+C+';'); + NewSource.Add('begin'); + NewSource.Add(' Application:='+C+'.Create(nil);'); + If (T<>'') then + NewSource.Add(' Application.Title:='''+T+''';'); + NewSource.Add(' Application.Run;'); + NewSource.Add(' Application.Free;'); + NewSource.Add('end.'); + NewSource.Add(''); + AProject.MainFile.SetSourceText(NewSource.Text); + NewSource.Free; +end; + +function TProjectConsoleApplicationDescriptor.CreateStartFiles( + AProject: TLazProject): TModalResult; +begin + Result:=LazarusIDE.DoOpenEditorFile(AProject.MainFile.Filename,-1,-1, + [ofProjectLoading,ofRegularFile]); +end; + initialization LazProjectFileDescriptors:=nil; diff --git a/lcl/include/control.inc b/lcl/include/control.inc index 4f44d23df9..78f6783d76 100644 --- a/lcl/include/control.inc +++ b/lcl/include/control.inc @@ -2659,7 +2659,9 @@ end; ------------------------------------------------------------------------------} procedure TControl.SetHint(const Value: TTranslateString); begin - if FHint <> Value then FHint := Value; + if FHint = Value then exit; + FHint := Value; + end; {------------------------------------------------------------------------------