mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-08 11:16:12 +02:00
Cleanups. Fixed source generation for autocreated forms from project options.
git-svn-id: trunk@3504 -
This commit is contained in:
parent
23a85fff62
commit
70db5f4b81
@ -39,7 +39,7 @@ unit SourceChanger;
|
||||
|
||||
interface
|
||||
|
||||
{ $DEFINE CTDEBUG}
|
||||
{$ DEFINE CTDEBUG}
|
||||
|
||||
uses
|
||||
Classes, SysUtils, CodeCache, BasicCodeTools, SourceLog, LinkScanner,
|
||||
|
@ -998,33 +998,37 @@ function TStandardCodeTool.SetAllCreateFromStatements(List: TStrings;
|
||||
}
|
||||
var Position, InsertPos, i, ColonPos, Indent: integer;
|
||||
StatementPos: TAtomPosition;
|
||||
var MainBeginNode: TCodeTreeNode;
|
||||
MainBeginNode: TCodeTreeNode;
|
||||
AClassName, AVarName: string;
|
||||
begin
|
||||
Result:=false;
|
||||
if (List=nil) or (SourceChangeCache=nil) then exit;
|
||||
Result:= false;
|
||||
if (List = nil) or (SourceChangeCache = nil) then exit;
|
||||
BuildTree(false);
|
||||
// first delete all CreateForm Statements
|
||||
SourceChangeCache.MainScanner:=Scanner;
|
||||
MainBeginNode:=FindMainBeginEndNode;
|
||||
if MainBeginNode=nil then exit;
|
||||
Position:=MainBeginNode.StartPos;
|
||||
InsertPos:=-1;
|
||||
|
||||
{ first delete all CreateForm Statements }
|
||||
SourceChangeCache.MainScanner:= Scanner;
|
||||
MainBeginNode:= FindMainBeginEndNode;
|
||||
if MainBeginNode = nil then exit;
|
||||
Position:= MainBeginNode.StartPos;
|
||||
InsertPos:= -1;
|
||||
repeat
|
||||
if FindCreateFormStatement(Position,'*','*',StatementPos)=-1 then
|
||||
break;
|
||||
Position:=StatementPos.EndPos;
|
||||
StatementPos.StartPos:=FindLineEndOrCodeInFrontOfPosition(
|
||||
StatementPos.StartPos);
|
||||
if InsertPos<1 then
|
||||
InsertPos:=StatementPos.StartPos;
|
||||
StatementPos.EndPos:=FindFirstLineEndAfterInCode(StatementPos.EndPos);
|
||||
SourceChangeCache.Replace(gtNone,gtNone,
|
||||
StatementPos.StartPos,StatementPos.EndPos,'');
|
||||
if FindCreateFormStatement(Position, '*', '*', StatementPos) = -1 then break;
|
||||
|
||||
Position:= StatementPos.EndPos;
|
||||
StatementPos.StartPos:= FindLineEndOrCodeInFrontOfPosition(StatementPos.StartPos);
|
||||
if InsertPos < 1 then InsertPos:= StatementPos.StartPos;
|
||||
|
||||
StatementPos.EndPos:= FindFirstLineEndAfterInCode(StatementPos.EndPos);
|
||||
|
||||
SourceChangeCache.Replace(gtNone,gtNone, StatementPos.StartPos, StatementPos.EndPos, '');
|
||||
until false;
|
||||
// then add all CreateForm Statements
|
||||
if InsertPos<1 then begin
|
||||
// there was no createform statement -> insert in front of Application.Run
|
||||
|
||||
Result:= SourceChangeCache.Apply;
|
||||
|
||||
{ then add all CreateForm Statements }
|
||||
if InsertPos < 1 then begin
|
||||
|
||||
{ there was no createform statement -> insert in front of Application.Run }
|
||||
MoveCursorToCleanPos(MainBeginNode.StartPos);
|
||||
repeat
|
||||
if ReadNextUpAtomIs('APPLICATION') then begin
|
||||
@ -1036,24 +1040,27 @@ begin
|
||||
InsertPos:=-1;
|
||||
end;
|
||||
until (CurPos.StartPos>SrcLen);
|
||||
if InsertPos<1 then exit;
|
||||
if InsertPos < 1 then exit;
|
||||
end;
|
||||
for i:=0 to List.Count-1 do begin
|
||||
ColonPos:=1;
|
||||
while (ColonPos<=length(List[i])) and (List[i][ColonPos]<>':') do
|
||||
inc(ColonPos);
|
||||
if (ColonPos>1) then begin
|
||||
AVarName:=copy(List[i],1,ColonPos);
|
||||
AClassName:=copy(List[i],ColonPos+1,length(List[i])-ColonPos);
|
||||
if AClassName='' then AClassName:='T'+AVarName;
|
||||
Indent:=GetLineIndent(Src,InsertPos);
|
||||
SourceChangeCache.Replace(gtNewLine,gtNewLine,InsertPos,InsertPos,
|
||||
SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
|
||||
'Application.CreateForm('+AClassName+','+AVarName+');',Indent)
|
||||
);
|
||||
end;
|
||||
|
||||
for i:= 0 to List.Count - 1 do begin
|
||||
if Length(List[i]) <= 1 then continue;
|
||||
|
||||
ColonPos:= Pos(List[i], ':');
|
||||
if (ColonPos > 1) then begin
|
||||
AVarName:= Copy(List[i], 1, ColonPos);
|
||||
AClassName:= Copy(List[i], ColonPos + 1, Length(List[i]) - ColonPos);
|
||||
end else begin
|
||||
AVarName:= List[i];
|
||||
AClassName:= 'T' + AVarName;
|
||||
end;
|
||||
Indent:= GetLineIndent(Src, InsertPos);
|
||||
|
||||
SourceChangeCache.Replace(gtNewLine, gtNewLine, InsertPos, InsertPos,
|
||||
SourceChangeCache.BeautifyCodeOptions.BeautifyStatement(
|
||||
'Application.CreateForm('+AClassName+','+AVarName+');', Indent));
|
||||
end;
|
||||
Result:=SourceChangeCache.Apply;
|
||||
Result:= Result and SourceChangeCache.Apply;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.RenameForm(const OldFormName,
|
||||
|
@ -800,33 +800,29 @@ end;
|
||||
|
||||
procedure TProjectOptionsDialog.SetAutoCreateForms;
|
||||
var i: integer;
|
||||
OldList, NewList: TStrings;
|
||||
OldList: TStrings;
|
||||
begin
|
||||
if (Project.MainUnit<0) or (Project.ProjectType in [ptCustomProgram]) then
|
||||
if (Project.MainUnit < 0) or (Project.ProjectType in [ptCustomProgram]) then
|
||||
exit;
|
||||
OldList:=GetAutoCreatedFormsList;
|
||||
if (OldList=nil) then exit;
|
||||
OldList:= GetAutoCreatedFormsList;
|
||||
if (OldList = nil) then exit;
|
||||
try
|
||||
if OldList.Count=FormsAutoCreatedListBox.Items.Count then begin
|
||||
i:=OldList.Count-1;
|
||||
while (i>=0)
|
||||
and (AnsiCompareText(OldList[i],FormsAutoCreatedListBox.Items[i])=0) do
|
||||
if OldList.Count = FormsAutoCreatedListBox.Items.Count then begin
|
||||
|
||||
{ Just exit if the form list is the same }
|
||||
i:= OldList.Count - 1;
|
||||
while (i >= 0)
|
||||
and (AnsiCompareText(OldList[i], FormsAutoCreatedListBox.Items[i])=0) do
|
||||
dec(i);
|
||||
if i<0 then begin
|
||||
// no change
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
NewList:=TStringList.Create;
|
||||
for i:=0 to FormsAutoCreatedListBox.Items.Count-1 do begin
|
||||
NewList.Add(FormsAutoCreatedListBox.Items[i]);
|
||||
if i < 0 then Exit;
|
||||
end;
|
||||
|
||||
if not CodeToolBoss.SetAllCreateFromStatements(
|
||||
Project.Units[Project.MainUnit].Source, NewList) then
|
||||
Project.Units[Project.MainUnit].Source, FormsAutoCreatedListBox.Items) then
|
||||
begin
|
||||
MessageDlg('Error',
|
||||
'Unable to change the auto create form list in the program source.'#13
|
||||
+'Plz fix errors first.',mtError,[mbCancel],0);
|
||||
'Unable to change the auto create form list in the program source.' + LineEnding +
|
||||
'Plz fix errors first.', mtError, [mbCancel], 0);
|
||||
end;
|
||||
finally
|
||||
OldList.Free;
|
||||
|
@ -330,7 +330,7 @@ type
|
||||
property AutoSize;
|
||||
property BorderStyle;
|
||||
property Caption;
|
||||
property Color;
|
||||
property Color default clBtnFace;
|
||||
property ClientHeight;
|
||||
property ClientWidth;
|
||||
property Constraints;
|
||||
|
@ -42,6 +42,7 @@ begin
|
||||
FAlignment := taCenter;
|
||||
Height := 41;
|
||||
Width := 185;
|
||||
Color:= clBackground;
|
||||
ParentColor := True;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user