Menu

[r3207]: / trunk / Src / FmMain.pas  Maximize  Restore  History

Download this file

1658 lines (1502 with data), 58.5 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
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
{
* 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) 2005-2013, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Application's main form. Handles the program's main window display and user
* interaction.
}
unit FmMain;
interface
uses
// Delphi
SysUtils, Menus, ExtActns, StdActns, Classes, ActnList, ImgList, Controls,
Forms, ExtCtrls, ComCtrls, ToolWin, Messages, AppEvnts,
// Project
Favourites.UManager, FmHelpAware, FrDetail, FrOverview, FrTitled,
IntfNotifier, UCompileMgr, UDialogMgr, UHistory, UMainDisplayMgr, USearch,
UStatusBarMgr, UUpdateCheckers, UWindowSettings;
type
/// <summary>Form that provides the application's main window.</summary>
TMainForm = class(THelpAwareForm)
actAbout: TAction;
actAddCategory: TAction;
actAddFavourite: TAction;
actAddSnippet: TAction;
actBackupDatabase: TAction;
actBugReport: TAction;
actCloseAllDetailsTabs: TAction;
actCloseDetailsTab: TAction;
actCloseUnselectedDetailsTabs: TAction;
actCollapseNode: TAction;
actCollapseTree: TAction;
actCompilers: TAction;
actCopy: TAction;
actCopyInfo: TAction;
actCopySnippet: TAction;
actCopySource: TAction;
actDeleteCategory: TAction;
actDeleteSnippet: TAction;
actDonate: TAction;
actDuplicateSnippet: TAction;
actEditSnippet: TAction;
actExit: TFileExit;
actExpandNode: TAction;
actExpandTree: TAction;
actExportCode: TAction;
actFavourites: TAction;
actFAQs: TBrowseURL;
actFindClear: TAction;
actFindCompiler: TAction;
actFindText: TAction;
actFindXRefs: TAction;
actGoBack: TAction;
actGoForward: TAction;
actHelpCompChecks: TAction;
actHelpContents: TAction;
actHelpQuickStart: TAction;
actHomePage: TBrowseURL;
actImportCode: TAction;
actLicense: TAction;
actLoadSelection: TAction;
actMoveUserDatabase: TAction;
actNextTab: TAction;
actNewDetailsTab: TAction;
actNews: TAction;
actPageSetup: TAction;
actPreferences: TAction;
actPreviousTab: TAction;
actPrint: TAction;
actPrivacy: TAction;
actProgramUpdates: TAction;
actProxyServer: TAction;
actRegister: TAction;
actRenameCategory: TAction;
actRestoreDatabase: TAction;
actSaveDatabase: TAction;
actSaveSelection: TAction;
actSaveSnippet: TAction;
actSaveUnit: TAction;
actSelectAll: TAction;
actSelectSnippets: TAction;
actSubmit: TAction;
actSWAGImport: TAction;
actTestBug: TAction;
actTestCompile: TAction;
actUpdateDbase: TAction;
actViewAlphabetical: TAction;
actViewCategorised: TAction;
actViewCompErrs: TAction;
actViewDependencies: TAction;
actViewSnippetKinds: TAction;
actViewTestUnit: TAction;
actWebSite: TBrowseURL;
actWelcome: TAction;
alMain: TActionList;
appEvents: TApplicationEvents;
frmDetail: TDetailFrame;
frmOverview: TOverviewFrame;
ilMain: TImageList;
miAbout: TMenuItem;
miAddCategory: TMenuItem;
miAddFavourite: TMenuItem;
miAddSnippet: TMenuItem;
miBackupDatabase: TMenuItem;
miCategories: TMenuItem;
miCheckUpdates: TMenuItem;
miCloseAllDetailsTabs: TMenuItem;
miCloseDetailsTab: TMenuItem;
miCollapseNode: TMenuItem;
miCollapseTree: TMenuItem;
miCompile: TMenuItem;
miCompilers: TMenuItem;
miCopy: TMenuItem;
miCopyInfo: TMenuItem;
miCopySnippet: TMenuItem;
miDatabase: TMenuItem;
miDeleteCategory: TMenuItem;
miDeleteSnippet: TMenuItem;
miDonate: TMenuItem;
miDuplicateSnippet: TMenuItem;
miEdit: TMenuItem;
miEditSnippet: TMenuItem;
miExit: TMenuItem;
miExpandNode: TMenuItem;
miExpandTree: TMenuItem;
miExportCode: TMenuItem;
miFavourites: TMenuItem;
miFAQs: TMenuItem;
miFile: TMenuItem;
miFindClear: TMenuItem;
miFindCompiler: TMenuItem;
miFindText: TMenuItem;
miFindXRefs: TMenuItem;
miGoBack: TMenuItem;
miGoForward: TMenuItem;
miHelp: TMenuItem;
miHelpCompChecks: TMenuItem;
miHelpContents: TMenuItem;
miHelpQuickStart: TMenuItem;
miHomePage: TMenuItem;
miImportCode: TMenuItem;
miLicense: TMenuItem;
miLoadSelection: TMenuItem;
miMoveUserDatabase: TMenuItem;
miNewDetailsTab: TMenuItem;
miNews: TMenuItem;
miPageSetup: TMenuItem;
miPreferences: TMenuItem;
miPrint: TMenuItem;
miPrivacy: TMenuItem;
miProxyServer: TMenuItem;
miRegister: TMenuItem;
miRenameCategory: TMenuItem;
miReportBug: TMenuItem;
miRestoreDatabase: TMenuItem;
miSaveDatabase: TMenuItem;
miSaveSelection: TMenuItem;
miSaveSnippet: TMenuItem;
miSaveUnit: TMenuItem;
miSearch: TMenuItem;
miSelectSnippets: TMenuItem;
miSelectAll: TMenuItem;
miSnippets: TMenuItem;
miSourceCode: TMenuItem;
miSpacer1: TMenuItem;
miSpacer2: TMenuItem;
miSpacer3: TMenuItem;
miSpacer4: TMenuItem;
miSpacer5: TMenuItem;
miSpacer6: TMenuItem;
miSpacer7: TMenuItem;
miSpacer8: TMenuItem;
miSpacer9: TMenuItem;
miSpacer10: TMenuItem;
miSpacer11: TMenuItem;
miSpacer12: TMenuItem;
miSpacer13: TMenuItem;
miSpacer14: TMenuItem;
miSpacer15: TMenuItem;
miSpacer16: TMenuItem;
miSpacer17: TMenuItem;
miSpacer18: TMenuItem;
miSpacer19: TMenuItem;
miSpacer20: TMenuItem;
miSubmit: TMenuItem;
miSWAGImport: TMenuItem;
miTestCompile: TMenuItem;
miTools: TMenuItem;
miUpdateDbase: TMenuItem;
miView: TMenuItem;
miViewCategorised: TMenuItem;
miViewCompErrs: TMenuItem;
miViewDependencies: TMenuItem;
miViewSnippetKinds: TMenuItem;
miViewTestUnit: TMenuItem;
miViewAlphabetical: TMenuItem;
miWebSite: TMenuItem;
miWelcome: TMenuItem;
mnuMain: TMainMenu;
pnlBody: TPanel;
pnlLeft: TPanel;
pnlRight: TPanel;
sbStatusBar: TStatusBar;
splitVert: TSplitter;
tbarMain: TToolBar;
tbAddSnippet: TToolButton;
tbDeleteSnippet: TToolButton;
tbEditSnippet: TToolButton;
tbFavourites: TToolButton;
tbFindClear: TToolButton;
tbFindCompiler: TToolButton;
tbFindText: TToolButton;
tbGoBack: TToolButton;
tbGoForward: TToolButton;
tbHelpContents: TToolButton;
tbPrint: TToolButton;
tbSaveDatabase: TToolButton;
tbSaveSnippet: TToolButton;
tbSaveUnit: TToolButton;
tbSelectSnippets: TToolButton;
tbSpacer1: TToolButton;
tbSpacer3: TToolButton;
tbSpacer4: TToolButton;
tbSpacer5: TToolButton;
tbSpacer6: TToolButton;
tbSpacer7: TToolButton;
tbSpacer8: TToolButton;
tbTestCompile: TToolButton;
tbUpdateDbase: TToolButton;
/// <summary>Displays About Box.</summary>
procedure actAboutExecute(Sender: TObject);
/// <summary>Gets a new category from user and adds to database.</summary>
procedure actAddCategoryExecute(Sender: TObject);
/// <summary>Adds current snippet to favourites.</summary>
procedure actAddFavouriteExecute(Sender: TObject);
/// <summary>Determines whether AddFavourites action can be enabled.
/// </summary>
procedure actAddFavouriteUpdate(Sender: TObject);
/// <summary>Opens Snippets Editor to add a new user defined snippet to the
/// database.</summary>
procedure actAddSnippetExecute(Sender: TObject);
/// <summary>Makes a backup of the user database.</summary>
procedure actBackupDatabaseExecute(Sender: TObject);
/// <summary>Displays Bug Report dialogue box.</summary>
procedure actBugReportExecute(Sender: TObject);
/// <summary>Closes all open tabs in details pane.</summary>
procedure actCloseAllDetailsTabsExecute(Sender: TObject);
/// <summary>Closes current tab in details pane.</summary>
procedure actCloseDetailsTabExecute(Sender: TObject);
/// <summary>Determines whether CloseDetailsTab action can be enabled.
/// </summary>
procedure actCloseDetailsTabsUpdate(Sender: TObject);
/// <summary>Closes all open tabs in details pane except for the current
/// tab.</summary>
procedure actCloseUnselectedDetailsTabsExecute(Sender: TObject);
/// <summary>Displays Configure Compilers dialogue box.</summary>
procedure actCompilersExecute(Sender: TObject);
/// <summary>Copies selected text from details pane to clipboard.</summary>
procedure actCopyExecute(Sender: TObject);
/// <summary>Copies information about current snippet to clipboard.
/// </summary>
procedure actCopyInfoExecute(Sender: TObject);
/// <summary>Determines whether CopyInfo action can be enabled.</summary>
procedure actCopyInfoUpdate(Sender: TObject);
/// <summary>Copies annotated source code of selected snippet or selected
/// category to clipboard.</summary>
procedure actCopySnippetExecute(Sender: TObject);
/// <summary>Determines whether CopySnippet action can be enabled.
/// </summary>
procedure actCopySnippetUpdate(Sender: TObject);
/// <summary>Copies current snippet's source code to clipboard.</summary>
procedure actCopySourceExecute(Sender: TObject);
/// <summary>Determines whether CopySource action can be enabled.</summary>
procedure actCopySourceUpdate(Sender: TObject);
/// <summary>Determines whether Copy action can be enabled.</summary>
procedure actCopyUpdate(Sender: TObject);
/// <summary>Displays a dialogue box that can be used to delete a user
/// defined category.</summary>
procedure actDeleteCategoryExecute(Sender: TObject);
/// <summary>Determines whether DeleteCategory action can be enabled.
/// </summary>
procedure actDeleteCategoryUpdate(Sender: TObject);
/// <summary>Attempts to delete the current user defined snippet from the
/// database.</summary>
procedure actDeleteSnippetExecute(Sender: TObject);
/// <summary>Displays Donate dialogue box.</summary>
procedure actDonateExecute(Sender: TObject);
/// <summary>Displays a dialogue box that can be used to duplicate the
/// selected snippet.</summary>
procedure actDuplicateSnippetExecute(Sender: TObject);
/// <summary>Determines whether DuplicateSnippet action can be enabled.
/// </summary>
procedure actDuplicateSnippetUpdate(Sender: TObject);
/// <summary>Determines whether the DeleteSnippet or EditSnippet actions
/// can be enabled.</summary>
procedure ActEditDeleteSnippetUpdate(Sender: TObject);
/// <summary>Displays a dialogue box that can be used to export one or
/// more user defined snippets.</summary>
procedure actExportCodeExecute(Sender: TObject);
/// <summary>Opens current user defined snippet in Snippets Editor for
/// editing.</summary>
procedure actEditSnippetExecute(Sender: TObject);
/// <summary>Displays the Favourites non-modal dialogue box.</summary>
procedure actFavouritesExecute(Sender: TObject);
/// <summary>Clears any current query and displays all snippets in the
/// database.</summary>
procedure actFindClearExecute(Sender: TObject);
/// <summary>Determines whether FindClear action can be enabled.</summary>
procedure actFindClearUpdate(Sender: TObject);
/// <summary>Performs compiler search. Displays Find Compiler dialogue box
/// to get search critria then executes the search.</summary>
procedure actFindCompilerExecute(Sender: TObject);
/// <summary>Performs plain text search. Displays Find Text dialogue box
/// to get search critria then executes the search.</summary>
procedure actFindTextExecute(Sender: TObject);
/// <summary>Performs cross-reference search. Displays Find Cross Refs
/// dialogue box to get search critria then executes the search.</summary>
procedure actFindXRefsExecute(Sender: TObject);
/// <summary>Determines whether FindXRefs action can be enabled.</summary>
procedure actFindXRefsUpdate(Sender: TObject);
/// <summary>Displays previous view item in history list.</summary>
procedure actGoBackExecute(Sender: TObject);
/// <summary>Determines whether GoBack action can be enabled.</summary>
procedure actGoBackUpdate(Sender: TObject);
/// <summary>Displays next view item in history list.</summary>
procedure actGoForwardExecute(Sender: TObject);
/// <summary>Determines whether GoForward action can be enabled.</summary>
procedure actGoForwardUpdate(Sender: TObject);
/// <summary>Displays About Compiler Checks help topic.</summary>
procedure actHelpCompChecksExecute(Sender: TObject);
/// <summary>Displays help table of contents with default help topic.
/// </summary>
procedure actHelpContentsExecute(Sender: TObject);
/// <summary>Displays Quick Start help topic.</summary>
procedure actHelpQuickStartExecute(Sender: TObject);
/// <summary>Displays Import Wizard dialogue box from where code snippets
/// can be imported.</summary>
procedure actImportCodeExecute(Sender: TObject);
/// <summary>Displays License help topic.</summary>
procedure actLicenseExecute(Sender: TObject);
/// <summary>Displays Load Selection dialogue box from where user can
/// load a snippet selection from file and display the selection.</summary>
procedure actLoadSelectionExecute(Sender: TObject);
/// <summary>Displays a dialogue box that can be used to move the user
/// database to a user defined directory.</summary>
/// <remarks>This action must be hidden in the portable edition.</remarks>
procedure actMoveUserDatabaseExecute(Sender: TObject);
/// <summary>Creates a new empty tab in details pane.</summary>
procedure actNewDetailsTabExecute(Sender: TObject);
/// <summary>Displays a dialogue box containing latest news from CodeSnip's
/// RSS feed.</summary>
procedure actNewsExecute(Sender: TObject);
/// <summary>Displays next tab in either overview or details pane depending
/// which pane is active.</summary>
procedure actNextTabExecute(Sender: TObject);
/// <summary>Determines whether actions that require a non-empty database
/// can be enabled.</summary>
procedure ActNonEmptyDBUpdate(Sender: TObject);
/// <summary>Selects a tab in the overview pane.</summary>
/// <remarks>The index of the tab to be selected is stored in the sending
/// action's Tag property.</remarks>
procedure ActOverviewTabExecute(Sender: TObject);
/// <summary>Updates checked state of OverviewTab action referenced by
/// Sender.</summary>
/// <remarks>Action is checked iff its index, stored in the Tag property,
/// is the currently selected overview tab index.</remarks>
procedure ActOverviewTabUpdate(Sender: TObject);
/// <summary>Displays the page setup dialogue box.</summary>
procedure actPageSetupExecute(Sender: TObject);
/// <summary>Displays the Preferences dialogue box.</summary>
procedure actPreferencesExecute(Sender: TObject);
/// <summary>Displays previous tab in either the overview or details pane
/// depending on which pane is active.</summary>
procedure actPreviousTabExecute(Sender: TObject);
/// <summary>Displays the Print dialogue box that can be used to print the
/// selected snippet or category.</summary>
procedure actPrintExecute(Sender: TObject);
/// <summary>Determines whether the Print action can be enabled.</summary>
procedure actPrintUpdate(Sender: TObject);
/// <summary>Displays the Privacy Statement help topic.</summary>
procedure actPrivacyExecute(Sender: TObject);
/// <summary>Displays the Check For Program Updates dialogue box that
/// displays the availability of any program updates.</summary>
procedure actProgramUpdatesExecute(Sender: TObject);
/// <summary>Displays the Proxy Server Configuration dialogue box that can
/// be used to specify a proxy server to use for internet access.</summary>
procedure actProxyServerExecute(Sender: TObject);
/// <summary>Displays the Registration Wizard that can be used to register
/// CodeSnip.</summary>
procedure actRegisterExecute(Sender: TObject);
/// <summary>Determines whether the Register action is visible.</summary>
/// <remarks>The action is visible iff the program is not already
/// registered.</remarks>
procedure actRegisterUpdate(Sender: TObject);
/// <summary>Displays a dialogue box that can be used to rename a user
/// defined category.</summary>
procedure actRenameCategoryExecute(Sender: TObject);
/// <summary>Determines whether the RenameCategory action can be enabled.
/// </summary>
procedure actRenameCategoryUpdate(Sender: TObject);
/// <summary>Displays a dialogue box from which a backup file can be
/// selected and used to restore the user defined database.</summary>
procedure actRestoreDatabaseExecute(Sender: TObject);
/// <summary>Save any changes in the user defined database to disk.
/// </summary>
procedure actSaveDatabaseExecute(Sender: TObject);
/// <summary>Determines whether the SaveDatabase action can be enabled.
/// </summary>
procedure actSaveDatabaseUpdate(Sender: TObject);
/// <summary>Save the current snippet selection to disk in a user-specified
/// file.</summary>
procedure actSaveSelectionExecute(Sender: TObject);
/// <summary>Determines whether the SaveSelection action can be enabled.
/// </summary>
procedure actSaveSelectionUpdate(Sender: TObject);
/// <summary>Saves annotated source code of the currently selected snippet
/// or category to disk in a user-specified file.</summary>
procedure actSaveSnippetExecute(Sender: TObject);
/// <summary>Determines whether the SaveSnippet action can be enabled.
/// </summary>
procedure actSaveSnippetUpdate(Sender: TObject);
/// <summary>Saves the current snippet selection to disk in a
/// user-specified file.</summary>
procedure actSaveUnitExecute(Sender: TObject);
/// <summary>Selects all text selected in the current detail pane.
/// </summary>
procedure actSelectAllExecute(Sender: TObject);
/// <summary>Determines whether the SelectAll action can be enabled.
/// </summary>
procedure actSelectAllUpdate(Sender: TObject);
/// <summary>Displays the Select Snippets dialogue box where the snippets
/// to be displayed can be chosen.</summary>
procedure actSelectSnippetsExecute(Sender: TObject);
/// <summary>Displays the Code Submission Wizard that enables user defined
/// snippets to be submitted for inclusion in the main database.</summary>
procedure actSubmitExecute(Sender: TObject);
/// <summary>Determines whether the Submit or ExportCode actions can be
/// enabled.</summary>
procedure ActSubmitOrExportUpdate(Sender: TObject);
/// <summary>Displays the SWAG import dialogue box that enables the user to
/// import snippets from the SWAG database into the user-defined database.
/// </summary>
procedure actSWAGImportExecute(Sender: TObject);
/// <summary>Generates an exception that simulates an uncaught exception.
/// </summary>
/// <exception>EBug exception always raised.</exception>
/// <remarks>This simulation is included to permit exception handling code
/// to be tested.</remarks>
procedure actTestBugExecute(Sender: TObject);
/// <summary>Test compiles the selected snippet in all available compilers.
/// </summary>
procedure actTestCompileExecute(Sender: TObject);
/// <summary>Determines whether TestCompile action can be enabled.
/// </summary>
procedure actTestCompileUpdate(Sender: TObject);
/// <summary>Expands or collapses tree is overview pane.</summary>
/// <remarks>The required expand or collapse operation is specified by the
/// value of the sending action's Tag property.</remarks>
procedure ActTreeStateChangeExecute(Sender: TObject);
/// <summary>Determines whether tree expand or collapse action referenced
/// by Sender can be enabled.</summary>
/// <remarks>The Tag property of the Action specifies the actual expand /
/// collapse operation.</remarks>
procedure ActTreeStateChangeUpdate(Sender: TObject);
/// <summary>Displays the Update From Web dialogue box that enables the
/// latest version of the online database to be downloaded. If the database
/// was changed it is reloaded.</summary>
procedure actUpdateDbaseExecute(Sender: TObject);
/// <summary>Displays a dialogue box giving details of any compiler errors
/// and warnings for the last compiled snippet.</summary>
procedure actViewCompErrsExecute(Sender: TObject);
/// <summary>Determines whether the ViewCompErrs action can be enabled.
/// </summary>
procedure actViewCompErrsUpdate(Sender: TObject);
/// <summary>Displays a dialogue box that shows any dependencies of the
/// current snippet.</summary>
procedure actViewDependenciesExecute(Sender: TObject);
/// <summary>Determines whether the ViewDependencies action can be enabled.
/// </summary>
procedure actViewDependenciesUpdate(Sender: TObject);
/// <summary>Displays the source code unit that would be used to test
/// compile the selected snippet.</summary>
procedure actViewTestUnitExecute(Sender: TObject);
/// <summary>Determines whether the ViewTestUnit action can be enabled.
/// </summary>
procedure actViewTestUnitUpdate(Sender: TObject);
/// <summary>Displays the Welcome page in the details pane.</summary>
procedure actWelcomeExecute(Sender: TObject);
/// <summary>Handles events triggered when a control issues a hint. The
/// hint is displayed in the form's status bar.</summary>
procedure appEventsHint(Sender: TObject);
/// <summary>Main form initialisation. Sets exception handle and handles
/// clearing of splash screen and disabling form's UI until it is
/// initialised.</summary>
procedure FormCreate(Sender: TObject);
/// <summary>Main form's finalisation code. Saves unsaved snippets and
/// stores main window state.</summary>
procedure FormDestroy(Sender: TObject);
/// <summary>Handles form resizing event by ensuring vertical splitter is
/// constrained to a sensible position.</summary>
procedure FormResize(Sender: TObject);
/// <summary>Called when splitter is moved. Determines if the new splitter
/// position is permitted and blocks the move if not.</summary>
procedure splitVertCanResize(Sender: TObject; var NewSize: Integer;
var Accept: Boolean);
strict private
var
/// <summary>Flag denoting if application is registered.</summary>
fIsAppRegistered: Boolean;
/// <summary>Object that notifies user-initiated events by triggering
/// actions.</summary>
fNotifier: INotifier;
/// <summary>Object that maintains a history of viewed item.</summary>
fHistory: THistory;
/// <summary>Component that saves and restores main window settings.
/// </summary>
fWindowSettings: TMainWindowSettings;
/// <summary>Object that manages the main display.</summary>
fMainDisplayMgr: TMainDisplayMgr;
/// <summary>Object that manages the status bar.</summary>
fStatusBarMgr: TStatusBarMgr;
/// <summary>Object that manages display of dialogue boxes.</summary>
fDialogMgr: TDialogMgr;
/// <summary>Object that manages test compilations.</summary>
fCompileMgr: TMainCompileMgr;
/// <summary>Object that manages favourites.</summary>
fFavouritesMgr: TFavouritesManager;
/// <summary>Object that checks for program and database updates in a
/// background thread.</summary>
fUpdateChecker: TUpdateCheckerMgr;
/// <summary>Displays view item given by TViewItemAction instance
/// referenced by Sender and adds to history list.</summary>
procedure ActViewItemExecute(Sender: TObject);
/// <summary>Displays view item from history list given by TViewItemAction
/// instance referenced by Sender.</summary>
procedure ActViewHistoryItemExecute(Sender: TObject);
/// <summary>Opens a named user defined snippet in Snippets Editor for
/// editing. The snippet name is provided by the TEditSnippetAction
/// instance referenced by Sender.</summary>
procedure ActEditSnippetByNameExecute(Sender: TObject);
/// <summary>Selects a tab in the details pane where the tab is provided by
/// the TDetailTabAction instance referenced by Sender.</summary>
procedure ActSelectDetailTabExecute(Sender: TObject);
/// <summary>Displays Preferences dialogue box containing the single page
/// specified by the TShowPrefsPageAction instance referenced by Sender.
/// </summary>
procedure ActShowPrefsPageExecute(Sender: TObject);
/// <summary>Handles events that inform of changes to the database. The
/// EvtInfo object provides information about the change.</summary>
procedure DBChangeHandler(Sender: TObject; const EvtInfo: IInterface);
/// <summary>Handles the given un-trapped application level exception E.
/// </summary>
/// <remarks>Display an error message for expected exceptions or a bug
/// report dialogue box for unexpected exceptions.</remarks>
procedure HandleExceptions(Sender: TObject; E: Exception);
/// <summary>Provides a wrapper round code that (re)loads the snippets
/// database. Wrapper code prepares and re-initialises the UI.</summary>
/// <param name="Loader">TProc [in] Closure that actually loads the
/// database.</param>
procedure LoadSnippets(const Loader: TProc);
/// <summary>Reloads the whole database in a separate thread.</summary>
procedure ReloadDatabase;
/// <summary>Filters snippets shown in main display according to search
/// criteria.</summary>
/// <param name="Search">ISearch [in] Search object to filter by.</param>
/// <param name="Refine">Boolean [in] Flag indicating whether any exiting
/// search should be refined (True) or search should be applied to whole
/// database (False).</param>
/// <remarks>A message box is dislayed if search returns no snippets.
/// </remarks>
procedure DoSearchFilter(const Search: ISearch;
const Refine: Boolean = False);
strict protected
/// <summary>Initialises form.</summary>
/// <remarks>Once initialisation is complete the splash window is cancelled
/// and the form is enabled.</remarks>
procedure InitForm; override;
/// <summary>Performs actions that need to run after the form is visible on
/// screen.</summary>
procedure AfterShowForm; override;
end;
var
// Instance of main form
MainForm: TMainForm;
implementation
uses
// Delphi
Windows, Graphics,
// Project
DB.UCategory, DB.UMain, DB.USnippet, FmSplash, FmTrappedBugReportDlg,
FmWaitDlg, IntfFrameMgrs, Notifications.UDisplayMgr, UActionFactory, UAppInfo,
UClassHelpers, UCodeShareMgr, UCommandBars, UConsts, UCopyInfoMgr,
UCopySourceMgr, UDatabaseLoader, UDatabaseLoaderUI, UDetailTabAction,
UEditSnippetAction, UExceptions, UHelpMgr, UHistoryMenus, UKeysHelper,
UMessageBox, UNotifier, UNulDropTarget, UPrintMgr, UQuery, USaveSnippetMgr,
USaveUnitMgr, USelectionIOMgr, UShowPrefsPageAction, UUserDBMgr, UView,
UViewItemAction, UWBExternal, Web.UInfo;
{$R *.dfm}
{ TMainForm }
procedure TMainForm.actAboutExecute(Sender: TObject);
begin
fDialogMgr.ShowAboutDlg;
if not fIsAppRegistered then
fIsAppRegistered := TAppInfo.IsRegistered;
end;
procedure TMainForm.actAddCategoryExecute(Sender: TObject);
begin
TUserDBMgr.AddCategory;
end;
procedure TMainForm.actAddFavouriteExecute(Sender: TObject);
begin
fFavouritesMgr.AddFavourite(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actAddFavouriteUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := fFavouritesMgr.CanAddFavourite(
fMainDisplayMgr.CurrentView
);
end;
procedure TMainForm.actAddSnippetExecute(Sender: TObject);
begin
TUserDBMgr.AddSnippet;
end;
procedure TMainForm.actBackupDatabaseExecute(Sender: TObject);
begin
TUserDBMgr.BackupDatabase(Self);
end;
procedure TMainForm.actBugReportExecute(Sender: TObject);
begin
fDialogMgr.ShowBugReportDlg;
end;
procedure TMainForm.actCloseAllDetailsTabsExecute(Sender: TObject);
begin
fMainDisplayMgr.CloseDetailsTabs(dtcAll);
end;
procedure TMainForm.actCloseDetailsTabExecute(Sender: TObject);
begin
fMainDisplayMgr.CloseDetailsTabs(dtcSelected);
end;
procedure TMainForm.actCloseDetailsTabsUpdate(Sender: TObject);
begin
// Enables one or more details tabs to be closed.
// Used by actCloseDetailsTab, actCloseUnselectedDetailsTabs and
// actCloseAllDetailsTabs.
(Sender as TAction).Enabled := fMainDisplayMgr.CanCloseDetailsTab;
end;
procedure TMainForm.actCloseUnselectedDetailsTabsExecute(Sender: TObject);
begin
fMainDisplayMgr.CloseDetailsTabs(dtcAllExceptSelected);
end;
procedure TMainForm.actCompilersExecute(Sender: TObject);
begin
if fCompileMgr.ConfigCompilers then
fMainDisplayMgr.Refresh;
end;
procedure TMainForm.actCopyExecute(Sender: TObject);
begin
fMainDisplayMgr.CopyToClipboard;
end;
procedure TMainForm.actCopyInfoExecute(Sender: TObject);
begin
TCopyInfoMgr.Execute(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actCopyInfoUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
TCopyInfoMgr.CanHandleView(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actCopySnippetExecute(Sender: TObject);
begin
TCopySnippetMgr.Execute(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actCopySnippetUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
TCopySnippetMgr.CanHandleView(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actCopySourceExecute(Sender: TObject);
begin
TCopySourceMgr.Execute(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actCopySourceUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
TCopySourceMgr.CanHandleView(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actCopyUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := fMainDisplayMgr.CanCopy;
end;
procedure TMainForm.actDeleteCategoryExecute(Sender: TObject);
begin
TUserDBMgr.DeleteACategory;
end;
procedure TMainForm.actDeleteCategoryUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := TUserDBMgr.CanDeleteACategory;
end;
procedure TMainForm.actDeleteSnippetExecute(Sender: TObject);
begin
Assert(TUserDBMgr.CanEdit(fMainDisplayMgr.CurrentView),
ClassName + '.actDeleteSnippetExecute: Can''t delete current view item');
TUserDBMgr.DeleteSnippet(fMainDisplayMgr.CurrentView);
// display update is handled by snippets change event handler
end;
procedure TMainForm.actDonateExecute(Sender: TObject);
begin
fDialogMgr.ShowDonateDlg
end;
procedure TMainForm.actDuplicateSnippetExecute(Sender: TObject);
begin
TUserDBMgr.DuplicateSnippet(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actDuplicateSnippetUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
TUserDBMgr.CanDuplicate(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.ActEditDeleteSnippetUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
TUserDBMgr.CanEdit(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.ActEditSnippetByNameExecute(Sender: TObject);
begin
TUserDBMgr.EditSnippet((Sender as TEditSnippetAction).SnippetName);
end;
procedure TMainForm.actEditSnippetExecute(Sender: TObject);
begin
Assert(TUserDBMgr.CanEdit(fMainDisplayMgr.CurrentView),
ClassName + '.actEditSnippetExecute: Can''t edit current view item');
fNotifier.EditSnippet(
(fMainDisplayMgr.CurrentView as ISnippetView).Snippet.Name
);
// display of updated snippet is handled by snippets change event handler
end;
procedure TMainForm.actExportCodeExecute(Sender: TObject);
begin
TCodeShareMgr.ExportCode(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actFavouritesExecute(Sender: TObject);
begin
fFavouritesMgr.ShowDialogue;
end;
procedure TMainForm.actFindClearExecute(Sender: TObject);
begin
Query.Reset;
fMainDisplayMgr.UpdateDisplayedQuery;
fStatusBarMgr.Update;
end;
procedure TMainForm.actFindClearUpdate(Sender: TObject);
begin
// We have an active search if current search's criteria is not null
(Sender as TAction).Enabled := Query.IsSearchActive;
end;
procedure TMainForm.actFindCompilerExecute(Sender: TObject);
var
Search: USearch.ISearch; // compiler search object
Refine: Boolean; // flag indicating if existing search to be refined
begin
// Display Find Compiler dialogue box to enable user to enter search criteria
// (dialogue box creates and returns search object from entered criteria)
if fDialogMgr.ExecFindCompilerDlg(Search, Refine) then
DoSearchFilter(Search, Refine);
end;
procedure TMainForm.actFindTextExecute(Sender: TObject);
var
Search: USearch.ISearch; // text search object
Refine: Boolean; // flag indicating if existing search to be refined
begin
// Display Find Text dialogue box to enable user to enter search criteria
// (dialogue box creates and returns search object from entered criteria)
if fDialogMgr.ExecFindTextDlg(Search, Refine) then
DoSearchFilter(Search, Refine);
end;
procedure TMainForm.actFindXRefsExecute(Sender: TObject);
var
Search: USearch.ISearch; // cross reference search object
begin
Assert(Supports(fMainDisplayMgr.CurrentView, ISnippetView),
ClassName + '.actFindXRefsExecute: Current view is not a snippet');
// Display Find Cross Refs dialogue box to enable user to enter search
// criteria (dialogue box creates and returns search object from entered
// criteria)
if fDialogMgr.ExecFindXRefsDlg(
(fMainDisplayMgr.CurrentView as ISnippetView).Snippet, Search
) then
DoSearchFilter(Search);
end;
procedure TMainForm.actFindXRefsUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
Supports(fMainDisplayMgr.CurrentView, ISnippetView);
end;
procedure TMainForm.actGoBackExecute(Sender: TObject);
var
ViewItem: IView; // previous view item in history list
const
// Bug error message
cHistoryError = '%s.actGoBackExecute: '
+ 'There are no items before current one in history list';
begin
// Get previous view item from history list and check it is assigned
ViewItem := fHistory.GoBack;
if not Assigned(ViewItem) then
raise EBug.CreateFmt(cHistoryError, [ClassName]);
// Display item, but don't record in history list
fMainDisplayMgr.DisplayViewItem(ViewItem, ssCtrl in ShiftKeysPressed);
end;
procedure TMainForm.actGoBackUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := fHistory.BackListCount > 0;
end;
procedure TMainForm.actGoForwardExecute(Sender: TObject);
var
ViewItem: IView; // next view item in history list
const
// Bug error message
cHistoryError = '%s.actGoForwardExecute: '
+ 'There are no items after current one in history list';
begin
// Get next view item from history list and check it is assigned
ViewItem := fHistory.GoForward;
if not Assigned(ViewItem) then
raise EBug.CreateFmt(cHistoryError, [ClassName]);
// Display item, but don't record in history list
fMainDisplayMgr.DisplayViewItem(ViewItem, ssCtrl in ShiftKeysPressed);
end;
procedure TMainForm.actGoForwardUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := fHistory.ForwardListCount > 0;
end;
procedure TMainForm.actHelpCompChecksExecute(Sender: TObject);
begin
// Displays help topic indirected via custom help topic action
DisplayHelp('CompChecks');
end;
procedure TMainForm.actHelpContentsExecute(Sender: TObject);
begin
HelpMgr.ShowContents;
end;
procedure TMainForm.actHelpQuickStartExecute(Sender: TObject);
begin
// Displays help topic indirected via custom help topic action
DisplayHelp('QuickStart');
end;
procedure TMainForm.actImportCodeExecute(Sender: TObject);
begin
TCodeShareMgr.ImportCode;
end;
procedure TMainForm.actLicenseExecute(Sender: TObject);
begin
DisplayHelp('License');
end;
procedure TMainForm.actLoadSelectionExecute(Sender: TObject);
var
Search: ISearch;
begin
if TSelectionIOMgr.LoadSelectionSearch(Search) then
DoSearchFilter(Search);
end;
procedure TMainForm.actMoveUserDatabaseExecute(Sender: TObject);
begin
TUserDBMgr.MoveDatabase;
end;
procedure TMainForm.actNewDetailsTabExecute(Sender: TObject);
begin
fMainDisplayMgr.CreateNewDetailsTab;
end;
procedure TMainForm.actNewsExecute(Sender: TObject);
begin
fDialogMgr.ShowNewsDlg;
end;
procedure TMainForm.actNextTabExecute(Sender: TObject);
begin
fMainDisplayMgr.SelectNextActiveTab;
end;
procedure TMainForm.ActNonEmptyDBUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := not Database.Snippets.IsEmpty;
end;
procedure TMainForm.ActOverviewTabExecute(Sender: TObject);
begin
// Action's Tag property specifies index of tab being selected
fMainDisplayMgr.SelectOverviewTab((Sender as TAction).Tag);
end;
procedure TMainForm.ActOverviewTabUpdate(Sender: TObject);
begin
// Action's Tag property specifies index of tab being updated
with Sender as TAction do
begin
Checked := fMainDisplayMgr.SelectedOverviewTab = Tag;
Enabled := True;
end;
end;
procedure TMainForm.actPageSetupExecute(Sender: TObject);
begin
fDialogMgr.ExecPageSetupDlg;
end;
procedure TMainForm.actPreferencesExecute(Sender: TObject);
var
UpdateUI: Boolean; // flag true if preference changes affect main window UI
begin
fDialogMgr.ExecPreferencesDlg(UpdateUI);
if UpdateUI then
fMainDisplayMgr.CompleteRefresh;
end;
procedure TMainForm.actPreviousTabExecute(Sender: TObject);
begin
fMainDisplayMgr.SelectPreviousActiveTab;
end;
procedure TMainForm.actPrintExecute(Sender: TObject);
begin
Assert(TPrintMgr.CanPrint(fMainDisplayMgr.CurrentView),
ClassName + '.actPrintExecute: View kind not vkRoutine');
// Display print dialogue box
if fDialogMgr.ExecPrintDlg then
// User OKd: print document
TPrintMgr.Print(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actPrintUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
TPrintMgr.CanPrint(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actPrivacyExecute(Sender: TObject);
begin
DisplayHelp('PrivacyStatement');
end;
procedure TMainForm.actProgramUpdatesExecute(Sender: TObject);
begin
fDialogMgr.ShowProgramUpdatesDlg;
end;
procedure TMainForm.actProxyServerExecute(Sender: TObject);
begin
fDialogMgr.ExecProxyServerDlg;
end;
procedure TMainForm.actRegisterExecute(Sender: TObject);
begin
if fDialogMgr.ExecRegistrationDlg then
fIsAppRegistered := True;
end;
procedure TMainForm.actRegisterUpdate(Sender: TObject);
begin
with Sender as TAction do
begin
Visible := not fIsAppRegistered;
Enabled := True;
end;
end;
procedure TMainForm.actRenameCategoryExecute(Sender: TObject);
begin
TUserDBMgr.RenameACategory;
end;
procedure TMainForm.actRenameCategoryUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := TUserDBMgr.CanRenameACategory;
end;
procedure TMainForm.actRestoreDatabaseExecute(Sender: TObject);
begin
if TUserDBMgr.RestoreDatabase(Self) then
ReloadDatabase;
end;
procedure TMainForm.actSaveDatabaseExecute(Sender: TObject);
begin
TUserDBMgr.Save(Self);
fStatusBarMgr.Update;
end;
procedure TMainForm.actSaveDatabaseUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := TUserDBMgr.CanSave;
end;
procedure TMainForm.actSaveSelectionExecute(Sender: TObject);
begin
TSelectionIOMgr.SaveCurrentSelection;
end;
procedure TMainForm.actSaveSelectionUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := TSelectionIOMgr.CanSaveCurrentSelection;
end;
procedure TMainForm.actSaveSnippetExecute(Sender: TObject);
begin
TSaveSnippetMgr.Execute(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actSaveSnippetUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
TSaveSnippetMgr.CanHandleView(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.actSaveUnitExecute(Sender: TObject);
begin
TSaveUnitMgr.Execute(Query.Selection);
end;
procedure TMainForm.actSelectAllExecute(Sender: TObject);
begin
fMainDisplayMgr.SelectAll;
end;
procedure TMainForm.actSelectAllUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := fMainDisplayMgr.CanSelectAll;
end;
procedure TMainForm.ActSelectDetailTabExecute(Sender: TObject);
begin
fMainDisplayMgr.SelectDetailTab((Sender as TDetailTabAction).TabIndex);
end;
procedure TMainForm.actSelectSnippetsExecute(Sender: TObject);
var
Search: USearch.ISearch; // selection search object
begin
// Display Select Snippets dialogue box to enable user to specify required
// snippets (dialogue box creates and returns search object for required
// snippets)
if fDialogMgr.ExecSelectionSearchDlg(Query.Selection, Search) then
DoSearchFilter(Search);
end;
procedure TMainForm.ActShowPrefsPageExecute(Sender: TObject);
var
UpdateUI: Boolean; // flag true if preference changes affect main window UI
begin
fDialogMgr.ExecPreferencesDlg(
(Sender as TShowPrefsPageAction).FrameClassName, UpdateUI
);
if UpdateUI then
fMainDisplayMgr.CompleteRefresh;
end;
procedure TMainForm.actSubmitExecute(Sender: TObject);
begin
TCodeShareMgr.Submit(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.ActSubmitOrExportUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := TCodeShareMgr.CanShare;
end;
procedure TMainForm.actSWAGImportExecute(Sender: TObject);
begin
fDialogMgr.ShowSWAGImportDlg;
end;
procedure TMainForm.actTestBugExecute(Sender: TObject);
const
// Bug error message
cFakeError = 'Bug check: raised by pressing Shift+Ctrl+Alt+B. '
+ 'This is a program generated bug used for testing purposes only. '
+ 'PLEASE DO NOT REPORT!';
begin
raise EBug.Create(cFakeError);
end;
procedure TMainForm.actTestCompileExecute(Sender: TObject);
begin
Assert(
fCompileMgr.CanCompile(fMainDisplayMgr.CurrentView),
ClassName + '.actTestCompileExecute: Can''t compile current view');
fDialogMgr.ShowTestCompileDlg(
fCompileMgr,
(fMainDisplayMgr.CurrentView as ISnippetView).Snippet
);
end;
procedure TMainForm.actTestCompileUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
fCompileMgr.CanCompile(fMainDisplayMgr.CurrentView);
end;
procedure TMainForm.ActTreeStateChangeExecute(Sender: TObject);
begin
fMainDisplayMgr.UpdateOverviewTreeState(
TTreeNodeAction((Sender as TAction).Tag)
);
end;
procedure TMainForm.ActTreeStateChangeUpdate(Sender: TObject);
var
Action: TAction; // action triggering this event
begin
Action := Sender as TAction;
Action.Enabled := fMainDisplayMgr.CanUpdateOverviewTreeState(
TTreeNodeAction(Action.Tag)
)
end;
procedure TMainForm.actUpdateDbaseExecute(Sender: TObject);
resourcestring
sConfirmSave = 'The user database has been changed. Do you wish to save it '
+ 'before updating the database?' + EOL2 + 'Clicking No will cause all '
+ 'recent changes to be lost.';
begin
if fDialogMgr.ExecDBUpdateDlg then
begin
// Database was updated: check if user database needs saving
if (Database as IDatabaseEdit).Updated
and TMessageBox.Confirm(Self, sConfirmSave) then
TUserDBMgr.Save(Self);
// Reload the databases
ReloadDatabase;
end;
end;
procedure TMainForm.actViewCompErrsExecute(Sender: TObject);
begin
fCompileMgr.ShowErrors;
end;
procedure TMainForm.actViewCompErrsUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
fCompileMgr.IsLastCompiledView(fMainDisplayMgr.CurrentView)
and fCompileMgr.HaveErrors;
end;
procedure TMainForm.actViewDependenciesExecute(Sender: TObject);
var
Search: ISearch;
begin
Assert(Supports(fMainDisplayMgr.CurrentView, ISnippetView),
ClassName + '.actViewDependenciesExecute: Snippet view expected');
Search := fDialogMgr.ShowDependenciesDlg(
(fMainDisplayMgr.CurrentView as ISnippetView).Snippet, 'DependenciesDlg'
);
if Assigned(Search) then
DoSearchFilter(Search);
end;
procedure TMainForm.actViewDependenciesUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled :=
Supports(fMainDisplayMgr.CurrentView, ISnippetView);
end;
procedure TMainForm.ActViewHistoryItemExecute(Sender: TObject);
begin
fMainDisplayMgr.DisplayViewItem(
(Sender as TViewItemAction).ViewItem, (Sender as TViewItemAction).NewTab
);
end;
procedure TMainForm.ActViewItemExecute(Sender: TObject);
begin
fMainDisplayMgr.DisplayViewItem(
(Sender as TViewItemAction).ViewItem, (Sender as TViewItemAction).NewTab
);
fHistory.NewItem((Sender as TViewItemAction).ViewItem);
end;
procedure TMainForm.actViewTestUnitExecute(Sender: TObject);
var
SelectedSnippet: TSnippet; // currently selected snippet
begin
Assert(Supports(fMainDisplayMgr.CurrentView, ISnippetView),
ClassName + '.actViewTestUnitExecute: Snippet view expected');
SelectedSnippet := (fMainDisplayMgr.CurrentView as ISnippetView).Snippet;
Assert(SelectedSnippet.CanCompile,
ClassName + '.actViewTestUnitExecute: Snippet is not compilable');
fDialogMgr.ShowTestUnitDlg(SelectedSnippet);
end;
procedure TMainForm.actViewTestUnitUpdate(Sender: TObject);
var
SnippetView: ISnippetView; // current view as snippet view if supported
begin
(Sender as TAction).Enabled :=
Supports(fMainDisplayMgr.CurrentView, ISnippetView, SnippetView)
and SnippetView.Snippet.CanCompile;
end;
procedure TMainForm.actWelcomeExecute(Sender: TObject);
begin
fMainDisplayMgr.ShowWelcomePage;
end;
procedure TMainForm.AfterShowForm;
begin
inherited;
// initialise display
fMainDisplayMgr.Initialise(fWindowSettings.OverviewTab);
fMainDisplayMgr.ShowWelcomePage;
end;
procedure TMainForm.appEventsHint(Sender: TObject);
begin
if Assigned(fStatusBarMgr) then
fStatusBarMgr.ShowHint(Application.Hint);
end;
procedure TMainForm.DBChangeHandler(Sender: TObject; const EvtInfo: IInterface);
begin
case (EvtInfo as IDatabaseChangeEventInfo).Kind of
evChangeBegin:
Enabled := False;
evChangeEnd:
Enabled := True;
end;
// Display updated database stats and search results in status bar
fStatusBarMgr.Update;
end;
procedure TMainForm.DoSearchFilter(const Search: USearch.ISearch;
const Refine: Boolean);
var
PrevSearchExists: Boolean; // flags if a search was active before this search
/// Returns a suitable error message depending on if a search was active
/// before this search was run and what action was taken on failure.
function FailureMessage: string;
resourcestring
// dialogue box message
sFailureMsg = 'The search did not find any snippets.';
sSearchNotChanged = 'No changes were made to the existing search results.';
sDatabaseSelected = 'The previous search results have been cleared.';
begin
Result := sFailureMsg;
if PrevSearchExists then
if Refine then
Result := Result + EOL2 + sSearchNotChanged
else
Result := Result + EOL2 + sDatabaseSelected;
end;
begin
// Check if a search is already active: needed to create error message
PrevSearchExists := Query.IsSearchActive;
if not Query.ApplySearch(Search, Refine) then
TMessageBox.Information(Self, FailureMessage);
fMainDisplayMgr.UpdateDisplayedQuery;
fStatusBarMgr.Update;
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
try
inherited;
// Disable form
Enabled := False;
// Set up application events
appEvents.OnException := HandleExceptions;
except
// Make sure form is enabled and splash form hidden on exception
Enabled := True;
SplashForm.RequestClose;
raise;
end;
end;
procedure TMainForm.FormDestroy(Sender: TObject);
begin
inherited;
// Stop update checking threads
fUpdateChecker.StopThreads;
fUpdateChecker.Free;
// Stop notification display sub-system
TNotificationDisplayMgr.Stop;
// Save any changes to user database
with Database as IDatabaseEdit do
begin
if Updated then
Save;
end;
// Unhook snippets event handler
Database.RemoveChangeEventHandler(DBChangeHandler);
// Save window state
fWindowSettings.SplitterPos := pnlLeft.Width;
fWindowSettings.OverviewTab := fMainDisplayMgr.SelectedOverviewTab;
fWindowSettings.Save;
// Free owned objects
fHistory.Free;
fMainDisplayMgr.Free;
fFavouritesMgr.Free;
// fStatusBarMgr MUST be nilled: otherwise it can be called after status bar
// control has been freed and so cause AV when trying to use the control
FreeAndNil(fStatusBarMgr);
end;
procedure TMainForm.FormResize(Sender: TObject);
begin
inherited;
if pnlLeft.Width > ClientWidth - TMainWindowSettings.MinRightPanelWidth
- splitVert.Width then
pnlLeft.Width := ClientWidth - TMainWindowSettings.MinRightPanelWidth
- splitVert.Width;
end;
procedure TMainForm.HandleExceptions(Sender: TObject; E: Exception);
begin
if (E is ECodeSnip) or (E is EFileStreamError) then
TMessageBox.Error(nil, E.Message)
else
TTrappedBugReportDlg.Execute(nil, E);
end;
procedure TMainForm.InitForm;
var
WBExternal: IDispatch; // external object of browser control
begin
try
inherited;
// Set up action image list
ilMain.LoadFromResource(RT_RCDATA, 'ACTIONIMAGES', 16, clFuchsia);
RefreshActions;
// Set window caption
Application.Title := TAppInfo.ProgramCaption;
Caption := TAppInfo.ProgramCaption;
if TWebInfo.UsingLocalHost then
Caption := Caption + ' [' + TWebInfo.LocalHost + ']';
// Restore window settings
fWindowSettings := TMainWindowSettings.CreateStandAlone(Self); // auto-freed
fWindowSettings.Restore; // sizes main window
pnlLeft.Width := fWindowSettings.SplitterPos;
// Initialise actions
// Browse actions have to have URLs set dynamically
actHomePage.URL := TWebInfo.ProgramHomeURL;
actWebSite.URL := TWebInfo.DelphiDabblerHomeURL;
actFAQs.URL := TWebInfo.FAQsURL;
// Tree control actions need shortcuts adding dynamically, and state stored
// in Tag property
actExpandNode.ShortCut := ShortCut(VK_ADD, [ssCtrl]);
actCollapseNode.ShortCut := ShortCut(VK_SUBTRACT, [ssCtrl]);
actExpandTree.ShortCut := ShortCut(VK_ADD, [ssCtrl, ssShift]);
actCollapseTree.ShortCut := ShortCut(VK_SUBTRACT, [ssCtrl, ssShift]);
actExpandTree.Tag := Ord(taExpandAll);
actExpandNode.Tag := Ord(taExpandNode);
actCollapseTree.Tag := Ord(taCollapseAll);
actCollapseNode.Tag := Ord(taCollapseNode);
// Overview tab actions have tab id in tags
actViewCategorised.Tag := cCategorisedTab;
actViewAlphabetical.Tag := cAlphabeticTab;
actViewSnippetKinds.Tag := cKindTab;
{$IFDEF PORTABLE}
// Move user database option not available in portable edition
actMoveUserDatabase.Visible := False;
{$ENDIF}
// Create notifier object and assign actions triggered by its methods
// note that actions created on fly are automatically freed
fNotifier := TNotifier.Create;
with fNotifier as ISetActions do
begin
SetUpdateDbaseAction(actUpdateDbase);
SetDisplaySnippetAction(TActionFactory.CreateSnippetAction(Self));
SetDisplayCategoryAction(TActionFactory.CreateCategoryAction(Self));
SetConfigCompilersAction(actCompilers);
SetShowViewItemAction(
TActionFactory.CreateViewItemAction(Self, ActViewItemExecute)
);
SetOverviewStyleChangeActions(
[actViewCategorised, actViewAlphabetical, actViewSnippetKinds]
);
SetDetailPaneChangeAction(
TActionFactory.CreateDetailTabAction(Self, ActSelectDetailTabExecute)
);
SetEditSnippetAction(
TActionFactory.CreateEditSnippetAction(
Self, ActEditSnippetByNameExecute
)
);
SetDonateAction(actDonate);
SetNewSnippetAction(actAddSnippet);
SetNewsAction(actNews);
SetCheckForUpdatesAction(actProgramUpdates);
SetAboutBoxAction(actAbout);
SetShowPrefsPageAction(
TActionFactory.CreateShowPrefsPageAction(Self, ActShowPrefsPageExecute)
);
end;
// Customise web browser controls in Details pane
WBExternal := TWBExternal.Create;
with frmDetail as IWBCustomiser do
begin
SetExternalObj(WBExternal);
SetDragDropHandler(TNulDropTarget.Create);
end;
// Set notifier for objects that trigger notifications
(WBExternal as ISetNotifier).SetNotifier(fNotifier);
(frmOverview as ISetNotifier).SetNotifier(fNotifier);
(frmDetail as ISetNotifier).SetNotifier(fNotifier);
// Create dialogue box manager
fDialogMgr := TDialogMgr.Create(Self); // automatically freed
// Create display manager
// NOTE: Don't display anything until after window has displayed (see
// AfterShowForm). This is to prevent any problems with IE 10 browser ctrl.
fMainDisplayMgr := TMainDisplayMgr.Create(frmOverview, frmDetail);
// Create status bar manager
fStatusBarMgr := TStatusBarMgr.Create(sbStatusBar);
// Create navigation history and menus
// history manager
fHistory := THistory.Create;
// history menus: note menu and action objects are automatically freed
tbGoBack.DropdownMenu := TBackHistoryMenu.Create(
Self,
fHistory,
TActionFactory.CreateViewItemAction(
Self, ActViewHistoryItemExecute
) as TViewItemAction
);
tbGoForward.DropdownMenu := TForwardHistoryMenu.Create(
Self,
fHistory,
TActionFactory.CreateViewItemAction(
Self, ActViewHistoryItemExecute
) as TViewItemAction
);
// Set up detail pane's popup menus
with frmDetail as ICommandBarConfig do
begin
// set images to use
SetImages(ilMain);
// detail view menus
AddAction(
TActionFactory.CreateLinkAction(Self),
[cDetailPopupMenuAnchor, cDetailPopupMenuImage]
);
AddSpacer([cDetailPopupMenuAnchor, cDetailPopupMenuImage]);
AddAction(actViewDependencies, cDetailPopupMenuIDs);
AddSpacer(cDetailPopupMenuIDs);
AddAction(actCopyInfo, cDetailPopupMenuIDs);
AddAction(actCopySnippet, cDetailPopupMenuIDs);
AddAction(actCopySource, cDetailPopupMenuIDs);
AddSpacer(cDetailPopupMenuIDs);
AddAction(actTestCompile, cDetailPopupMenuIDs);
AddSpacer(cDetailPopupMenuIDs);
AddAction(actSaveSnippet, cDetailPopupMenuIDs);
AddAction(actPrint, cDetailPopupMenuIDs);
AddSpacer(cDetailPopupMenuIDs);
AddAction(actCopy, cDetailPopupMenuTextSelect);
AddAction(actSelectAll, cDetailPopupMenuIDs);
AddSpacer(cDetailPopupMenuIDs);
AddAction(actCloseDetailsTab, cDetailPopupMenuIDs);
// tab set menu
AddAction(actCloseDetailsTab, cDetailTabSetPopupMenu);
AddAction(actCloseUnselectedDetailsTabs, cDetailTabSetPopupMenu);
end;
// Set up overview pane's toolbar and popup menu
with frmOverview as ICommandBarConfig do
begin
SetImages(ilMain);
// add toolbar actions (in reverse order we want them!)
AddAction(actCollapseTree, cOverviewToolBar);
AddAction(actExpandTree, cOverviewToolBar);
// add popup menu actions
AddAction(actViewDependencies, cOverviewPopupMenu);
AddSpacer(cOverviewPopupMenu);
AddAction(actCopyInfo, cOverviewPopupMenu);
AddAction(actCopySnippet, cOverviewPopupMenu);
AddAction(actCopySource, cOverviewPopupMenu);
AddSpacer(cOverviewPopupMenu);
AddAction(actSaveSnippet, cOverviewPopupMenu);
AddAction(actPrint, cOverviewPopupMenu);
AddSpacer(cOverviewPopupMenu);
AddAction(actEditSnippet, cOverviewPopupMenu);
AddSpacer(cOverviewPopupMenu);
AddAction(actCollapseNode, cOverviewPopupMenu);
AddAction(actExpandNode, cOverviewPopupMenu);
end;
// Create object to handle compilation and assoicated UI and dialogues
fCompileMgr := TMainCompileMgr.Create(Self); // auto-freed
// Record if app is registered
fIsAppRegistered := TAppInfo.IsRegistered;
// Set event handler for snippets database
Database.AddChangeEventHandler(DBChangeHandler);
// Load snippets database
LoadSnippets(
procedure
begin
try
TDatabaseLoader.Load;
except
on E: ECodeSnip do
Application.HandleException(E);
end;
end
);
// Create favourites manager
// *** Must be done AFTER database has loaded ***
fFavouritesMgr := TFavouritesManager.Create(fNotifier);
// Start notification display sub-system
TNotificationDisplayMgr.Start(Self);
// Start update checking manager
// *** Should be done after notification window listener starts
fUpdateChecker := TUpdateCheckerMgr.Create;
fUpdateChecker.StartThreads;
finally
// Ready to start using app: request splash form closes and enable form
SplashForm.RequestClose;
Enabled := True;
end;
end;
procedure TMainForm.LoadSnippets(const Loader: TProc);
resourcestring
sLoadingDatabase = 'Loading database...'; // status bar message
begin
// Inform that database is being loaded via status bar
fStatusBarMgr.ShowSimpleMessage(sLoadingDatabase);
fHistory.Clear;
// Load the database
try
Loader;
except
on E: ECodeSnip do
Application.HandleException(E);
end;
// Re-initialise display
fMainDisplayMgr.ReStart;
// Display updated database stats and search results in status bar
fStatusBarMgr.Update;
end;
procedure TMainForm.ReloadDatabase;
begin
fMainDisplayMgr.PrepareForDBReload;
LoadSnippets(
procedure
begin
TDatabaseLoaderUI.Execute(Self);
end
);
fMainDisplayMgr.ShowDBUpdatedPage;
end;
procedure TMainForm.splitVertCanResize(Sender: TObject;
var NewSize: Integer; var Accept: Boolean);
begin
if (NewSize < TMainWindowSettings.MinLeftPanelWidth)
or (NewSize > ClientWidth - TMainWindowSettings.MinRightPanelWidth) then
Accept := False;
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.