Menu

[r3136]: / branches / experimental / Src / TrunkSrc / UPreferences.pas  Maximize  Restore  History

Download this file

1190 lines (1027 with data), 47.7 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
{
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2006-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Implements a singletion object that exposes and persists user preferences.
}
unit UPreferences;
interface
uses
// Delphi
Graphics,
// Project
Hiliter.UGlobals, UIStringList, UMeasurement, UPrintInfo,
USnippetPageStructure, USourceFileInfo, USourceGen, UWarnings;
type
/// <summary>Possible values for startup state of overview treeview.
/// </summary>
TOverviewStartState = (
ossExpanded, // start treeview fully expanded
ossCollapsed // start treeview fully collapsed
);
type
/// <summary>Interface supported by objects that maintain user preferences.
/// </summary>
IPreferences = interface(IInterface)
['{381B9A92-B528-47E1-AC04-90E1FFFDADA7}']
/// <summary>Gets style of commenting used to describe snippets in
/// generated code.</summary>
function GetSourceCommentStyle: TCommentStyle;
/// <summary>Sets style of commenting to be used describe snippets in
/// generated code.</summary>
procedure SetSourceCommentStyle(const Value: TCommentStyle);
/// <summary>Commenting style used to describe snippets in generated source
/// code.</summary>
property SourceCommentStyle: TCommentStyle
read GetSourceCommentStyle write SetSourceCommentStyle;
/// <summary>Gets flag that determines whether multi-paragraph source code
/// is truncated to first paragraph in source code comments.</summary>
function GetTruncateSourceComments: Boolean;
/// <summary>Sets flag that determines whether multi-paragraph source code
/// is truncated to first paragraph in source code comments.</summary>
procedure SetTruncateSourceComments(const Value: Boolean);
/// <summary>Flag determining whether multi-paragraph source code is
/// truncated to first paragraph in source code comments.</summary>
property TruncateSourceComments: Boolean
read GetTruncateSourceComments write SetTruncateSourceComments;
/// <summary>Gets current default file extension / type used when writing
/// code snippets to file.</summary>
function GetSourceDefaultFileType: TSourceFileType;
/// <summary>Sets default file extension / type to be used when writing
/// code snippets to file.</summary>
procedure SetSourceDefaultFileType(const Value: TSourceFileType);
/// <summary>Default file extension / type used when writing code snippets
/// to file.</summary>
property SourceDefaultFileType: TSourceFileType
read GetSourceDefaultFileType write SetSourceDefaultFileType;
/// <summary>Gets current indicator of whether generated source is
/// highlighted by default.</summary>
function GetSourceSyntaxHilited: Boolean;
/// <summary>Sets flag indicating whether generated source is highlighted
/// by default.</summary>
procedure SetSourceSyntaxHilited(const Value: Boolean);
/// <summary>Indicates whether generated source is highlighted by default.
/// </summary>
property SourceSyntaxHilited: Boolean
read GetSourceSyntaxHilited write SetSourceSyntaxHilited;
/// <summary>Gets measurement units used by application.</summary>
function GetMeasurementUnits: TMeasurementUnits;
/// <summary>Sets measurement units to be used by application.</summary>
procedure SetMeasurementUnits(const Value: TMeasurementUnits);
/// <summary>Measurement units used by application.</summary>
property MeasurementUnits: TMeasurementUnits
read GetMeasurementUnits write SetMeasurementUnits;
/// <summary>Gets startup state of overview tree view.</summary>
function GetOverviewStartState: TOverviewStartState;
/// <summary>Sets startup state of overview tree view.</summary>
procedure SetOverviewStartState(const Value: TOverviewStartState);
/// <summary>Startup state of overview treeview.</summary>
property OverviewStartState: TOverviewStartState
read GetOverviewStartState write SetOverviewStartState;
/// <summary>Gets flag that indicates whether empty sections are displayed
/// in overview pane.</summary>
function GetShowEmptySections: Boolean;
/// <summary>Sets flag that indicates whether empty sections are displayed
/// in overview pane.</summary>
procedure SetShowEmptySections(const Value: Boolean);
/// <summary>Indicates whether empty sections are displayed in overview
/// pane.</summary>
property ShowEmptySections: Boolean
read GetShowEmptySections write SetShowEmptySections;
/// <summary>Gets flag that indicates whether new snippets and categories
/// are displayed in new tabs in details pane.</summary>
function GetShowNewSnippetsInNewTabs: Boolean;
/// <summary>Sets flag that indicates whether new snippets and categories
/// are displayed in new tabs in details pane.</summary>
procedure SetShowNewSnippetsInNewTabs(const Value: Boolean);
/// <summary>Indicates whether new snippets and ca-tegories are displayed
/// in new tabs in details pane.</summary>
property ShowNewSnippetsInNewTabs: Boolean
read GetShowNewSnippetsInNewTabs write SetShowNewSnippetsInNewTabs;
/// <summary>Gets heading colour used for snippets from a specified
/// database.</summary>
/// <param name="UserDefined">Boolean [in] Required database: True for user
/// database and False for inline database.</param>
/// <returns>TColor. Required colour.</returns>
function GetDBHeadingColour(UserDefined: Boolean): TColor;
/// <summary>Sets heading colour used for snippets from a specified
/// database.</summary>
/// <param name="UserDefined">Boolean [in] Required database: True for user
/// database and False for online database.</param>
/// <param name="Value">TColor [in] Required heading colour.</param>
procedure SetDBHeadingColour(UserDefined: Boolean;
const Value: TColor);
/// <summary>Records colour to be used for headings of items from either
/// online database (UserDefined = False) or user database (UserDefined =
/// True).</summary>
property DBHeadingColours[UserDefined: Boolean]: TColor
read GetDBHeadingColour write SetDBHeadingColour;
/// <summary>Gets custom colours available for headings for specified
/// database.</summary>
/// <param name="UserDefined">Boolean [in] Required database: True for user
/// database and False for online database.</param>
/// <returns>IStringList. String list containing custom colours.</returns>
function GetDBHeadingCustomColours(UserDefined: Boolean): IStringList;
/// <summary>Sets custom colours available for headings for specified
/// database.</summary>
/// <param name="UserDefined">Boolean [in] Required database: True for user
/// database and False for online database.</param>
/// <param name="Value">IStringList [in] String list containing custom
/// colours.</param>
procedure SetDBHeadingCustomColours(UserDefined: Boolean;
Value: IStringList);
/// <summary>Records custom colours available for headings of items from
/// either online database (UserDefined = False) or user database
/// (UserDefined = True).</summary>
property DBHeadingCustomColours[UserDefined: Boolean]: IStringList
read GetDBHeadingCustomColours write SetDBHeadingCustomColours;
/// <summary>Gets colour used for background of source code in main
/// display.</summary>
function GetSourceCodeBGColour: TColor;
/// <summary>Sets colour used for background of source code in main
/// display.</summary>
procedure SetSourceCodeBGColour(const Value: TColor);
/// <summary>Colour used for background of source code in main display.
/// </summary>
property SourceCodeBGColour: TColor
read GetSourceCodeBGColour write SetSourceCodeBGColour;
/// <summary>Gets custom colours available for use as background colour of
/// source code in main display as a string list.</summary>
function GetSourceCodeBGCustomColours: IStringList;
/// <summary>Sets custom colours available for use as background colour of
/// source code in main display from given string list.</summary>
procedure SetSourceCodeBGCustomColours(Value: IStringList);
/// <summary>Records custom colours available for use as background colour
/// of source code in main display as a string list.</summary>
property SourceCodeBGCustomColours: IStringList
read GetSourceCodeBGCustomColours write SetSourceCodeBGCustomColours;
/// <summary>Gets default print options.</summary>
function GetPrinterOptions: TPrintOptions;
/// <summary>Sets default print options.</summary>
procedure SetPrinterOptions(const Options: TPrintOptions);
/// <summary>Default print options.</summary>
property PrinterOptions: TPrintOptions
read GetPrinterOptions write SetPrinterOptions;
/// <summary>Gets default printer page margins.</summary>
function GetPrinterPageMargins: TPageMargins;
/// <summary>Sets new default printer page margins.</summary>
procedure SetPrinterPageMargins(const Margins: TPageMargins);
/// <summary>Default printer page margins.</summary>
property PrinterPageMargins: TPageMargins
read GetPrinterPageMargins write SetPrinterPageMargins;
/// <summary>Gets current user defined syntax highlighter.</summary>
function GetHiliteAttrs: IHiliteAttrs;
/// <summary>Sets current user defined syntax highlighter.</summary>
procedure SetHiliteAttrs(const Attrs: IHiliteAttrs);
/// <summary>Attributes of current user defined syntax highlighter.
/// </summary>
property HiliteAttrs: IHiliteAttrs
read GetHiliteAttrs write SetHiliteAttrs;
/// <summary>Gets object containing the attributes of all the named user
/// defined syntax highlighters.</summary>
function GetNamedHiliteAttrs: INamedHiliteAttrs;
/// <summary>Stores a copy of the given object containing the attributes of
/// all the 'named' user defined syntax highlighters.</summary>
procedure SetNamedHiliteAttrs(NamedHiliteAttrs: INamedHiliteAttrs);
/// <summary>Reference tp object containing attributes of all the 'named'
/// user defined syntax highlighters.</summary>
property NamedHiliteAttrs: INamedHiliteAttrs
read GetNamedHiliteAttrs write SetNamedHiliteAttrs;
/// <summary>Gets custom colours available for syntax highlighter.
/// </summary>
function GetCustomHiliteColours: IStringList;
/// <summary>Sets custom colours available for syntax highlighter.
/// </summary>
procedure SetCustomHiliteColours(const Colours: IStringList);
/// <summary>Custom colours available for syntax highlighters.</summary>
property CustomHiliteColours: IStringList
read GetCustomHiliteColours write SetCustomHiliteColours;
/// <summary>Gets object containing information about warnings to be
/// enabled or disabled by code generator.</summary>
function GetWarnings: IWarnings;
/// <summary>Stores a copy of the object containing information about
/// warnings to be enabled or disabled by code generator.</summary>
procedure SetWarnings(Warnings: IWarnings);
/// <summary>Reference to object containing information about warnings to
/// be enabled or disabled by code generator.</summary>
property Warnings: IWarnings
read GetWarnings write SetWarnings;
/// <summary>Gets maximum age of items to be read from news feed.</summary>
function GetNewsAge: Integer;
/// <summary>Sets maximum age of items to be read from news feed.</summary>
procedure SetNewsAge(const Age: Integer);
/// <summary>Maximum age of items to be read from news feed.</summary>
property NewsAge: Integer
read GetNewsAge write SetNewsAge;
/// <summary>Gets information describing snippet detail page
/// customisations.</summary>
function GetPageStructures: TSnippetPageStructures;
/// <summary>Updates information describing snippet detail page
/// customisations.</summary>
procedure SetPageStructures(PageStructures: TSnippetPageStructures);
/// <summary>Information describing snippet detail page customisations.
/// </summary>
property PageStructures: TSnippetPageStructures
read GetPageStructures write SetPageStructures;
/// <summary>Gets frequency, in days, that the program should automatically
/// check for program updates.</summary>
function GetAutoCheckProgramFrequency: Word;
/// <summary>Sets frequency, in days, that the program should automatically
/// check for program updates.</summary>
procedure SetAutoCheckProgramFrequency(const Value: Word);
/// <summary>Frequency, in days, that the program should automatically
/// check for program updates.</summary>
/// <remarks>A value of zero indicates that no update checking should
/// take place.</remarks>
property AutoCheckProgramFrequency: Word
read GetAutoCheckProgramFrequency write SetAutoCheckProgramFrequency;
/// <summary>Gets frequency, in days, that the program should automatically
/// check for database updates.</summary>
function GetAutoCheckDatabaseFrequency: Word;
/// <summary>Sets frequency, in days, that the program should automatically
/// check for database updates.</summary>
procedure SetAutoCheckDatabaseFrequency(const Value: Word);
/// <summary>Frequency, in days, that the program should automatically
/// check for database updates.</summary>
/// <remarks>A value of zero indicates that no update checking should
/// take place.</remarks>
property AutoCheckDatabaseFrequency: Word
read GetAutoCheckDatabaseFrequency write SetAutoCheckDatabaseFrequency;
end;
/// <summary>Provides access to a singleton implementation IPreferences that
/// can also persist the preferences.</summary>
function Preferences: IPreferences;
implementation
uses
// Delphi
SysUtils,
// Project
Hiliter.UAttrs, Hiliter.UPersist, IntfCommon, UExceptions, UColours,
USettings;
type
/// <summary>Class that maintains a copy of the user preferences.</summary>
/// <remarks>
/// <para>This class does not persist the preferences. It is intended for
/// use as a temporary local copy of the preferences singleton for
/// modification.</para>
/// <para>To save changes made to an instance of this class, assign the
/// instance to the singleton.</para>
/// <para>Instances should not be created directly: the singleton's Clone
/// method must be used to do this.</para>
/// </remarks>
TPreferences = class(TInterfacedObject,
IPreferences, IAssignable
)
strict protected
var
/// <summary>Default file extension / type used when writing code
/// snippets file.</summary>
fSourceDefaultFileType: TSourceFileType;
/// <summary>Commenting style used to describe snippets in generated
/// source code.</summary>
fSourceCommentStyle: TCommentStyle;
/// <summary>Flag determining whether multi-paragraph source code is
/// truncated to first paragraph in source code comments.</summary>
fTruncateSourceComments: Boolean;
/// <summary>Indicates whether generated source is highlighted by
/// default.</summary>
fSourceSyntaxHilited: Boolean;
/// <summary>Measurement units used by application.</summary>
fMeasurementUnits: TMeasurementUnits;
/// <summary>Startup state of overview treeview.</summary>
fOverviewStartState: TOverviewStartState;
/// <summary>Indicates whether empty sections are displayed in overview
/// pane.</summary>
fShowEmptySections: Boolean;
/// <summary>Indicates whether new snippets and ca-tegories are displayed
/// in new tabs in details pane.</summary>
fShowNewSnippetsInNewTabs: Boolean;
/// <summary>Records colour to be used for headings of items from either
/// online database (UserDefined = False) or user database (UserDefined =
/// True).</summary>
fDBHeadingColours: array[Boolean] of TColor;
/// <summary>Records custom colours available for headings of items from
/// either online database (UserDefined = False) or user database
/// (UserDefined = True).</summary>
fDBHeadingCustomColours: array[Boolean] of IStringList;
/// <summary>Records colour used for background of source code in main
/// display.</summary>
fSourceCodeBGColour: TColor;
/// <summary>Records custom colours available for use as background
/// colour of source code in main display.</summary>
fSourceCodeBGCustomColours: IStringList;
/// <summary>Default print options.</summary>
fPrinterOptions: TPrintOptions;
/// <summary>Default printer page margins.</summary>
fPrinterPageMargins: TPageMargins;
/// <summary>Attributes of current user defined syntax highlighter.
/// </summary>
fHiliteAttrs: IHiliteAttrs;
/// <summary>Reference tp object containing attributes of all the 'named'
/// user defined syntax highlighters.</summary>
fNamedHiliteAttrs: INamedHiliteAttrs;
/// <summary>Custom colours available for syntax highlighters.</summary>
fHiliteCustomColours: IStringList;
/// <summary>Reference to object containing information about warnings to
/// be enabled or disabled by code generator.</summary>
fWarnings: IWarnings;
/// <summary>Maximum age of items to be read from news feed.</summary>
fNewsAge: Integer;
/// <summary>Information describing snippet detail page customisations.
/// </summary>
fPageStructures: TSnippetPageStructures;
/// <summary>Frequency, in days, that the program should automatically
/// check for program updates.</summary>
/// <remarks>A value of zero indicates that no update checking should
/// take place.</remarks>
fAutoCheckProgramFrequency: Word;
/// <summary>Frequency, in days, that the program should automatically
/// check for database updates.</summary>
/// <remarks>A value of zero indicates that no update checking should
/// take place.</remarks>
fAutoCheckDatabaseFrequency: Word;
public
/// <summary>Constructs a new object instance.</summary>
constructor Create;
/// <summary>Destroys object instance.</summary>
destructor Destroy; override;
/// <summary>Gets style of commenting used to describe snippets in
/// generated code.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetSourceCommentStyle: TCommentStyle;
/// <summary>Sets style of commenting to be used describe snippets in
/// generated code.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetSourceCommentStyle(const Value: TCommentStyle);
/// <summary>Gets flag that determines whether multi-paragraph source code
/// is truncated to first paragraph in source code comments.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetTruncateSourceComments: Boolean;
/// <summary>Sets flag that determines whether multi-paragraph source code
/// is truncated to first paragraph in source code comments.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetTruncateSourceComments(const Value: Boolean);
/// <summary>Gets current default file extension / type used when writing
/// code snippets to file.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetSourceDefaultFileType: TSourceFileType;
/// <summary>Sets default file extension / type to be used when writing
/// code snippets to file.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetSourceDefaultFileType(const Value: TSourceFileType);
/// <summary>Gets current indicator of whether generated source is
/// highlighted by default.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetSourceSyntaxHilited: Boolean;
/// <summary>Sets flag indicating whether generated source is highlighted
/// by default.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetSourceSyntaxHilited(const Value: Boolean);
/// <summary>Gets measurement units used by application.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetMeasurementUnits: TMeasurementUnits;
/// <summary>Sets measurement units to be used by application.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetMeasurementUnits(const Value: TMeasurementUnits);
/// <summary>Gets startup state of overview tree view.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetOverviewStartState: TOverviewStartState;
/// <summary>Sets startup state of overview tree view.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetOverviewStartState(const Value: TOverviewStartState);
/// <summary>Gets flag that indicates whether empty sections are displayed
/// in overview pane.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetShowEmptySections: Boolean;
/// <summary>Sets flag that indicates whether empty sections are displayed
/// in overview pane.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetShowEmptySections(const Value: Boolean);
/// <summary>Gets flag that indicates whether new snippets and categories
/// are displayed in new tabs in details pane.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetShowNewSnippetsInNewTabs: Boolean;
/// <summary>Sets flag that indicates whether new snippets and categories
/// are displayed in new tabs in details pane.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetShowNewSnippetsInNewTabs(const Value: Boolean);
/// <summary>Gets heading colour used for snippets from a specified
/// database.</summary>
/// <param name="UserDefined">Boolean [in] Required database: True for user
/// database and False for inline database.</param>
/// <returns>TColor. Required colour.</returns>
/// <remarks>Method of IPreferences.</remarks>
function GetDBHeadingColour(UserDefined: Boolean): TColor;
/// <summary>Sets heading colour used for snippets from a specified
/// database.</summary>
/// <param name="UserDefined">Boolean [in] Required database: True for user
/// database and False for online database.</param>
/// <param name="Value">TColor [in] Required heading colour.</param>
/// <remarks>Method of IPreferences.</remarks>
procedure SetDBHeadingColour(UserDefined: Boolean;
const Value: TColor);
/// <summary>Gets custom colours available for headings for specified
/// database.</summary>
/// <param name="UserDefined">Boolean [in] Required database: True for user
/// database and False for online database.</param>
/// <returns>IStringList. String list containing custom colours.</returns>
/// <remarks>Method of IPreferences.</remarks>
function GetDBHeadingCustomColours(UserDefined: Boolean): IStringList;
/// <summary>Sets custom colours available for headings for specified
/// database.</summary>
/// <param name="UserDefined">Boolean [in] Required database: True for user
/// database and False for online database.</param>
/// <param name="Value">IStringList [in] String list containing custom
/// colours.</param>
/// <remarks>Method of IPreferences.</remarks>
procedure SetDBHeadingCustomColours(UserDefined: Boolean;
Value: IStringList);
/// <summary>Gets colour used for background of source code in main
/// display.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetSourceCodeBGColour: TColor;
/// <summary>Sets colour used for background of source code in main
/// display.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetSourceCodeBGColour(const Value: TColor);
/// <summary>Gets custom colours available for use as background colour of
/// source code in main display as a string list.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetSourceCodeBGCustomColours: IStringList;
/// <summary>Sets custom colours available for use as background colour of
/// source code in main display from given string list.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetSourceCodeBGCustomColours(Value: IStringList);
/// <summary>Gets default print options.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetPrinterOptions: TPrintOptions;
/// <summary>Sets default print options.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetPrinterOptions(const Options: TPrintOptions);
/// <summary>Gets default printer page margins.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetPrinterPageMargins: TPageMargins;
/// <summary>Sets new default printer page margins.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetPrinterPageMargins(const Margins: TPageMargins);
/// <summary>Gets current user defined syntax highlighter.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetHiliteAttrs: IHiliteAttrs;
/// <summary>Sets current user defined syntax highlighter.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetHiliteAttrs(const Attrs: IHiliteAttrs);
/// <summary>Gets object containing the attributes of all the named user
/// defined syntax highlighters.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetNamedHiliteAttrs: INamedHiliteAttrs;
/// <summary>Stores a copy of the given object containing the attributes of
/// all the 'named' user defined syntax highlighters.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetNamedHiliteAttrs(NamedHiliteAttrs: INamedHiliteAttrs);
/// <summary>Gets custom colours available for syntax highlighter.
/// </summary>
/// <remarks>Method of IPreferences.</remarks>
function GetCustomHiliteColours: IStringList;
/// <summary>Sets custom colours available for syntax highlighter.
/// </summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetCustomHiliteColours(const Colours: IStringList);
/// <summary>Gets object containing information about warnings to be
/// enabled or disabled by code generator.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetWarnings: IWarnings;
/// <summary>Stores a copy of the object containing information about
/// warnings to be enabled or disabled by code generator.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetWarnings(Warnings: IWarnings);
/// <summary>Gets maximum age of items to be read from news feed.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetNewsAge: Integer;
/// <summary>Sets maximum age of items to be read from news feed.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetNewsAge(const Age: Integer);
/// <summary>Gets information describing snippet detail page
/// customisations.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetPageStructures: TSnippetPageStructures;
/// <summary>Updates information describing snippet detail page
/// customisations.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetPageStructures(PageStructures: TSnippetPageStructures);
/// <summary>Gets frequency, in days, that the program should automatically
/// check for program updates.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetAutoCheckProgramFrequency: Word;
/// <summary>Sets frequency, in days, that the program should automatically
/// check for program updates.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetAutoCheckProgramFrequency(const Value: Word);
/// <summary>Gets frequency, in days, that the program should automatically
/// check for database updates.</summary>
/// <remarks>Method of IPreferences.</remarks>
function GetAutoCheckDatabaseFrequency: Word;
/// <summary>Sets frequency, in days, that the program should automatically
/// check for database updates.</summary>
/// <remarks>Method of IPreferences.</remarks>
procedure SetAutoCheckDatabaseFrequency(const Value: Word);
/// <summary>Assigns the properties of the given object to this object.
/// </summary>
/// <exceptions>Raises EBug if Src does not support IPreferences.
/// </exceptions>
/// <remarks>Method of IAssignable</remarks>
procedure Assign(const Src: IInterface);
end;
type
/// <summary>Descendant class that adds the ability to persist preferences to
/// storage.</summary>
/// <remarks>Designed for use as a singleton with the ability to create
/// non-persistent clones of itself that can be used for editing. Data from
/// such clones can be assigned to the singleton.</remarks>
TPreferencesPersist = class(TPreferences,
IPreferences, IAssignable, IClonable
)
strict private
const
// Sub-sections of ssPreferences ini file section
cGeneral = 'General';
cSourceCode = 'SourceCode';
cPrinting = 'Printing';
cHiliter = 'Hiliter';
cCodeGenerator = 'CodeGen';
cNews = 'News';
cDisplay = 'Display';
cPageStructures = 'SnippetPageStructure';
cUpdating = 'Updating';
class var
/// <summary>Stores reference to singleton instance of this class.
/// </summary>
fInstance: IPreferences;
strict private
/// <summary>Returns singleton instance initialised from persistent
/// storage.</summary>
class function GetInstance: IPreferences; static;
public
/// <summary>Creates a new object instance and reads properties from
/// persistent storage.</summary>
constructor Create;
/// <summary>Writes properties to persistent storage then destroys the
/// instance.</summary>
destructor Destroy; override;
/// <summary>Creates a new non-persistent instance that is a copy of this
/// object.</summary>
/// <remarks>Method of IClonable.</remarks>
function Clone: IInterface;
/// <summary>Returns a reference to a singleton instance of the class.
/// </summary>
class property Instance: IPreferences
read GetInstance;
end;
function Preferences: IPreferences;
begin
Result := TPreferencesPersist.Instance;
end;
{ TPreferences }
procedure TPreferences.Assign(const Src: IInterface);
var
SrcPref: IPreferences; // IPreferences interface of Src
begin
// Get IPreferences interface of given object
if not Supports(Src, IPreferences, SrcPref) then
raise EBug.Create(ClassName + '.Assign: Src is wrong type');
// Copy the data
Self.fSourceDefaultFileType := SrcPref.SourceDefaultFileType;
Self.fSourceCommentStyle := SrcPref.SourceCommentStyle;
Self.fTruncateSourceComments := SrcPref.TruncateSourceComments;
Self.fSourceSyntaxHilited := SrcPref.SourceSyntaxHilited;
Self.fMeasurementUnits := SrcPref.MeasurementUnits;
Self.fOverviewStartState := SrcPref.OverviewStartState;
Self.fShowEmptySections := SrcPref.ShowEmptySections;
Self.fShowNewSnippetsInNewTabs := SrcPref.ShowNewSnippetsInNewTabs;
Self.fDBHeadingColours[False] := SrcPref.DBHeadingColours[False];
Self.fDBHeadingCustomColours[False] := SrcPref.DBHeadingCustomColours[False];
Self.fDBHeadingColours[True] := SrcPref.DBHeadingColours[True];
Self.fDBHeadingCustomColours[True] := SrcPref.DBHeadingCustomColours[True];
Self.fSourceCodeBGColour := SrcPref.SourceCodeBGColour;
Self.fSourceCodeBGCustomColours := SrcPref.SourceCodeBGCustomColours;
Self.fPrinterOptions := SrcPref.PrinterOptions;
Self.fPrinterPageMargins := SrcPref.PrinterPageMargins;
Self.SetHiliteAttrs(SrcPref.HiliteAttrs);
Self.SetNamedHiliteAttrs(SrcPref.NamedHiliteAttrs);
Self.SetCustomHiliteColours(SrcPref.CustomHiliteColours);
Self.SetWarnings(SrcPref.Warnings);
Self.SetNewsAge(SrcPref.NewsAge);
Self.SetPageStructures(SrcPref.PageStructures);
Self.fAutoCheckProgramFrequency := SrcPref.AutoCheckProgramFrequency;
Self.fAutoCheckDatabaseFrequency := SrcPref.AutoCheckDatabaseFrequency;
end;
constructor TPreferences.Create;
begin
inherited Create;
fHiliteAttrs := THiliteAttrsFactory.CreateDefaultAttrs;
fNamedHiliteAttrs := THiliteAttrsFactory.CreateNamedAttrs;
fHiliteCustomColours := TIStringList.Create;
fWarnings := TWarnings.Create;
fDBHeadingCustomColours[False] := TIStringList.Create;
fDBHeadingCustomColours[True] := TIStringList.Create;
fPageStructures := TSnippetPageStructures.Create;
TDefaultPageStructures.SetDefaults(fPageStructures);
end;
destructor TPreferences.Destroy;
begin
fPageStructures.Free;
inherited;
end;
function TPreferences.GetAutoCheckDatabaseFrequency: Word;
begin
Result := fAutoCheckDatabaseFrequency;
end;
function TPreferences.GetAutoCheckProgramFrequency: Word;
begin
Result := fAutoCheckProgramFrequency;
end;
function TPreferences.GetCustomHiliteColours: IStringList;
begin
Result := fHiliteCustomColours;
end;
function TPreferences.GetDBHeadingColour(UserDefined: Boolean): TColor;
begin
Result := fDBHeadingColours[UserDefined];
end;
function TPreferences.GetDBHeadingCustomColours(
UserDefined: Boolean): IStringList;
begin
Result := fDBHeadingCustomColours[UserDefined];
end;
function TPreferences.GetHiliteAttrs: IHiliteAttrs;
begin
Result := fHiliteAttrs;
end;
function TPreferences.GetMeasurementUnits: TMeasurementUnits;
begin
Result := fMeasurementUnits;
end;
function TPreferences.GetNamedHiliteAttrs: INamedHiliteAttrs;
begin
Result := fNamedHiliteAttrs;
end;
function TPreferences.GetNewsAge: Integer;
begin
Result := fNewsAge;
end;
function TPreferences.GetOverviewStartState: TOverviewStartState;
begin
Result := fOverviewStartState;
end;
function TPreferences.GetPageStructures: TSnippetPageStructures;
begin
Result := fPageStructures;
end;
function TPreferences.GetPrinterOptions: TPrintOptions;
begin
Result := fPrinterOptions;
end;
function TPreferences.GetPrinterPageMargins: TPageMargins;
begin
Result := fPrinterPageMargins;
end;
function TPreferences.GetShowEmptySections: Boolean;
begin
Result := fShowEmptySections;
end;
function TPreferences.GetShowNewSnippetsInNewTabs: Boolean;
begin
Result := fShowNewSnippetsInNewTabs;
end;
function TPreferences.GetSourceCodeBGColour: TColor;
begin
Result := fSourceCodeBGColour;
end;
function TPreferences.GetSourceCodeBGCustomColours: IStringList;
begin
Result := fSourceCodeBGCustomColours;
end;
function TPreferences.GetSourceCommentStyle: TCommentStyle;
begin
Result := fSourceCommentStyle;
end;
function TPreferences.GetSourceDefaultFileType: TSourceFileType;
begin
Result := fSourceDefaultFileType;
end;
function TPreferences.GetSourceSyntaxHilited: Boolean;
begin
Result := fSourceSyntaxHilited;
end;
function TPreferences.GetTruncateSourceComments: Boolean;
begin
Result := fTruncateSourceComments;
end;
function TPreferences.GetWarnings: IWarnings;
begin
Result := fWarnings;
end;
procedure TPreferences.SetAutoCheckDatabaseFrequency(const Value: Word);
begin
fAutoCheckDatabaseFrequency := Value;
end;
procedure TPreferences.SetAutoCheckProgramFrequency(const Value: Word);
begin
fAutoCheckProgramFrequency := Value;
end;
procedure TPreferences.SetCustomHiliteColours(const Colours: IStringList);
begin
fHiliteCustomColours := Colours;
end;
procedure TPreferences.SetDBHeadingColour(UserDefined: Boolean;
const Value: TColor);
begin
fDBHeadingColours[UserDefined] := Value;
end;
procedure TPreferences.SetDBHeadingCustomColours(UserDefined: Boolean;
Value: IStringList);
begin
fDBHeadingCustomColours[UserDefined] := Value;
end;
procedure TPreferences.SetHiliteAttrs(const Attrs: IHiliteAttrs);
begin
(fHiliteAttrs as IAssignable).Assign(Attrs);
end;
procedure TPreferences.SetMeasurementUnits(const Value: TMeasurementUnits);
begin
fMeasurementUnits := Value;
end;
procedure TPreferences.SetNamedHiliteAttrs(NamedHiliteAttrs: INamedHiliteAttrs);
begin
(fNamedHiliteAttrs as IAssignable).Assign(NamedHiliteAttrs);
end;
procedure TPreferences.SetNewsAge(const Age: Integer);
begin
fNewsAge := Age;
end;
procedure TPreferences.SetOverviewStartState(const Value: TOverviewStartState);
begin
fOverviewStartState := Value;
end;
procedure TPreferences.SetPageStructures(
PageStructures: TSnippetPageStructures);
begin
fPageStructures.Assign(PageStructures);
end;
procedure TPreferences.SetPrinterOptions(const Options: TPrintOptions);
begin
fPrinterOptions := Options;
end;
procedure TPreferences.SetPrinterPageMargins(const Margins: TPageMargins);
begin
fPrinterPageMargins := Margins;
end;
procedure TPreferences.SetShowEmptySections(const Value: Boolean);
begin
fShowEmptySections := Value;
end;
procedure TPreferences.SetShowNewSnippetsInNewTabs(const Value: Boolean);
begin
fShowNewSnippetsInNewTabs := Value;
end;
procedure TPreferences.SetSourceCodeBGColour(const Value: TColor);
begin
fSourceCodeBGColour := Value;
end;
procedure TPreferences.SetSourceCodeBGCustomColours(Value: IStringList);
begin
fSourceCodeBGCustomColours := Value;
end;
procedure TPreferences.SetSourceCommentStyle(const Value: TCommentStyle);
begin
fSourceCommentStyle := Value;
end;
procedure TPreferences.SetSourceDefaultFileType(const Value: TSourceFileType);
begin
fSourceDefaultFileType := Value;
end;
procedure TPreferences.SetSourceSyntaxHilited(const Value: Boolean);
begin
fSourceSyntaxHilited := Value;
end;
procedure TPreferences.SetTruncateSourceComments(const Value: Boolean);
begin
fTruncateSourceComments := Value;
end;
procedure TPreferences.SetWarnings(Warnings: IWarnings);
begin
(fWarnings as IAssignable).Assign(Warnings);
end;
{ TPreferencesPersist }
function TPreferencesPersist.Clone: IInterface;
var
NewPref: IPreferences; // reference to new object's IPreferences interface
begin
// Create new object
Result := TPreferences.Create;
// Copy properties to it
NewPref := Result as IPreferences;
NewPref.SourceDefaultFileType := Self.fSourceDefaultFileType;
NewPref.SourceCommentStyle := Self.fSourceCommentStyle;
NewPref.TruncateSourceComments := Self.fTruncateSourceComments;
NewPref.SourceSyntaxHilited := Self.fSourceSyntaxHilited;
NewPref.MeasurementUnits := Self.fMeasurementUnits;
NewPref.OverviewStartState := Self.fOverviewStartState;
NewPref.ShowEmptySections := Self.fShowEmptySections;
NewPref.ShowNewSnippetsInNewTabs := Self.fShowNewSnippetsInNewTabs;
NewPref.DBHeadingColours[False] := Self.fDBHeadingColours[False];
NewPref.DBHeadingCustomColours[False] := Self.fDBHeadingCustomColours[False];
NewPref.DBHeadingColours[True] := Self.fDBHeadingColours[True];
NewPref.DBHeadingCustomColours[True] := Self.fDBHeadingCustomColours[True];
NewPref.SourceCodeBGColour := Self.fSourceCodeBGColour;
NewPref.SourceCodeBGCustomColours := Self.fSourceCodeBGCustomColours;
NewPref.PrinterOptions := Self.fPrinterOptions;
NewPref.PrinterPageMargins := Self.fPrinterPageMargins;
NewPref.HiliteAttrs := Self.GetHiliteAttrs;
NewPref.NamedHiliteAttrs := Self.GetNamedHiliteAttrs;
NewPref.CustomHiliteColours := Self.GetCustomHiliteColours;
NewPref.Warnings := Self.GetWarnings;
NewPref.NewsAge := Self.fNewsAge;
NewPref.PageStructures := Self.fPageStructures;
NewPref.AutoCheckProgramFrequency := Self.fAutoCheckProgramFrequency;
NewPref.AutoCheckDatabaseFrequency := Self.fAutoCheckDatabaseFrequency;
end;
constructor TPreferencesPersist.Create;
var
Storage: ISettingsSection; // object used to access persistent storage
const
// Default margin size in millimeters
cPrintPageMarginSizeMM = 25.0;
// Default maximum age of news items
cDefNewsAge = 92;
begin
inherited Create;
// Read general section
Storage := Settings.ReadSection(ssPreferences, cGeneral);
fMeasurementUnits := TMeasurementUnits(
Storage.GetInteger('Units', Ord(DefaultMeasurementUnits))
);
// Read display section
Storage := Settings.ReadSection(ssPreferences, cDisplay);
fOverviewStartState := TOverviewStartState(
Storage.GetInteger('OverviewStartState', Ord(ossExpanded))
);
fShowEmptySections := Storage.GetBoolean('ShowEmptySections', False);
fShowNewSnippetsInNewTabs := Storage.GetBoolean(
'ShowNewSnippetsInNewTabs', False
);
fDBHeadingColours[False] := TColor(
Storage.GetInteger('MainDBHeadingColour', clMainSnippet)
);
fDBHeadingColours[True] := TColor(
Storage.GetInteger('UserDBHeadingColour', clUserSnippet)
);
fSourceCodeBGColour := TColor(
Storage.GetInteger('SourceCodeBGColour', clSourceBg)
);
fDBHeadingCustomColours[False] := Storage.GetStrings(
'MainDBHeadingCustomColourCount', 'MainDBHeadingCustomColour%d'
);
fDBHeadingCustomColours[True] := Storage.GetStrings(
'UserDBHeadingCustomColourCount', 'UserDBHeadingCustomColour%d'
);
fSourceCodeBGCustomColours := Storage.GetStrings(
'SourceCodeBGCustomColourCount', 'SourceCodeBGCustomColour%d'
);
// Read source code section
Storage := Settings.ReadSection(ssPreferences, cSourceCode);
fSourceDefaultFileType := TSourceFileType(
Storage.GetInteger('FileType', Ord(sfPascal))
);
fSourceCommentStyle := TCommentStyle(
Storage.GetInteger('CommentStyle', Ord(csAfter))
);
fTruncateSourceComments := Storage.GetBoolean('TruncateComments', False);
fSourceSyntaxHilited := Storage.GetBoolean('UseSyntaxHiliting', False);
// Read printing section
Storage := Settings.ReadSection(ssPreferences, cPrinting);
fPrinterOptions := [];
if Storage.GetBoolean('UseColor', True) then
Include(fPrinterOptions, poUseColor);
if Storage.GetBoolean('SyntaxPrint', True) then
Include(fPrinterOptions, poSyntaxPrint);
fPrinterPageMargins := TPageMargins.Create(
Storage.GetFloat('LeftMargin', cPrintPageMarginSizeMM),
Storage.GetFloat('TopMargin', cPrintPageMarginSizeMM),
Storage.GetFloat('RightMargin', cPrintPageMarginSizeMM),
Storage.GetFloat('BottomMargin', cPrintPageMarginSizeMM)
);
// Read syntax highlighter section
Storage := Settings.ReadSection(ssPreferences, cHiliter);
// syntax highlighter attributes
THiliterPersist.Load(Storage, fHiliteAttrs);
THiliterPersist.LoadNamed(Storage, fNamedHiliteAttrs);
// custom colours
fHiliteCustomColours := Storage.GetStrings(
'CustomColourCount', 'CustomColour%d'
);
// Read code generator section
Storage := Settings.ReadSection(ssPreferences, cCodeGenerator);
TWarningsPersist.Load(Storage, fWarnings);
// Read news section
Storage := Settings.ReadSection(ssPreferences, cNews);
fNewsAge := Storage.GetInteger('MaxAge', cDefNewsAge);
// Read page structure section
Storage := Settings.ReadSection(ssPreferences, cPageStructures);
TSnippetPageStructuresPersist.Load(Storage, fPageStructures);
// Read updating section
Storage := Settings.ReadSection(ssPreferences, cUpdating);
fAutoCheckProgramFrequency := Storage.GetInteger(
'AutoCheckProgramFrequency', 7 // checks for updates every week
);
fAutoCheckDatabaseFrequency := Storage.GetInteger(
'AutoCheckDatabaseFrequency', 7 // checks for updates every week
);
end;
destructor TPreferencesPersist.Destroy;
var
Storage: ISettingsSection; // object used to access persistent storage
begin
// Write general section
Storage := Settings.EmptySection(ssPreferences, cGeneral);
Storage.SetInteger('Units', Ord(fMeasurementUnits));
Storage.Save;
// Write display section
Storage := Settings.EmptySection(ssPreferences, cDisplay);
Storage.SetInteger('OverviewStartState', Ord(fOverviewStartState));
Storage.SetBoolean('ShowEmptySections', fShowEmptySections);
Storage.SetBoolean('ShowNewSnippetsInNewTabs', fShowNewSnippetsInNewTabs);
Storage.SetInteger('MainDBHeadingColour', fDBHeadingColours[False]);
Storage.SetInteger('UserDBHeadingColour', fDBHeadingColours[True]);
Storage.SetInteger('SourceCodeBGColour', fSourceCodeBGColour);
Storage.SetStrings(
'MainDBHeadingCustomColourCount',
'MainDBHeadingCustomColour%d',
fDBHeadingCustomColours[False]
);
Storage.SetStrings(
'UserDBHeadingCustomColourCount',
'UserDBHeadingCustomColour%d',
fDBHeadingCustomColours[True]
);
Storage.SetStrings(
'SourceCodeBGCustomColourCount',
'SourceCodeBGCustomColour%d',
fSourceCodeBGCustomColours
);
Storage.Save;
// Write source code section
Storage := Settings.EmptySection(ssPreferences, cSourceCode);
Storage.SetInteger('FileType', Ord(fSourceDefaultFileType));
Storage.SetInteger('CommentStyle', Ord(fSourceCommentStyle));
Storage.SetBoolean('TruncateComments', fTruncateSourceComments);
Storage.SetBoolean('UseSyntaxHiliting', fSourceSyntaxHilited);
Storage.Save;
// Write printing section
Storage := Settings.EmptySection(ssPreferences, cPrinting);
Storage.SetBoolean('UseColor', poUseColor in fPrinterOptions);
Storage.SetBoolean('SyntaxPrint', poSyntaxPrint in fPrinterOptions);
Storage.SetFloat('LeftMargin', fPrinterPageMargins.Left);
Storage.SetFloat('TopMargin', fPrinterPageMargins.Top);
Storage.SetFloat('RightMargin', fPrinterPageMargins.Right);
Storage.SetFloat('BottomMargin', fPrinterPageMargins.Bottom);
Storage.Save;
// Write syntax highlighter section
Storage := Settings.EmptySection(ssPreferences, cHiliter);
// syntax highlighter attributes
THiliterPersist.Save(Storage, fHiliteAttrs);
THiliterPersist.SaveNamed(Storage, fNamedHiliteAttrs);
// custom colours
Storage.SetStrings(
'CustomColourCount', 'CustomColour%d', fHiliteCustomColours
);
Storage.Save;
// Write code generation section
Storage := Settings.EmptySection(ssPreferences, cCodeGenerator);
TWarningsPersist.Save(Storage, fWarnings);
// Write news section
Storage := Settings.EmptySection(ssPreferences, cNews);
Storage.SetInteger('MaxAge', fNewsAge);
Storage.Save;
// Write page structure section
Storage := Settings.EmptySection(ssPreferences, cPageStructures);
TSnippetPageStructuresPersist.Save(Storage, fPageStructures);
// Write updating section
Storage := Settings.EmptySection(ssPreferences, cUpdating);
Storage.SetInteger('AutoCheckProgramFrequency', fAutoCheckProgramFrequency);
Storage.SetInteger('AutoCheckDatabaseFrequency', fAutoCheckDatabaseFrequency);
Storage.Save;
inherited;
end;
class function TPreferencesPersist.GetInstance: IPreferences;
begin
if not Assigned(fInstance) then
fInstance := TPreferencesPersist.Create;
Result := fInstance;
end;
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.