IDE, SourceEditor: refactor / clean up - Colors for completion drop down.

This commit is contained in:
Martin 2024-10-21 10:54:44 +02:00
parent 6a0efcb8c0
commit a8b95b354c
4 changed files with 131 additions and 129 deletions

View File

@ -7689,44 +7689,9 @@ begin
begin begin
IDESynEdit := TIDESynEditor(ASynEdit); IDESynEdit := TIDESynEditor(ASynEdit);
Attri := GetUsedAttr(ahaIdentComplWindow); for aha := low(TIdentWindowAhaColorRange) to high(TIdentWindowAhaColorRange) do begin
if Attri<>nil then Attri := GetUsedAttr(aha);
begin Attri.ApplyTo(IDESynEdit.MarkupIdentComplWindow.Color[aha]);
IDESynEdit.MarkupIdentComplWindow.TextColor := Attri.Foreground;
IDESynEdit.MarkupIdentComplWindow.WindowColor:= Attri.Background;
end else
begin
IDESynEdit.MarkupIdentComplWindow.TextColor := clNone;
IDESynEdit.MarkupIdentComplWindow.WindowColor:= clNone;
end;
Attri := GetUsedAttr(ahaIdentComplWindowBorder);
if Attri<>nil then
IDESynEdit.MarkupIdentComplWindow.BorderColor:= Attri.Foreground
else
IDESynEdit.MarkupIdentComplWindow.BorderColor:= clNone;
Attri := GetUsedAttr(ahaIdentComplRecent);
if Attri<>nil then
IDESynEdit.MarkupIdentComplWindow.HistoryTextColor := Attri.Foreground
else
IDESynEdit.MarkupIdentComplWindow.HistoryTextColor := clNone;
Attri := GetUsedAttr(ahaIdentComplWindowHighlight);
if Attri<>nil then
IDESynEdit.MarkupIdentComplWindow.HighlightColor:= Attri.Foreground
else
IDESynEdit.MarkupIdentComplWindow.HighlightColor:= clNone;
Attri := GetUsedAttr(ahaIdentComplWindowSelection);
if Attri<>nil then
begin
IDESynEdit.MarkupIdentComplWindow.TextSelectedColor:= Attri.Foreground;
IDESynEdit.MarkupIdentComplWindow.BackgroundSelectedColor:= Attri.Background;
end else
begin
IDESynEdit.MarkupIdentComplWindow.TextSelectedColor := clNone;
IDESynEdit.MarkupIdentComplWindow.BackgroundSelectedColor:= clNone;
end; end;
end; end;

View File

@ -129,6 +129,7 @@ type
FIdentCompletionJumpToError: boolean; FIdentCompletionJumpToError: boolean;
ccSelection: String; ccSelection: String;
// colors for the completion form (popup form, e.g. word completion) // colors for the completion form (popup form, e.g. word completion)
FColors: TSynMarkupIdentComplWindow;
FActiveEditBackgroundColor: TColor; FActiveEditBackgroundColor: TColor;
FActiveEditBackgroundSelectedColor: TColor; FActiveEditBackgroundSelectedColor: TColor;
@ -167,6 +168,7 @@ type
function GetCompletionFormClass: TSynBaseCompletionFormClass; override; function GetCompletionFormClass: TSynBaseCompletionFormClass; override;
public public
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property IdentCompletionJumpToError: Boolean property IdentCompletionJumpToError: Boolean
read FIdentCompletionJumpToError write FIdentCompletionJumpToError; read FIdentCompletionJumpToError write FIdentCompletionJumpToError;
end; end;
@ -2443,7 +2445,6 @@ var
Prefix: String; Prefix: String;
I: Integer; I: Integer;
NewStr: String; NewStr: String;
SynEditor: TIDESynEditor;
Template: TTemplate; Template: TTemplate;
A: TIdentComplSortMethod; A: TIdentComplSortMethod;
Begin Begin
@ -2478,13 +2479,12 @@ Begin
A=CodeToolBoss.IdentifierList.SortMethodForCompletion; A=CodeToolBoss.IdentifierList.SortMethodForCompletion;
end; end;
FActiveHistoryTextColor := clNone; FColors.Clear;
FActiveEditTextColor := Editor.Font.Color; FColors.Color[ahaIdentComplWindow].Foreground := Editor.Font.Color;
FActiveEditBorderColor := RGBToColor(200, 200, 200); FColors.Color[ahaIdentComplWindow].Background := Editor.Color;
FActiveEditBackgroundColor := Editor.Color; FColors.Color[ahaIdentComplWindowBorder].Foreground := RGBToColor(200, 200, 200);
FActiveEditTextSelectedColor := TSynEdit(Editor).SelectedColor.Foreground; FColors.Color[ahaIdentComplWindowSelection].Foreground := TSynEdit(Editor).SelectedColor.Foreground;
FActiveEditBackgroundSelectedColor := TSynEdit(Editor).SelectedColor.Background; FColors.Color[ahaIdentComplWindowSelection].Background := TSynEdit(Editor).SelectedColor.Background;
FActiveEditTextHighLightColor := clNone;
if Editor.Highlighter<>nil if Editor.Highlighter<>nil
then begin then begin
@ -2492,30 +2492,16 @@ Begin
if IdentifierAttribute<>nil if IdentifierAttribute<>nil
then begin then begin
if IdentifierAttribute.ForeGround<>clNone then if IdentifierAttribute.ForeGround<>clNone then
FActiveEditTextColor:=IdentifierAttribute.ForeGround; FColors.Color[ahaIdentComplWindow].Foreground := IdentifierAttribute.ForeGround;
if IdentifierAttribute.BackGround<>clNone then if IdentifierAttribute.BackGround<>clNone then
FActiveEditBackgroundColor:=IdentifierAttribute.BackGround; FColors.Color[ahaIdentComplWindow].Background := IdentifierAttribute.BackGround;
end; end;
end; end;
end; end;
if Editor is TIDESynEditor then if Editor is TIDESynEditor then
begin begin
SynEditor := TIDESynEditor(Editor); FColors.Merge(TIDESynEditor(Editor).MarkupIdentComplWindow);
if SynEditor.MarkupIdentComplWindow.TextColor<>clNone then
FActiveEditTextColor := SynEditor.MarkupIdentComplWindow.TextColor;
if SynEditor.MarkupIdentComplWindow.BorderColor<>clNone then
FActiveEditBorderColor := SynEditor.MarkupIdentComplWindow.BorderColor;
if SynEditor.MarkupIdentComplWindow.WindowColor<>clNone then
FActiveEditBackgroundColor := SynEditor.MarkupIdentComplWindow.WindowColor;
if SynEditor.MarkupIdentComplWindow.TextSelectedColor<>clNone then
FActiveEditTextSelectedColor := SynEditor.MarkupIdentComplWindow.TextSelectedColor;
if SynEditor.MarkupIdentComplWindow.BackgroundSelectedColor<>clNone then
FActiveEditBackgroundSelectedColor := SynEditor.MarkupIdentComplWindow.BackgroundSelectedColor;
if SynEditor.MarkupIdentComplWindow.HighlightColor<>clNone then
FActiveEditTextHighLightColor := SynEditor.MarkupIdentComplWindow.HighlightColor;
if SynEditor.MarkupIdentComplWindow.HistoryTextColor<>clNone then
FActiveHistoryTextColor:=SynEditor.MarkupIdentComplWindow.HistoryTextColor;
end; end;
SL := TStringList.Create; SL := TStringList.Create;
@ -2563,12 +2549,12 @@ Begin
// set colors // set colors
if (Editor<>nil) and (TheForm<>nil) then begin if (Editor<>nil) and (TheForm<>nil) then begin
with TheForm as TSourceEditCompletionForm do begin with TheForm as TSourceEditCompletionForm do begin
DrawBorderColor := FActiveEditBorderColor; DrawBorderColor := FColors[ahaIdentComplWindowBorder].Foreground;
BackgroundColor := FActiveEditBackgroundColor; BackgroundColor := FColors[ahaIdentComplWindow].Background;
clSelect := FActiveEditBackgroundSelectedColor; clSelect := FColors[ahaIdentComplWindowSelection].Background;
TextColor := FActiveEditTextColor; TextColor := FColors[ahaIdentComplWindow].Foreground;
TextSelectedColor := FActiveEditTextSelectedColor; TextSelectedColor := FColors[ahaIdentComplWindowSelection].Foreground;
TextHighLightColor:= FActiveEditTextHighLightColor; TextHighLightColor:= FColors[ahaIdentComplWindowHighlight].Foreground;
//debugln('TSourceEditCompletion.ccExecute A Color=',DbgS(Color), //debugln('TSourceEditCompletion.ccExecute A Color=',DbgS(Color),
// ' clSelect=',DbgS(clSelect), // ' clSelect=',DbgS(clSelect),
// ' TextColor=',DbgS(TextColor), // ' TextColor=',DbgS(TextColor),
@ -2766,7 +2752,6 @@ var
MaxX: Integer; MaxX: Integer;
t: TCompletionType; t: TCompletionType;
hl: TSynCustomHighlighter; hl: TSynCustomHighlighter;
Colors: TPaintCompletionItemColors;
begin begin
try try
with ACanvas do begin with ACanvas do begin
@ -2779,20 +2764,12 @@ begin
Font.Style:=[]; Font.Style:=[];
end; end;
if (CurrentCompletionType = ctIdentCompletion) and FColors.UseRecent :=
(CurrentCompletionType = ctIdentCompletion) and
(CodeToolBoss.IdentifierList.SortForHistory) and (CodeToolBoss.IdentifierList.SortForHistory) and
(iliIsRecentItem in CodeToolBoss.IdentifierList.FilteredItems[Index].Flags) and (iliIsRecentItem in CodeToolBoss.IdentifierList.FilteredItems[Index].Flags) and
(FActiveHistoryTextColor <> clNone) (FColors[ahaIdentComplRecent].Foreground <> clNone);
then begin
Colors.TextColor := FActiveHistoryTextColor; // - to display history items
end else begin
Colors.TextColor := FActiveEditTextColor;
end;
Colors.BackgroundColor := FActiveEditBackgroundColor;
Colors.BackgroundSelectedColor := FActiveEditBackgroundSelectedColor;
Colors.TextSelectedColor := FActiveEditTextSelectedColor;
Colors.TextHilightColor := FActiveEditTextHighLightColor;
MaxX:=TheForm.ClientWidth; MaxX:=TheForm.ClientWidth;
t:=CurrentCompletionType; t:=CurrentCompletionType;
if Manager.ActiveCompletionPlugin<>nil then if Manager.ActiveCompletionPlugin<>nil then
@ -2807,7 +2784,7 @@ begin
hl := nil; hl := nil;
if Editor <> nil then if Editor <> nil then
hl := Editor.Highlighter; hl := Editor.Highlighter;
PaintCompletionItem(AKey, ACanvas, X, Y, MaxX, ItemSelected, Index, self, t, hl, @Colors); PaintCompletionItem(AKey, ACanvas, X, Y, MaxX, ItemSelected, Index, self, t, hl, FColors);
Result:=true; Result:=true;
except except
DebugLn('OnSynCompletionPaintItem failed'); DebugLn('OnSynCompletionPaintItem failed');
@ -3122,6 +3099,7 @@ end;
constructor TSourceEditCompletion.Create(AOwner: TComponent); constructor TSourceEditCompletion.Create(AOwner: TComponent);
begin begin
inherited; inherited;
FColors := TSynMarkupIdentComplWindow.Create;
EndOfTokenChr:='()[].,;:-+=^*<>/'; EndOfTokenChr:='()[].,;:-+=^*<>/';
Width:=400; Width:=400;
OnExecute := @ccExecute; OnExecute := @ccExecute;
@ -3143,6 +3121,12 @@ begin
TheForm.OnDragResized := @CompletionFormResized; TheForm.OnDragResized := @CompletionFormResized;
end; end;
destructor TSourceEditCompletion.Destroy;
begin
inherited Destroy;
FColors.Free;
end;
{ TSourceEditorSharedValues } { TSourceEditorSharedValues }
function TSourceEditorSharedValues.GetSharedEditors(Index: Integer): TSourceEditor; function TSourceEditorSharedValues.GetSharedEditors(Index: Integer): TSourceEditor;

View File

@ -50,7 +50,7 @@ uses
// IdeIntf // IdeIntf
LazIDEIntf, IDEImagesIntf, TextTools, IDETextConverter, LazIDEIntf, IDEImagesIntf, TextTools, IDETextConverter,
// IDE // IDE
DialogProcs, EditorOptions, CodeToolsOptions; DialogProcs, EditorOptions, CodeToolsOptions, SourceSynEditor;
type type
@ -110,20 +110,11 @@ type
icvNone icvNone
); );
TPaintCompletionItemColors = record
BackgroundColor: TColor;
BackgroundSelectedColor: TColor;
TextColor: TColor;
TextSelectedColor: TColor;
TextHilightColor: TColor;
end;
PPaintCompletionItemColors = ^TPaintCompletionItemColors;
// completion form and functions // completion form and functions
function PaintCompletionItem(const AKey: string; ACanvas: TCanvas; function PaintCompletionItem(const AKey: string; ACanvas: TCanvas;
X, Y, MaxX: integer; ItemSelected: boolean; Index: integer; X, Y, MaxX: integer; ItemSelected: boolean; Index: integer;
{%H-}aCompletion : TSynCompletion; CurrentCompletionType: TCompletionType; {%H-}aCompletion : TSynCompletion; CurrentCompletionType: TCompletionType;
Highlighter: TSrcIDEHighlighter; Colors: PPaintCompletionItemColors; Highlighter: TSrcIDEHighlighter; Colors: TSynMarkupIdentComplWindow;
MeasureOnly: Boolean = False): TPoint; MeasureOnly: Boolean = False): TPoint;
function GetIdentCompletionValue(aCompletion : TSynCompletion; function GetIdentCompletionValue(aCompletion : TSynCompletion;
@ -155,11 +146,10 @@ begin
FreeAndNil(TextConverterToolClasses); FreeAndNil(TextConverterToolClasses);
end; end;
function PaintCompletionItem(const AKey: string; ACanvas: TCanvas; X, Y, function PaintCompletionItem(const AKey: string; ACanvas: TCanvas; X, Y, MaxX: integer;
MaxX: integer; ItemSelected: boolean; Index: integer; ItemSelected: boolean; Index: integer; aCompletion: TSynCompletion;
aCompletion: TSynCompletion; CurrentCompletionType: TCompletionType; CurrentCompletionType: TCompletionType; Highlighter: TSrcIDEHighlighter;
Highlighter: TSrcIDEHighlighter; Colors: PPaintCompletionItemColors; Colors: TSynMarkupIdentComplWindow; MeasureOnly: Boolean): TPoint;
MeasureOnly: Boolean): TPoint;
const const
HintModifierImage: array[TPascalHintModifier] of String = ( HintModifierImage: array[TPascalHintModifier] of String = (
@ -343,19 +333,26 @@ begin
begin begin
if ItemSelected then if ItemSelected then
begin begin
AllowFontColor := Colors^.TextSelectedColor=clNone; AllowFontColor := Colors.TextSelectedColor=clNone;
if AllowFontColor then if AllowFontColor then begin
ForegroundColor := ColorToRGB(Colors^.TextColor) if Colors.UseRecent then
ForegroundColor := ColorToRGB(Colors.RecentColor)
else else
ForegroundColor := ColorToRGB(Colors^.TextSelectedColor); ForegroundColor := ColorToRGB(Colors.TextColor);
BackgroundColor:=ColorToRGB(Colors^.BackgroundSelectedColor); end
else
ForegroundColor := ColorToRGB(Colors.TextSelectedColor);
BackgroundColor:=ColorToRGB(Colors.BackgroundSelectedColor);
end else end else
begin begin
ForegroundColor := ColorToRGB(Colors^.TextColor); if Colors.UseRecent then
ForegroundColor := ColorToRGB(Colors.RecentColor)
else
ForegroundColor := ColorToRGB(Colors.TextColor);
AllowFontColor := True; AllowFontColor := True;
BackgroundColor:=ColorToRGB(Colors^.BackgroundColor); BackgroundColor:=ColorToRGB(Colors.BackgroundColor);
end; end;
TextHilightColor:=ColorToRGB(Colors^.TextHilightColor); TextHilightColor:=ColorToRGB(Colors.TextHilightColor);
end else end else
begin begin
ForegroundColor := clBlack; ForegroundColor := clBlack;

View File

@ -62,7 +62,7 @@ uses
SynEditMarkupHighAll, SynEditKeyCmds, SynEditMarkupIfDef, SynEditMiscProcs, SynEditMarkupHighAll, SynEditKeyCmds, SynEditMarkupIfDef, SynEditMiscProcs,
SynPluginMultiCaret, SynEditPointClasses, SynPluginMultiCaret, SynEditPointClasses,
SynEditMarkupFoldColoring, SynEditTextTabExpander, SynEditMouseCmds, SynEditMarkupFoldColoring, SynEditTextTabExpander, SynEditMouseCmds,
etSrcEditMarks, LazarusIDEStrConsts; etSrcEditMarks, LazarusIDEStrConsts, SourceMarks;
type type
@ -220,25 +220,33 @@ type
property IfDefTree; property IfDefTree;
end; end;
TIdentWindowAhaColorRange = ahaIdentComplWindow..ahaIdentComplWindowHighlight;
{ TSynMarkupIdentComplWindow }
TSynMarkupIdentComplWindow = class // don't inherit from TSynEditMarkup, no regular markup TSynMarkupIdentComplWindow = class // don't inherit from TSynEditMarkup, no regular markup
private private
FBackgroundSelectedColor: TColor; FColor: array[TIdentWindowAhaColorRange] of TSynHighlighterAttributes;
FBorderColor: TColor; FUseRecent: boolean;
FHighlightColor: TColor;
FTextColor: TColor; function GetColor(AnIndex: TIdentWindowAhaColorRange): TSynHighlighterAttributes;
FHistoryTextColor: TColor; function GetForegroundColor(AnIndex: TAdditionalHilightAttribute): TColor;
FTextSelectedColor: TColor; function GetBackgroundColor(AnIndex: TAdditionalHilightAttribute): TColor;
FWindowColor: TColor;
public public
constructor Create; constructor Create;
destructor Destroy; override;
procedure Clear;
procedure Merge(AColors: TSynMarkupIdentComplWindow);
public public
property WindowColor: TColor read FWindowColor write FWindowColor; property Color [AnIndex: TIdentWindowAhaColorRange]: TSynHighlighterAttributes read GetColor; default;
property TextColor: TColor read FTextColor write FTextColor;
property HistoryTextColor: TColor read FHistoryTextColor write FHistoryTextColor; property TextColor: TColor index ahaIdentComplWindow read GetForegroundColor;
property BorderColor: TColor read FBorderColor write FBorderColor; property BackgroundColor: TColor index ahaIdentComplWindow read GetBackgroundColor;
property HighlightColor: TColor read FHighlightColor write FHighlightColor; property TextSelectedColor: TColor index ahaIdentComplWindowSelection read GetForegroundColor;
property TextSelectedColor: TColor read FTextSelectedColor write FTextSelectedColor; property BackgroundSelectedColor: TColor index ahaIdentComplWindowSelection read GetBackgroundColor;
property BackgroundSelectedColor: TColor read FBackgroundSelectedColor write FBackgroundSelectedColor; property TextHilightColor : TColor index ahaIdentComplWindowHighlight read GetForegroundColor;
property RecentColor: TColor index ahaIdentComplRecent read GetForegroundColor;
property UseRecent: boolean read FUseRecent write FUseRecent;
end; end;
{ TIDESynEditor } { TIDESynEditor }
@ -543,21 +551,69 @@ type
implementation implementation
uses SourceMarks;
{ TSynMarkupIdentComplWindow } { TSynMarkupIdentComplWindow }
function TSynMarkupIdentComplWindow.GetColor(AnIndex: TIdentWindowAhaColorRange
): TSynHighlighterAttributes;
begin
Result := FColor[AnIndex];
end;
function TSynMarkupIdentComplWindow.GetForegroundColor(AnIndex: TAdditionalHilightAttribute
): TColor;
begin
Result := FColor[AnIndex].Foreground;
end;
function TSynMarkupIdentComplWindow.GetBackgroundColor(AnIndex: TAdditionalHilightAttribute
): TColor;
begin
Result := FColor[AnIndex].Background
end;
constructor TSynMarkupIdentComplWindow.Create; constructor TSynMarkupIdentComplWindow.Create;
var
i: TIdentWindowAhaColorRange;
begin begin
inherited Create; inherited Create;
FBackgroundSelectedColor := clNone; for i := low(TIdentWindowAhaColorRange) to high(TIdentWindowAhaColorRange) do
FBorderColor := clNone; FColor[i] := TSynHighlighterAttributes.Create;
FHighlightColor := clNone; Clear;
FTextColor := clNone; end;
FHistoryTextColor := clNone;
FTextSelectedColor := clNone; destructor TSynMarkupIdentComplWindow.Destroy;
FWindowColor := clNone; var
i: TIdentWindowAhaColorRange;
begin
inherited Destroy;
for i := low(TIdentWindowAhaColorRange) to high(TIdentWindowAhaColorRange) do
FColor[i].Free;
end;
procedure TSynMarkupIdentComplWindow.Clear;
var
i: TIdentWindowAhaColorRange;
begin
FUseRecent := False;
for i := low(TIdentWindowAhaColorRange) to high(TIdentWindowAhaColorRange) do begin
FColor[i].Foreground := clNone;
FColor[i].Background := clNone;
end;
end;
procedure TSynMarkupIdentComplWindow.Merge(AColors: TSynMarkupIdentComplWindow);
var
i: TIdentWindowAhaColorRange;
begin
for i := low(TIdentWindowAhaColorRange) to high(TIdentWindowAhaColorRange) do begin
if AColors[i].Foreground <> clNone then
FColor[i].Foreground := AColors.FColor[i].Foreground;
if AColors[i].Background <> clNone then
FColor[i].Background := AColors.FColor[i].Background;
end;
end; end;
{ TSourceSynSearchTermDict } { TSourceSynSearchTermDict }