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
|
unit frm_main;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, fpg_base, fpg_main, fpg_form, fpg_panel, fpg_tab,
fpg_tree, fpg_splitter, fpg_menu, fpg_button, fpg_listbox,
fpg_label, fpg_edit, fpg_radiobutton, fpg_progressbar, fpg_mru,
HelpFile, RichTextView;
type
TMainForm = class(TfpgForm)
private
{@VFD_HEAD_BEGIN: MainForm}
bvlStatusBar: TfpgBevel;
bvlBody: TfpgBevel;
PageControl1: TfpgPageControl;
tsContents: TfpgTabSheet;
tsIndex: TfpgTabSheet;
tsSearch: TfpgTabSheet;
tsNotes: TfpgTabSheet;
tsHistory: TfpgTabSheet;
tvContents: TfpgTreeView;
Splitter1: TfpgSplitter;
Memo1: TRichTextView;
// Memo1: TfpgMemo;
MainMenu: TfpgMenuBar;
miFile: TfpgPopupMenu;
miSettings: TfpgPopupMenu;
miBookmarks: TfpgPopupMenu;
miHelp: TfpgPopupMenu;
miOpenRecentMenu: TfpgPopupMenu;
btnIndex: TfpgButton;
btnGo: TfpgButton;
ListBox1: TfpgListBox;
btnNotesAdd: TfpgButton;
btnNotesEdit: TfpgButton;
btnNotesDel: TfpgButton;
btnNotesGoto: TfpgButton;
lbHistory: TfpgListBox;
Label1: TfpgLabel;
edSearchText: TfpgEdit;
Label2: TfpgLabel;
RadioButton1: TfpgRadioButton;
RadioButton2: TfpgRadioButton;
RadioButton3: TfpgRadioButton;
RadioButton4: TfpgRadioButton;
RadioButton5: TfpgRadioButton;
RadioButton6: TfpgRadioButton;
lbSearchResults: TfpgListBox;
Label3: TfpgLabel;
ProgressBar: TfpgProgressBar;
lblStatus: TfpgLabel;
lbIndex: TfpgListBox;
btnSearch: TfpgButton;
{@VFD_HEAD_END: MainForm}
Files: TList; // current open help files.
Debug: boolean;
mru: TfpgMRU;
FFileOpenRecent: TfpgMenuItem;
// while loading... so owe can display progress
LoadingFilenameList: TStringList;
LoadingFileIndex: integer;
LoadingTotalSize: longint;
LoadingSizeSoFar: longint;
procedure MainFormShow(Sender: TObject);
procedure MainFormDestroy(Sender: TObject);
procedure miFileQuitClicked(Sender: TObject);
procedure miFileOpenClicked(Sender: TObject);
procedure miFileCloseClicked(Sender: TObject);
procedure miHelpProdInfoClicked(Sender: TObject);
procedure miHelpAboutFPGui(Sender: TObject);
procedure miDebugHeader(Sender: TObject);
procedure miDebugHex(Sender: TObject);
procedure miMRUClick(Sender: TObject; const FileName: String);
procedure btnShowIndex(Sender: TObject);
procedure btnGoClicked(Sender: TObject);
procedure tvContentsChange(Sender: TObject);
procedure MainFormException(Sender: TObject; E: Exception);
procedure MainFormCloseQuery(Sender: TObject; var CanClose: boolean);
procedure PageControl1Change(Sender: TObject; NewActiveSheet: TfpgTabSheet);
procedure tvContentsDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
procedure lbIndexDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
procedure lbSearchResultsDoubleClick(Sender: TObject; AButton: TMouseButton; AShift: TShiftState; const AMousePos: TPoint);
procedure btnSearchClicked(Sender: TObject);
procedure FileOpen;
function OpenFile(const AFileNames: string): boolean;
procedure CloseFile;
procedure OnHelpFileLoadProgress(n, outof: integer; AMessage: string);
procedure LoadNotes(AHelpFile: THelpFile);
procedure LoadContents;
// Used in loading contents
procedure AddChildNodes(AHelpFile: THelpFile; AParentNode: TfpgTreeNode; ALevel: longint; var ATopicIndex: longint );
procedure ClearNotes;
procedure SaveNotes(AHelpFile: THelpFile);
procedure DisplayTopic;
procedure ResetProgress;
procedure SetStatus(const AText: TfpgString);
function TranslateEnvironmentVar(AFilenames: TfpgString): TfpgString;
// Given a "filename" which may include a path, find it in various paths and extensions
function FindHelpFile(AFileName: TfpgString ): TfpgString;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure AfterCreate; override;
end;
{@VFD_NEWFORM_DECL}
const
cTitle = 'fpGUI Help Viewer';
implementation
uses
fpg_dialogs
,fpg_constants
,fpg_iniutils
,nvUtilities
,HelpTopic
{$IFDEF Timing}
,EpikTimer
{$ENDIF}
,TextSearchQuery
,SearchUnit
;
{@VFD_NEWFORM_IMPL}
procedure TMainForm.MainFormException(Sender: TObject; E: Exception);
begin
TfpgMessageDialog.Critical('An unexpected error occurred.', E.Message);
end;
procedure TMainForm.MainFormShow(Sender: TObject);
{$IFDEF Timing}
var
t: TEpikTimer;
{$ENDIF}
begin
bvlBody.Realign;
if Paramcount > 0 then
begin
{$IFDEF Timing}
t := TEpikTimer.Create(nil);
t.Start;
{$ENDIF}
OpenFile(ParamStr(1));
{$IFDEF Timing}
t.Stop;
writeln(t.ElapsedDHMS);
{$ENDIF}
end;
// restore previous window position and size
gINI.ReadFormState(self);
PageControl1.Width := gINI.ReadInteger('Options', 'SplitterLeft', 260);
UpdateWindowPosition;
end;
procedure TMainForm.MainFormDestroy(Sender: TObject);
begin
// save splitter position
gINI.WriteInteger('Options', 'SplitterLeft', PageControl1.Width);
// save form size and position
gINI.WriteFormState(self);
end;
procedure TMainForm.miFileQuitClicked(Sender: TObject);
begin
Close;
end;
procedure TMainForm.miFileOpenClicked(Sender: TObject);
begin
FileOpen;
end;
procedure TMainForm.miFileCloseClicked(Sender: TObject);
begin
CloseFile;
end;
procedure TMainForm.miHelpProdInfoClicked(Sender: TObject);
begin
TfpgMessageDialog.Information('Product Information', 'Created by Graeme Geldenhuys');
end;
procedure TMainForm.miHelpAboutFPGui(Sender: TObject);
begin
TfpgMessageDialog.AboutFPGui;
end;
procedure TMainForm.miDebugHeader(Sender: TObject);
var
f: THelpFile;
i: integer;
sl: TStringList;
begin
Memo1.Clear;
sl := TStringList.Create;
f := THelpFile(Files[0]);
with sl do
begin
Add('<b><u>Filename:</u></b> <red>' + f.Filename + '<black>');
Add('');
Add('<b>Title:</b> ' + f.Title);
Add('<b>Dictionary count:</b> ' + IntToStr(f.DictionaryCount));
Add('<b>Topic count:</b> ' + IntToStr(f.TopicCount));
Add('<b>Index count:</b> ' + IntToStr(f.Index.Count));
Add(' ');
//Add('Dictionary contents:');
//for i := 0 to f.DictionaryCount-1 do
// Add('[' + IntToStr(i) + '] = <' + f.DictionaryWords[i] + '>');
end;
Memo1.AddText(PChar(sl.Text));
// Memo1.Lines.EndUpdate;
sl.Free;
end;
procedure TMainForm.miDebugHex(Sender: TObject);
begin
Debug := not Debug;
DisplayTopic;
end;
procedure TMainForm.miMRUClick(Sender: TObject; const FileName: String);
begin
OpenFile(FileName);
end;
procedure TMainForm.btnShowIndex(Sender: TObject);
var
Count: integer;
i: integer;
s: TfpgString;
f: THelpFile;
begin
f := THelpFile(Files[0]);
lbIndex.Items.Clear;
for i := 0 to f.Index.Count-1 do
lbIndex.Items.AddObject(f.Index[i], f.Topics[i]);
lbIndex.Invalidate
end;
procedure TMainForm.btnGoClicked(Sender: TObject);
begin
if tvContents.Selection <> nil then
DisplayTopic;
end;
procedure TMainForm.tvContentsChange(Sender: TObject);
begin
DisplayTopic;
end;
procedure TMainForm.MainFormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
CloseFile;
end;
procedure TMainForm.PageControl1Change(Sender: TObject; NewActiveSheet: TfpgTabSheet);
begin
if NewActiveSheet = tsIndex then
begin
if lbIndex.Items.Count = 0 then
btnShowIndex(nil);
end;
end;
procedure TMainForm.tvContentsDoubleClick(Sender: TObject; AButton: TMouseButton;
AShift: TShiftState; const AMousePos: TPoint);
begin
if tvContents.Selection <> nil then
DisplayTopic;
end;
procedure TMainForm.lbIndexDoubleClick(Sender: TObject; AButton: TMouseButton;
AShift: TShiftState; const AMousePos: TPoint);
begin
DisplayTopic;
end;
procedure TMainForm.lbSearchResultsDoubleClick(Sender: TObject; AButton: TMouseButton;
AShift: TShiftState; const AMousePos: TPoint);
begin
DisplayTopic;
end;
procedure TMainForm.btnSearchClicked(Sender: TObject);
var
Query: TTextSearchQuery;
SearchText: TfpgString;
SearchResults: TList;
TopicIndex: integer;
Topic: TTopic;
FileIndex: integer;
HelpFile: THelpFile;
begin
SearchText:= trim(edSearchText.Text);
if SearchText = '' then
Exit; //==>
try
Query := TTextSearchQuery.Create( SearchText );
except
on e: ESearchSyntaxError do
begin
ShowMessage( 'Error in search syntax: '
+ e.Message );
exit;
end;
end;
SearchResults := TList.Create;
// Search open help file
for FileIndex := 0 to Files.Count - 1 do
begin
HelpFile := THelpFile(Files[ FileIndex ]);
SearchHelpFile( HelpFile,
Query,
SearchResults, // SearchResults get populated
HelpFile.HighlightWords ); // HighlightWords get populate here!
end;
// Sort results across all files by relevance
SearchResults.Sort( @TopicRelevanceCompare );
// Load topics into search results list.
lbSearchResults.BeginUpdate;
lbSearchResults.Items.Clear;
for TopicIndex := 0 to SearchResults.Count - 1 do
begin
Topic := TTopic(SearchResults[ TopicIndex ]);
lbSearchResults.Items.AddObject( Topic.Title
+ ' ['
+ IntToStr( Topic.SearchRelevance )
+ ']',
Topic );
end;
lbSearchResults.FocusItem := -1;
lbSearchResults.EndUpdate;
fpgApplication.ProcessMessages; // make sure list gets displayed
Query.Free;
SearchResults.Free;
if lbSearchResults.Items.Count > 0 then
lbSearchResults.FocusItem := 0
else
lbSearchResults.Items.Add( '(No matches found for "' + SearchText + '")' );
end;
procedure TMainForm.FileOpen;
var
dlg: TfpgFileDialog;
begin
dlg := TfpgFileDialog.Create(nil);
try
dlg.WindowTitle := 'Open Help File';
dlg.Filter := 'Help Files (*.hlp, *.inf)|*.inf;*.hlp ';
// and a catch all filter
dlg.Filter := dlg.Filter + '|(' + rsAllFiles + ' (*)|*';
if dlg.RunOpenFile then
begin
// FHelpFile := dlg.FileName;
mru.AddItem(dlg.Filename);
OpenFile(dlg.Filename);
{ TODO -oGraeme : Add support for multiple files. }
// OpenFile( ListToString( dlg.FileNames, '+' ) );
end;
finally
dlg.Free;
end;
end;
function TMainForm.OpenFile(const AFileNames: string): boolean;
var
HelpFiles: TList;
HelpFile: THelpFile;
lFilename: string;
FullFilePath: string;
FileIndex: integer;
lFileSize: longint;
RemainingFileNames: string;
begin
ProfileEvent('OpenFile >>>');
lbHistory.Items.Clear;
HelpFiles := TList.Create;
ProfileEvent( 'Translate environment vars' );
RemainingFileNames := TranslateEnvironmentVar(AFilenames);
LoadingFilenameList := TStringList.Create;
LoadingTotalSize := 0;
while RemainingFileNames <> '' do
begin
lFileName := ExtractNextValue(RemainingFileNames, '+');
ProfileEvent( ' File: ' + lFileName );
FullFilePath := FindHelpFile(lFilename);
if FullFilePath <> '' then
begin
lFileName := FullFilePath;
lFileSize := GetFileSize(lFilename);
inc(LoadingTotalSize, lFileSize);
end;
ProfileEvent( ' Full path: ' + FullFilePath );
LoadingFilenameList.Values[lFileName] := IntToStr(lFileSize);
end;
LoadingSizeSoFar := 0;
for FileIndex := 0 to LoadingFilenameList.Count - 1 do
begin
lFilename := LoadingFilenameList.Names[FileIndex];
ProfileEvent( ' Loading: ' + lFilename );
try
LoadingFileIndex := FileIndex;
HelpFile := THelpFile.Create(lFileName, @OnHelpFileLoadProgress);
inc(LoadingSizeSoFar, StrToInt(LoadingFilenameList.Values[lFileName]));
HelpFiles.Add(HelpFile);
except
on E: Exception do
begin
if E is EHelpFileException then
ShowMessage( 'Could not open ' + lFileName + ': ' + E.Message )
else
ShowMessage( 'An error occurred loading ' + lFileName
+ '. It may be a damaged help file '
+ 'or there may be a bug in this program.' + #10 + #10 + E.Message );
Result := False;
// cleanup memory used
while HelpFiles.Count > 0 do
begin
HelpFile := THelpFile(HelpFiles[0]);
HelpFile.Free;
HelpFiles.Delete(0);
end;
LoadingFilenameList.Free;
HelpFiles.Free;
ResetProgress;
Exit; //==>
end { exception }
end; { try/except }
end; { for FileIndex... }
// Now that we have successfully loaded the new help file(s)
// close the existing one.
CloseFile;
Files.Assign(HelpFiles);
// AssignList(HelpFiles, Files);
ProgressBar.Position:= 50;
SetStatus( 'Displaying... ' );
fpgApplication.ProcessMessages;
LoadingFilenameList.Free;
HelpFiles.Free;
Result := True;
WindowTitle := cTitle + ' - ' + THelpFile( Files[ 0 ] ).Title;
fpgApplication.ProcessMessages;
{ TODO -oGraeme : Do MRU files list handling here }
ProgressBar.Position := 51;
SetStatus( 'Loading notes... ' );
{ TODO -oGraeme : Load previous notes here }
for FileIndex:= 0 to Files.Count - 1 do
begin
HelpFile := THelpFile(Files[ FileIndex ]);
LoadNotes( HelpFile );
end;
ProgressBar.Position := 55;
SetStatus( 'Display contents... ' );
LoadContents;
if tvContents.RootNode.Count = 1 then
begin
ProfileEvent( ' Expand first node' );
// Contents has only one top level node... expand it
tvContents.RootNode.FirstSubNode.Expand;
end;
ProgressBar.Position:= 57;
SetStatus( 'Display first topic... ' );
ProfileEvent( ' Display first topic' );
tvContents.Selection := tvContents.RootNode.FirstSubNode;
tvContents.Invalidate;
btnGoClicked(nil);
{ TODO -oGraeme : Load Index here }
lbSearchResults.Items.Clear;
ProgressBar.Position := 100;
SetStatus( 'Done' );
end;
procedure TMainForm.CloseFile;
var
FileIndex: longint;
lHelpFile: THelpFile;
begin
WindowTitle := cTitle + ' - No file';
tvContents.Selection := nil;
tvContents.RootNode.Clear;
tvContents.Invalidate;
Memo1.Clear;
// Memo1.Lines.Clear;
// First save notes. It's important we do this first
// since we scan all notes each time to find the ones
// belonging to this file.
for FileIndex := 0 to Files.Count - 1 do
begin
lHelpFile := THelpFile(Files[FileIndex]);
SaveNotes( lHelpFile );
end;
// Now destroy help files
for FileIndex := 0 to Files.Count - 1 do
begin
lHelpFile := THelpFile(Files[FileIndex]);
lHelpFile.Free;
end;
Files.Clear;
ClearNotes;
end;
procedure TMainForm.OnHelpFileLoadProgress(n, outof: integer; AMessage: string);
begin
//
end;
procedure TMainForm.LoadNotes(AHelpFile: THelpFile);
begin
// NotesFileName:= ChangeFileExt( HelpFile.FileName, '.nte' );
end;
procedure TMainForm.LoadContents;
var
FileIndex: integer;
HelpFile: THelpFile;
TopicIndex: integer;
Node: TfpgTreeNode;
Topic: TTopic;
begin
ProfileEvent( 'Load contents treeview' );
tvContents.RootNode.Clear;
ProfileEvent( 'Loop files' );
Node := nil;
for FileIndex:= 0 to Files.Count - 1 do
begin
HelpFile:= THelpFile(Files[ FileIndex ]);
ProfileEvent( 'File ' + IntToStr( FileIndex ) );
TopicIndex:= 0;
ProfileEvent('TopicCount=' + IntToStr(HelpFile.TopicCount));
while TopicIndex < HelpFile.TopicCount do
begin
Topic := HelpFile.Topics[ TopicIndex ];
if Topic.ShowInContents then
begin
if Topic.ContentsLevel = 1 then
begin
Node := tvContents.RootNode.AppendText(Topic.Title);
Node.Data := Topic;
inc( TopicIndex );
end
else
begin
// child nodes
AddChildNodes( HelpFile,
Node,
Topic.ContentsLevel,
TopicIndex );
Node := nil;
end;
end
else
begin
inc( TopicIndex );
end;
end;
end;
end;
procedure TMainForm.AddChildNodes(AHelpFile: THelpFile; AParentNode: TfpgTreeNode;
ALevel: longint; var ATopicIndex: longint);
var
Topic: TTopic;
Node: TfpgTreeNode;
begin
Node := nil;
while ATopicIndex < AHelpFile.TopicCount do
begin
Topic := AHelpFile.Topics[ ATopicIndex ];
if Topic.ShowInContents then
begin
if Topic.ContentsLevel < ALevel then
break;
if Topic.ContentsLevel = ALevel then
begin
Node := AParentNode.AppendText(Topic.Title);
Node.Data := Topic;
inc( ATopicIndex );
end
else
begin
AddChildNodes( AHelpFile,
Node,
Topic.ContentsLevel,
ATopicIndex );
Node := nil;
end
end
else
begin
inc( ATopicIndex );
end;
end; { while }
end;
procedure TMainForm.ClearNotes;
begin
{ TODO -oGraeme : Implement me }
end;
procedure TMainForm.SaveNotes(AHelpFile: THelpFile);
begin
{ TODO -oGraeme : Implement me }
end;
procedure TMainForm.DisplayTopic;
var
lText: String;
ImageIndices: TList;
LinkIndex: longint;
Link: THelpLink;
HelpFile: THelpFile;
Topic: TTopic;
Begin
ProfileEvent('DisplayTopic >>>>');
case PageControl1.ActivePageIndex of
0: begin // TOC tab
if tvContents.Selection = nil then
begin
ShowMessage('You must select a topic first by clicking it.');
Exit; //==>
end
else
Topic := TTopic(tvContents.Selection.Data);
ProfileEvent('Got Topic from Treeview');
end;
1: begin // Index tab
if lbIndex.FocusItem = -1 then
begin
ShowMessage('You must select a index first by clicking it.');
Exit; //==>
end
else
Topic := TTopic(lbIndex.Items.Objects[lbIndex.FocusItem]);
ProfileEvent('Got Topic from Index listbox');
end;
2: begin // Search tab
if lbSearchResults.FocusItem = -1 then
begin
ShowMessage('You must select a search result first by clicking it.');
Exit; //==>
end
else
Topic := TTopic(lbSearchResults.Items.Objects[lbSearchResults.FocusItem]);
ProfileEvent('Got Topic from Search Results listbox');
end;
end;
Memo1.Clear;
// Memo1.Lines.Clear;
ImageIndices := TList.Create;
ProfileEvent('Cleared memo...');
HelpFile := TopicFile(Topic);
if HelpFile = nil then
raise Exception.Create('Failed to get active HelpFile from Topic');
if HelpFile.HighlightWords <> nil then
ProfileEvent('highlightwords is ok');
lText := '';
ProfileEvent('Debug show hex values = ' + BoolToStr(Debug));
if ImageIndices <> nil then
ProfileEvent('ImageIndices initialized');
Topic.GetText(HelpFile.HighlightWords,
Debug,
lText,
ImageIndices);
{ TODO -oGraeme : We do not support images yet }
ImageIndices.Free;
Memo1.AddText(PChar(lText));
// Memo1.Lines.Text := lText;
end;
procedure TMainForm.ResetProgress;
begin
{ TODO -oGraeme : implement ResetProgress }
end;
procedure TMainForm.SetStatus(const AText: TfpgString);
begin
lblStatus.Text := AText;
end;
function TMainForm.TranslateEnvironmentVar(AFilenames: TfpgString): TfpgString;
var
EnvironmentVarValue: string;
begin
EnvironmentVarValue := GetEnvironmentVariable(UpperCase(AFilenames));
if EnvironmentVarValue <> '' then
Result := EnvironmentVarValue
else
Result := AFileNames;
end;
function TMainForm.FindHelpFile(AFileName: TfpgString): TfpgString;
begin
{ TODO -oGraeme : Implement FindHelpFile()}
Result := AFilename;
end;
constructor TMainForm.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
fpgApplication.OnException := @MainFormException;
OnShow := @MainFormShow;
OnDestroy :=@MainFormDestroy;
Files := TList.Create;
{ TODO -oGraeme : Make Debug a menu option }
Debug := False;
end;
destructor TMainForm.Destroy;
begin
Files.Free;
inherited Destroy;
end;
procedure TMainForm.AfterCreate;
begin
{%region 'Auto-generated GUI code' -fold}
{@VFD_BODY_BEGIN: MainForm}
Name := 'MainForm';
SetPosition(602, 274, 654, 386);
WindowTitle := 'fpGUI Help Viewer';
WindowPosition := wpUser;
OnCloseQuery := @MainFormCloseQuery;
bvlStatusBar := TfpgBevel.Create(self);
with bvlStatusBar do
begin
Name := 'bvlStatusBar';
SetPosition(0, 366, 653, 20);
Anchors := [anLeft,anRight,anBottom];
Style := bsLowered;
end;
bvlBody := TfpgBevel.Create(self);
with bvlBody do
begin
Name := 'bvlBody';
SetPosition(0, 31, 653, 334);
Anchors := [anLeft,anRight,anTop,anBottom];
Shape := bsSpacer;
end;
PageControl1 := TfpgPageControl.Create(bvlBody);
with PageControl1 do
begin
Name := 'PageControl1';
SetPosition(0, 0, 260, 328);
ActivePageIndex := 2;
TabOrder := 0;
Align := alLeft;
OnChange := @PageControl1Change;
end;
tsContents := TfpgTabSheet.Create(PageControl1);
with tsContents do
begin
Name := 'tsContents';
SetPosition(3, 24, 254, 301);
Text := 'Contents';
end;
tsIndex := TfpgTabSheet.Create(PageControl1);
with tsIndex do
begin
Name := 'tsIndex';
SetPosition(3, 24, 254, 301);
Text := 'Index';
end;
tsSearch := TfpgTabSheet.Create(PageControl1);
with tsSearch do
begin
Name := 'tsSearch';
SetPosition(3, 24, 254, 301);
Text := 'Search';
end;
tsNotes := TfpgTabSheet.Create(PageControl1);
with tsNotes do
begin
Name := 'tsNotes';
SetPosition(3, 24, 254, 301);
Text := 'Notes';
end;
tsHistory := TfpgTabSheet.Create(PageControl1);
with tsHistory do
begin
Name := 'tsHistory';
SetPosition(3, 24, 254, 301);
Text := 'History';
end;
tvContents := TfpgTreeView.Create(tsContents);
with tvContents do
begin
Name := 'tvContents';
SetPosition(4, 32, 242, 264);
Anchors := [anLeft,anRight,anTop,anBottom];
FontDesc := '#Label1';
ScrollWheelDelta := 60;
ShowImages := True;
TabOrder := 0;
OnChange := @tvContentsChange;
//OnDoubleClick := @tvContentsDoubleClick;
end;
Splitter1 := TfpgSplitter.Create(bvlBody);
with Splitter1 do
begin
Name := 'Splitter1';
SetPosition(265, 4, 8, 284);
Align := alLeft;
end;
//Memo1 := TfpgMemo.Create(bvlBody);
//with Memo1 do
//begin
// Name := 'Memo1';
// SetPosition(276, 36, 244, 232);
// FontDesc := '#Edit1';
// TabOrder := 2;
// Align := alClient;
//end;
Memo1 := TRichTextView.Create(bvlBody);
with Memo1 do
begin
Name := 'Memo1';
SetPosition(276, 36, 244, 232);
TabOrder := 2;
Align := alClient;
end;
MainMenu := TfpgMenuBar.Create(self);
with MainMenu do
begin
Name := 'MainMenu';
SetPosition(0, 0, 654, 24);
Anchors := [anLeft,anRight,anTop];
end;
miFile := TfpgPopupMenu.Create(self);
with miFile do
begin
Name := 'miFile';
SetPosition(292, 28, 132, 20);
AddMenuItem('Open...', '', @miFileOpenClicked);
AddMenuItem('Close', '', @miFileCloseClicked);
AddMenuitem('-', '', nil);
FFileOpenRecent := AddMenuItem('Open Recent...', '', nil);
AddMenuitem('-', '', nil);
AddMenuItem('Quit', '', @miFileQuitClicked);
end;
miSettings := TfpgPopupMenu.Create(self);
with miSettings do
begin
Name := 'miSettings';
SetPosition(292, 52, 132, 20);
AddMenuItem('Options...', '', nil);
end;
miBookmarks := TfpgPopupMenu.Create(self);
with miBookmarks do
begin
Name := 'miBookmarks';
SetPosition(292, 76, 132, 20);
AddMenuItem('Add..', '', nil);
AddMenuItem('Show', '', nil);
end;
miHelp := TfpgPopupMenu.Create(self);
with miHelp do
begin
Name := 'miHelp';
SetPosition(292, 100, 132, 20);
AddMenuItem('Contents...', '', nil);
AddMenuItem('Help using help', '', nil);
AddMenuItem('-', '', nil);
AddMenuItem('Debug: Header', '', @miDebugHeader);
AddMenuItem('Toggle Hex INF Values in Contents', '', @miDebugHex);
AddMenuItem('-', '', nil);
AddMenuItem('About fpGUI Toolkit', '', @miHelpAboutFPGui);
AddMenuItem('Product Information...', '', @miHelpProdInfoClicked);
end;
miOpenRecentMenu := TfpgPopupMenu.Create(self);
with miOpenRecentMenu do
begin
Name := 'miOpenRecentMenu';
SetPosition(293, 124, 132, 20);
end;
btnIndex := TfpgButton.Create(tsIndex);
with btnIndex do
begin
Name := 'btnIndex';
SetPosition(166, 4, 80, 24);
Anchors := [anRight,anTop];
Text := 'Go to';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 1;
OnClick := @btnShowIndex;
end;
btnGo := TfpgButton.Create(tsContents);
with btnGo do
begin
Name := 'btnGo';
SetPosition(166, 4, 80, 24);
Anchors := [anRight,anTop];
Text := 'Go to';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 1;
OnClick := @btnGoClicked;
end;
ListBox1 := TfpgListBox.Create(tsNotes);
with ListBox1 do
begin
Name := 'ListBox1';
SetPosition(4, 32, 242, 264);
Anchors := [anLeft,anRight,anTop,anBottom];
FontDesc := '#List';
HotTrack := False;
PopupFrame := False;
TabOrder := 0;
end;
btnNotesAdd := TfpgButton.Create(tsNotes);
with btnNotesAdd do
begin
Name := 'btnNotesAdd';
SetPosition(4, 4, 24, 24);
Text := '';
FontDesc := '#Label1';
Hint := '';
ImageMargin := 0;
ImageName := 'stdimg.add';
TabOrder := 1;
end;
btnNotesEdit := TfpgButton.Create(tsNotes);
with btnNotesEdit do
begin
Name := 'btnNotesEdit';
SetPosition(32, 4, 24, 24);
Text := '';
FontDesc := '#Label1';
Hint := '';
ImageMargin := 0;
ImageName := 'stdimg.edit';
TabOrder := 2;
end;
btnNotesDel := TfpgButton.Create(tsNotes);
with btnNotesDel do
begin
Name := 'btnNotesDel';
SetPosition(60, 4, 24, 24);
Text := '';
FontDesc := '#Label1';
Hint := '';
ImageMargin := 0;
ImageName := 'stdimg.remove';
TabOrder := 3;
end;
btnNotesGoto := TfpgButton.Create(tsNotes);
with btnNotesGoto do
begin
Name := 'btnNotesGoto';
SetPosition(166, 4, 80, 24);
Anchors := [anRight,anTop];
Text := 'Go to';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 4;
end;
lbHistory := TfpgListBox.Create(tsHistory);
with lbHistory do
begin
Name := 'lbHistory';
SetPosition(4, 8, 242, 288);
Anchors := [anLeft,anRight,anTop,anBottom];
FontDesc := '#List';
HotTrack := False;
PopupFrame := False;
TabOrder := 0;
end;
Label1 := TfpgLabel.Create(tsSearch);
with Label1 do
begin
Name := 'Label1';
SetPosition(4, 4, 120, 16);
FontDesc := '#Label1';
Hint := '';
Text := 'Search for:';
end;
edSearchText := TfpgEdit.Create(tsSearch);
with edSearchText do
begin
Name := 'edSearchText';
SetPosition(4, 20, 210, 26);
Anchors := [anLeft,anRight,anTop];
TabOrder := 1;
Text := '';
FontDesc := '#Edit1';
end;
Label2 := TfpgLabel.Create(tsSearch);
with Label2 do
begin
Name := 'Label2';
SetPosition(4, 48, 172, 16);
FontDesc := '#Label1';
Hint := '';
Text := 'Criteria:';
end;
RadioButton1 := TfpgRadioButton.Create(tsSearch);
with RadioButton1 do
begin
Name := 'RadioButton1';
SetPosition(12, 68, 192, 20);
FontDesc := '#Label1';
GroupIndex := 0;
TabOrder := 3;
Text := 'This section';
end;
RadioButton2 := TfpgRadioButton.Create(tsSearch);
with RadioButton2 do
begin
Name := 'RadioButton2';
SetPosition(12, 88, 192, 20);
FontDesc := '#Label1';
GroupIndex := 0;
TabOrder := 4;
Text := 'Marked sections';
end;
RadioButton3 := TfpgRadioButton.Create(tsSearch);
with RadioButton3 do
begin
Name := 'RadioButton3';
SetPosition(12, 108, 192, 20);
FontDesc := '#Label1';
GroupIndex := 0;
TabOrder := 5;
Text := 'All sections';
end;
RadioButton4 := TfpgRadioButton.Create(tsSearch);
with RadioButton4 do
begin
Name := 'RadioButton4';
SetPosition(12, 128, 192, 20);
FontDesc := '#Label1';
GroupIndex := 0;
TabOrder := 6;
Text := 'Index';
end;
RadioButton5 := TfpgRadioButton.Create(tsSearch);
with RadioButton5 do
begin
Name := 'RadioButton5';
SetPosition(12, 148, 192, 20);
FontDesc := '#Label1';
GroupIndex := 0;
TabOrder := 7;
Text := 'Marked libraries';
end;
RadioButton6 := TfpgRadioButton.Create(tsSearch);
with RadioButton6 do
begin
Name := 'RadioButton6';
SetPosition(12, 168, 192, 20);
FontDesc := '#Label1';
GroupIndex := 0;
TabOrder := 8;
Text := 'All libraries';
end;
lbSearchResults := TfpgListBox.Create(tsSearch);
with lbSearchResults do
begin
Name := 'lbSearchResults';
SetPosition(4, 220, 242, 76);
Anchors := [anLeft,anRight,anTop,anBottom];
FontDesc := '#List';
HotTrack := False;
PopupFrame := False;
TabOrder := 9;
OnDoubleClick := @lbSearchResultsDoubleClick;
end;
Label3 := TfpgLabel.Create(tsSearch);
with Label3 do
begin
Name := 'Label3';
SetPosition(4, 200, 196, 16);
FontDesc := '#Label1';
Hint := '';
Text := 'Search results:';
end;
ProgressBar := TfpgProgressBar.Create(bvlStatusBar);
with ProgressBar do
begin
Name := 'ProgressBar';
SetPosition(501, 2, 150, 16);
Anchors := [anRight,anBottom];
end;
lblStatus := TfpgLabel.Create(bvlStatusBar);
with lblStatus do
begin
Name := 'lblStatus';
SetPosition(4, 2, 380, 16);
Anchors := [anLeft,anRight,anBottom];
FontDesc := '#Label1';
Hint := '';
Text := '';
end;
lbIndex := TfpgListBox.Create(tsIndex);
with lbIndex do
begin
Name := 'lbIndex';
SetPosition(4, 32, 242, 264);
Anchors := [anLeft,anRight,anTop,anBottom];
FontDesc := '#List';
HotTrack := False;
PopupFrame := False;
TabOrder := 1;
OnDoubleClick := @lbIndexDoubleClick;
end;
btnSearch := TfpgButton.Create(tsSearch);
with btnSearch do
begin
Name := 'btnSearch';
SetPosition(220, 20, 28, 26);
Anchors := [anRight,anTop];
Text := 'Go';
FontDesc := '#Label1';
Hint := '';
ImageName := '';
TabOrder := 11;
OnClick := @btnSearchClicked;
end;
{@VFD_BODY_END: MainForm}
{%endregion}
// hook up the sub-menus.
MainMenu.AddMenuItem('&File', nil).SubMenu := miFile;
MainMenu.AddMenuItem('&Settings', nil).SubMenu := miSettings;
MainMenu.AddMenuItem('&Bookmarks', nil).SubMenu := miBookmarks;
MainMenu.AddMenuItem('&Help', nil).SubMenu := miHelp;
FFileOpenRecent.SubMenu := miOpenRecentMenu;
// correct default visible tabsheet
PageControl1.ActivePageIndex := 0;
// most recently used files
mru := TfpgMRU.Create(self);
mru.ParentMenuItem := miOpenRecentMenu;
mru.OnClick :=@miMRUClick;
mru.MaxItems := gINI.ReadInteger('Options', 'MRUFileCount', 8);
mru.ShowFullPath := gINI.ReadBool('Options', 'ShowFullPath', True);
mru.LoadMRU;
end;
end.
|