MG: started form renaming

git-svn-id: trunk@2741 -
This commit is contained in:
lazarus 2002-08-18 08:53:21 +00:00
parent d500258da2
commit b598a3b831
9 changed files with 416 additions and 53 deletions

View File

@ -21,10 +21,9 @@
Author: Mattias Gaertner Author: Mattias Gaertner
Abstract: Abstract:
Basic pascal code functions. Most of the functions have counterparts in the Basic pascal code functions. Many of the functions have counterparts in the
code tools, which are faster, more flexible and aware of compiler settings code tools, which are faster, more flexible and aware of compiler settings
and directives. They are only used for code building. and directives.
} }
unit BasicCodeTools; unit BasicCodeTools;
@ -119,15 +118,30 @@ function ReadRawNextPascalAtom(const Source:string;
var Position,AtomStart:integer):string; var Position,AtomStart:integer):string;
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// comments
function FindCommentEnd(const ASource: string; StartPos: integer;
NestedComments: boolean): integer;
function FindNextCompilerDirective(const ASource: string; StartPos: integer;
NestedComments: boolean): integer;
// line ranges and indent
procedure GetLineStartEndAtPosition(const Source:string; Position:integer; procedure GetLineStartEndAtPosition(const Source:string; Position:integer;
var LineStart,LineEnd:integer); var LineStart,LineEnd:integer);
function GetLineIndent(const Source: string; Position: integer): integer;
function GetIndentStr(Indent: integer): string;
function LineEndCount(const Txt: string; var LengthOfLastLine:integer): integer;
// identifiers
procedure GetIdentStartEndAtPosition(const Source:string; Position:integer; procedure GetIdentStartEndAtPosition(const Source:string; Position:integer;
var IdentStart,IdentEnd:integer); var IdentStart,IdentEnd:integer);
function GetIdentLen(Identifier: PChar): integer; function GetIdentLen(Identifier: PChar): integer;
function LineEndCount(const Txt: string; var LengthOfLastLine:integer): integer; function GetIdentifier(Identifier: PChar): string;
function FindNextIdentifier(const Source: string; StartPos, MaxPos: integer
): integer;
// line/code ends
function FindFirstNonSpaceCharInLine(const Source: string; function FindFirstNonSpaceCharInLine(const Source: string;
Position: integer): integer; Position: integer): integer;
function GetLineIndent(const Source: string; Position: integer): integer;
function FindLineEndOrCodeInFrontOfPosition(const Source: string; function FindLineEndOrCodeInFrontOfPosition(const Source: string;
Position, MinPosition: integer; NestedComments: boolean): integer; Position, MinPosition: integer; NestedComments: boolean): integer;
function FindLineEndOrCodeAfterPosition(const Source: string; function FindLineEndOrCodeAfterPosition(const Source: string;
@ -136,6 +150,8 @@ function FindFirstLineEndInFrontOfInCode(const Source: string;
Position, MinPosition: integer; NestedComments: boolean): integer; Position, MinPosition: integer; NestedComments: boolean): integer;
function FindFirstLineEndAfterInCode(const Source: string; function FindFirstLineEndAfterInCode(const Source: string;
Position, MaxPosition: integer; NestedComments: boolean): integer; Position, MaxPosition: integer; NestedComments: boolean): integer;
// replacements
function ReplacementNeedsLineEnd(const Source: string; function ReplacementNeedsLineEnd(const Source: string;
FromPos, ToPos, NewLength, MaxLineLength: integer): boolean; FromPos, ToPos, NewLength, MaxLineLength: integer): boolean;
function CountNeededLineEndsToAddForward(const Src: string; function CountNeededLineEndsToAddForward(const Src: string;
@ -143,23 +159,22 @@ function CountNeededLineEndsToAddForward(const Src: string;
function CountNeededLineEndsToAddBackward(const Src: string; function CountNeededLineEndsToAddBackward(const Src: string;
StartPos, MinLineEnds: integer): integer; StartPos, MinLineEnds: integer): integer;
// comparison
function CompareTextIgnoringSpace(const Txt1, Txt2: string; function CompareTextIgnoringSpace(const Txt1, Txt2: string;
CaseSensitive: boolean): integer; CaseSensitive: boolean): integer;
function CompareSubStrings(const Find, Txt: string; function CompareSubStrings(const Find, Txt: string;
FindStartPos, TxtStartPos, Len: integer; CaseSensitive: boolean): integer; FindStartPos, TxtStartPos, Len: integer; CaseSensitive: boolean): integer;
function CompareIdentifiers(Identifier1, Identifier2: PChar): integer;
//
function CleanCodeFromComments(const DirtyCode: string; function CleanCodeFromComments(const DirtyCode: string;
NestedComments: boolean): string; NestedComments: boolean): string;
function CompareIdentifiers(Identifier1, Identifier2: PChar): integer;
function GetIdentifier(Identifier: PChar): string;
function TrimCodeSpace(const ACode: string): string; function TrimCodeSpace(const ACode: string): string;
function GetIndentStr(Indent: integer): string;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const const
MaxLineLength:integer=80; MaxLineLength: integer = 80;
const const
// ToDo: find the constant in the fpc units. // ToDo: find the constant in the fpc units.
@ -892,6 +907,123 @@ begin
until false; until false;
end; end;
function FindNextCompilerDirective(const ASource: string; StartPos: integer;
NestedComments: boolean): integer;
var
MaxPos: integer;
begin
MaxPos:=length(ASource);
Result:=StartPos;
while (Result<=MaxPos) do begin
case ASource[Result] of
'''':
begin
inc(Result);
while (Result<=MaxPos) do begin
if (ASource[Result]<>'''') then
inc(Result)
else begin
inc(Result);
break;
end;
end;
end;
'/':
begin
inc(Result);
if (Result<=MaxPos) and (ASource[Result]='/') then begin
// skip Delphi comment
while (Result<=MaxPos) and (not (ASource[Result] in [#10,#13])) do
inc(Result);
end;
end;
'{':
begin
if (Result<MaxPos) and (ASource[Result+1]='$') then
exit;
// skip pascal comment
Result:=FindCommentEnd(ASource,Result,NestedComments);
end;
'(':
begin
if (Result<MaxPos) and (ASource[Result+1]='*') then begin
if (Result+2<=MaxPos) and (ASource[Result+2]='$') then
exit;
// skip TP comment
Result:=FindCommentEnd(ASource,Result,NestedComments);
end else
inc(Result);
end;
else
inc(Result);
end;
end;
if Result>MaxPos+1 then Result:=MaxPos+1;
end;
function FindCommentEnd(const ASource: string; StartPos: integer;
NestedComments: boolean): integer;
var
MaxPos, CommentLvl: integer;
begin
MaxPos:=length(ASource);
Result:=StartPos;
if Result>MaxPos then exit;
case ASource[Result] of
'/':
begin
if (Result<MaxPos) and (ASource[Result+1]='/') then begin
// skip Delphi comment
while (Result<=MaxPos) and (not (ASource[Result] in [#10,#13])) do
inc(Result);
end;
end;
'{':
begin
CommentLvl:=1;
inc(Result);
while Result<=MaxPos do begin
case ASource[Result] of
'{':
if NestedComments then
inc(CommentLvl);
'}':
begin
dec(CommentLvl);
if CommentLvl=0 then begin
inc(Result);
break;
end;
end;
end;
inc(Result);
end;
end;
'(':
if (Result<MaxPos) and (ASource[Result+1]='*') then begin
inc(Result,2);
while (Result<=MaxPos) do begin
if (Result<MaxPos) and (ASource[Result]='*') and (ASource[Result+1]=')')
then begin
inc(Result,2);
break;
end;
inc(Result);
end;
end;
end;
end;
procedure GetLineStartEndAtPosition(const Source:string; Position:integer; procedure GetLineStartEndAtPosition(const Source:string; Position:integer;
var LineStart,LineEnd:integer); var LineStart,LineEnd:integer);
begin begin
@ -1759,6 +1891,14 @@ begin
Result:=''; Result:='';
end; end;
function FindNextIdentifier(const Source: string; StartPos, MaxPos: integer
): integer;
begin
Result:=StartPos;
while (Result<=MaxPos) and (not IsIDStartChar[Source[Result]]) do
inc(Result);
end;
function GetIndentStr(Indent: integer): string; function GetIndentStr(Indent: integer): string;
begin begin
SetLength(Result,Indent); SetLength(Result,Indent);

View File

@ -183,6 +183,9 @@ type
function FindEnclosingIncludeDirective(Code: TCodeBuffer; X,Y: integer; function FindEnclosingIncludeDirective(Code: TCodeBuffer; X,Y: integer;
var NewCode: TCodeBuffer; var NewCode: TCodeBuffer;
var NewX, NewY, NewTopLine: integer): boolean; var NewX, NewY, NewTopLine: integer): boolean;
// keywords
function IsKeyword(Code: TCodeBuffer; const KeyWord: string): boolean;
// blocks (e.g. begin..end, case..end, try..finally..end, repeat..until) // blocks (e.g. begin..end, case..end, try..finally..end, repeat..until)
function FindBlockCounterPart(Code: TCodeBuffer; X,Y: integer; function FindBlockCounterPart(Code: TCodeBuffer; X,Y: integer;
@ -204,7 +207,7 @@ type
function FindDeclaration(Code: TCodeBuffer; X,Y: integer; function FindDeclaration(Code: TCodeBuffer; X,Y: integer;
var NewCode: TCodeBuffer; var NewCode: TCodeBuffer;
var NewX, NewY, NewTopLine: integer): boolean; var NewX, NewY, NewTopLine: integer): boolean;
// functions for events in the object inspector // functions for events in the object inspector
function GetCompatiblePublishedMethods(Code: TCodeBuffer; function GetCompatiblePublishedMethods(Code: TCodeBuffer;
const AClassName: string; TypeData: PTypeData; const AClassName: string; TypeData: PTypeData;
@ -272,6 +275,11 @@ type
function SetAllCreateFromStatements(Code: TCodeBuffer; function SetAllCreateFromStatements(Code: TCodeBuffer;
List: TStrings): boolean; List: TStrings): boolean;
// forms
function RenameForm(Code: TCodeBuffer;
const OldFormName, OldFormClassName: string;
const NewFormName, NewFormClassName: string): boolean;
// form components // form components
function PublishedVariableExists(Code: TCodeBuffer; function PublishedVariableExists(Code: TCodeBuffer;
const AClassName, AVarName: string): boolean; const AClassName, AVarName: string): boolean;
@ -282,6 +290,7 @@ type
function RenamePublishedVariable(Code: TCodeBuffer; function RenamePublishedVariable(Code: TCodeBuffer;
const AClassName, OldVariableName, NewVarName, const AClassName, OldVariableName, NewVarName,
VarType: shortstring): boolean; VarType: shortstring): boolean;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -297,7 +306,6 @@ type
var CodeToolBoss: TCodeToolManager; var CodeToolBoss: TCodeToolManager;
implementation implementation
@ -721,6 +729,21 @@ begin
end; end;
end; end;
function TCodeToolManager.IsKeyword(Code: TCodeBuffer; const KeyWord: string
): boolean;
begin
Result:=false;
{$IFDEF CTDEBUG}
writeln('TCodeToolManager.IsKeyword A ',Code.Filename,' Keyword=',KeyWord);
{$ENDIF}
if not InitCurCodeTool(Code) then exit;
try
Result:=FCurCodeTool.StringIsKeyWord(KeyWord);
except
on e: Exception do Result:=HandleException(e);
end;
end;
function TCodeToolManager.FindBlockCounterPart(Code: TCodeBuffer; function TCodeToolManager.FindBlockCounterPart(Code: TCodeBuffer;
X, Y: integer; var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer X, Y: integer; var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer
): boolean; ): boolean;
@ -1327,6 +1350,25 @@ begin
end; end;
end; end;
function TCodeToolManager.RenameForm(Code: TCodeBuffer; const OldFormName,
OldFormClassName: string; const NewFormName, NewFormClassName: string
): boolean;
begin
Result:=false;
{$IFDEF CTDEBUG}
writeln('TCodeToolManager.RenameForm A ',Code.Filename,
' OldFormName=',OldFormName,' OldFormClassName=',OldFormClassName,
' NewFormName=',NewFormName,' NewFormClassName=',NewFormClassName);
{$ENDIF}
if not InitCurCodeTool(Code) then exit;
try
Result:=FCurCodeTool.RenameForm(OldFormName,OldFormClassName,
NewFormName,NewFormClassName,SourceChangeCache);
except
on e: Exception do Result:=HandleException(e);
end;
end;
function TCodeToolManager.PublishedVariableExists(Code: TCodeBuffer; function TCodeToolManager.PublishedVariableExists(Code: TCodeBuffer;
const AClassName, AVarName: string): boolean; const AClassName, AVarName: string): boolean;
begin begin

View File

@ -123,6 +123,8 @@ type
procedure BeginParsingAndGetCleanPos(DeleteNodes, procedure BeginParsingAndGetCleanPos(DeleteNodes,
OnlyInterfaceNeeded: boolean; CursorPos: TCodeXYPosition; OnlyInterfaceNeeded: boolean; CursorPos: TCodeXYPosition;
var CleanCursorPos: integer); var CleanCursorPos: integer);
function StringIsKeyWord(const Word: string): boolean;
procedure MoveCursorToNodeStart(ANode: TCodeTreeNode); procedure MoveCursorToNodeStart(ANode: TCodeTreeNode);
procedure MoveCursorToCleanPos(ACleanPos: integer); procedure MoveCursorToCleanPos(ACleanPos: integer);
@ -1352,6 +1354,12 @@ begin
RaiseException(ctsCursorPosOutsideOfCode); RaiseException(ctsCursorPosOutsideOfCode);
end; end;
function TCustomCodeTool.StringIsKeyWord(const Word: string): boolean;
begin
Result:=(Word<>'') and IsIdentStartChar[Word[1]]
and WordIsKeyWord.DoItUpperCase(Word,1,length(Word));
end;
procedure TCustomCodeTool.MoveCursorToNodeStart(ANode: TCodeTreeNode); procedure TCustomCodeTool.MoveCursorToNodeStart(ANode: TCodeTreeNode);
begin begin
MoveCursorToCleanPos(ANode.StartPos); MoveCursorToCleanPos(ANode.StartPos);

View File

@ -2298,8 +2298,9 @@ var
UnitLinkListValid:=true; UnitLinkListValid:=true;
end; end;
// function TDefinePool.CreateFPCSrcTemplate( // function CreateFPCSrcTemplate(const FPCSrcDir,
// const FPCSrcDir: string): TDefineTemplate; // UnitSearchPath: string;
// UnitLinkListValid: boolean; var UnitLinkList: string): TDefineTemplate;
var var
DefTempl, MainDir, FCLDir, RTLDir, PackagesDir, CompilerDir: TDefineTemplate; DefTempl, MainDir, FCLDir, RTLDir, PackagesDir, CompilerDir: TDefineTemplate;
s: string; s: string;
@ -2362,10 +2363,11 @@ begin
da_Directory); da_Directory);
MainDir.AddChild(FCLDir); MainDir.AddChild(FCLDir);
FCLDir.AddChild(TDefineTemplate.Create('Include Path', FCLDir.AddChild(TDefineTemplate.Create('Include Path',
Format(ctsIncludeDirectoriesPlusDirs,['inc']), Format(ctsIncludeDirectoriesPlusDirs,['inc,'+SrcOS]),
ExternalMacroStart+'IncPath', ExternalMacroStart+'IncPath',
IncPathMacro IncPathMacro
+';'+Dir+'fcl/inc/' +';'+Dir+'fcl'+DS+'inc'+DS
+';'+Dir+'fcl'+DS+SrcOS+DS
,da_DefineRecurse)); ,da_DefineRecurse));
// packages // packages

View File

@ -252,8 +252,7 @@ type
function LinkCleanedEndPos(Index: integer): integer; function LinkCleanedEndPos(Index: integer): integer;
function FindFirstSiblingLink(LinkIndex: integer): integer; function FindFirstSiblingLink(LinkIndex: integer): integer;
function FindParentLink(LinkIndex: integer): integer; function FindParentLink(LinkIndex: integer): integer;
//function FindFirstLinkIndexOfCodeInCleanPos
function CleanedSrc: string; function CleanedSrc: string;
function CursorToCleanPos(ACursorPos: integer; ACode: pointer; function CursorToCleanPos(ACursorPos: integer; ACode: pointer;
var ACleanPos: integer): integer; // 0=valid CleanPos var ACleanPos: integer): integer; // 0=valid CleanPos
@ -395,11 +394,57 @@ var
PSourceChangeStepMemManager: TPSourceChangeStepMemManager; PSourceChangeStepMemManager: TPSourceChangeStepMemManager;
procedure AddCodeToUniqueList(ACode: Pointer; UniqueSortedCodeList: TList);
function IndexOfCodeInUniqueList(ACode: Pointer;
UniqueSortedCodeList: TList): integer;
implementation implementation
// useful procs ---------------------------------------------------------------- // useful procs ----------------------------------------------------------------
function IndexOfCodeInUniqueList(ACode: Pointer;
UniqueSortedCodeList: TList): integer;
var l,m,r: integer;
begin
l:=0;
r:=UniqueSortedCodeList.Count-1;
m:=0;
while r>=l do begin
m:=(l+r) shr 1;
if UniqueSortedCodeList[m]<ACode then
r:=m-1
else if UniqueSortedCodeList[m]>ACode then
l:=m+1
else begin
Result:=m;
exit;
end;
end;
Result:=-1;
end;
procedure AddCodeToUniqueList(ACode: Pointer; UniqueSortedCodeList: TList);
var l,m,r: integer;
begin
l:=0;
r:=UniqueSortedCodeList.Count-1;
m:=0;
while r>=l do begin
m:=(l+r) shr 1;
if UniqueSortedCodeList[m]<ACode then
r:=m-1
else if UniqueSortedCodeList[m]>ACode then
l:=m+1
else
exit;
end;
if (m<UniqueSortedCodeList.Count) and (UniqueSortedCodeList[m]<ACode) then
inc(m);
UniqueSortedCodeList.Insert(m,ACode);
end;
function CompareUpToken(const UpToken: shortstring; const Txt: string; function CompareUpToken(const UpToken: shortstring; const Txt: string;
TxtStartPos, TxtEndPos: integer): boolean; TxtStartPos, TxtEndPos: integer): boolean;
var len, i: integer; var len, i: integer;
@ -2355,27 +2400,6 @@ end;
procedure TLinkScanner.FindCodeInRange(CleanStartPos, CleanEndPos: integer; procedure TLinkScanner.FindCodeInRange(CleanStartPos, CleanEndPos: integer;
UniqueSortedCodeList: TList); UniqueSortedCodeList: TList);
procedure AddCodeToList(ACode: Pointer);
var l,m,r: integer;
begin
l:=0;
r:=UniqueSortedCodeList.Count-1;
m:=0;
while r>=l do begin
m:=(l+r) shr 1;
if UniqueSortedCodeList[m]<ACode then
r:=m-1
else if UniqueSortedCodeList[m]>ACode then
l:=m+1
else
exit;
end;
if (m<UniqueSortedCodeList.Count) and (UniqueSortedCodeList[m]<ACode) then
inc(m);
UniqueSortedCodeList.Insert(m,ACode);
end;
var ACode: Pointer; var ACode: Pointer;
LinkIndex: integer; LinkIndex: integer;
begin begin
@ -2384,14 +2408,14 @@ begin
LinkIndex:=LinkIndexAtCleanPos(CleanStartPos); LinkIndex:=LinkIndexAtCleanPos(CleanStartPos);
if LinkIndex<0 then exit; if LinkIndex<0 then exit;
ACode:=Links[LinkIndex].Code; ACode:=Links[LinkIndex].Code;
AddCodeToList(ACode); AddCodeToUniqueList(ACode,UniqueSortedCodeList);
repeat repeat
inc(LinkIndex); inc(LinkIndex);
if (LinkIndex>=LinkCount) or (Links[LinkIndex].CleanedPos>CleanEndPos) then if (LinkIndex>=LinkCount) or (Links[LinkIndex].CleanedPos>CleanEndPos) then
exit; exit;
if ACode<>Links[LinkIndex].Code then begin if ACode<>Links[LinkIndex].Code then begin
ACode:=Links[LinkIndex].Code; ACode:=Links[LinkIndex].Code;
AddCodeToList(ACode); AddCodeToUniqueList(ACode,UniqueSortedCodeList);
end; end;
until false; until false;
end; end;

View File

@ -360,7 +360,7 @@ begin
end; end;
// add entry // add entry
NewEntry:=TSourceChangeCacheEntry.Create(FrontGap,AfterGap,FromPos,ToPos, NewEntry:=TSourceChangeCacheEntry.Create(FrontGap,AfterGap,FromPos,ToPos,
Text,FromCode,FromDirectPos); Text,FromCode,FromDirectPos);
ANode:=FEntries.Add(NewEntry); ANode:=FEntries.Add(NewEntry);
if ToPos=FromPos then if ToPos=FromPos then
FEntries.MoveDataLeftMost(ANode) FEntries.MoveDataLeftMost(ANode)
@ -368,6 +368,7 @@ begin
// the new entry is a delete operation -> put it rightmost, so that it will // the new entry is a delete operation -> put it rightmost, so that it will
// be applied first // be applied first
FEntries.MoveDataRightMost(ANode); FEntries.MoveDataRightMost(ANode);
FBuffersToModifyNeedsUpdate:=true; FBuffersToModifyNeedsUpdate:=true;
Result:=true; Result:=true;
{$IFDEF CTDEBUG} {$IFDEF CTDEBUG}

View File

@ -29,9 +29,6 @@
- Application.CreateForm statements - Application.CreateForm statements
- published variables - published variables
ToDo:
-Insert class method body in pipClassOrder
} }
unit StdCodeTools; unit StdCodeTools;
@ -58,6 +55,10 @@ type
function ReadForwardTilAnyBracketClose: boolean; function ReadForwardTilAnyBracketClose: boolean;
function ReadBackwardTilAnyBracketClose: boolean; function ReadBackwardTilAnyBracketClose: boolean;
public public
// search & replace
function ReplaceIdentifiers(IdentList: TStrings;
SourceChangeCache: TSourceChangeCache): boolean;
// source name e.g. 'unit UnitName;' // source name e.g. 'unit UnitName;'
function GetSourceNamePos(var NamePos: TAtomPosition): boolean; function GetSourceNamePos(var NamePos: TAtomPosition): boolean;
function GetSourceName: string; function GetSourceName: string;
@ -115,6 +116,11 @@ type
function SetAllCreateFromStatements(List: TStrings; function SetAllCreateFromStatements(List: TStrings;
SourceChangeCache: TSourceChangeCache): boolean; SourceChangeCache: TSourceChangeCache): boolean;
// forms
function RenameForm(const OldFormName, OldFormClassName: string;
const NewFormName, NewFormClassName: string;
SourceChangeCache: TSourceChangeCache): boolean;
// form components // form components
function FindPublishedVariable(const UpperClassName, function FindPublishedVariable(const UpperClassName,
UpperVarName: string): TCodeTreeNode; UpperVarName: string): TCodeTreeNode;
@ -923,6 +929,106 @@ begin
Result:=SourceChangeCache.Apply; Result:=SourceChangeCache.Apply;
end; end;
function TStandardCodeTool.RenameForm(const OldFormName,
OldFormClassName: string; const NewFormName, NewFormClassName: string;
SourceChangeCache: TSourceChangeCache): boolean;
var
IdentList: TStringList;
begin
Result:=false;
if (OldFormName='') or (OldFormClassName='')
or (NewFormName='') or (NewFormClassName='')
or (SourceChangeCache=nil) then exit;
IdentList:=TStringList.Create;
try
IdentList.Add(OldFormName);
IdentList.Add(NewFormName);
IdentList.Add(OldFormClassName);
IdentList.Add(NewFormClassName);
Result:=ReplaceIdentifiers(IdentList,SourceChangeCache);
finally
IdentList.Free;
end;
end;
{-------------------------------------------------------------------------------
function TStandardCodeTool.ReplaceIdentifiers(IdentList: TStrings;
SourceChangeCache: TSourceChangeCache): boolean;
Search in all used sources (not the cleaned source) for identifiers.
It will find all identifiers, except identifiers in compiler directives.
This includes identifiers in string constants and comments.
-------------------------------------------------------------------------------}
function TStandardCodeTool.ReplaceIdentifiers(IdentList: TStrings;
SourceChangeCache: TSourceChangeCache): boolean;
procedure ReplaceIdentifiersInSource(Code: TCodeBuffer);
var
StartPos, EndPos, MaxPos, IdentStart: integer;
CurSource: string;
i: integer;
begin
CurSource:=Code.Source;
MaxPos:=length(CurSource);
StartPos:=1;
// go through all source parts between compiler directives
repeat
EndPos:=FindNextCompilerDirective(CurSource,StartPos,
Scanner.NestedComments);
if EndPos>MaxPos then EndPos:=MaxPos+1;
// search all identifiers
repeat
IdentStart:=FindNextIdentifier(CurSource,StartPos,EndPos-1);
if IdentStart<EndPos then begin
i:=0;
while i<IdentList.Count do begin
if BasicCodeTools.CompareIdentifiers(PChar(IdentList[i]),
@CurSource[IdentStart])=0 then
begin
// identifier found -> replace
break;
end;
inc(i,2);
end;
// skip identifier
StartPos:=IdentStart;
while (StartPos<MaxPos) and IsIdentChar[CurSource[StartPos]] do
inc(StartPos);
end else begin
break;
end;
until false;
if EndPos<=MaxPos then begin
// skip comment
StartPos:=FindCommentEnd(CurSource,EndPos,Scanner.NestedComments);
if StartPos>MaxPos then break;
end else begin
break;
end;
until false;
end;
var
SourceList: TList;
i: integer;
begin
Result:=false;
if (IdentList=nil) or (IdentList.Count=0) or (SourceChangeCache=nil)
or (Odd(IdentList.Count)) then exit;
BuildTree(false);
if Scanner=nil then exit;
SourceList:=TList.Create;
try
Scanner.FindCodeInRange(1,SrcLen,SourceList);
for i:=0 to SourceList.Count-1 do begin
ReplaceIdentifiersInSource(TCodeBuffer(SourceList[i]));
end;
finally
SourceList.Free;
end;
end;
function TStandardCodeTool.FindPublishedVariable(const UpperClassName, function TStandardCodeTool.FindPublishedVariable(const UpperClassName,
UpperVarName: string): TCodeTreeNode; UpperVarName: string): TCodeTreeNode;
var ClassNode, SectionNode: TCodeTreeNode; var ClassNode, SectionNode: TCodeTreeNode;

View File

@ -5507,7 +5507,7 @@ procedure TMainIDE.OnDesignerModified(Sender: TObject);
var i: integer; var i: integer;
SrcEdit: TSourceEditor; SrcEdit: TSourceEditor;
begin begin
i:=Project1.IndexOfUnitWithForm(TDesigner(Sender).Form,false); i:=Project1.IndexOfUnitWithForm(TDesigner(Sender).Form,false,nil);
if i>=0 then begin if i>=0 then begin
Project1.Units[i].Modified:=true; Project1.Units[i].Modified:=true;
if Project1.Units[i].Loaded then if Project1.Units[i].Loaded then
@ -6079,11 +6079,15 @@ procedure TMainIDE.OnDesignerRenameComponent(ADesigner: TDesigner;
var var
ActiveSrcEdit: TSourceEditor; ActiveSrcEdit: TSourceEditor;
ActiveUnitInfo: TUnitInfo; ActiveUnitInfo: TUnitInfo;
i: integer;
NewClassName: string;
begin begin
BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,false); BeginCodeTool(ActiveSrcEdit,ActiveUnitInfo,false);
ActiveUnitInfo:=Project1.UnitWithForm(ADesigner.Form);
if CodeToolBoss.IsKeyWord(ActiveUnitInfo.Source,NewName) then
raise Exception.Create('Component name "'+Newname+'" is keyword');
if AComponent.Owner<>nil then begin if AComponent.Owner<>nil then begin
// rename published variable in form source // rename published variable in form source
ActiveUnitInfo:=Project1.UnitWithForm(ADesigner.Form);
if CodeToolBoss.RenamePublishedVariable(ActiveUnitInfo.Source, if CodeToolBoss.RenamePublishedVariable(ActiveUnitInfo.Source,
ADesigner.Form.ClassName, ADesigner.Form.ClassName,
AComponent.Name,NewName,AComponent.ClassName) then AComponent.Name,NewName,AComponent.ClassName) then
@ -6096,11 +6100,33 @@ begin
+'See messages.'); +'See messages.');
end; end;
end else if AComponent=ADesigner.Form then begin end else if AComponent=ADesigner.Form then begin
// rename form
// ToDo: // ToDo:
// rename form in source // rename form in source
// rename form variable // rename formclass
// replace createform statement // replace createform statement
// delete old form resource in resource file
// check if formname already exists
i:=Project1.IndexOfUnitWithFormName(NewName,true,ActiveUnitInfo);
if i>=0 then
raise Exception.Create(
'There is already a form with the name "'+Newname+'"');
NewClassName:='T'+NewName;
// rename form in source
if CodeToolBoss.RenameForm(ActiveUnitInfo.Source,
AComponent.Name,AComponent.ClassName,
NewName,NewClassName) then
begin
ApplyCodeToolChanges;
end else begin
ApplyCodeToolChanges;
DoJumpToCodeToolBossError;
raise Exception.Create('Unable to rename form in source.'#13
+'See messages.');
end;
MessageDlg('Not implemented yet.', MessageDlg('Not implemented yet.',
'Form renaming in source is not implemented yet.', 'Form renaming in source is not implemented yet.',
mtInformation,[mbOk],0); mtInformation,[mbOk],0);
@ -6339,7 +6365,7 @@ procedure TMainIDE.DoSwitchToFormSrc(var ActiveSourceEditor: TSourceEditor;
var i: integer; var i: integer;
begin begin
if PropertyEditorHook1.LookupRoot<>nil then begin if PropertyEditorHook1.LookupRoot<>nil then begin
i:=Project1.IndexOfUnitWithForm(PropertyEditorHook1.LookupRoot,false); i:=Project1.IndexOfUnitWithForm(PropertyEditorHook1.LookupRoot,false,nil);
if (i>=0) then begin if (i>=0) then begin
i:=Project1.Units[i].EditorIndex; i:=Project1.Units[i].EditorIndex;
if (i>=0) then begin if (i>=0) then begin
@ -6603,6 +6629,9 @@ end.
{ ============================================================================= { =============================================================================
$Log$ $Log$
Revision 1.346 2002/08/23 07:05:14 lazarus
MG: started form renaming
Revision 1.345 2002/08/21 07:16:57 lazarus Revision 1.345 2002/08/21 07:16:57 lazarus
MG: reduced mem leak of clipping stuff, still not fixed MG: reduced mem leak of clipping stuff, still not fixed

View File

@ -60,10 +60,12 @@ type
fOptions: TOuputFilterOptions; fOptions: TOuputFilterOptions;
fProject: TProject; fProject: TProject;
fPrgSourceFilename: string; fPrgSourceFilename: string;
FStopExecute: boolean;
procedure DoAddFilteredLine(const s: string); procedure DoAddFilteredLine(const s: string);
procedure DoAddLastLinkerMessages; procedure DoAddLastLinkerMessages;
procedure DoAddLastAssemblerMessages; procedure DoAddLastAssemblerMessages;
function SearchIncludeFile(const ShortIncFilename: string): string; function SearchIncludeFile(const ShortIncFilename: string): string;
procedure SetStopExecute(const AValue: boolean);
public public
procedure Execute(TheProcess: TProcess); procedure Execute(TheProcess: TProcess);
function GetSourcePosition(const Line: string; var Filename:string; function GetSourcePosition(const Line: string; var Filename:string;
@ -79,6 +81,7 @@ type
function ReadMakeLine(const s: string): boolean; function ReadMakeLine(const s: string): boolean;
property CurrentDirectory: string read fCurrentDirectory; property CurrentDirectory: string read fCurrentDirectory;
property FilteredLines: TStringList read fFilteredOutput; property FilteredLines: TStringList read fFilteredOutput;
property StopExecute: boolean read FStopExecute write SetStopExecute;
property Lines: TStringList read fOutput; property Lines: TStringList read fOutput;
property LastErrorType: TErrorType read fLastErrorType; property LastErrorType: TErrorType read fLastErrorType;
property LastMessageType: TOutputMessageType read fLastMessageType; property LastMessageType: TOutputMessageType read fLastMessageType;
@ -130,6 +133,7 @@ begin
fFilteredOutput.Clear; fFilteredOutput.Clear;
if fCompilingHistory<>nil then fCompilingHistory.Clear; if fCompilingHistory<>nil then fCompilingHistory.Clear;
if fMakeDirHistory<>nil then fMakeDirHistory.Clear; if fMakeDirHistory<>nil then fMakeDirHistory.Clear;
FStopExecute:=false;
end; end;
procedure TOutputFilter.Execute(TheProcess: TProcess); procedure TOutputFilter.Execute(TheProcess: TProcess);
@ -148,11 +152,13 @@ begin
and (fCurrentDirectory[length(fCurrentDirectory)]<>PathDelim) then and (fCurrentDirectory[length(fCurrentDirectory)]<>PathDelim) then
fCurrentDirectory:=fCurrentDirectory+PathDelim; fCurrentDirectory:=fCurrentDirectory+PathDelim;
SetLength(Buf,BufSize); SetLength(Buf,BufSize);
Application.ProcessMessages;
OutputLine:=''; OutputLine:='';
ErrorExists:=false; ErrorExists:=false;
repeat repeat
Application.ProcessMessages;
if StopExecute then exit;
if TheProcess.Output<>nil then if TheProcess.Output<>nil then
Count:=TheProcess.Output.Read(Buf[1],length(Buf)) Count:=TheProcess.Output.Read(Buf[1],length(Buf))
else else
@ -542,6 +548,11 @@ begin
Result:=ShortIncFilename; Result:=ShortIncFilename;
end; end;
procedure TOutputFilter.SetStopExecute(const AValue: boolean);
begin
FStopExecute:=AValue;
end;
destructor TOutputFilter.Destroy; destructor TOutputFilter.Destroy;
begin begin
fFilteredOutput.Free; fFilteredOutput.Free;