Skip to content

Commit 042dd8a

Browse files
committed
Add DetailFontSize preference & change font size defaults
Change font size defaults for overview pane and detail pane to get defaults that apply to underlying OS, rather than hard wiring them. Setting either detail pane or overview pane font size preferences to an out of range value resets the preference to its default value.
1 parent 4887bd1 commit 042dd8a

File tree

1 file changed

+60
-3
lines changed

1 file changed

+60
-3
lines changed

Src/UPreferences.pas

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ interface
183183
property OverviewFontSize: Integer
184184
read GetOverviewFontSize write SetOverviewFontSize;
185185

186+
/// <summary>Gets size of base font used in detail pane.</summary>
187+
function GetDetailFontSize: Integer;
188+
/// <summary>Sets size of base font used in detail pane.</summary>
189+
procedure SetDetailFontSize(const Value: Integer);
190+
/// <summary>Size of base font used in detail pane.</summary>
191+
property DetailFontSize: Integer
192+
read GetDetailFontSize write SetDetailFontSize;
193+
186194
/// <summary>Gets colour used for background of source code in main
187195
/// display.</summary>
188196
function GetSourceCodeBGColour: TColor;
@@ -289,7 +297,7 @@ implementation
289297
SysUtils,
290298
// Project
291299
Hiliter.UAttrs, Hiliter.UPersist, IntfCommon, UExceptions, UColours,
292-
USettings;
300+
UFontHelper, USettings;
293301

294302

295303
type
@@ -342,6 +350,8 @@ TPreferences = class(TInterfacedObject,
342350
/// <summary>Records size of font used in overview pane tree view.
343351
/// </summary>
344352
fOverviewFontSize: Integer;
353+
/// <summary>Records size of font used in details pane.</summary>
354+
fDetailFontSize: Integer;
345355
/// <summary>Records colour used for background of source code in main
346356
/// display.</summary>
347357
fSourceCodeBGColour: TColor;
@@ -366,6 +376,11 @@ TPreferences = class(TInterfacedObject,
366376
/// <summary>Information describing snippet detail page customisations.
367377
/// </summary>
368378
fPageStructures: TSnippetPageStructures;
379+
/// <summary>Returns default font size for overview pane tree view.
380+
/// </summary>
381+
function DefaultOverviewFontSize: Integer;
382+
/// <summary>Returns default font size for details pane.</summary>
383+
function DefaultDetailFontSize: Integer;
369384
public
370385
/// <summary>Constructs a new object instance.</summary>
371386
constructor Create;
@@ -510,6 +525,14 @@ TPreferences = class(TInterfacedObject,
510525
/// <remarks>Method of IPreferences.</remarks>
511526
procedure SetOverviewFontSize(const Value: Integer);
512527

528+
/// <summary>Gets size of base font used in detail pane.</summary>
529+
/// <remarks>Method of IPreferences.</remarks>
530+
function GetDetailFontSize: Integer;
531+
532+
/// <summary>Sets size of base font used in detail pane.</summary>
533+
/// <remarks>Method of IPreferences.</remarks>
534+
procedure SetDetailFontSize(const Value: Integer);
535+
513536
/// <summary>Gets colour used for background of source code in main
514537
/// display.</summary>
515538
/// <remarks>Method of IPreferences.</remarks>
@@ -677,6 +700,7 @@ procedure TPreferences.Assign(const Src: IInterface);
677700
Self.fDBHeadingColours[True] := SrcPref.DBHeadingColours[True];
678701
Self.fDBHeadingCustomColours[True] := SrcPref.DBHeadingCustomColours[True];
679702
Self.fOverviewFontSize := SrcPref.OverviewFontSize;
703+
Self.fDetailFontSize := SrcPref.DetailFontSize;
680704
Self.fSourceCodeBGColour := SrcPref.SourceCodeBGColour;
681705
Self.fSourceCodeBGCustomColours := SrcPref.SourceCodeBGCustomColours;
682706
Self.fPrinterOptions := SrcPref.PrinterOptions;
@@ -701,6 +725,16 @@ constructor TPreferences.Create;
701725
TDefaultPageStructures.SetDefaults(fPageStructures);
702726
end;
703727

728+
function TPreferences.DefaultDetailFontSize: Integer;
729+
begin
730+
Result := TFontHelper.GetDefaultContentFontSize;
731+
end;
732+
733+
function TPreferences.DefaultOverviewFontSize: Integer;
734+
begin
735+
Result := TFontHelper.GetDefaultFontSize;
736+
end;
737+
704738
destructor TPreferences.Destroy;
705739
begin
706740
fPageStructures.Free;
@@ -723,6 +757,11 @@ function TPreferences.GetDBHeadingCustomColours(
723757
Result := fDBHeadingCustomColours[UserDefined];
724758
end;
725759

760+
function TPreferences.GetDetailFontSize: Integer;
761+
begin
762+
Result := fDetailFontSize;
763+
end;
764+
726765
function TPreferences.GetHiliteAttrs: IHiliteAttrs;
727766
begin
728767
Result := fHiliteAttrs;
@@ -830,6 +869,14 @@ procedure TPreferences.SetDBHeadingCustomColours(UserDefined: Boolean;
830869
fDBHeadingCustomColours[UserDefined] := Value;
831870
end;
832871

872+
procedure TPreferences.SetDetailFontSize(const Value: Integer);
873+
begin
874+
if TFontHelper.IsInCommonFontSizeRange(Value) then
875+
fDetailFontSize := Value
876+
else
877+
fDetailFontSize := DefaultDetailFontSize;
878+
end;
879+
833880
procedure TPreferences.SetHiliteAttrs(const Attrs: IHiliteAttrs);
834881
begin
835882
(fHiliteAttrs as IAssignable).Assign(Attrs);
@@ -852,7 +899,10 @@ procedure TPreferences.SetNamedHiliteAttrs(NamedHiliteAttrs: INamedHiliteAttrs);
852899

853900
procedure TPreferences.SetOverviewFontSize(const Value: Integer);
854901
begin
855-
fOverviewFontSize := Value;
902+
if TFontHelper.IsInCommonFontSizeRange(Value) then
903+
fOverviewFontSize := Value
904+
else
905+
fOverviewFontSize := DefaultOverviewFontSize;
856906
end;
857907

858908
procedure TPreferences.SetOverviewStartState(const Value: TOverviewStartState);
@@ -945,6 +995,7 @@ function TPreferencesPersist.Clone: IInterface;
945995
NewPref.DBHeadingColours[True] := Self.fDBHeadingColours[True];
946996
NewPref.DBHeadingCustomColours[True] := Self.fDBHeadingCustomColours[True];
947997
NewPref.OverviewFontSize := Self.fOverviewFontSize;
998+
NewPref.DetailFontSize := Self.fDetailFontSize;
948999
NewPref.SourceCodeBGColour := Self.fSourceCodeBGColour;
9491000
NewPref.SourceCodeBGCustomColours := Self.fSourceCodeBGCustomColours;
9501001
NewPref.PrinterOptions := Self.fPrinterOptions;
@@ -999,7 +1050,12 @@ constructor TPreferencesPersist.Create;
9991050
fDBHeadingCustomColours[True] := Storage.GetStrings(
10001051
'UserDBHeadingCustomColourCount', 'UserDBHeadingCustomColour%d'
10011052
);
1002-
fOverviewFontSize := Storage.GetInteger('OverviewFontSize', 9);
1053+
fOverviewFontSize := Storage.GetInteger(
1054+
'OverviewFontSize', DefaultOverviewFontSize
1055+
);
1056+
fDetailFontSize := Storage.GetInteger(
1057+
'DetailFontSize', DefaultDetailFontSize
1058+
);
10031059
fSourceCodeBGCustomColours := Storage.GetStrings(
10041060
'SourceCodeBGCustomColourCount', 'SourceCodeBGCustomColour%d'
10051061
);
@@ -1071,6 +1127,7 @@ destructor TPreferencesPersist.Destroy;
10711127
Storage.SetInteger('MainDBHeadingColour', fDBHeadingColours[False]);
10721128
Storage.SetInteger('UserDBHeadingColour', fDBHeadingColours[True]);
10731129
Storage.SetInteger('OverviewFontSize', fOverviewFontSize);
1130+
Storage.SetInteger('DetailFontSize', fDetailFontSize);
10741131
Storage.SetInteger('SourceCodeBGColour', fSourceCodeBGColour);
10751132
Storage.SetStrings(
10761133
'MainDBHeadingCustomColourCount',

0 commit comments

Comments
 (0)