mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 13:59:31 +02:00
IDE+codetools: renaming a component now renames in the whole unit
git-svn-id: trunk@10160 -
This commit is contained in:
parent
ba83e8416b
commit
567453b914
@ -356,6 +356,8 @@ type
|
||||
var ListOfPCodeXYPosition: TFPList): boolean;
|
||||
function RenameIdentifier(TreeOfPCodeXYPosition: TAVLTree;
|
||||
const OldIdentifier, NewIdentifier: string): boolean;
|
||||
function ReplaceWord(Code: TCodeBuffer; const OldWord, NewWord: string
|
||||
): boolean;
|
||||
|
||||
// resourcestring sections
|
||||
function GatherResourceStringSections(
|
||||
@ -1945,6 +1947,24 @@ begin
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
function TCodeToolManager.ReplaceWord(Code: TCodeBuffer; const OldWord,
|
||||
NewWord: string): boolean;
|
||||
var
|
||||
CursorPos, SectionPos, NearestPos: TCodeXYPosition;
|
||||
begin
|
||||
Result:=false;
|
||||
{$IFDEF CTDEBUG}
|
||||
DebugLn('TCodeToolManager.ReplaceWord A ',Code.Filename,' OldWord="',OldWord,'" NewWord="',NewWord,'"');
|
||||
{$ENDIF}
|
||||
if not InitCurCodeTool(Code) then exit;
|
||||
try
|
||||
Result:=FCurCodeTool.ReplaceWord(OldWord, NewWord,
|
||||
SourceChangeCache);
|
||||
except
|
||||
on e: Exception do HandleException(e);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TCodeToolManager.GatherResourceStringSections(Code: TCodeBuffer;
|
||||
X, Y: integer; CodePositions: TCodeXYPositions): boolean;
|
||||
var
|
||||
|
@ -9,25 +9,6 @@
|
||||
<IconPath Value="./"/>
|
||||
<TargetFileExt Value=""/>
|
||||
</General>
|
||||
<VersionInfo>
|
||||
<UseVersionInfo Value="False"/>
|
||||
<AutoIncrementBuild Value="False"/>
|
||||
<CurrentVersionNr Value="0"/>
|
||||
<CurrentMajorRevNr Value="0"/>
|
||||
<CurrentMinorRevNr Value="0"/>
|
||||
<CurrentBuildNr Value="0"/>
|
||||
<ProjectVersion Value="1.0.0.0"/>
|
||||
<Language Value="0409"/>
|
||||
<CharSet Value="04E4"/>
|
||||
<Comments Value=""/>
|
||||
<CompanyName Value=""/>
|
||||
<FileDescription Value=""/>
|
||||
<InternalName Value=""/>
|
||||
<LegalCopyright Value=""/>
|
||||
<LegalTrademarks Value=""/>
|
||||
<OriginalFilename Value=""/>
|
||||
<ProductName Value=""/>
|
||||
</VersionInfo>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
|
@ -50,7 +50,7 @@ uses
|
||||
MemCheck,
|
||||
{$ENDIF}
|
||||
Classes, SysUtils, CodeToolsStrConsts, CodeToolMemManager, FileProcs,
|
||||
ExprEval, SourceLog, KeywordFuncLists, BasicCodeTools;
|
||||
AVL_Tree, ExprEval, SourceLog, KeywordFuncLists, BasicCodeTools;
|
||||
|
||||
const
|
||||
PascalCompilerDefine = ExternalMacroStart+'Compiler';
|
||||
@ -305,7 +305,7 @@ type
|
||||
|
||||
// links
|
||||
property Links[Index: integer]: TSourceLink read GetLinks write SetLinks;
|
||||
function LinkCount: integer;
|
||||
property LinkCount: integer read FLinkCount;
|
||||
function LinkIndexAtCleanPos(ACleanPos: integer): integer;
|
||||
function LinkIndexAtCursorPos(ACursorPos: integer; ACode: Pointer): integer;
|
||||
function LinkSize(Index: integer): integer;
|
||||
@ -314,6 +314,7 @@ type
|
||||
function FindParentLink(LinkIndex: integer): integer;
|
||||
function LinkIndexNearCursorPos(ACursorPos: integer; ACode: Pointer;
|
||||
var CursorInLink: boolean): integer;
|
||||
function CreateTreeOfSourceCodes: TAVLTree;
|
||||
|
||||
// source mapping (Cleaned <-> Original)
|
||||
function CleanedSrc: string;
|
||||
@ -760,6 +761,19 @@ begin
|
||||
Result:=BestLinkIndex;
|
||||
end;
|
||||
|
||||
function TLinkScanner.CreateTreeOfSourceCodes: TAVLTree;
|
||||
var
|
||||
CurCode: Pointer;
|
||||
i: Integer;
|
||||
begin
|
||||
Result:=TAVLTree.Create(@ComparePointers);
|
||||
for i:=0 to LinkCount-1 do begin
|
||||
CurCode:=FLinks[i].Code;
|
||||
if Result.Find(CurCode)=nil then
|
||||
Result.Add(CurCode);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TLinkScanner.LinkIndexAtCleanPos(ACleanPos: integer): integer;
|
||||
|
||||
procedure ConsistencyError1;
|
||||
@ -873,11 +887,6 @@ begin
|
||||
else inc(FChangeStep);
|
||||
end;
|
||||
|
||||
function TLinkScanner.LinkCount: integer;
|
||||
begin
|
||||
Result:=FLinkCount;
|
||||
end;
|
||||
|
||||
function TLinkScanner.ReturnFromIncludeFileAndIsEnd: boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
|
@ -194,7 +194,7 @@ type
|
||||
public
|
||||
BeautifyCodeOptions: TBeautifyCodeOptions;
|
||||
procedure BeginUpdate;
|
||||
procedure EndUpdate;
|
||||
function EndUpdate: boolean;
|
||||
property MainScanner: TLinkScanner read FMainScanner write SetMainScanner;
|
||||
property MainScannerNeeded: boolean read FMainScannerNeeded;
|
||||
function Replace(FrontGap, AfterGap: TGapTyp; FromPos, ToPos: integer;
|
||||
@ -861,12 +861,13 @@ begin
|
||||
inc(FUpdateLock);
|
||||
end;
|
||||
|
||||
procedure TSourceChangeCache.EndUpdate;
|
||||
function TSourceChangeCache.EndUpdate: boolean;
|
||||
begin
|
||||
Result:=true;
|
||||
if FUpdateLock<=0 then exit;
|
||||
dec(FUpdateLock);
|
||||
if FUpdateLock<=0 then
|
||||
Apply;
|
||||
Result:=Apply;
|
||||
end;
|
||||
|
||||
procedure TSourceChangeCache.SetMainScanner(NewScanner: TLinkScanner);
|
||||
|
@ -222,10 +222,12 @@ type
|
||||
var MissingIncludeFilesCodeXYPos: TFPList): boolean;
|
||||
|
||||
// search & replace
|
||||
function ReplaceIdentifiers(IdentList: TStrings;
|
||||
function ReplaceWords(IdentList: TStrings;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
function FindNearestIdentifierNode(const CursorPos: TCodeXYPosition;
|
||||
IdentTree: TAVLTree): TAVLTreeNode;
|
||||
function ReplaceWord(const OldWord, NewWord: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
// expressions
|
||||
function GetStringConstBounds(const CursorPos: TCodeXYPosition;
|
||||
@ -2436,7 +2438,7 @@ begin
|
||||
IdentList.Add(OldFormClassName);
|
||||
IdentList.Add(NewFormClassName);
|
||||
end;
|
||||
Result:=ReplaceIdentifiers(IdentList,SourceChangeCache);
|
||||
Result:=ReplaceWords(IdentList,SourceChangeCache);
|
||||
finally
|
||||
IdentList.Free;
|
||||
end;
|
||||
@ -2469,17 +2471,17 @@ begin
|
||||
end;
|
||||
|
||||
{-------------------------------------------------------------------------------
|
||||
function TStandardCodeTool.ReplaceIdentifiers(IdentList: TStrings;
|
||||
function TStandardCodeTool.ReplaceWords(IdentList: TStrings;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
Search in all used sources (not the cleaned source) for identifiers.
|
||||
Search in all used sources (not only 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;
|
||||
function TStandardCodeTool.ReplaceWords(IdentList: TStrings;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
|
||||
procedure ReplaceIdentifiersInSource(ACode: TCodeBuffer);
|
||||
procedure ReplaceWordsInSource(ACode: TCodeBuffer);
|
||||
var
|
||||
StartPos, EndPos, MaxPos, IdentStart, IdentEnd: integer;
|
||||
CurSource: string;
|
||||
@ -2489,7 +2491,7 @@ function TStandardCodeTool.ReplaceIdentifiers(IdentList: TStrings;
|
||||
MaxPos:=length(CurSource);
|
||||
StartPos:=1;
|
||||
// go through all source parts between compiler directives
|
||||
DebugLn('TStandardCodeTool.ReplaceIdentifiers ',ACode.Filename);
|
||||
DebugLn('TStandardCodeTool.ReplaceWords ',ACode.Filename);
|
||||
repeat
|
||||
EndPos:=FindNextCompilerDirective(CurSource,StartPos,
|
||||
Scanner.NestedComments);
|
||||
@ -2507,7 +2509,7 @@ function TStandardCodeTool.ReplaceIdentifiers(IdentList: TStrings;
|
||||
begin
|
||||
// identifier found -> replace
|
||||
IdentEnd:=IdentStart+length(IdentList[i]);
|
||||
//DebugLn('TStandardCodeTool.ReplaceIdentifiers replacing: ',
|
||||
//DebugLn('TStandardCodeTool.ReplaceWords replacing: ',
|
||||
//' "',copy(CurSource,IdentStart,IdentEnd-IdentStart),'" -> "',IdentList[i+1],'" at ',IdentStart
|
||||
//);
|
||||
SourceChangeCache.ReplaceEx(gtNone,gtNone,1,1,
|
||||
@ -2548,7 +2550,7 @@ begin
|
||||
try
|
||||
Scanner.FindCodeInRange(1,SrcLen,SourceList);
|
||||
for i:=0 to SourceList.Count-1 do begin
|
||||
ReplaceIdentifiersInSource(TCodeBuffer(SourceList[i]));
|
||||
ReplaceWordsInSource(TCodeBuffer(SourceList[i]));
|
||||
end;
|
||||
finally
|
||||
SourceList.Free;
|
||||
@ -2588,6 +2590,25 @@ begin
|
||||
until CurPos.EndPos>SrcLen;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.ReplaceWord(const OldWord, NewWord: string;
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
var
|
||||
IdentList: TStringList;
|
||||
begin
|
||||
Result:=false;
|
||||
if OldWord='' then exit;
|
||||
if OldWord=NewWord then exit(true);
|
||||
if (SourceChangeCache=nil) then exit;
|
||||
IdentList:=TStringList.Create;
|
||||
try
|
||||
IdentList.Add(OldWord);
|
||||
IdentList.Add(NewWord);
|
||||
Result:=ReplaceWords(IdentList,SourceChangeCache);
|
||||
finally
|
||||
IdentList.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TStandardCodeTool.GetStringConstBounds(
|
||||
const CursorPos: TCodeXYPosition;
|
||||
var StartPos, EndPos: TCodeXYPosition; ResolveComments: boolean): boolean;
|
||||
@ -3991,8 +4012,10 @@ function TStandardCodeTool.RenamePublishedVariable(const UpperClassName,
|
||||
SourceChangeCache: TSourceChangeCache): boolean;
|
||||
var
|
||||
TypeNode, VarNode: TCodeTreeNode;
|
||||
ApplyNeeded: Boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
BuildTree(false);
|
||||
VarNode:=FindPublishedVariable(UpperClassName,UpperOldVarName,
|
||||
ExceptionOnClassNotFound);
|
||||
if VarNode<>nil then begin
|
||||
@ -4001,24 +4024,20 @@ begin
|
||||
TypeNode:=FindTypeNodeOfDefinition(VarNode);
|
||||
MoveCursorToNodeStart(TypeNode);
|
||||
ReadNextAtom;
|
||||
if UpAtomIs(UpperCaseStr(VarType)) then begin
|
||||
// rename the identifier
|
||||
MoveCursorToNodeStart(VarNode);
|
||||
ReadNextAtom;
|
||||
SourceChangeCache.MainScanner:=Scanner;
|
||||
SourceChangeCache.MainScanner:=Scanner;
|
||||
ApplyNeeded:=false;
|
||||
if (not AtomIs(VarType)) then begin
|
||||
// change the type
|
||||
ApplyNeeded:=true;
|
||||
if not SourceChangeCache.Replace(gtNone,gtNone,
|
||||
CurPos.StartPos,CurPos.EndPos,NewVarName)
|
||||
then begin
|
||||
RaiseException('Unable to replace name');
|
||||
RaiseException('Unable to replace type');
|
||||
end;
|
||||
end else begin
|
||||
// auto correct type
|
||||
|
||||
// ToDo: auto correct
|
||||
RaiseExceptionFmt(ctsStrExpectedButAtomFound,[VarType,GetAtom]);
|
||||
|
||||
end;
|
||||
Result:=SourceChangeCache.Apply;
|
||||
// rename variable in source
|
||||
if not ReplaceWord(UpperOldVarName,NewVarName,SourceChangeCache) then exit;
|
||||
Result:=(not ApplyNeeded) or SourceChangeCache.Apply;
|
||||
end else begin
|
||||
// old variable not found -> add it
|
||||
Result:=AddPublishedVariable(UpperClassName,NewVarName,VarType,
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# Don't edit, this file is generated by FPCMake Version 2.0.0 [2006/10/11]
|
||||
# Don't edit, this file is generated by FPCMake Version 2.0.0 [2006/09/20]
|
||||
#
|
||||
default: all
|
||||
MAKEFILETARGETS=i386-linux i386-go32v2 i386-win32 i386-os2 i386-freebsd i386-beos i386-netbsd i386-solaris i386-qnx i386-netware i386-openbsd i386-wdosx i386-darwin i386-emx i386-watcom i386-netwlibc i386-wince m68k-linux m68k-freebsd m68k-netbsd m68k-amiga m68k-atari m68k-openbsd m68k-palmos powerpc-linux powerpc-netbsd powerpc-amiga powerpc-macos powerpc-darwin powerpc-morphos sparc-linux sparc-netbsd sparc-solaris x86_64-linux x86_64-freebsd x86_64-win64 arm-linux arm-palmos arm-wince arm-gba powerpc64-linux
|
||||
@ -235,9 +235,13 @@ ifndef LCL_PLATFORM
|
||||
ifeq ($(OS_TARGET),win32)
|
||||
LCL_PLATFORM=win32
|
||||
else
|
||||
ifeq ($(OS_TARGET),win64)
|
||||
LCL_PLATFORM=win32
|
||||
else
|
||||
LCL_PLATFORM=gtk
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
export LCL_PLATFORM
|
||||
ifeq ($(FULL_TARGET),i386-linux)
|
||||
override TARGET_UNITS+=runtimetypeinfocontrols.pas
|
||||
@ -1798,7 +1802,7 @@ ifeq ($(CPU_TARGET),powerpc)
|
||||
FPCCPUOPT:=-O1r
|
||||
endif
|
||||
else
|
||||
FPCCPUOPT:=-O2
|
||||
FPCCPUOPT:=-O1r
|
||||
endif
|
||||
override FPCOPT+=-Ur -Xs $(FPCCPUOPT) -n
|
||||
override FPCOPTDEF+=RELEASE
|
||||
|
@ -24,9 +24,13 @@ ifndef LCL_PLATFORM
|
||||
ifeq ($(OS_TARGET),win32)
|
||||
LCL_PLATFORM=win32
|
||||
else
|
||||
ifeq ($(OS_TARGET),win64)
|
||||
LCL_PLATFORM=win32
|
||||
else
|
||||
LCL_PLATFORM=gtk
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
export LCL_PLATFORM
|
||||
|
||||
[rules]
|
||||
|
@ -5043,10 +5043,10 @@ Begin
|
||||
CheckFont;
|
||||
end;
|
||||
|
||||
Procedure TSourceNotebook.CloseFile(PageIndex:integer);
|
||||
procedure TSourceNotebook.CloseFile(PageIndex:integer);
|
||||
var
|
||||
TempEditor: TSourceEditor;
|
||||
Begin
|
||||
begin
|
||||
{$IFDEF IDE_DEBUG}
|
||||
writeln('TSourceNotebook.CloseFile A PageIndex=',PageIndex);
|
||||
{$ENDIF}
|
||||
@ -5066,6 +5066,10 @@ Begin
|
||||
Notebook.Pages.Delete(PageIndex);
|
||||
//writeln('TSourceNotebook.CloseFile C PageIndex=',PageIndex,' Notebook.PageCount=',Notebook.PageCount);
|
||||
UpdateStatusBar;
|
||||
// set focus to new editor
|
||||
TempEditor:=FindSourceEditorWithPageIndex(Notebook.PageIndex);
|
||||
if TempEditor<>nil then
|
||||
ActiveControl:=TempEditor.EditorComponent;
|
||||
end else
|
||||
begin
|
||||
//writeln('TSourceNotebook.CloseFile D PageIndex=',PageIndex);
|
||||
|
@ -301,7 +301,6 @@ var
|
||||
Mess: TLMActivate;
|
||||
begin
|
||||
Result:= True;
|
||||
DebugLn(['gtkactivateCB ',DbgSName(TControl(Data))]);
|
||||
{$IFDEF EventTrace}
|
||||
EventTrace('activate', data);
|
||||
{$ENDIF}
|
||||
|
Loading…
Reference in New Issue
Block a user