IDE: Ask about auto-creating form after adding a unit.

git-svn-id: trunk@64870 -
This commit is contained in:
juha 2021-03-25 09:59:38 +00:00
parent 566adc9a29
commit 6be311758d
3 changed files with 41 additions and 49 deletions

View File

@ -981,9 +981,9 @@ type
function UpdateIsPartOfProjectFromMainUnit: TModalResult;
// Application.CreateForm statements
function AddCreateFormToProjectFile(const AClassName, AName:string):boolean;
function AddCreateFormToProjectFile(const AClassName, AName:string): boolean;
function RemoveCreateFormFromProjectFile(const AName: string): boolean;
function FormIsCreatedInProjectFile(const AClassname, AName:string):boolean;
function FormIsCreatedInProjectFile(const AClassname, AName:string): boolean;
function GetAutoCreatedFormsList: TStrings;
property TmpAutoCreatedForms: TStrings read FTmpAutoCreatedForms write FTmpAutoCreatedForms;
@ -4072,16 +4072,11 @@ begin
until ProjectUnitWithShortFilename(Result)=nil;
end;
function TProject.AddCreateFormToProjectFile(const AClassName, AName: string):boolean;
function TProject.AddCreateFormToProjectFile(const AClassName, AName: string): boolean;
begin
if (pfMainUnitHasCreateFormStatements in Project1.Flags) then begin
Result:=CodeToolBoss.AddCreateFormStatement(MainUnitInfo.Source,AClassName,AName);
if Result then begin
MainUnitInfo.Modified:=true;
end;
end else begin
Result:=false;
end;
Result:=CodeToolBoss.AddCreateFormStatement(MainUnitInfo.Source,AClassName,AName);
if Result then
MainUnitInfo.Modified:=true;
end;
function TProject.RemoveCreateFormFromProjectFile(const AName:string):boolean;
@ -4091,7 +4086,7 @@ begin
MainUnitInfo.Modified:=true;
end;
function TProject.FormIsCreatedInProjectFile(const AClassname,AName:string):boolean;
function TProject.FormIsCreatedInProjectFile(const AClassname,AName:string): boolean;
var p: integer;
begin
Result:=(CodeToolBoss.FindCreateFormStatement(MainUnitInfo.Source,

View File

@ -289,7 +289,7 @@ implementation
function UpdateUnitInfoResourceBaseClass(AnUnitInfo: TUnitInfo; Quiet: boolean): boolean;
var
LFMFilename, LFMClassName, LFMType, Ancestor, LFMComponentName: String;
LFMFilename, LFMType, Ancestor, LFMClassName, LFMComponentName: String;
LFMCode, Code: TCodeBuffer;
LoadFileFlags: TLoadBufferFlags;
ClearOldInfo: Boolean;
@ -354,7 +354,7 @@ begin
if Node=nil then
exit(Tool.FindImplementationNode<>nil); // class not found, reliable if whole interface was read
if (Node=nil) or (Node.Desc<>ctnTypeDefinition)
if (Node.Desc<>ctnTypeDefinition)
or (Node.FirstChild=nil) or (Node.FirstChild.Desc<>ctnClass) then
exit(true); // this is not a class
Tool.FindClassAndAncestors(Node.FirstChild,ListOfPFindContext,false);
@ -366,22 +366,41 @@ begin
Ancestor:=UpperCase(Context^.Tool.ExtractClassName(Context^.Node,false));
if (Ancestor='TFORM') then begin
AnUnitInfo.ResourceBaseClass:=pfcbcForm;
exit(true);
Result:=true;
Break;
end else if (Ancestor='TCUSTOMFORM') then begin
AnUnitInfo.ResourceBaseClass:=pfcbcCustomForm;
exit(true);
Result:=true;
Break;
end else if Ancestor='TDATAMODULE' then begin
AnUnitInfo.ResourceBaseClass:=pfcbcDataModule;
exit(true);
Result:=true;
Break;
end else if (Ancestor='TFRAME') or (Ancestor='TCUSTOMFRAME') then begin
AnUnitInfo.ResourceBaseClass:=pfcbcFrame;
exit(true);
end else if Ancestor='TCOMPONENT' then
exit(true);
Result:=true;
Break;
end else if Ancestor='TCOMPONENT' then begin
Result:=true;
Break;
end;
end;
except
exit; // syntax error or unit not found
end;
if not Result then exit;
// Maybe auto-create it
// (pfMainUnitHasCreateFormStatements in Project1.Flags)
// and Project1.AutoCreateForms are checked by caller.
if (AnUnitInfo.ResourceBaseClass in [pfcbcForm,pfcbcCustomForm,pfcbcDataModule])
and (LFMComponentName<>'')
and (IDEMessageDialog(lisAddToStartupComponents,
Format(lisShouldTheComponentBeAutoCreatedWhenTheApplicationS,
[LFMComponentName]),
mtInformation,[mbYes,mbNo])=mrYes)
then
Project1.AddCreateFormToProjectFile(LFMClassName,LFMComponentName);
finally
FreeListOfPFindContext(ListOfPFindContext);
end;

View File

@ -216,8 +216,8 @@ function FindSourceFileImpl(const AFilename, BaseDirectory: string;
Flags: TFindSourceFlags): string;
function FindUnitsOfOwnerImpl(TheOwner: TObject; Flags: TFindUnitsOfOwnerFlags): TStrings;
// project
function AddUnitToProject(const AEditor: TSourceEditorInterface): TModalResult;
function AddActiveUnitToProject: TModalResult;
function AddUnitToProject(const AEditor: TSourceEditorInterface): TModalResult;
function RemoveFromProjectDialog: TModalResult;
function InitNewProject(ProjectDesc: TProjectDescriptor): TModalResult;
function InitOpenedProjectFile(AFileName: string; Flags: TOpenFlags): TModalResult;
@ -1753,17 +1753,21 @@ begin
MainIDE.SaveEnvironment;
end;
function AddActiveUnitToProject: TModalResult;
begin
Result := AddUnitToProject(nil);
end;
function AddUnitToProject(const AEditor: TSourceEditorInterface): TModalResult;
var
ActiveSourceEditor: TSourceEditor;
ActiveUnitInfo: TUnitInfo;
s, ShortUnitName, LFMFilename, LFMType, LFMComponentName, LFMClassName: string;
s, ShortUnitName: string;
OkToAdd, IsPascal: boolean;
Owners: TFPList;
i: Integer;
APackage: TLazPackage;
MsgResult: TModalResult;
LFMCode: TCodeBuffer;
begin
Result:=mrCancel;
if AEditor<>nil then
@ -1864,28 +1868,7 @@ begin
if Project1.AutoCreateForms and IsPascal
and (pfMainUnitHasCreateFormStatements in Project1.Flags) then
begin
UpdateUnitInfoResourceBaseClass(ActiveUnitInfo,true);
if ActiveUnitInfo.ResourceBaseClass in [pfcbcForm,pfcbcCustomForm,pfcbcDataModule] then
begin
LFMFilename:=ActiveUnitInfo.UnitResourceFileformat.GetUnitResourceFilename(ActiveUnitInfo.Filename,true);
if LoadCodeBuffer(LFMCode,LFMFilename,[lbfUpdateFromDisk],false)=mrOk then
begin
// read lfm header
ReadLFMHeader(LFMCode.Source,LFMType,LFMComponentName,LFMClassName);
if (LFMComponentName<>'')
and (LFMClassName<>'') then begin
if IDEMessageDialog(lisAddToStartupComponents,
Format(lisShouldTheComponentBeAutoCreatedWhenTheApplicationS, [
LFMComponentName]),
mtInformation,[mbYes,mbNo])=mrYes then
begin
Project1.AddCreateFormToProjectFile(LFMClassName,LFMComponentName);
end;
end;
end;
end;
end;
end;
procedure UpdateSourceNames;
@ -3532,11 +3515,6 @@ begin
end;
end;
function AddActiveUnitToProject: TModalResult;
begin
Result := AddUnitToProject(nil);
end;
function RemoveFromProjectDialog: TModalResult;
var
ViewUnitEntries: TViewUnitEntries;