IDE: Improve logic for updating Application.Title statement. Now it gets removed, too. Issue #34318.

git-svn-id: trunk@59147 -
This commit is contained in:
juha 2018-09-23 11:06:01 +00:00
parent 3a2e657bca
commit 04c36eeea0

View File

@ -4933,89 +4933,78 @@ end;
procedure TMainIDE.ProjectOptionsAfterWrite(Sender: TObject; Restore: boolean); procedure TMainIDE.ProjectOptionsAfterWrite(Sender: TObject; Restore: boolean);
var var
AProject: TProject; AProject: TProject;
aFilename: String;
function GetTitle: String;
begin
Result := '';
if (AProject = nil) or (AProject.MainUnitID < 0) then
Exit;
CodeToolBoss.GetApplicationTitleStatement(AProject.MainUnitInfo.Source, Result);
end;
function SetTitle: Boolean; function SetTitle: Boolean;
var var
OldTitle: String; TitleStat, ProjTitle: String;
NewTitle: String;
begin begin
Result := True; Result := True;
if (AProject.MainUnitID < 0) or TitleStat := '';
(not (pfMainUnitHasTitleStatement in AProject.Flags)) then CodeToolBoss.GetApplicationTitleStatement(AProject.MainUnitInfo.Source, TitleStat);
ProjTitle:=AProject.GetTitle;
//DebugLn(['ProjectOptionsAfterWrite: Project title=',ProjTitle,
// ', Default=',AProject.GetDefaultTitle,', Title Statement=',TitleStat]);
if pfMainUnitHasTitleStatement in AProject.Flags then
begin // Add Title statement if not there already.
if ((TitleStat = '') or (TitleStat = ProjTitle)) and AProject.TitleIsDefault then
Exit; Exit;
OldTitle := GetTitle; //DebugLn(['ProjectOptionsAfterWrite: Setting Title to ',ProjTitle]);
if (OldTitle = '') and AProject.TitleIsDefault then if not CodeToolBoss.SetApplicationTitleStatement(AProject.MainUnitInfo.Source, ProjTitle) then
Exit;
NewTitle:=AProject.GetTitle;
if (OldTitle <> NewTitle) and (not AProject.TitleIsDefault) then
if not CodeToolBoss.SetApplicationTitleStatement(AProject.MainUnitInfo.Source, NewTitle) then
begin begin
IDEMessageDialog(lisProjOptsError, IDEMessageDialog(lisProjOptsError,
Format(lisUnableToChangeProjectTitleInSource, [LineEnding, CodeToolBoss.ErrorMessage]), Format(lisUnableToChangeProjectTitleInSource, [LineEnding, CodeToolBoss.ErrorMessage]),
mtWarning, [mbOk]); mtWarning, [mbOk]);
Result := False; Result := False;
end;
end
else begin // Remove Title statement if it is there.
if TitleStat <> ProjTitle then
Exit; Exit;
end;// set Application.Title:= statement //DebugLn(['ProjectOptionsAfterWrite: Removing Title']);
if (OldTitle <> '') and AProject.TitleIsDefault then
if not CodeToolBoss.RemoveApplicationTitleStatement(AProject.MainUnitInfo.Source) then if not CodeToolBoss.RemoveApplicationTitleStatement(AProject.MainUnitInfo.Source) then
begin begin
IDEMessageDialog(lisProjOptsError, IDEMessageDialog(lisProjOptsError,
Format(lisUnableToRemoveProjectTitleFromSource, [LineEnding, CodeToolBoss.ErrorMessage]), Format(lisUnableToRemoveProjectTitleFromSource, [LineEnding, CodeToolBoss.ErrorMessage]),
mtWarning, [mbOk]); mtWarning, [mbOk]);
Result := False; Result := False;
Exit;
end;// delete title
end; end;
end;
function GetScaled: Boolean;
begin
Result := False;
if (AProject = nil) or (AProject.MainUnitID < 0) then
Exit;
CodeToolBoss.GetApplicationScaledStatement(AProject.MainUnitInfo.Source, Result);
end; end;
function SetScaled: Boolean; function SetScaled: Boolean;
var var
OldScaled, NewScaled: Boolean; ScaledStat, ProjScaled: Boolean;
begin begin
Result := True; Result := True;
if (AProject.MainUnitID < 0) or ScaledStat := False;
(not (pfMainUnitHasScaledStatement in AProject.Flags)) then CodeToolBoss.GetApplicationScaledStatement(AProject.MainUnitInfo.Source, ScaledStat);
ProjScaled:=AProject.Scaled;
//DebugLn(['ProjectOptionsAfterWrite: Project Scaled=',ProjScaled,', Scaled Statement=',ScaledStat]);
if pfMainUnitHasScaledStatement in AProject.Flags then
begin // Add Scaled statement if not there already.
if (ScaledStat = ProjScaled) or not ProjScaled then
Exit; Exit;
OldScaled := GetScaled; //DebugLn(['ProjectOptionsAfterWrite: Setting Scaled to ',ProjScaled]);
if not CodeToolBoss.SetApplicationScaledStatement(AProject.MainUnitInfo.Source, ProjScaled) then
NewScaled:=AProject.Scaled;
if (OldScaled <> NewScaled) and NewScaled then
if not CodeToolBoss.SetApplicationScaledStatement(AProject.MainUnitInfo.Source, NewScaled) then
begin begin
IDEMessageDialog(lisProjOptsError, IDEMessageDialog(lisProjOptsError,
Format(lisUnableToChangeProjectScaledInSource, [LineEnding, CodeToolBoss.ErrorMessage]), Format(lisUnableToChangeProjectScaledInSource, [LineEnding, CodeToolBoss.ErrorMessage]),
mtWarning, [mbOk]); mtWarning, [mbOk]);
Result := False; Result := False;
end;
end
else begin // Remove Scaled statement if it is there.
if ScaledStat <> ProjScaled then
Exit; Exit;
end;// set Application.Scaled:= statement //DebugLn(['ProjectOptionsAfterWrite: Removing Scaled']);
if OldScaled and not NewScaled then
if not CodeToolBoss.RemoveApplicationScaledStatement(AProject.MainUnitInfo.Source) then if not CodeToolBoss.RemoveApplicationScaledStatement(AProject.MainUnitInfo.Source) then
begin begin
IDEMessageDialog(lisProjOptsError, IDEMessageDialog(lisProjOptsError,
Format(lisUnableToRemoveProjectScaledFromSource, [LineEnding, CodeToolBoss.ErrorMessage]), Format(lisUnableToRemoveProjectScaledFromSource, [LineEnding, CodeToolBoss.ErrorMessage]),
mtWarning, [mbOk]); mtWarning, [mbOk]);
Result := False; Result := False;
Exit; end;
end;// delete Scaled end;
end; end;
function SetAutoCreateForms: boolean; function SetAutoCreateForms: boolean;
@ -5024,8 +5013,7 @@ var
OldList: TStrings; OldList: TStrings;
begin begin
Result := True; Result := True;
if (AProject.MainUnitID < 0) or if not (pfMainUnitHasCreateFormStatements in AProject.Flags) then
(not (pfMainUnitHasCreateFormStatements in AProject.Flags)) then
Exit; Exit;
OldList := AProject.GetAutoCreatedFormsList; OldList := AProject.GetAutoCreatedFormsList;
if (OldList = nil) then if (OldList = nil) then
@ -5056,23 +5044,26 @@ var
end; end;
end; end;
var
aFilename: String;
begin begin
//debugln(['TMainIDE.DoProjectOptionsAfterWrite ',DbgSName(Sender),' Restore=',Restore]); //debugln(['TMainIDE.DoProjectOptionsAfterWrite ',DbgSName(Sender),' Restore=',Restore]);
if not (Sender is TProjectIDEOptions) then exit; if not (Sender is TProjectIDEOptions) then exit;
AProject:=TProjectIDEOptions(Sender).Project; AProject:=TProjectIDEOptions(Sender).Project;
Assert(Assigned(AProject), 'TMainIDE.ProjectOptionsAfterWrite: Project=Nil.');
if Restore then if Restore then
begin begin
AProject.RestoreBuildModes; AProject.RestoreBuildModes;
AProject.RestoreSession; AProject.RestoreSession;
end end
else begin else begin
if AProject.MainUnitID >= 0 then
begin
SetTitle; SetTitle;
SetScaled; SetScaled;
SetAutoCreateForms; SetAutoCreateForms;
// extend include path AProject.AutoAddOutputDirToIncPath; // extend include path
AProject.AutoAddOutputDirToIncPath; if AProject.ProjResources.Modified then
if AProject.ProjResources.Modified and (AProject.MainUnitID >= 0) then
begin
if not AProject.ProjResources.Regenerate(AProject.MainFilename, True, False, '') then if not AProject.ProjResources.Regenerate(AProject.MainFilename, True, False, '') then
IDEMessageDialog(lisCCOWarningCaption, AProject.ProjResources.Messages.Text, IDEMessageDialog(lisCCOWarningCaption, AProject.ProjResources.Messages.Text,
mtWarning, [mbOk]); mtWarning, [mbOk]);