Skip to content

Reverse order of compilers in Configure Compilers dialogue box #51

Closed
@delphidabbler

Description

@delphidabbler

The list of compilers in the Configure Compilers dialogue box starts with Delphi 2 and you have to scroll to get to any of the more recent compilers. Reversing the order in the list would make it easier to edit the later compilers.

Activity

self-assigned this
on Jul 1, 2022
delphidabbler

delphidabbler commented on Jul 7, 2022

@delphidabbler
OwnerAuthor

The current code maps the compiler ID to the compiler list box index:

Result := fCompilers[TCompilerID(fLB.ItemIndex)];

This relationship is also relied upon in the custom draw handler:

Compiler := fCompilers[TCompilerID(Index)];

We're going to need to either (a) create a parallel array to the list items mapping item indices to compiler IDs or (b) to create custom list items that store the related compiler ID.

Not good code, but there it is.

delphidabbler

delphidabbler commented on Jul 7, 2022

@delphidabbler
OwnerAuthor

The parallel array method may be the easiest to implement. Some ideas:

Declare fields

fMapIdxToComp: TArray<TCompilerID>;
fMapCompToIdx: array[TCompilerID] of Integer;

In the Initialise method:

procedure TCompilerListMgr.Initialise;
var
  CompID: TCompilerID;  // loops thru supported compilers
  Idx: Integer;
begin
  inherited;
  // Add empty list items - one per supported compiler. Note we don't need item
  // text since we handle drawing of list items ourselves and get details from
  // compiler objects.
  SetLength(fMapIdxToComp, Length (fMapCompToIdx);
  Idx := 0;
  for CompID := High(TCompilerID) downto LowTCompilerID) do
  begin
    fLB.Items.Add('');
    fMapIdxToComp[Idx] := CompID;
    fMapCompToIdx[CompID] := Idx;
    Inc(Idx);
  end;
  // Select first compiler in list and trigger selection event for it
  fLB.ItemIndex := 0;
  DoSelect;
end;

In the GetSelected method:

function TCompilerListMgr.GetSelected: ICompiler;
begin
  Result := fCompilers[fMapIdxToComp[fLB.ItemIndex]];
end;

And in list box custom draw method:

procedure TCompilerListMgr.LBDrawItemHandler(Control: TWinControl;
  Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
  ...
  // Compiler object associated with list item
  Compiler := fCompilers[fMapIdxToComp[fLB.ItemIndex]];
  ...
end;

And the Refresh method:

procedure TCompilerListMgr.Refresh(Compiler: ICompiler);
var
  InvalidRect: TRectEx;
begin
  InvalidRect := fLB.ItemRect(fMapCompIDToIdx[Compiler.GetID]);
  InvalidateRect(fLB.Handle, @InvalidRect, False);
end;

Not tested any of this.

delphidabbler

delphidabbler commented on Dec 12, 2022

@delphidabbler
OwnerAuthor

💡 Order of compilers in Find Compilers dialogue box could also benefit from being revered.

changed the title [-]Reverse order of compilers Configure Compilers dialogue box[/-] [+]Reverse order of compilers in Configure Compilers dialogue box[/+] on Dec 16, 2022

15 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

completedWork has been completed on this issue and changes have been committed to `develop` branch..feature requestRequest for a new feature

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @delphidabbler

      Issue actions

        Reverse order of compilers in Configure Compilers dialogue box · Issue #51 · delphidabbler/codesnip