Skip to content

Commit 4edaefe

Browse files
committed
Reverse order of compiler list in compiler setup dlg
1 parent 54f8839 commit 4edaefe

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Src/FmCompilersDlg.UCompilerListMgr.pas

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
44
* obtain one at https://mozilla.org/MPL/2.0/
55
*
6-
* Copyright (C) 2011-2021, Peter Johnson (gravatar.com/delphidabbler).
6+
* Copyright (C) 2011-2023, Peter Johnson (gravatar.com/delphidabbler).
77
*
88
* Implements a class that manages display of compiler names in an owner draw
99
* list box.
@@ -34,6 +34,8 @@ TCompilerListMgr = class(TObject)
3434
/// <summary>Reference to managed list box.</summary>
3535
/// <remarks>Must be owner draw.</remarks>
3636
fLB: TListBox;
37+
fMapIdxToComp: TArray<TCompilerID>;
38+
fMapCompToIdx: array[TCompilerID] of Integer;
3739
/// <summary>List of compilers to be displayed in list box.</summary>
3840
fCompilers: ICompilers;
3941
/// <summary>Reference to OnSelect event handler.</summary>
@@ -87,11 +89,16 @@ implementation
8789

8890
constructor TCompilerListMgr.Create(const LB: TListBox;
8991
const Compilers: ICompilers);
92+
var
93+
CompID: TCompilerID;
9094
begin
9195
inherited Create;
9296
fLB := LB;
9397
fLB.OnClick := LBClickHandler;
9498
fLB.OnDrawItem := LBDrawItemHandler;
99+
fLB.Clear;
100+
for CompID := Low(TCompilerID) to High(TCompilerID) do
101+
fLB.Items.Add('');
95102
fCompilers := Compilers;
96103
end;
97104

@@ -103,19 +110,27 @@ procedure TCompilerListMgr.DoSelect;
103110

104111
function TCompilerListMgr.GetSelected: ICompiler;
105112
begin
106-
Result := fCompilers[TCompilerID(fLB.ItemIndex)];
113+
Result := fCompilers[fMapIdxToComp[fLB.ItemIndex]];
107114
end;
108115

109116
procedure TCompilerListMgr.Initialise;
110117
var
111118
CompID: TCompilerID; // loops thru supported compilers
119+
Idx: Integer;
112120
begin
113121
inherited;
122+
114123
// Add empty list items - one per supported compiler. Note we don't need item
115124
// text since we handle drawing of list items ourselves and get details from
116125
// compiler objects.
126+
SetLength(fMapIdxToComp, Length(fMapCompToIdx));
127+
Idx := High(fMapIdxToComp);
117128
for CompID := Low(TCompilerID) to High(TCompilerID) do
118-
fLB.Items.Add('');
129+
begin
130+
fMapIdxToComp[Idx] := CompID;
131+
fMapCompToIdx[CompID] := Idx;
132+
Dec(Idx);
133+
end;
119134
// Select first compiler in list and trigger selection event for it
120135
fLB.ItemIndex := 0;
121136
DoSelect;
@@ -139,7 +154,7 @@ procedure TCompilerListMgr.LBDrawItemHandler(Control: TWinControl;
139154
ItemRect := Rect;
140155

141156
// Compiler object associated with list item
142-
Compiler := fCompilers[TCompilerID(Index)];
157+
Compiler := fCompilers[fMapIdxToComp[Index]];
143158

144159
// Use bold font if compiler available
145160
if Compiler.IsAvailable then
@@ -208,7 +223,7 @@ procedure TCompilerListMgr.Refresh(Compiler: ICompiler);
208223
var
209224
InvalidRect: TRectEx;
210225
begin
211-
InvalidRect := fLB.ItemRect(Ord(Compiler.GetID));
226+
InvalidRect := fLB.ItemRect(fMapCompToIdx[Compiler.GetID]);
212227
InvalidateRect(fLB.Handle, @InvalidRect, False);
213228
end;
214229

0 commit comments

Comments
 (0)