Codetools: Identifier completion, add limit for recent history items shown. issue #40332 Patch by WooBean007

This commit is contained in:
Martin 2023-07-17 18:06:27 +02:00
parent c32f97c6c8
commit e7c438c50b
5 changed files with 91 additions and 24 deletions

View File

@ -237,6 +237,7 @@ type
FContextFlags: TIdentifierListContextFlags;
FOnGatherUserIdentifiersToFilteredList: TOnGatherUserIdentifiersToFilteredList;
FSortForHistory: boolean;
FSortForHistoryLimit:integer;
FSortMethodForCompletion: TIdentComplSortMethod;
FStartAtom: TAtomPosition;
FStartAtomBehind: TAtomPosition;
@ -257,6 +258,7 @@ type
function CompareIdentListItems({%H-}Tree: TAvlTree; Data1, Data2: Pointer): integer;
procedure SetHistory(const AValue: TIdentifierHistoryList);
procedure SetSortForHistory(AValue: boolean);
procedure SetSortForHistoryLimit(AValue: integer);
procedure SetSortMethodForCompletion(AValue: TIdentComplSortMethod);
procedure UpdateFilteredList;
function GetFilteredItems(Index: integer): TIdentifierListItem;
@ -288,6 +290,8 @@ type
property History: TIdentifierHistoryList read FHistory write SetHistory;
property Prefix: string read FPrefix write SetPrefix;
property SortForHistory: boolean read FSortForHistory write SetSortForHistory;
property SortForHistoryLimit: integer read FSortForHistoryLimit
write SetSortForHistoryLimit;
property SortMethodForCompletion: TIdentComplSortMethod read FSortMethodForCompletion
write SetSortMethodForCompletion;
@ -600,11 +604,19 @@ begin
if SortForHistory then begin
// then sort for History (lower is better)
if Item1.HistoryIndex<Item2.HistoryIndex then begin
Result:=-1;
exit;
end else if Item1.HistoryIndex>Item2.HistoryIndex then begin
Result:=1;
exit;
if Item1.HistoryIndex <SortForHistoryLimit then
begin
Result:=-1;
exit;
end;
end else
if Item1.HistoryIndex>Item2.HistoryIndex then
begin
if Item2.HistoryIndex <SortForHistoryLimit then
begin
Result:=1;
exit;
end;
end;
end;
@ -733,6 +745,13 @@ begin
Clear;
end;
procedure TIdentifierList.SetSortForHistoryLimit(AValue: integer);
begin
if FSortForHistoryLimit=AValue then Exit;
FSortForHistoryLimit:=AValue;
Clear;
end;
function TIdentifierList.GetFilteredItems(Index: integer): TIdentifierListItem;
begin
UpdateFilteredList;
@ -750,6 +769,7 @@ begin
FIdentSearchItem:=TIdentifierListSearchItem.Create;
FCreatedIdentifiers:=TFPList.Create;
FSortForHistory:=true;
FSortForHistoryLimit:=5;
FSortMethodForCompletion:=icsScopedAlphabetic;
end;

View File

@ -79,6 +79,7 @@ type
FAdjustTopLineDueToComment: boolean;
FAvoidUnnecessaryJumps: boolean;
FIdentComplSortForHistory: boolean;
FIdentComplHistoryLimit: integer;
FIdentComplSortMethod: TIdentComplSortMethod;
FJumpSingleLinePos: integer;
FJumpCodeBlockPos: integer;
@ -290,6 +291,8 @@ type
write FIdentComplShowHelp;
property IdentComplSortForHistory: boolean read FIdentComplSortForHistory
write FIdentComplSortForHistory;
property IdentComplHistoryLimit: integer read FIdentComplHistoryLimit
write FIdentComplHistoryLimit;
property IdentComplSortMethod: TIdentComplSortMethod read FIdentComplSortMethod
write FIdentComplSortMethod;
@ -621,6 +624,8 @@ begin
'CodeToolsOptions/IdentifierCompletion/ShowHelp',false);
FIdentComplSortForHistory:=XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/SortForHistory',true);
FIdentComplHistoryLimit := XMLConfig.GetValue(
'CodeToolsOptions/IdentifierCompletion/SortForHistoryLimit',5);
FIdentComplSortMethod := icsAlphabetic;
if XMLConfig.GetValue(
@ -815,6 +820,8 @@ begin
FIdentComplShowHelp,false);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/SortForHistory',
FIdentComplSortForHistory,true);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/SortForHistoryLimit',
FIdentComplHistoryLimit,5);
XMLConfig.SetDeleteValue('CodeToolsOptions/IdentifierCompletion/SortForMethod',
FIdentComplSortMethod, int64(ord(icsScopedAlphabetic)), TypeInfo(TIdentComplSortMethod));
XMLConfig.DeleteValue('CodeToolsOptions/IdentifierCompletion/SortForScope');
@ -967,6 +974,7 @@ begin
FIdentComplJumpToError:=CodeToolsOpts.FIdentComplJumpToError;
FIdentComplShowHelp:=CodeToolsOpts.FIdentComplShowHelp;
FIdentComplSortForHistory:=CodeToolsOpts.FIdentComplSortForHistory;
FIdentComplHistoryLimit:=CodeToolsOpts.FIdentComplHistoryLimit;
FIdentComplSortMethod:=CodeToolsOpts.FIdentComplSortMethod;
end
@ -1041,6 +1049,7 @@ begin
FIdentComplJumpToError:=true;
FIdentComplShowHelp:=false;
FIdentComplSortForHistory:=true;
FIdentComplHistoryLimit:=5;
FIdentComplSortMethod:=icsScopedAlphabetic;
// indentation
@ -1133,6 +1142,7 @@ begin
and (FIdentComplJumpToError=CodeToolsOpts.FIdentComplJumpToError)
and (FIdentComplShowHelp=CodeToolsOpts.FIdentComplShowHelp)
and (FIdentComplSortForHistory=CodeToolsOpts.FIdentComplSortForHistory)
and (FIdentComplHistoryLimit=CodeToolsOpts.FIdentComplHistoryLimit)
and (FIdentComplSortMethod=CodeToolsOpts.FIdentComplSortMethod)
;
end;
@ -1207,6 +1217,7 @@ begin
// Identifier Completion - - - - - - - - - - - - - - - - - - - - - - - - - -
Boss.IdentifierList.SortForHistory:=IdentComplSortForHistory;
Boss.IdentifierList.SortMethodForCompletion:=IdentComplSortMethod;
Boss.IdentifierList.SortForHistoryLimit:=IdentComplHistoryLimit;
// Code Templates- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
aFilename:=CodeCompletionTemplateFileName;

View File

@ -91,12 +91,12 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 489
Top = 492
Width = 123
Caption = 'ICReplaceCheckBox'
ParentShowHint = False
ShowHint = True
TabOrder = 17
TabOrder = 18
end
object ICAddDoCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -116,8 +116,9 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 313
Top = 316
Width = 158
BorderSpacing.Top = 3
Caption = 'ICSortForHistoryCheckBox'
ParentShowHint = False
TabOrder = 11
@ -175,7 +176,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 474
Top = 477
Width = 537
Caption = 'ICMiscDividerBevel'
Anchors = [akTop, akLeft, akRight]
@ -190,12 +191,12 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 19
Top = 508
Top = 511
Width = 149
Caption = 'ICJumpToErrorCheckBox'
ParentShowHint = False
ShowHint = True
TabOrder = 18
TabOrder = 19
end
object ICAutoUseSingleIdent: TCheckBox
AnchorSideLeft.Control = Owner
@ -218,10 +219,10 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 350
Top = 353
Width = 155
Caption = 'ICContainsFilterCheckBox'
TabOrder = 19
TabOrder = 20
end
object ICAppearanceDividerBevel: TDividerBevel
AnchorSideLeft.Control = Owner
@ -231,7 +232,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 438
Top = 441
Width = 537
Caption = 'ICAppearanceDividerBevel'
Anchors = [akTop, akLeft, akRight]
@ -245,10 +246,10 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 453
Top = 456
Width = 222
Caption = 'ICUseIconsInCompletionBoxCheckBox'
TabOrder = 16
TabOrder = 17
end
object ICContentDividerBevel: TDividerBevel
AnchorSideLeft.Control = Owner
@ -258,7 +259,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideRight.Side = asrBottom
Left = 0
Height = 15
Top = 335
Top = 338
Width = 537
Caption = 'ICContentDividerBevel'
Anchors = [akTop, akLeft, akRight]
@ -271,7 +272,7 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrCenter
Left = 0
Height = 15
Top = 375
Top = 378
Width = 112
Caption = 'ICIncludeWordsLabel'
ParentColor = False
@ -283,13 +284,13 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 117
Height = 23
Top = 371
Top = 374
Width = 200
BorderSpacing.Left = 5
BorderSpacing.Top = 2
ItemHeight = 15
Style = csDropDownList
TabOrder = 13
TabOrder = 14
end
object ICIncludeKeywordsCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -297,11 +298,11 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 396
Top = 399
Width = 172
BorderSpacing.Top = 2
Caption = 'ICIncludeKeywordsCheckBox'
TabOrder = 14
TabOrder = 15
end
object ICIncludeCodeTemplatesCheckBox: TCheckBox
AnchorSideLeft.Control = Owner
@ -309,11 +310,11 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
AnchorSideTop.Side = asrBottom
Left = 0
Height = 19
Top = 417
Top = 420
Width = 203
BorderSpacing.Top = 2
Caption = 'ICIncludeCodeTemplatesCheckBox'
TabOrder = 15
TabOrder = 16
end
object ICAutoOnTypeUseTimer: TCheckBox
AnchorSideLeft.Control = Owner
@ -405,6 +406,35 @@ object CodetoolsIndentifierCompletionOptionsFrame: TCodetoolsIndentifierCompleti
)
ParentShowHint = False
ShowHint = True
TabOrder = 13
end
object ICHistoryLimitSpinEdit: TSpinEdit
AnchorSideLeft.Control = ICHistoryLimitLabel
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ICSortOrderRadioGroup
AnchorSideTop.Side = asrBottom
Left = 312
Height = 23
Top = 316
Width = 50
BorderSpacing.Left = 16
BorderSpacing.Top = 3
MaxValue = 30
MinValue = 1
TabOrder = 12
Value = 5
end
object ICHistoryLimitLabel: TLabel
AnchorSideLeft.Control = ICSortForHistoryCheckBox
AnchorSideLeft.Side = asrBottom
AnchorSideTop.Control = ICSortOrderRadioGroup
AnchorSideTop.Side = asrBottom
Left = 192
Height = 15
Top = 318
Width = 104
BorderSpacing.Left = 34
BorderSpacing.Top = 5
Caption = 'ICHistoryLimitLabel'
end
end

View File

@ -68,6 +68,8 @@ type
ICAutoOnTypeMinLengthLbl: TLabel;
ICAutoOnTypeMinLength: TSpinEdit;
ICSortOrderRadioGroup: TRadioGroup;
ICHistoryLimitLabel: TLabel;
ICHistoryLimitSpinEdit: TSpinEdit;
private
public
function GetTitle: String; override;
@ -111,6 +113,7 @@ begin
ICSortDividerBevel.Caption:=lisSorting;
ICSortForHistoryCheckBox.Caption:=lisShowRecentlyUsedIdentifiersAtTop;
ICHistoryLimitLabel.Caption := lisSortHistoryLimit;
ICSortOrderRadioGroup.Hint:=lisForExampleShowAtTopTheLocalVariablesThenTheMembers;
ICSortOrderRadioGroup.Caption:=lisSortOrderTitle;
ICSortOrderRadioGroup.Items[0]:= lisSortOrderScopedAlphabetic;
@ -155,6 +158,7 @@ begin
ICJumpToErrorCheckBox.Checked:=IdentComplJumpToError;
ICShowHelpCheckBox.Checked:=IdentComplShowHelp;
ICSortForHistoryCheckBox.Checked:=IdentComplSortForHistory;
ICHistoryLimitSpinEdit.Value:= IdentComplHistoryLimit;
case IdentComplSortMethod of
icsScopedAlphabetic: ICSortOrderRadioGroup.ItemIndex:= 0;
icsAlphabetic: ICSortOrderRadioGroup.ItemIndex:= 1;
@ -193,6 +197,7 @@ begin
IdentComplJumpToError:=ICJumpToErrorCheckBox.Checked;
IdentComplShowHelp:=ICShowHelpCheckBox.Checked;
IdentComplSortForHistory:=ICSortForHistoryCheckBox.Checked;
IdentComplHistoryLimit:=ICHistoryLimitSpinEdit.Value;
case ICSortOrderRadioGroup.ItemIndex of
0: IdentComplSortMethod:=icsScopedAlphabetic;
1: IdentComplSortMethod:=icsAlphabetic;

View File

@ -5783,6 +5783,7 @@ resourcestring
lisForExampleShowAtTopTheLocalVariablesThenTheMembers = '"Scoped" sorting will show'
+' local variables on top, then the members of current class, then of the'
+' ancestors, then the current unit, then of used units';
lisSortHistoryLimit = 'History items limit';
lisSortOrderTitle = 'Order by';
lisSortOrderDefinition = 'Definition (Scoped)';
lisSortOrderScopedAlphabetic = 'Alphabetic (Scoped)';