ide: find/rename identifier: added option find overrides

This commit is contained in:
mattias 2025-01-29 17:07:36 +01:00
parent 90ddf0774e
commit f302e2508c
4 changed files with 93 additions and 62 deletions

View File

@ -1,12 +1,12 @@
object FindRenameIdentifierDialog: TFindRenameIdentifierDialog
Left = 314
Height = 500
Height = 525
Top = 188
Width = 460
AutoSize = True
BorderIcons = [biSystemMenu]
Caption = 'FindRenameIdentifierDialog'
ClientHeight = 500
ClientHeight = 525
ClientWidth = 460
Constraints.MinHeight = 450
Constraints.MinWidth = 460
@ -22,34 +22,35 @@ object FindRenameIdentifierDialog: TFindRenameIdentifierDialog
Align = alClient
BorderSpacing.Around = 6
Caption = 'CurrentGroupBox'
ClientHeight = 81
ClientWidth = 444
ClientHeight = 83
ClientWidth = 446
Constraints.MinHeight = 100
TabOrder = 0
object CurrentListBox: TListBox
Left = 6
Height = 69
Height = 71
Top = 6
Width = 432
Width = 434
Align = alClient
BorderSpacing.Around = 6
ClickOnSelChange = False
ItemHeight = 0
ScrollWidth = 430
TabOrder = 0
TopIndex = -1
end
end
object NewGroupBox: TGroupBox
Left = 6
Height = 118
Top = 83
Height = 115
Top = 91
Width = 448
Align = alBottom
AutoSize = True
BorderSpacing.Around = 6
Caption = 'NewGroupBox'
ClientHeight = 99
ClientWidth = 444
ClientHeight = 98
ClientWidth = 446
TabOrder = 1
object NewEdit: TEdit
AnchorSideLeft.Control = NewGroupBox
@ -58,9 +59,9 @@ object FindRenameIdentifierDialog: TFindRenameIdentifierDialog
AnchorSideRight.Control = NewGroupBox
AnchorSideRight.Side = asrBottom
Left = 6
Height = 27
Top = 66
Width = 432
Height = 28
Top = 64
Width = 434
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
TabOrder = 2
@ -69,9 +70,9 @@ object FindRenameIdentifierDialog: TFindRenameIdentifierDialog
end
object RenameCheckBox: TCheckBox
Left = 6
Height = 24
Height = 23
Top = 6
Width = 432
Width = 434
Align = alTop
BorderSpacing.Around = 6
Caption = 'RenameCheckBox'
@ -85,9 +86,9 @@ object FindRenameIdentifierDialog: TFindRenameIdentifierDialog
AnchorSideRight.Control = NewGroupBox
AnchorSideRight.Side = asrBottom
Left = 6
Height = 24
Top = 36
Width = 432
Height = 23
Top = 35
Width = 434
Anchors = [akTop, akLeft, akRight]
BorderSpacing.Around = 6
Caption = 'ShowResultCheckBox'
@ -96,31 +97,44 @@ object FindRenameIdentifierDialog: TFindRenameIdentifierDialog
end
object ScopeGroupBox: TGroupBox
Left = 6
Height = 252
Top = 207
Height = 271
Top = 212
Width = 448
Align = alBottom
AutoSize = True
BorderSpacing.Around = 6
Caption = 'ScopeGroupBox'
ClientHeight = 233
ClientWidth = 444
ClientHeight = 254
ClientWidth = 446
TabOrder = 2
object ScopeCommentsCheckBox: TCheckBox
object ExtraFilesGroupBox: TGroupBox
Left = 6
Height = 24
Top = 203
Width = 432
Height = 57
Top = 133
Width = 434
Align = alTop
AutoSize = True
BorderSpacing.Around = 6
Caption = 'ExtraFilesGroupBox'
ClientHeight = 40
ClientWidth = 432
TabOrder = 1
object ExtraFilesEdit: TEdit
Left = 6
Height = 28
Top = 6
Width = 420
Align = alTop
BorderSpacing.Around = 6
Caption = 'ScopeCommentsCheckBox'
TabOrder = 2
TabOrder = 0
Text = 'ExtraFilesEdit'
end
end
object ScopeRadioGroup: TRadioGroup
Left = 6
Height = 127
Height = 121
Top = 6
Width = 432
Width = 434
Align = alTop
AutoFill = True
AutoSize = True
@ -134,8 +148,8 @@ object FindRenameIdentifierDialog: TFindRenameIdentifierDialog
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
ClientHeight = 108
ClientWidth = 428
ClientHeight = 104
ClientWidth = 432
Items.Strings = (
'in current unit'
'in main project'
@ -144,34 +158,31 @@ object FindRenameIdentifierDialog: TFindRenameIdentifierDialog
)
TabOrder = 0
end
object ExtraFilesGroupBox: TGroupBox
object ScopeCommentsCheckBox: TCheckBox
Left = 6
Height = 58
Top = 139
Width = 432
Align = alTop
AutoSize = True
BorderSpacing.Around = 6
Caption = 'ExtraFilesGroupBox'
ClientHeight = 39
ClientWidth = 428
TabOrder = 1
object ExtraFilesEdit: TEdit
Left = 6
Height = 27
Top = 6
Width = 416
Height = 23
Top = 196
Width = 434
Align = alTop
BorderSpacing.Around = 6
TabOrder = 0
Text = 'ExtraFilesEdit'
Caption = 'ScopeCommentsCheckBox'
TabOrder = 2
end
object ScopeOverridesCheckBox: TCheckBox
Left = 6
Height = 23
Top = 225
Width = 434
Align = alTop
BorderSpacing.Around = 6
Caption = 'ScopeOverridesCheckBox'
TabOrder = 3
end
end
object ButtonPanel1: TButtonPanel
Left = 6
Height = 29
Top = 465
Height = 30
Top = 489
Width = 448
OKButton.Name = 'OKButton'
OKButton.DefaultCaption = True

View File

@ -48,7 +48,7 @@ uses
TransferMacros, IDEProcs, SearchPathProcs,
// IDE
LazarusIDEStrConsts, MiscOptions, CodeToolsOptions, SearchResultView, CodeHelp, CustomCodeTool,
SourceFileManager, Project;
FindDeclarationTool, SourceFileManager, Project;
type
@ -56,6 +56,7 @@ type
TFindRenameIdentifierDialog = class(TForm)
ButtonPanel1: TButtonPanel;
ScopeOverridesCheckBox: TCheckBox;
ShowResultCheckBox: TCheckBox;
CurrentGroupBox: TGroupBox;
CurrentListBox: TListBox;
@ -118,7 +119,7 @@ function DoFindRenameIdentifier(
function GatherIdentifierReferences(Files: TStringList;
DeclarationCode: TCodeBuffer; const DeclarationCaretXY: TPoint;
SearchInComments: boolean;
var TreeOfPCodeXYPosition: TAVLTree): TModalResult;
var TreeOfPCodeXYPosition: TAVLTree; const Flags: TFindRefsFlags): TModalResult;
function ShowIdentifierReferences(
DeclarationCode: TCodeBuffer; const DeclarationCaretXY: TPoint;
TreeOfPCodeXYPosition: TAVLTree;
@ -272,6 +273,7 @@ var
UGUnit: TUGUnit;
TargetFilename, OrigFileName, ChangedFileType, srcNamed, lfmString: string;
SkipRenamingFile, isConflicted: Boolean;
FindRefFlags: TFindRefsFlags;
begin
Result:=mrCancel;
if not LazarusIDE.BeginCodeTools then exit(mrCancel);
@ -388,8 +390,11 @@ begin
end;
// search pascal source references
FindRefFlags:=[];
if Options.Overrides then
Include(FindRefFlags,frfMethodOverrides);
Result:=GatherIdentifierReferences(Files,DeclCode,
DeclarationCaretXY,Options.SearchInComments,PascalReferences);
DeclarationCaretXY,Options.SearchInComments,PascalReferences,FindRefFlags);
if CodeToolBoss.ErrorMessage<>'' then
LazarusIDE.DoJumpToCodeToolBossError;
if Result<>mrOk then begin
@ -499,7 +504,7 @@ begin
//cursor pos for declaration is the same as before renaming
CodeToolBoss.FreeTreeOfPCodeXYPosition(PascalReferences);
Result:=GatherIdentifierReferences(Files,DeclCode,
DeclarationCaretXY,Options.SearchInComments,PascalReferences);
DeclarationCaretXY,Options.SearchInComments,PascalReferences,FindRefFlags);
if CodeToolBoss.ErrorMessage<>'' then
LazarusIDE.DoJumpToCodeToolBossError;
if Result<>mrOk then begin
@ -527,10 +532,9 @@ begin
end;
end;
function GatherIdentifierReferences(Files: TStringList;
DeclarationCode: TCodeBuffer; const DeclarationCaretXY: TPoint;
SearchInComments: boolean;
var TreeOfPCodeXYPosition: TAVLTree): TModalResult;
function GatherIdentifierReferences(Files: TStringList; DeclarationCode: TCodeBuffer;
const DeclarationCaretXY: TPoint; SearchInComments: boolean; var TreeOfPCodeXYPosition: TAVLTree;
const Flags: TFindRefsFlags): TModalResult;
var
i: Integer;
LoadResult: TModalResult;
@ -561,7 +565,7 @@ begin
CodeToolBoss.FreeListOfPCodeXYPosition(ListOfPCodeXYPosition);
if not CodeToolBoss.FindReferences(
DeclarationCode,DeclarationCaretXY.X,DeclarationCaretXY.Y,
Code, not SearchInComments, ListOfPCodeXYPosition, Cache) then
Code, not SearchInComments, ListOfPCodeXYPosition, Cache, Flags) then
begin
debugln('GatherIdentifierReferences unable to FindReferences in "',Code.Filename,'"');
Result:=mrAbort;
@ -859,6 +863,7 @@ begin
RenameCheckBox.Caption:=lisRename;
ShowResultCheckBox.Caption:=lisRenameShowResult;
ScopeCommentsCheckBox.Caption:=lisFRISearchInCommentsToo;
ScopeOverridesCheckBox.Caption:=lisFindOverridesToo;
ScopeGroupBox.Caption:=lisFRISearch;
ScopeRadioGroup.Caption:=dlgSearchScope;
ScopeRadioGroup.Items[0]:=lisFRIinCurrentUnit;
@ -1150,6 +1155,7 @@ begin
NewEdit.Text:=Options.RenameTo;
ShowResultCheckBox.Checked:=Options.RenameShowResult;
ScopeCommentsCheckBox.Checked:=Options.SearchInComments;
ScopeOverridesCheckBox.Checked:=Options.Overrides;
case Options.Scope of
frCurrentUnit: ScopeRadioGroup.ItemIndex:=0;
frProject: ScopeRadioGroup.ItemIndex:=1;
@ -1169,6 +1175,7 @@ begin
Options.RenameTo:=NewEdit.Text;
Options.RenameShowResult := ShowResultCheckBox.Checked;
Options.SearchInComments:=ScopeCommentsCheckBox.Checked;
Options.Overrides:=ScopeOverridesCheckBox.Checked;
if ScopeRadioGroup.Enabled then
case ScopeRadioGroup.ItemIndex of
0: Options.Scope:=frCurrentUnit;

View File

@ -3615,6 +3615,7 @@ resourcestring
lisFRIRenaming = 'Renaming';
lisFRISearchInCommentsToo = 'Search in comments too';
lisFRISearch = 'Search';
lisFindOverridesToo = 'Find overrides too';
lisCodeToolsOptsColon = 'Colon';
lisCodeToolsOptsSemicolon = 'Semicolon';
lisCodeToolsOptsComma = 'Comma';

View File

@ -60,6 +60,7 @@ type
FExtraFiles: TStrings;
FIdentifierFilename: string;
FIdentifierPosition: TPoint;
FOverrides: boolean;
FRename: boolean;
FRenameShowResult: boolean;
FRenameTo: string;
@ -70,6 +71,7 @@ type
procedure SetExtraFiles(AValue: TStrings);
procedure SetIdentifierFilename(AValue: string);
procedure SetIdentifierPosition(AValue: TPoint);
procedure SetOverrides(const AValue: boolean);
procedure SetModified(AValue: boolean);
procedure SetRename(AValue: boolean);
procedure SetRenameShowResult(AValue: boolean);
@ -89,6 +91,7 @@ type
property Rename: boolean read FRename write SetRename;
property RenameTo: string read FRenameTo write SetRenameTo;
property SearchInComments: boolean read FSearchInComments write SetSearchInComments;
property Overrides: boolean read FOverrides write SetOverrides;
property RenameShowResult: boolean read FRenameShowResult write SetRenameShowResult;
property Scope: TFindRenameScope read FScope write SetScope;
property ExtraFiles: TStrings read FExtraFiles write SetExtraFiles;
@ -422,6 +425,13 @@ begin
IncreaseChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetOverrides(const AValue: boolean);
begin
if FOverrides=AValue then Exit;
FOverrides:=AValue;
IncreaseChangeStamp;
end;
procedure TFindRenameIdentifierOptions.SetModified(AValue: boolean);
begin
if AValue then
@ -486,6 +496,7 @@ begin
fRename:=XMLConfig.GetValue(Path+'Rename/Value',false);
fRenameTo:=XMLConfig.GetValue(Path+'Rename/Identifier','');
fSearchInComments:=XMLConfig.GetValue(Path+'SearchInComments/Value',true);
FOverrides:=XMLConfig.GetValue(Path+'Overrides/Value',true);
fRenameShowResult:=XMLConfig.GetValue(Path+'RenameShowResult/Value',false);
fScope:=FindRenameScopeNameToScope(XMLConfig.GetValue(Path+'Scope/Value',
FindRenameScopeNames[frAllOpenProjectsAndPackages]));
@ -501,6 +512,7 @@ begin
XMLConfig.SetDeleteValue(Path+'Rename/Value',Rename,false);
XMLConfig.SetDeleteValue(Path+'Rename/Identifier',RenameTo,'');
XMLConfig.SetDeleteValue(Path+'SearchInComments/Value',SearchInComments,true);
XMLConfig.SetDeleteValue(Path+'Overrides/Value',Overrides,true);
XMLConfig.SetDeleteValue(Path+'RenameShowResult/Value',RenameShowResult,false);
XMLConfig.SetDeleteValue(Path+'Scope/Value',FindRenameScopeNames[Scope],
FindRenameScopeNames[frAllOpenProjectsAndPackages]);