mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-23 05:19:31 +02:00
implemented Use Unit option for package units to allow units, that are not always compiled
git-svn-id: trunk@7192 -
This commit is contained in:
parent
b2ba0f4418
commit
536fc01a98
@ -2448,6 +2448,10 @@ resourcestring
|
||||
lisPckEditCallRegisterProcedureOfSelectedUnit = 'Call %sRegister%s '
|
||||
+'procedure of selected unit';
|
||||
lisPckEditRegisteredPlugins = 'Registered plugins';
|
||||
lisPkgMangAddUnitToUsesClauseOfPackageDisableThisOnlyForUnit = 'Add unit to '
|
||||
+'uses clause of package. Disable this only for units, that should not be '
|
||||
+'compiled in all cases.';
|
||||
lisPkgMangUseUnit = 'Use unit';
|
||||
lisPckEditMinimumVersion = 'Minimum Version:';
|
||||
lisPckEditMaximumVersion = 'Maximum Version:';
|
||||
lisPckEditApplyChanges = 'Apply changes';
|
||||
|
@ -135,10 +135,13 @@ const
|
||||
type
|
||||
TPkgFileFlag = (
|
||||
pffHasRegisterProc, // file is unit and has a 'register' procedure
|
||||
pffAddToPkgUsesSection,// unit is added to uses section if package source
|
||||
pffReportedAsRemoved // file has been reported as removed
|
||||
);
|
||||
TPkgFileFlags = set of TPkgFileFlag;
|
||||
|
||||
{ TPkgFile }
|
||||
|
||||
TPkgFile = class
|
||||
private
|
||||
FAutoReferenceSourceDir: boolean;
|
||||
@ -153,8 +156,10 @@ type
|
||||
FSourceDirectoryReferenced: boolean;
|
||||
FSourceDirNeedReference: boolean;
|
||||
FUnitName: string;
|
||||
function GetAddToUsesPkgSection: boolean;
|
||||
function GetComponents(Index: integer): TPkgComponent;
|
||||
function GetHasRegisterProc: boolean;
|
||||
procedure SetAddToUsesPkgSection(const AValue: boolean);
|
||||
procedure SetAutoReferenceSourceDir(const AValue: boolean);
|
||||
procedure SetRemoved(const AValue: boolean);
|
||||
procedure SetFilename(const AValue: string);
|
||||
@ -187,7 +192,9 @@ type
|
||||
property FileType: TPkgFileType read FFileType write SetFileType;
|
||||
property Flags: TPkgFileFlags read FFlags write SetFlags;
|
||||
property HasRegisterProc: boolean
|
||||
read GetHasRegisterProc write SetHasRegisterProc;
|
||||
read GetHasRegisterProc write SetHasRegisterProc;
|
||||
property AddToUsesPkgSection: boolean
|
||||
read GetAddToUsesPkgSection write SetAddToUsesPkgSection;
|
||||
property LazPackage: TLazPackage read FPackage;
|
||||
property UnitName: string read FUnitName write FUnitName;
|
||||
property ComponentPriority: TComponentPriority read FComponentPriority
|
||||
@ -766,7 +773,7 @@ const
|
||||
PkgFileTypeIdents: array[TPkgFileType] of string = (
|
||||
'Unit', 'Virtual Unit', 'LFM', 'LRS', 'Include', 'Text', 'Binary');
|
||||
PkgFileFlag: array[TPkgFileFlag] of string = (
|
||||
'pffHasRegisterProc', 'pffReportedAsRemoved');
|
||||
'pffHasRegisterProc', 'pffAddToPkgUsesSection', 'pffReportedAsRemoved');
|
||||
PkgDependencyFlagNames: array[TPkgDependencyFlag] of string = (
|
||||
'pdfMinVersion', 'pdfMaxVersion');
|
||||
LazPackageTypeNames: array[TLazPackageType] of string = (
|
||||
@ -1224,6 +1231,15 @@ begin
|
||||
Result:=pffHasRegisterProc in FFlags;
|
||||
end;
|
||||
|
||||
procedure TPkgFile.SetAddToUsesPkgSection(const AValue: boolean);
|
||||
begin
|
||||
if AddToUsesPkgSection=AValue then exit;
|
||||
if AValue then
|
||||
Include(FFlags,pffAddToPkgUsesSection)
|
||||
else
|
||||
Exclude(FFlags,pffAddToPkgUsesSection);
|
||||
end;
|
||||
|
||||
procedure TPkgFile.SetAutoReferenceSourceDir(const AValue: boolean);
|
||||
begin
|
||||
if FAutoReferenceSourceDir=AValue then exit;
|
||||
@ -1245,6 +1261,11 @@ begin
|
||||
Result:=TPkgComponent(FComponents[Index]);
|
||||
end;
|
||||
|
||||
function TPkgFile.GetAddToUsesPkgSection: boolean;
|
||||
begin
|
||||
Result:=pffAddToPkgUsesSection in FFlags;
|
||||
end;
|
||||
|
||||
procedure TPkgFile.SetFileType(const AValue: TPkgFileType);
|
||||
begin
|
||||
if FFileType=AValue then exit;
|
||||
@ -1352,6 +1373,8 @@ begin
|
||||
Filename:=AFilename;
|
||||
FileType:=PkgFileTypeIdentToType(XMLConfig.GetValue(Path+'Type/Value',''));
|
||||
HasRegisterProc:=XMLConfig.GetValue(Path+'HasRegisterProc/Value',false);
|
||||
AddToUsesPkgSection:=XMLConfig.GetValue(Path+'AddToUsesPkgSection/Value',
|
||||
FileType in PkgFileUnitTypes);
|
||||
fUnitName:=XMLConfig.GetValue(Path+'UnitName/Value','');
|
||||
if FileType in PkgFileUnitTypes then begin
|
||||
// make sure the unitname makes sense
|
||||
@ -1370,6 +1393,8 @@ begin
|
||||
XMLConfig.SetDeleteValue(Path+'Filename/Value',TmpFilename,'');
|
||||
XMLConfig.SetDeleteValue(Path+'HasRegisterProc/Value',HasRegisterProc,
|
||||
false);
|
||||
XMLConfig.SetDeleteValue(Path+'AddToUsesPkgSection/Value',AddToUsesPkgSection,
|
||||
FileType in PkgFileUnitTypes);
|
||||
XMLConfig.SetDeleteValue(Path+'Type/Value',PkgFileTypeIdents[FileType],
|
||||
PkgFileTypeIdents[pftUnit]);
|
||||
XMLConfig.SetDeleteValue(Path+'UnitName/Value',FUnitName,'');
|
||||
|
@ -108,6 +108,7 @@ type
|
||||
FilePropsGroupBox: TGroupBox;
|
||||
// file properties
|
||||
CallRegisterProcCheckBox: TCheckBox;
|
||||
AddToUsesPkgSectionCheckBox: TCheckBox;
|
||||
RegisteredPluginsGroupBox: TGroupBox;
|
||||
RegisteredListBox: TListBox;
|
||||
// dependency properties
|
||||
@ -122,6 +123,7 @@ type
|
||||
ImageList: TImageList;
|
||||
FilesPopupMenu: TPopupMenu;
|
||||
procedure AddBitBtnClick(Sender: TObject);
|
||||
procedure AddToUsesPkgSectionCheckBoxClick(Sender: TObject);
|
||||
procedure ApplyDependencyButtonClick(Sender: TObject);
|
||||
procedure CallRegisterProcCheckBoxClick(Sender: TObject);
|
||||
procedure ChangeFileTypeMenuItemClick(Sender: TObject);
|
||||
@ -855,10 +857,16 @@ procedure TPackageEditorForm.FilePropsGroupBoxResize(Sender: TObject);
|
||||
var
|
||||
y: Integer;
|
||||
x: Integer;
|
||||
w: Integer;
|
||||
begin
|
||||
// components for files
|
||||
w:=(ClientWidth-15) div 2;
|
||||
with CallRegisterProcCheckBox do
|
||||
SetBounds(3,0,Parent.ClientWidth,Height);
|
||||
SetBounds(3,0,w,Height);
|
||||
x:=3+w+9;
|
||||
|
||||
with AddToUsesPkgSectionCheckBox do
|
||||
SetBounds(x,0,w,Height);
|
||||
|
||||
y:=CallRegisterProcCheckBox.Top+CallRegisterProcCheckBox.Height+3;
|
||||
with RegisteredPluginsGroupBox do
|
||||
@ -990,6 +998,20 @@ begin
|
||||
PackageGraph.EndUpdate;
|
||||
end;
|
||||
|
||||
procedure TPackageEditorForm.AddToUsesPkgSectionCheckBoxClick(Sender: TObject);
|
||||
var
|
||||
CurFile: TPkgFile;
|
||||
Removed: boolean;
|
||||
begin
|
||||
if LazPackage=nil then exit;
|
||||
CurFile:=GetCurrentFile(Removed);
|
||||
if (CurFile=nil) then exit;
|
||||
if CurFile.AddToUsesPkgSection=AddToUsesPkgSectionCheckBox.Checked then exit;
|
||||
CurFile.AddToUsesPkgSection:=AddToUsesPkgSectionCheckBox.Checked;
|
||||
LazPackage.Modified:=not Removed;
|
||||
UpdateAll;
|
||||
end;
|
||||
|
||||
procedure TPackageEditorForm.ApplyDependencyButtonClick(Sender: TObject);
|
||||
var
|
||||
CurDependency: TPkgDependency;
|
||||
@ -1045,6 +1067,7 @@ begin
|
||||
if LazPackage=nil then exit;
|
||||
CurFile:=GetCurrentFile(Removed);
|
||||
if (CurFile=nil) then exit;
|
||||
if CurFile.HasRegisterProc=CallRegisterProcCheckBox.Checked then exit;
|
||||
CurFile.HasRegisterProc:=CallRegisterProcCheckBox.Checked;
|
||||
LazPackage.Modified:=not Removed;
|
||||
UpdateAll;
|
||||
@ -1316,6 +1339,17 @@ begin
|
||||
ShowHint:=true;
|
||||
end;
|
||||
|
||||
AddToUsesPkgSectionCheckBox:=TCheckBox.Create(Self);
|
||||
with AddToUsesPkgSectionCheckBox do begin
|
||||
Name:='AddToUsesPkgSectionCheckBox';
|
||||
Parent:=FilePropsGroupBox;
|
||||
Caption:=lisPkgMangUseUnit;
|
||||
UseOnChange:=true;
|
||||
OnClick:=@AddToUsesPkgSectionCheckBoxClick;
|
||||
Hint:=lisPkgMangAddUnitToUsesClauseOfPackageDisableThisOnlyForUnit;
|
||||
ShowHint:=true;
|
||||
end;
|
||||
|
||||
RegisteredPluginsGroupBox:=TGroupBox.Create(Self);
|
||||
with RegisteredPluginsGroupBox do begin
|
||||
Name:='RegisteredPluginsGroupBox';
|
||||
@ -1593,6 +1627,7 @@ begin
|
||||
ApplyDependencyButton.Visible:=Dependency<>nil;
|
||||
|
||||
CallRegisterProcCheckBox.Visible:=CurFile<>nil;
|
||||
AddToUsesPkgSectionCheckBox.Visible:=CurFile<>nil;
|
||||
RegisteredPluginsGroupBox.Visible:=CurFile<>nil;
|
||||
|
||||
if CurFile<>nil then begin
|
||||
@ -1602,6 +1637,9 @@ begin
|
||||
CallRegisterProcCheckBox.Enabled:=(not LazPackage.ReadOnly)
|
||||
and (CurFile.FileType in [pftUnit,pftVirtualUnit]);
|
||||
CallRegisterProcCheckBox.Checked:=pffHasRegisterProc in CurFile.Flags;
|
||||
AddToUsesPkgSectionCheckBox.Checked:=pffAddToPkgUsesSection in CurFile.Flags;
|
||||
AddToUsesPkgSectionCheckBox.Enabled:=(not LazPackage.ReadOnly)
|
||||
and (CurFile.FileType in PkgFileUnitTypes);
|
||||
// fetch all registered plugins
|
||||
CurListIndex:=0;
|
||||
RegCompCnt:=CurFile.ComponentCount;
|
||||
|
@ -2554,6 +2554,7 @@ var
|
||||
OutputDir: String;
|
||||
OldSrc: String;
|
||||
CaseInsensitiveUnitName: String;
|
||||
NeedsRegisterProcCall: boolean;
|
||||
begin
|
||||
{$IFDEF VerbosePkgCompile}
|
||||
writeln('TPkgManager.DoSavePackageMainSource A');
|
||||
@ -2603,11 +2604,14 @@ begin
|
||||
if SysUtils.CompareText(CurUnitName,CaseInsensitiveUnitName)<>0 then
|
||||
CurUnitName:=CaseInsensitiveUnitName;
|
||||
if (CurUnitName<>'') and IsValidIdent(CurUnitName) then begin
|
||||
if UsedUnits<>'' then
|
||||
UsedUnits:=UsedUnits+', ';
|
||||
UsedUnits:=UsedUnits+CurUnitName;
|
||||
if (APackage.PackageType in [lptDesignTime,lptRunAndDesignTime])
|
||||
and CurFile.HasRegisterProc then begin
|
||||
NeedsRegisterProcCall:=CurFile.HasRegisterProc
|
||||
and (APackage.PackageType in [lptDesignTime,lptRunAndDesignTime]);
|
||||
if NeedsRegisterProcCall or CurFile.AddToUsesPkgSection then begin
|
||||
if UsedUnits<>'' then
|
||||
UsedUnits:=UsedUnits+', ';
|
||||
UsedUnits:=UsedUnits+CurUnitName;
|
||||
end;
|
||||
if NeedsRegisterProcCall then begin
|
||||
RegistrationCode:=RegistrationCode+
|
||||
' RegisterUnit('''+CurUnitName+''',@'+CurUnitName+'.Register);'+e;
|
||||
end;
|
||||
|
Loading…
Reference in New Issue
Block a user