mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-15 20:19:50 +02:00
ide: find/rename in lfm: skip searching declarations not possible in lfm
This commit is contained in:
parent
0f05729f28
commit
af90467660
@ -718,7 +718,8 @@ type
|
|||||||
// flags for FindReferences
|
// flags for FindReferences
|
||||||
TFindRefsFlag = (
|
TFindRefsFlag = (
|
||||||
frfMethodOverrides, // continue search on method overrides
|
frfMethodOverrides, // continue search on method overrides
|
||||||
frfIncludingLFM // find references in LFM files
|
frfIncludingLFM, // find references in LFM files
|
||||||
|
frfRename // for rename
|
||||||
);
|
);
|
||||||
TFindRefsFlags = set of TFindRefsFlag;
|
TFindRefsFlags = set of TFindRefsFlag;
|
||||||
|
|
||||||
|
@ -158,6 +158,7 @@ function GatherLFMsReferences(Files:TStringList;
|
|||||||
DeclNode: TCodeTreeNode;
|
DeclNode: TCodeTreeNode;
|
||||||
var ListOfReferences: TCodeXYPositions;
|
var ListOfReferences: TCodeXYPositions;
|
||||||
const Flags: TFindRefsFlags): TModalResult;
|
const Flags: TFindRefsFlags): TModalResult;
|
||||||
|
function DeclarationCanBeInLFM(DeclNode: TCodeTreeNode): boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -295,6 +296,26 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure CheckDeclOfDesigner(const Identifier: string; DeclTool: TCodeTool; DeclNode: TCodeTreeNode);
|
||||||
|
var
|
||||||
|
UnitInfo: TUnitInfo;
|
||||||
|
aComponent: TComponent;
|
||||||
|
begin
|
||||||
|
UnitInfo:=Project1.UnitInfoWithFilename(DeclTool.MainFilename);
|
||||||
|
if UnitInfo=nil then exit;
|
||||||
|
aComponent:=UnitInfo.Component;
|
||||||
|
if aComponent=nil then exit;
|
||||||
|
|
||||||
|
if DeclNode.Desc=ctnVarDefinition then begin
|
||||||
|
if (DeclNode.Parent.Desc in [ctnImplementation,ctnProgram])
|
||||||
|
and SameText(Identifier,aComponent.Name) then
|
||||||
|
begin
|
||||||
|
// renaming a designer root component
|
||||||
|
// todo
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function GatherLFMsReferences(Files: TStringList; const Identifier: string; DeclTool: TCodeTool;
|
function GatherLFMsReferences(Files: TStringList; const Identifier: string; DeclTool: TCodeTool;
|
||||||
DeclNode: TCodeTreeNode; var ListOfReferences: TCodeXYPositions; const Flags: TFindRefsFlags
|
DeclNode: TCodeTreeNode; var ListOfReferences: TCodeXYPositions; const Flags: TFindRefsFlags
|
||||||
): TModalResult;
|
): TModalResult;
|
||||||
@ -314,6 +335,8 @@ begin
|
|||||||
DeclFilename:=DeclTool.MainFilename;
|
DeclFilename:=DeclTool.MainFilename;
|
||||||
if not FilenameIsPascalUnit(DeclTool.MainFilename) then exit;
|
if not FilenameIsPascalUnit(DeclTool.MainFilename) then exit;
|
||||||
|
|
||||||
|
if not DeclarationCanBeInLFM(DeclNode) then exit;
|
||||||
|
|
||||||
{$IFNDEF EnableFindLFMRefs}
|
{$IFNDEF EnableFindLFMRefs}
|
||||||
exit;
|
exit;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
@ -323,6 +346,10 @@ begin
|
|||||||
|
|
||||||
aCache:=CodeToolsStructs.TPointerToPointerTree.Create;
|
aCache:=CodeToolsStructs.TPointerToPointerTree.Create;
|
||||||
try
|
try
|
||||||
|
if frfRename in Flags then
|
||||||
|
CheckDeclOfDesigner(Identifier,DeclTool,DeclNode);
|
||||||
|
|
||||||
|
// search in other lfm
|
||||||
for i:=0 to Files.Count-1 do begin
|
for i:=0 to Files.Count-1 do begin
|
||||||
UnitInfo:=Project1.UnitInfoWithFilename(Files[i]);
|
UnitInfo:=Project1.UnitInfoWithFilename(Files[i]);
|
||||||
if UnitInfo=nil then
|
if UnitInfo=nil then
|
||||||
@ -360,6 +387,30 @@ begin
|
|||||||
Result:= mrOK;
|
Result:= mrOK;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function DeclarationCanBeInLFM(DeclNode: TCodeTreeNode): boolean;
|
||||||
|
begin
|
||||||
|
Result:=false;
|
||||||
|
if DeclNode.HasParentOfType(ctnImplementation) then
|
||||||
|
exit; // cant be referenced in lfm
|
||||||
|
if DeclNode.Desc=ctnProcedureHead then
|
||||||
|
DeclNode:=DeclNode.Parent;
|
||||||
|
case DeclNode.Desc of
|
||||||
|
ctnProperty:
|
||||||
|
; // even private properties can later be made published -> must be searched
|
||||||
|
ctnVarDefinition:
|
||||||
|
if not (DeclNode.Parent.Desc in AllClassBaseSections) then
|
||||||
|
exit; // not a field, e.g. a parameter or local var
|
||||||
|
ctnProcedure:
|
||||||
|
if not (DeclNode.Parent.Desc in AllClassBaseSections) then
|
||||||
|
exit; // not a method
|
||||||
|
ctnTypeDefinition: ;
|
||||||
|
ctnEnumIdentifier: ;
|
||||||
|
else
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Result:=true;
|
||||||
|
end;
|
||||||
|
|
||||||
function DoFindRenameIdentifier(AllowRename: boolean; SetRenameActive: boolean;
|
function DoFindRenameIdentifier(AllowRename: boolean; SetRenameActive: boolean;
|
||||||
Options: TFindRenameIdentifierOptions): TModalResult;
|
Options: TFindRenameIdentifierOptions): TModalResult;
|
||||||
var
|
var
|
||||||
@ -715,6 +766,8 @@ begin
|
|||||||
|
|
||||||
// search pascal source references
|
// search pascal source references
|
||||||
FindRefFlags:=[];
|
FindRefFlags:=[];
|
||||||
|
if Options.Rename then
|
||||||
|
Include(FindRefFlags,frfRename);
|
||||||
if Options.Overrides then
|
if Options.Overrides then
|
||||||
Include(FindRefFlags,frfMethodOverrides);
|
Include(FindRefFlags,frfMethodOverrides);
|
||||||
if not GatherIdentifierReferences(Files,DeclCodeXY,DeclTool,DeclNode,
|
if not GatherIdentifierReferences(Files,DeclCodeXY,DeclTool,DeclNode,
|
||||||
|
Loading…
Reference in New Issue
Block a user