Skip to content

Commit

Permalink
Remove deprecated SimbaSettings.RegisterChangeHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Oct 1, 2023
1 parent fd13dcc commit 0e8d298
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 132 deletions.
102 changes: 49 additions & 53 deletions Source/editor/simba.editor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ TSimbaEditor = class(TSimbaSynEdit)

procedure MaybeReplaceModifiers;

procedure SimbaSettingChanged(Setting: TSimbaSetting);
procedure DoSimbaSettingChanged_Colors(Setting: TSimbaSetting);
procedure DoSettingChanged_Colors(Setting: TSimbaSetting);
procedure DoSettingChanged_AllowCaretPastEOL(Setting: TSimbaSetting);
procedure DoSettingChanged_RightMargin(Setting: TSimbaSetting);
procedure DoSettingChanged_RightMarginVisible(Setting: TSimbaSetting);
procedure DoSettingChanged_AntiAliased(Setting: TSimbaSetting);
procedure DoSettingChanged_FontSize(Setting: TSimbaSetting);
procedure DoSettingChanged_FontName(Setting: TSimbaSetting);

// Accept drop from TTreeView
procedure DoDragDrop(Sender, Source: TObject; X, Y: Integer);
Expand Down Expand Up @@ -100,8 +105,7 @@ TSimbaEditor = class(TSimbaSynEdit)
implementation

uses
SynEditPointClasses, SynGutterBase, SynGutter, SynHighlighterPas_Simba, SynEditMarkupHighAll,
LazSynEditMouseCmdsTypes, Forms,
SynEditPointClasses, SynGutter, SynHighlighterPas_Simba, SynEditMarkupHighAll, LazSynEditMouseCmdsTypes, Forms,
simba.fonthelpers, simba.editor_blockcompletion,
simba.editor_docgenerator, simba.editor_commentblock,
simba.editor_mousewheelzoom, simba.editor_multicaret,
Expand Down Expand Up @@ -290,52 +294,47 @@ procedure TSimbaEditor.MaybeReplaceModifiers;
ReplaceKeyStrokeModifiers(ssCtrl, ssMeta);
end;

procedure TSimbaEditor.SimbaSettingChanged(Setting: TSimbaSetting);
procedure TSimbaEditor.DoSettingChanged_Colors(Setting: TSimbaSetting);
begin
case Setting.Name of
'Editor.FontSize':
begin
Font.Size := Setting.Value;
end;
if FUseSimbaColors then
FAttributes.LoadFromFile(Setting.Value);
end;

'Editor.FontName':
begin
if IsFontFixed(Setting.Value) then
Font.Name := Setting.Value;
end;
procedure TSimbaEditor.DoSettingChanged_AllowCaretPastEOL(Setting: TSimbaSetting);
begin
if Setting.Value then
Options := Options + [eoTrimTrailingSpaces, eoScrollPastEol]
else
Options := Options - [eoTrimTrailingSpaces, eoScrollPastEol];
end;

'Editor.RightMargin':
begin
RightEdge := Setting.Value;
end;
procedure TSimbaEditor.DoSettingChanged_RightMargin(Setting: TSimbaSetting);
begin
RightEdge := Setting.Value;
end;

'Editor.RightMarginVisible':
begin
if Setting.Value then
Options := Options - [eoHideRightMargin]
else
Options := Options + [eoHideRightMargin];
end;
procedure TSimbaEditor.DoSettingChanged_RightMarginVisible(Setting: TSimbaSetting);
begin
if Setting.Value then
Options := Options - [eoHideRightMargin]
else
Options := Options + [eoHideRightMargin];
end;

'Editor.AntiAliased':
begin
FontAntialising := Setting.Value;
end;
procedure TSimbaEditor.DoSettingChanged_AntiAliased(Setting: TSimbaSetting);
begin
FontAntialising := Setting.Value;
end;

'Editor.AllowCaretPastEOL':
begin
if Setting.Value then
Options := Options + [eoTrimTrailingSpaces, eoScrollPastEol]
else
Options := Options - [eoTrimTrailingSpaces, eoScrollPastEol];
end;
end;
procedure TSimbaEditor.DoSettingChanged_FontSize(Setting: TSimbaSetting);
begin
Font.Size := Setting.Value;
end;

procedure TSimbaEditor.DoSimbaSettingChanged_Colors(Setting: TSimbaSetting);
procedure TSimbaEditor.DoSettingChanged_FontName(Setting: TSimbaSetting);
begin
if FUseSimbaColors then
FAttributes.LoadFromFile(Setting.Value);
if IsFontFixed(Setting.Value) then
Font.Name := Setting.Value;
end;

procedure TSimbaEditor.DoSpecialLineColor(Sender: TObject; Line: Integer; var Special: Boolean; AMarkup: TSynSelectedColor);
Expand Down Expand Up @@ -501,23 +500,20 @@ constructor TSimbaEditor.Create(AOwner: TComponent);
MaybeReplaceModifiers();
{$ENDIF}

SimbaSettingChanged(SimbaSettings.Editor.AllowCaretPastEOL);
SimbaSettingChanged(SimbaSettings.Editor.RightMarginVisible);
SimbaSettingChanged(SimbaSettings.Editor.AntiAliased);
SimbaSettingChanged(SimbaSettings.Editor.FontSize);
SimbaSettingChanged(SimbaSettings.Editor.FontName);

SimbaSettings.RegisterChangeHandler(@SimbaSettingChanged);

with SimbaSettings do
RegisterChangeHandler(Self, Editor.CustomColors, @DoSimbaSettingChanged_Colors);
begin
RegisterChangeHandler(Self, Editor.CustomColors, @DoSettingChanged_Colors);
RegisterChangeHandler(Self, Editor.AllowCaretPastEOL, @DoSettingChanged_AllowCaretPastEOL, True);
RegisterChangeHandler(Self, Editor.RightMargin, @DoSettingChanged_RightMargin, True);
RegisterChangeHandler(Self, Editor.RightMarginVisible, @DoSettingChanged_RightMarginVisible, True);
RegisterChangeHandler(Self, Editor.AntiAliased, @DoSettingChanged_AntiAliased, True);
RegisterChangeHandler(Self, Editor.FontSize, @DoSettingChanged_FontSize, True);
RegisterChangeHandler(Self, Editor.FontName, @DoSettingChanged_FontName, True);
end;
end;

destructor TSimbaEditor.Destroy;
begin
if (SimbaSettings <> nil) then
SimbaSettings.UnRegisterChangeHandler(@SimbaSettingChanged);

if (FAttributes <> nil) then
FreeAndNil(FAttributes);

Expand Down
48 changes: 27 additions & 21 deletions Source/forms/simba.main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,12 @@ TSimbaForm = class(TForm)
procedure SetupCompleted;

procedure DoColorPicked(Data: PtrInt);
procedure DoSettingChanged_Toolbar(Setting: TSimbaSetting);

procedure SimbaSettingChanged(Setting: TSimbaSetting);
procedure DoSettingChanged_Toolbar(Setting: TSimbaSetting);
procedure DoSettingChanged_CustomFontSize(Setting: TSimbaSetting);
procedure DoSettingChanged_LockLayout(Setting: TSimbaSetting);
procedure DoSettingChanged_TrayIconVisible(Setting: TSimbaSetting);
procedure DoSettingChanged_ConsoleVisible(Setting: TSimbaSetting);

procedure HandleRecentFileClick(Sender: TObject);
procedure HandleException(Sender: TObject; E: Exception);
Expand Down Expand Up @@ -638,19 +641,17 @@ procedure TSimbaForm.Setup;
SimbaIDEEvents.RegisterMethodOnScriptTabChange(@DoScriptTabChange);
SimbaIDEEvents.RegisterMethodOnScriptStateChange(@DoScriptStateChange);

SimbaSettings.RegisterChangeHandler(@SimbaSettingChanged);

with SimbaSettings do
begin
RegisterChangeHandler(Self, General.ToolbarSize, @DoSettingChanged_Toolbar, True);
RegisterChangeHandler(Self, General.ToolbarPosition, @DoSettingChanged_Toolbar, True);
RegisterChangeHandler(Self, General.ToolBarSpacing, @DoSettingChanged_Toolbar, True);
end;

SimbaSettingChanged(SimbaSettings.General.CustomFontSize);
SimbaSettingChanged(SimbaSettings.General.LockLayout);
SimbaSettingChanged(SimbaSettings.General.TrayIconVisible);
SimbaSettingChanged(SimbaSettings.General.ConsoleVisible);
RegisterChangeHandler(Self, General.CustomFontSize, @DoSettingChanged_CustomFontSize, True);
RegisterChangeHandler(Self, General.LockLayout, @DoSettingChanged_LockLayout, True);
RegisterChangeHandler(Self, General.TrayIconVisible, @DoSettingChanged_TrayIconVisible, True);
RegisterChangeHandler(Self, General.ConsoleVisible, @DoSettingChanged_ConsoleVisible, True);
end;

Application.CaptureExceptions := True;
Application.OnException := @Self.HandleException;
Expand Down Expand Up @@ -708,9 +709,6 @@ procedure TSimbaForm.FormDestroy(Sender: TObject);
FreeAndNil(FMouseLogger);
end;

if (SimbaSettings <> nil) then
SimbaSettings.UnRegisterChangeHandler(@SimbaSettingChanged);

if (FRecentFiles <> nil) then
begin
SimbaSettings.General.RecentFiles.Value := FRecentFiles.Text;
Expand Down Expand Up @@ -847,16 +845,24 @@ procedure TSimbaForm.DoSettingChanged_Toolbar(Setting: TSimbaSetting);
ToolBar.BorderSpacing.Around := Setting.Value;
end;

procedure TSimbaForm.SimbaSettingChanged(Setting: TSimbaSetting);
procedure TSimbaForm.DoSettingChanged_CustomFontSize(Setting: TSimbaSetting);
begin
SetCustomFontSize(Setting.Value);
end;

procedure TSimbaForm.DoSettingChanged_LockLayout(Setting: TSimbaSetting);
begin
SetLayoutLocked(Setting.Value);
end;

procedure TSimbaForm.DoSettingChanged_TrayIconVisible(Setting: TSimbaSetting);
begin
SetTrayIconVisible(Setting.Value);
end;

procedure TSimbaForm.DoSettingChanged_ConsoleVisible(Setting: TSimbaSetting);
begin
if (Setting = SimbaSettings.General.CustomFontSize) then
SetCustomFontSize(Setting.Value);
if (Setting = SimbaSettings.General.ConsoleVisible) then
SetConsoleVisible(Setting.Value);
if (Setting = SimbaSettings.General.LockLayout) then
SetLayoutLocked(Setting.Value);
if (Setting = SimbaSettings.General.TrayIconVisible) then
SetTrayIconVisible(Setting.Value);
SetConsoleVisible(Setting.Value);
end;

procedure TSimbaForm.MenuCloseTabClick(Sender: TObject);
Expand Down
34 changes: 18 additions & 16 deletions Source/forms/simba.outputform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ TSimbaOutputBox = class(TSimbaMemo)
end;
end;

procedure SimbaSettingChanged(Setting: TSimbaSetting);
procedure DoSettingChange_FontName(Setting: TSimbaSetting);
procedure DoSettingChange_FontSize(Setting: TSimbaSetting);
procedure DoSettingChange_FontAntiAliased(Setting: TSimbaSetting);

procedure DoOpenLink(Data: PtrInt);
procedure DoSpecialLineMarkup(Sender: TObject; Line: Integer; var Special: Boolean; AMarkup: TSynSelectedColor);
Expand Down Expand Up @@ -160,18 +162,22 @@ function TSimbaOutputBox.GetTab: TSimbaTab;
Result := TSimbaTab(Parent);
end;

procedure TSimbaOutputBox.SimbaSettingChanged(Setting: TSimbaSetting);
procedure TSimbaOutputBox.DoSettingChange_FontName(Setting: TSimbaSetting);
begin
if Setting.Equals(SimbaSettings.OutputBox.FontAntiAliased) then
FontAntialising := Setting.Value
else
if Setting.Equals(SimbaSettings.OutputBox.FontSize) then
Font.Size := Setting.Value
else
if Setting.Equals(SimbaSettings.OutputBox.FontName) and IsFontFixed(Setting.Value) then
if IsFontFixed(Setting.Value) then
Font.Name := Setting.Value;
end;

procedure TSimbaOutputBox.DoSettingChange_FontSize(Setting: TSimbaSetting);
begin
Font.Size := Setting.Value;
end;

procedure TSimbaOutputBox.DoSettingChange_FontAntiAliased(Setting: TSimbaSetting);
begin
FontAntialising := Setting.Value;
end;

procedure TSimbaOutputBox.DoOpenLink(Data: PtrInt);
begin
if (FMouseLink.DocPos.FileName <> '') then
Expand Down Expand Up @@ -244,8 +250,6 @@ procedure TSimbaOutputBox.DoMouseLinkClick(Sender: TObject; Button: TMouseButton
end;

constructor TSimbaOutputBox.Create(AOwner: TComponent);
var
Setting: TSimbaSetting;
begin
inherited Create(AOwner, False);

Expand All @@ -269,15 +273,13 @@ constructor TSimbaOutputBox.Create(AOwner: TComponent);
with MouseTextActions.Add() do
Command := emcMouseLink;

SimbaSettings.RegisterChangeHandler(@SimbaSettingChanged);
for Setting in [SimbaSettings.OutputBox.FontSize, SimbaSettings.OutputBox.FontName, SimbaSettings.OutputBox.FontAntiAliased] do
SimbaSettingChanged(Setting);
SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.OutputBox.FontName, @DoSettingChange_FontName, True);
SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.OutputBox.FontSize, @DoSettingChange_FontSize, True);
SimbaSettings.RegisterChangeHandler(Self, SimbaSettings.OutputBox.FontAntiAliased, @DoSettingChange_FontAntiAliased, True);
end;

destructor TSimbaOutputBox.Destroy;
begin
SimbaSettings.UnRegisterChangeHandler(@SimbaSettingChanged);

if (FLock <> nil) then
FreeAndNil(FLock);
if (FBuffer <> nil) then
Expand Down
4 changes: 2 additions & 2 deletions Source/forms/simba.settingsform_editor_colors.pas
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ procedure TEditorColorsFrame.Save;
FEditor.Attributes.SaveToFile(FileName);

SimbaSettings.Editor.CustomColors.Value := FileName;
SimbaSettings.Changed(SimbaSettings.Editor.CustomColors);
SimbaSettings.Editor.CustomColors.Changed();
end;

procedure TEditorColorsFrame.DoSaveButtonClick(Sender: TObject);
Expand All @@ -205,7 +205,7 @@ procedure TEditorColorsFrame.DoSaveButtonClick(Sender: TObject);
FEditor.Attributes.SaveToFile(FileName);

SimbaSettings.Editor.CustomColors.Value := FileName;
SimbaSettings.Changed(SimbaSettings.Editor.CustomColors);
SimbaSettings.Editor.CustomColors.Changed();
end;
finally
Free();
Expand Down
Loading

0 comments on commit 0e8d298

Please sign in to comment.