buildintf: added TProjectFileDescriptor.Initialized, IDE: newfile: set HasResources before calling Initialized

This commit is contained in:
mattias 2022-02-06 13:30:07 +01:00
parent 595a4673e4
commit b9cfb64b7b
2 changed files with 29 additions and 16 deletions

View File

@ -123,6 +123,7 @@ type
procedure UpdateDefaultPascalFileExtension(const DefPasExt: string); virtual;
function Init(var {%H-}NewFilename: string; {%H-}NewOwner: TObject;
var {%H-}NewSource: string; {%H-}Quiet: boolean): TModalResult; virtual;
function Initialized({%H-}NewFile: TLazProjectFile): TModalResult; virtual; // ready to open in source editor
public
property Owner: TIDEProjPackBase read FOwner write FOwner; // project, package or nil
property Name: string read FName write SetName;
@ -1063,6 +1064,12 @@ begin
Result:=mrOk;
end;
function TProjectFileDescriptor.Initialized(NewFile: TLazProjectFile
): TModalResult;
begin
Result:=mrOk;
end;
{ TFileDescPascalUnit }
constructor TFileDescPascalUnit.Create;

View File

@ -2178,6 +2178,28 @@ begin
and (pfMainUnitHasUsesSectionForAllUnits in AProject.Flags));
end;
NewSrcEdit := Nil;
// Update HasResources property (if the .lfm file was created separately)
if (not NewUnitInfo.HasResources)
and FilenameIsPascalUnit(NewUnitInfo.Filename) then begin
//debugln('NewFile no HasResources ',NewUnitInfo.Filename);
LFMFilename:=ChangeFileExt(NewUnitInfo.Filename,'.lfm');
SearchFlags:=[];
if NewUnitInfo.IsPartOfProject then
Include(SearchFlags,pfsfOnlyProjectFiles);
if NewUnitInfo.IsVirtual then
Include(SearchFlags,pfsfOnlyVirtualFiles);
if (AProject.UnitInfoWithFilename(LFMFilename,SearchFlags)<>nil) then begin
//debugln('NewFile no HasResources ',NewUnitInfo.Filename,' ResourceFile exists');
NewUnitInfo.HasResources:=true;
end;
end;
// call hook
Result:=NewFileDescriptor.Initialized(NewUnitInfo);
if Result<>mrOk then
exit(mrCancel);
if nfOpenInEditor in NewFlags then begin
// open a new sourceeditor
SrcNoteBook := SourceEditorManager.ActiveOrNewSourceWindow;
@ -2271,22 +2293,6 @@ begin
// do not open in editor
end;
// Update HasResources property (if the .lfm file was created separately)
if (not NewUnitInfo.HasResources)
and FilenameIsPascalUnit(NewUnitInfo.Filename) then begin
//debugln('NewFile no HasResources ',NewUnitInfo.Filename);
LFMFilename:=ChangeFileExt(NewUnitInfo.Filename,'.lfm');
SearchFlags:=[];
if NewUnitInfo.IsPartOfProject then
Include(SearchFlags,pfsfOnlyProjectFiles);
if NewUnitInfo.IsVirtual then
Include(SearchFlags,pfsfOnlyVirtualFiles);
if (AProject.UnitInfoWithFilename(LFMFilename,SearchFlags)<>nil) then begin
//debugln('NewFile no HasResources ',NewUnitInfo.Filename,' ResourceFile exists');
NewUnitInfo.HasResources:=true;
end;
end;
if (nfAskForFilename in NewFlags) then begin
// save and ask for filename
NewUnitInfo.Modified:=true;