Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Customizing the LMDEditView intellisense menu

Hi,

I would like to customize the items within the LMDEditView intellisense/completion menu. For instance I would like to display the parameters for the functions listed as well as change the color of list items depending on preset types. I have seen that there are a number of completion list events for example OnCompletionCustomDraw and OnFillCompletionList but I'm unsure if these are the correct events to use and if so where to begin. A simple example would be great or a point in the right direction. 

Kind Regards,

Francois

Comments

  • 6 Comments sorted by Votes Date Added
  • Hi,

    Thank you for your reply and I have had a look at the post you mention however I'm still unable to understand how to set the width of the combobox that pops up for code completion when hitting Ctrl Space after a dot.

    There is no width option in the CompletionCustomDraw, CompletionMeasureItem, or FillCompletionList methods. I understand how to use the MeasureItem method of a standard popupmenu but the popup on the Editor seems to be a built in one and I don't know how to change it's width. 

    I have the following code for the above mentioned methods:

    procedure TfTextEditor.lmdEditorCompletionMeasureItem(Sender: TObject;
      AItems: TStrings; Index: Integer; Canvas: TCanvas; var Height: Integer);
    begin
      Height := Canvas.TextHeight(AItems[Index]) + 2; //This correctly sets the height of the popup combo
      Width  := Canvas.TextWidth(AItems[Index]) + 2;  //This sets the width of the editor and not the combobox
    end;

    procedure TfTextEditor.lmdEditorCompletionCustomDraw(Sender: TObject;
      AItems: TStrings; Index: Integer; Rect: TRect; State: TOwnerDrawState;
      Canvas: TCanvas);
    var
        s: string;
    begin
      if not (odSelected in State) then
        Canvas.Brush.Color := clWhite
      else
        Canvas.Font.Style := Canvas.Font.Style + [fsBold];

      s := AItems[Index];

      Canvas.FillRect(Rect);
      Canvas.TextRect(Rect, Rect.Left + 2, Rect.Top, s);
      //I have tried setting the canvas width but this only sets the width of the items in the combo and not the width of the combo itself.
    end;

    procedure TfTextEditor.lmdEditorFillCompletionList(Sender: TObject;
      Items: TStrings; CursorPoint: TPoint; Cause: TLMDEditFillCompletionCause;
      const LeftPart: TLMDString; var PosForCombo: TPoint; var Handled: Boolean);
    var
      TokenSeg: TLMDSegment;
      Token: string;
    begin
      if (Cause = fcForced) and Assigned(OnFillIntellisense) and (LeftPart = '') then
      begin
        TokenSeg := lmdDocument.FindNearWord(lmdEditor.CursorOffset - 1, -1, true);
        if TokenSeg.Start > -1 then
        begin

          Token := LMDSegToString(TokenSeg);
          OnFillIntellisense(Trim(Token), Items);
          Handled := True;
        end;
      end;
    end;

    Any assistance would be greatly appreciated. 

    Example of too narrow popup attached. image
  • Hi,

    Currently, there no way to set up the width programmatically. However, as you probably already noted, the user can resize drop-down list using mouse. 
    Btw, I've added the Width property to completion settings of the editor view. So, if you have access to LMD SVN, you can update your sources now, otherwise, please wait for the next minor release.
  • Hi balabuev, thank you for your reply. I have found a way to set the width programmatically as follows:

      TComboBox(TLMDCustomEditView(Sender).Controls[0])

    Ideally one should probably loop through all the controls on the EditView (Sender) and find the one that matches the TComplList type however I noticed that there is always only one control belonging to the EditView hence the index of zero.

    It will certainly be easier now that you have added the Width property to the completion settings but I'm working as a part of a larger group and will update the source when it is scheduled for the group. In the mean time the above solution works perfectly.

    Kind Regards,

Sign In or Register to comment.