From 70db5f4b81a34cfb09d22db6587d0608d4a07571 Mon Sep 17 00:00:00 2001 From: lazarus Date: Sun, 13 Oct 2002 21:36:42 +0000 Subject: [PATCH] Cleanups. Fixed source generation for autocreated forms from project options. git-svn-id: trunk@3504 - --- components/codetools/sourcechanger.pas | 2 +- components/codetools/stdcodetools.pas | 83 ++++++++++++++------------ ide/projectopts.pp | 34 +++++------ lcl/forms.pp | 2 +- lcl/include/custompanel.inc | 1 + 5 files changed, 63 insertions(+), 59 deletions(-) diff --git a/components/codetools/sourcechanger.pas b/components/codetools/sourcechanger.pas index 4dce6237c3..7b7a3cf552 100644 --- a/components/codetools/sourcechanger.pas +++ b/components/codetools/sourcechanger.pas @@ -39,7 +39,7 @@ unit SourceChanger; interface -{ $DEFINE CTDEBUG} +{$ DEFINE CTDEBUG} uses Classes, SysUtils, CodeCache, BasicCodeTools, SourceLog, LinkScanner, diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 96e9efab6d..4f9c9e1bde 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -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, diff --git a/ide/projectopts.pp b/ide/projectopts.pp index 588147e072..51cc0f8c78 100644 --- a/ide/projectopts.pp +++ b/ide/projectopts.pp @@ -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; diff --git a/lcl/forms.pp b/lcl/forms.pp index 53932e1392..a25db0a913 100644 --- a/lcl/forms.pp +++ b/lcl/forms.pp @@ -330,7 +330,7 @@ type property AutoSize; property BorderStyle; property Caption; - property Color; + property Color default clBtnFace; property ClientHeight; property ClientWidth; property Constraints; diff --git a/lcl/include/custompanel.inc b/lcl/include/custompanel.inc index 64f4fc2ce4..38961a1c60 100644 --- a/lcl/include/custompanel.inc +++ b/lcl/include/custompanel.inc @@ -42,6 +42,7 @@ begin FAlignment := taCenter; Height := 41; Width := 185; + Color:= clBackground; ParentColor := True; end;