Skip to content

Commit

Permalink
Settings form: Improve editor colors
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Jun 2, 2023
1 parent 0c5f559 commit 9f5f1f3
Show file tree
Hide file tree
Showing 7 changed files with 493 additions and 380 deletions.
47 changes: 26 additions & 21 deletions Source/editor/simba.editor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface
type
TSimbaEditor = class(TSimbaSynEdit)
protected
FUseSimbaColors: Boolean;
FAutoComplete: TSimbaAutoComplete;
FParamHint: TSimbaParamHint;

Expand All @@ -42,19 +43,19 @@ TSimbaEditor = class(TSimbaSynEdit)

procedure FontChanged(Sender: TObject); override;
procedure SimbaSettingChanged(Setting: TSimbaSetting);
procedure DoSimbaSettingChanged_Colors(Setting: TSimbaSetting);

procedure DoDragDrop(Sender, Source: TObject; X, Y: Integer);
procedure DoDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);

// Temp line coloring
procedure DoSpecialLineColor(Sender: TObject; Line: Integer; var Special: Boolean; AMarkup: TSynSelectedColor);
// Enable/Disable TSynEditMarkupHighlightAllCaret depending on has selection
procedure DoStatusChanged(Sender: TObject; Changes: TSynStatusChanges);

procedure SetUpdateState(NewUpdating: Boolean; Sender: TObject); override;

procedure SetColorModified(Value: TColor);
procedure SetColorSaved(Value: TColor);
procedure SetUseSimbaColors(Value: Boolean);
public
FileName: String;

Expand All @@ -68,6 +69,7 @@ TSimbaEditor = class(TSimbaSynEdit)

property ColorSaved: TColor read FColorSaved write SetColorSaved;
property ColorModified: TColor read FColorModified write SetColorModified;
property UseSimbaColors: Boolean read FUseSimbaColors write SetUseSimbaColors;

function GetCaretPos(GoBackToWord: Boolean): Integer;

Expand All @@ -93,7 +95,7 @@ TSimbaEditor = class(TSimbaSynEdit)
procedure ClearFocusedLines;
procedure FocusLine(Line, Column: Integer; AColor: TColor);

constructor Create(AOwner: TComponent; LoadColors: Boolean = True); reintroduce;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;

Expand Down Expand Up @@ -225,20 +227,13 @@ procedure TSimbaEditor.DoDragOver(Sender, Source: TObject; X, Y: Integer; State:
Accept := Source is TTreeView;
end;

procedure TSimbaEditor.DoStatusChanged(Sender: TObject; Changes: TSynStatusChanges);
begin
ClearFocusedLines();

//if (scSelection in Changes) then
// MarkupByClass[TSynEditMarkupHighlightAllCaret].Enabled := SelAvail;
end;

procedure TSimbaEditor.SetUpdateState(NewUpdating: Boolean; Sender: TObject);
begin
inherited SetUpdateState(NewUpdating, Sender);

if (not NewUpdating) and (FLastTextChangeStamp <> ChangeStamp) then
begin
ClearFocusedLines();
if Assigned(FModifiedEvent) then
FModifiedEvent(Self);

Expand Down Expand Up @@ -278,6 +273,16 @@ procedure TSimbaEditor.SetColorSaved(Value: TColor);
ModifiedLinesGutter.ColorSaved := FColorSaved;
end;

procedure TSimbaEditor.SetUseSimbaColors(Value: Boolean);
begin
if (FUseSimbaColors = Value) then
Exit;
FUseSimbaColors := Value;

if FUseSimbaColors then
FAttributes.LoadFromFile(SimbaSettings.Editor.CustomColors.Value);
end;

procedure TSimbaEditor.FontChanged(Sender: TObject);
begin
inherited FontChanged(Sender);
Expand All @@ -301,11 +306,6 @@ procedure TSimbaEditor.SimbaSettingChanged(Setting: TSimbaSetting);
Font.Name := Setting.Value;
end;

'Editor.CustomColors':
begin
FAttributes.LoadFromFile(Setting.Value);
end;

'Editor.RightMargin':
begin
RightEdge := Setting.Value;
Expand Down Expand Up @@ -360,6 +360,12 @@ procedure TSimbaEditor.SimbaSettingChanged(Setting: TSimbaSetting);
end;
end;

procedure TSimbaEditor.DoSimbaSettingChanged_Colors(Setting: TSimbaSetting);
begin
if FUseSimbaColors then
FAttributes.LoadFromFile(Setting.Value);
end;

procedure TSimbaEditor.DoSpecialLineColor(Sender: TObject; Line: Integer; var Special: Boolean; AMarkup: TSynSelectedColor);
var
I: Integer;
Expand Down Expand Up @@ -438,7 +444,7 @@ function TSimbaEditor.GetExpressionEx(X, Y: Integer): String;
Result := GetExpression(EndX - 1, Y);
end;

constructor TSimbaEditor.Create(AOwner: TComponent; LoadColors: Boolean);
constructor TSimbaEditor.Create(AOwner: TComponent);
var
I: Integer;
begin
Expand Down Expand Up @@ -466,8 +472,6 @@ constructor TSimbaEditor.Create(AOwner: TComponent; LoadColors: Boolean);

MouseActions.AddCommand(emcOverViewGutterScrollTo, False, LazSynEditMouseCmdsTypes.mbLeft, ccSingle, cdDown, [], []);

RegisterStatusChangedHandler(@DoStatusChanged, [scCaretX, scCaretY, scModified, scSelection]);

Highlighter := TSynFreePascalSyn.Create(Self);

FScreenCaretPainterClass := TSynEditScreenCaretPainterInternal;
Expand Down Expand Up @@ -516,8 +520,6 @@ constructor TSimbaEditor.Create(AOwner: TComponent; LoadColors: Boolean);
Gutter.LineNumberPart().Visible := True;
Gutter.CodeFoldPart().Visible := True;

//if LoadColors then
// SimbaSettingChanged(SimbaSettings.Editor.CustomColors);
SimbaSettingChanged(SimbaSettings.Editor.AllowCaretPastEOL);
SimbaSettingChanged(SimbaSettings.Editor.RightMarginVisible);
SimbaSettingChanged(SimbaSettings.Editor.AntiAliased);
Expand All @@ -526,6 +528,9 @@ constructor TSimbaEditor.Create(AOwner: TComponent; LoadColors: Boolean);
SimbaSettingChanged(SimbaSettings.General.MacOSKeystrokes);

SimbaSettings.RegisterChangeHandler(@SimbaSettingChanged);

with SimbaSettings do
RegisterChangeHandler(Self, Editor.CustomColors, @DoSimbaSettingChanged_Colors);
end;

destructor TSimbaEditor.Destroy;
Expand Down
3 changes: 1 addition & 2 deletions Source/editor/simba.editor_attributes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,14 @@ constructor TSimbaEditor_Attributes.Create(Editor: TSynEdit);
MarkupInfo.Background := RGBToColor(128, 0, 128);
MarkupInfo.BackAlpha := 220;

Add('Editor.Highlight All', MarkupInfo);
Add('Editor.Find Matches', MarkupInfo);
end;

Add('Editor.Line Highlight', Editor.LineHighlightColor);
Add('Editor.Folded Code', Editor.FoldedCodeColor);
Add('Editor.Folded Code Line', Editor.FoldedCodeLineColor);
Add('Editor.Bracket Match', Editor.BracketMatchColor);
Add('Editor.Selected', Editor.SelectedColor);
Add('Editor.Highlight All', Editor.HighlightAllColor);
Add('Editor.Mouse Link', Editor.MouseLinkColor);
Add('Editor.Background', TSimbaEditor_BackgroundColorAttribute.Create());
Add('Editor.Indent Line', TSimbaEditor_IndentColorAttribute.Create());
Expand Down
1 change: 0 additions & 1 deletion Source/forms/simba.functionlistform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ TFunctionListState = record
// Sort so order is: Types, Constants, Variables, Methods
function CompareDecl(A, B: TTreeNode): Integer;
public

constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
end;
Expand Down
Loading

0 comments on commit 9f5f1f3

Please sign in to comment.