IDE: implemented adding packages when creating new unit

git-svn-id: trunk@15394 -
This commit is contained in:
mattias 2008-06-12 10:04:25 +00:00
parent 730b5f6b42
commit e05e391f2b
5 changed files with 54 additions and 19 deletions

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, Forms;
Type
TCustomFormClass = Class of TForm;
TFormClass = Class of TForm;
{ TCustomFormDescr }
@ -18,13 +18,13 @@ Type
FCaption: String;
FCategory: String;
FDescription: String;
FFormClass: TCustomFormClass;
FFormClass: TFormClass;
FLazPackage: String;
FUnitName: String;
public
Constructor Create(AFormClass : TCustomFormClass; const APackage: string);
Constructor Create(AFormClass : TCustomFormClass; Const ACaption,ADescription,AUnit,APackage : String);
Property FormClass : TCustomFormClass Read FFormClass Write FFormClass;
Constructor Create(AFormClass : TFormClass; const APackage: string);
Constructor Create(AFormClass : TFormClass; Const ACaption,ADescription,AUnit,APackage : String);
Property FormClass : TFormClass Read FFormClass Write FFormClass;
Property Caption : String Read FCaption Write FCaption;
Property Description : String Read FDescription Write FDescription;
Property UnitName : String Read FUnitName Write FUnitName;
@ -34,8 +34,8 @@ Type
end;
Procedure RegisterCustomForm(Descr : TCustomFormDescr);
Procedure RegisterCustomForm(AFormClass : TCustomFormClass; const APackage: string);
Procedure RegisterCustomForm(AFormClass : TCustomFormClass; Const AUnitName, APackage : String);
Procedure RegisterCustomForm(AFormClass : TFormClass; const APackage: string);
Procedure RegisterCustomForm(AFormClass : TFormClass; Const AUnitName, APackage : String);
Procedure Register;
@ -49,7 +49,7 @@ Const
{ TCustomFormDescr }
constructor TCustomFormDescr.Create(AFormClass: TCustomFormClass;
constructor TCustomFormDescr.Create(AFormClass: TFormClass;
const APackage: string);
Var
@ -63,7 +63,7 @@ begin
Create(AFormClass,N,Format(SInstanceOf,[N]),U,APackage);
end;
constructor TCustomFormDescr.Create(AFormClass: TCustomFormClass;
constructor TCustomFormDescr.Create(AFormClass: TFormClass;
const ACaption, ADescription, AUnit, APackage: String);
begin
FFormClass:=AFormClass;
@ -98,6 +98,7 @@ begin
ResourceClass:=FFormDescr.FFormClass;
Name:=FFormDescr.Caption;
RequiredPackages:=ADescr.LazPackage;
//Writeln('TCustomFormFileDescriptor.Create RequiredPackages=',RequiredPackages);
end;
function TCustomFormFileDescriptor.GetLocalizedName: String;
@ -127,13 +128,13 @@ begin
CustomFormList.Add(Descr);
end;
Procedure RegisterCustomForm(AFormClass : TCustomFormClass; const APackage: string);
Procedure RegisterCustomForm(AFormClass : TFormClass; const APackage: string);
begin
RegisterCustomForm(TCustomFormDescr.Create(AFormClass,APackage));
end;
Procedure RegisterCustomForm(AFormClass : TCustomFormClass; Const AUnitName, APackage : String);
Procedure RegisterCustomForm(AFormClass : TFormClass; Const AUnitName, APackage : String);
Var
D : TCustomFormDescr;

View File

@ -6913,6 +6913,13 @@ begin
// syntax highlighter type
NewUnitInfo.SyntaxHighlighter:=
ExtensionToLazSyntaxHighlighter(ExtractFileExt(NewFilename));
// required packages
if NewUnitInfo.IsPartOfProject and (NewFileDescriptor.RequiredPackages<>'')
then begin
if PkgBoss.AddProjectDependencies(Project1,NewFileDescriptor.RequiredPackages
)<>mrOk then exit;
end;
if nfOpenInEditor in NewFlags then begin
// open a new sourceeditor

View File

@ -344,8 +344,8 @@ type
procedure SetDefaultSourceName(const AValue: string); virtual;
procedure SetDefaultResFileExt(const AValue: string); virtual;
procedure SetName(const AValue: string); virtual;
procedure SetRequiredPackages(const AValue: string); virtual;
procedure SetResourceClass(const AValue: TPersistentClass); virtual;
procedure SetRequiredPackages(const AValue: string); virtual;
public
constructor Create; virtual;
function GetLocalizedName: string; virtual;
@ -363,8 +363,8 @@ type
property DefaultSourceName: string read FDefaultSourceName write SetDefaultSourceName;
property DefaultResFileExt: string read FDefaultResFileExt write SetDefaultResFileExt;
property DefaultResourceName: string read FDefaultResourceName write FDefaultResourceName;
property RequiredPackages: string read FRequiredPackages write SetRequiredPackages; // package names separated by semicolon
property ResourceClass: TPersistentClass read FResourceClass write SetResourceClass;
property RequiredPackages: string read FRequiredPackages write SetRequiredPackages; // package names separated by semicolon
property IsComponent: boolean read FIsComponent;
property UseCreateFormStatements: boolean read FUseCreateFormStatements write FUseCreateFormStatements;
property VisibleInNewDialog: boolean read FVisibleInNewDialog write FVisibleInNewDialog;
@ -838,6 +838,12 @@ begin
FDefaultSourceName:=AValue;
end;
procedure TProjectFileDescriptor.SetRequiredPackages(const AValue: string);
begin
if FRequiredPackages=AValue then exit;
FRequiredPackages:=AValue;
end;
procedure TProjectFileDescriptor.SetDefaultFilename(const AValue: string);
begin
if FDefaultFilename=AValue then exit;
@ -852,12 +858,6 @@ begin
FName:=AValue;
end;
procedure TProjectFileDescriptor.SetRequiredPackages(const AValue: string);
begin
if FRequiredPackages=AValue then exit;
FRequiredPackages:=AValue;
end;
constructor TProjectFileDescriptor.Create;
begin
FReferenceCount:=1;

View File

@ -95,6 +95,8 @@ type
procedure AddProjectRegCompDependency(AProject: TProject;
ARegisteredComponent: TRegisteredComponent); virtual; abstract;
procedure AddProjectLCLDependency(AProject: TProject); virtual; abstract;
function AddProjectDependencies(AProject: TProject; const Packages: string;
OnlyTestIfPossible: boolean = false): TModalResult; virtual; abstract;
function CheckProjectHasInstalledPackages(AProject: TProject; Interactive: boolean): TModalResult; virtual; abstract;
function CanOpenDesignerForm(AnUnitInfo: TUnitInfo;
Interactive: boolean): TModalResult; virtual; abstract;

View File

@ -250,6 +250,8 @@ type
procedure AddProjectRegCompDependency(AProject: TProject;
ARegisteredComponent: TRegisteredComponent); override;
procedure AddProjectLCLDependency(AProject: TProject); override;
function AddProjectDependencies(AProject: TProject; const Packages: string;
OnlyTestIfPossible: boolean = false): TModalResult; override;
function OnProjectInspectorOpen(Sender: TObject): boolean; override;
function OnProjectInspectorAddDependency(Sender: TObject;
ADependency: TPkgDependency): TModalResult; override;
@ -2249,6 +2251,29 @@ begin
AddProjectDependency(AProject,PackageGraph.LCLPackage);
end;
function TPkgManager.AddProjectDependencies(AProject: TProject;
const Packages: string; OnlyTestIfPossible: boolean): TModalResult;
var
RequiredPackages: TStrings;
i: Integer;
PkgName: string;
APackage: TLazPackage;
begin
RequiredPackages:=SplitString(Packages,';');
for i:=0 to RequiredPackages.Count-1 do begin
PkgName:=Trim(RequiredPackages[i]);
if (PkgName='') or (not IsValidIdent(PkgName)) then continue;
APackage:=PackageGraph.FindAPackageWithName(PkgName,nil);
if APackage=nil then begin
DebugLn(['TPkgManager.AddProjectDependencies package not found: ',PkgName]);
continue;
end;
AddProjectDependency(AProject,APackage);
end;
RequiredPackages.Free;
Result:=mrOk;
end;
function TPkgManager.CheckProjectHasInstalledPackages(AProject: TProject;
Interactive: boolean): TModalResult;
var