Changeset 342 for trunk/NewView/HelpFile.pas
- Timestamp:
- Jun 1, 2009, 2:42:16 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/NewView/HelpFile.pas
r252 r342 22 22 23 23 type 24 25 TIndexEntry = class 26 private 27 name: String; 28 topic: TTopic; 29 flags: uint8; 30 public 31 CONSTRUCTOR Create(aName: String; aTopic: TTopic; aFlags: uint8); 32 DESTRUCTOR Destroy; override; 33 34 PROPERTY getTopic: TTopic read topic; 35 FUNCTION getLabel: String; 36 FUNCTION isGlobal: boolean; 37 FUNCTION getLevel: integer; 38 end; 39 40 41 TIndex = class 42 private 43 entries: TStringList; 44 // labels: TStringList; 45 public 46 CONSTRUCTOR Create; 47 DESTRUCTOR Destroy; override; 48 49 FUNCTION Count: longint; 50 FUNCTION GetLabels: TStringList; 51 FUNCTION GetTopic(aPos: longint): TTopic; 52 PROCEDURE Add(anIndexEntry: TIndexEntry); 53 end; 54 55 24 56 THelpFile = class 25 57 protected … … 37 69 _Dictionary: TList; // pointers to strings. 38 70 39 _Index: T StringList;71 _Index: TIndex; 40 72 41 73 _SearchTable: TSearchTable; … … 82 114 function GetDictionaryWordPtr( Index: longint ): pstring; 83 115 84 function GetIndexEntryPtr( Index: longint ): pstring;85 116 function GetHighlightWords: UInt32ArrayPointer; 86 117 … … 94 125 95 126 public 96 constructor Create( const FileName: string );127 constructor Create( const aFileName: string ); 97 128 98 129 destructor Destroy; override; 99 130 100 function GetIndex: T StringList;131 function GetIndex: TIndex; 101 132 102 133 property Title: string read _Title; … … 104 135 property TopicList: TList read _Topics; 105 136 property TopicCount: longint read GetTopicCount; 106 property Index: TStringList read GetIndex; 107 property IndexEntryPtr[ index: longint ]: pstring read GetIndexEntryPtr; 137 property Index: TIndex read GetIndex; 108 138 property Filename: string read _FileName; 109 139 … … 170 200 FileErrorInUse: string; 171 201 FileErrorInvalidHeader: string; 202 203 204 // ----------- 205 // TIndexEntry 206 // ----------- 207 208 CONSTRUCTOR TIndexEntry.Create(aName: String; aTopic: TTopic; aFlags: uint8); 209 begin 210 LogEvent(LogObjConstDest, 'TIndexEntry.Create'); 211 name := aName; 212 topic := aTopic; 213 flags := aFlags; 214 end; 215 216 217 DESTRUCTOR TIndexEntry.Destroy; 218 begin 219 LogEvent(LogObjConstDest, 'TIndexEntry.Destroy'); 220 topic := nil; 221 // inherited Destroy; 222 end; 223 224 225 FUNCTION TIndexEntry.getLabel: String; 226 begin 227 result := name; 228 229 // index level check (level 1 or 2) 230 if (getLevel) > 1 then 231 begin 232 result := '- ' + result; 233 end; 234 235 if isGlobal then 236 begin 237 result := result + ' (g)'; 238 end; 239 end; 240 241 242 FUNCTION TIndexEntry.isGlobal: boolean; 243 begin 244 result := (flags and 64) > 0 245 end; 246 247 248 FUNCTION TIndexEntry.getLevel: integer; 249 begin 250 result := 1; 251 252 // index level check (level 1 or 2) 253 if (flags and 2 ) > 0 then 254 begin 255 result := 2; 256 end; 257 end; 258 259 260 261 262 // ----------- 263 // TIndex 264 // ----------- 265 CONSTRUCTOR TIndex.Create; 266 begin 267 inherited Create; 268 269 entries := TStringList.Create; 270 // labels := nil; // lazy 271 end; 272 273 274 DESTRUCTOR TIndex.Destroy; 275 var 276 i : longint; 277 tmpEntry : TIndexEntry; 278 begin 279 LogEvent(LogObjConstDest, 'TIndex.Destroy (size:' + IntToStr(entries.Count) + ')'); 280 281 for i := 0 to entries.Count - 1 do 282 begin 283 tmpEntry := TIndexEntry(entries.Objects[i]); 284 if tmpEntry <> nil then 285 begin 286 tmpEntry.Destroy; 287 entries.Objects[i] := nil; 288 end; 289 end; 290 entries.Destroy; 291 292 inherited Destroy; 293 end; 294 295 296 FUNCTION TIndex.Count: longint; 297 begin 298 result := entries.Count; 299 end; 300 301 302 FUNCTION TIndex.GetLabels: TStringList; 303 begin 304 result := entries; 305 end; 306 307 308 FUNCTION TIndex.GetTopic(aPos: longint): TTopic; 309 begin 310 result := TTopic(entries.Objects[aPos]); 311 end; 312 313 314 PROCEDURE TIndex.add(anIndexEntry: TIndexEntry); 315 begin 316 // LogEvent(LogDebug, 'TIndex.add(' + aName + ', ' + anIndexEntry.ClassName); 317 entries.AddObject(anIndexEntry.getLabel, anIndexEntry); 318 end; 319 320 321 172 322 173 323 Procedure OnLanguageEvent( Language: TLanguageFile; … … 221 371 end; 222 372 223 constructor THelpFile.Create( const FileName: string ); 224 begin 225 LogEvent(LogParse, 'Helpfile Load: ' + FileName); 226 227 _FileName := FileName; 373 374 constructor THelpFile.Create(const aFileName: string); 375 begin 376 LogEvent(LogObjConstDest, 'THelpFile.Create (file:' + aFileName + ')'); 377 LogEvent(LogParse, 'Helpfile Load: ' + aFileName); 378 379 _FileName := aFileName; 228 380 229 381 InitMembers; … … 248 400 end; 249 401 402 250 403 destructor THelpFile.Destroy; 251 404 begin 405 LogEvent(LogObjConstDest, 'THelpFile.Destroy'); 252 406 DeallocateMemory( _pHeader ); 253 407 DeallocateMemory( _pExtendedHeader ); … … 262 416 DeallocateMemory( _pHighlightWords ); 263 417 418 // index entries are pointing to topics 419 // so let us clean them first 420 if Assigned( _Index ) then 421 begin 422 _Index.Destroy; 423 end; 424 264 425 if Assigned( _Topics ) then 426 begin 265 427 DestroyListAndObjects( _Topics ); 266 267 if Assigned( _Index ) then 268 _Index.Destroy; 428 end; 269 429 270 430 _Dictionary.Free; … … 453 613 end; 454 614 455 function THelpFile.GetIndex: TStringList; 615 616 function THelpFile.GetIndex: TIndex; 456 617 begin 457 618 if _Index = nil then … … 477 638 pEnd: pointer; 478 639 pIndexData: pointer; 640 641 tmpIndexEntry: TIndexEntry; 479 642 begin 480 643 LogEvent(LogParse, 'Read index'); 481 644 482 _Index := T StringList.Create;645 _Index := TIndex.Create; 483 646 484 647 if _pHeader^.nindex = 0 then … … 504 667 505 668 GetMemString( p, EntryText, IndexTitleLen ); 506 if ( pEntryHeader^.flags and 2 ) > 0 then 507 EntryText := '- ' + EntryText; 669 508 670 if pEntryHeader^.TOCIndex < _Topics.Count then 509 _Index.AddObject( EntryText, _Topics[ pEntryHeader^.TOCIndex ] ) 671 begin 672 tmpIndexEntry := TIndexEntry.Create(EntryText, _Topics[pEntryHeader^.TOCIndex], pEntryHeader^.flags); 673 _Index.Add(tmpIndexEntry); 674 end 510 675 else 511 676 // raise EHelpFileException.Create( 'Error reading help file index - out of range topic reference' ); … … 666 831 end; 667 832 833 834 // TODO move to index class 668 835 function THelpFile.FindTopicByIndexStartsWith( const SearchText: string ): TTopic; 669 836 var 670 837 i: longint; 671 tmp Index: String;838 tmpLabel: String; 672 839 begin 673 840 result := nil; 674 841 GetIndex; // make sure it's read 842 675 843 for i := 0 to _Index.Count - 1 do 676 844 begin 677 tmp Index := _Index.ValuePtrs[i]^;678 if StrStartsWithIgnoringCase(tmp Index, SearchText) then845 tmpLabel := _Index.GetLabels.ValuePtrs[i]^; 846 if StrStartsWithIgnoringCase(tmpLabel, SearchText) then 679 847 begin 680 848 // found 681 result := TTopic( Index.Objects[ i ]);849 result := Index.getTopic(i); 682 850 exit; 683 851 end; … … 685 853 end; 686 854 687 function THelpFile.FindTopicByIndexContains( const SearchText: string ): TTopic; 855 856 function THelpFile.FindTopicByIndexContains(const SearchText: string): TTopic; 688 857 var 689 858 i: longint; 859 tmpLabel: String; 690 860 begin 691 861 result := nil; 692 862 GetIndex; // make sure it's read 863 693 864 for i := 0 to _Index.Count - 1 do 694 865 begin 695 if CaseInsensitivePos( SearchText, _Index.ValuePtrs[ i ] ^ ) > 0 then 866 tmpLabel := _Index.GetLabels.ValuePtrs[i]^; 867 if CaseInsensitivePos(SearchText, tmpLabel) > 0 then 696 868 begin 697 869 // found 698 result := TTopic( Index.Objects[ i ]);870 result := Index.getTopic(i); 699 871 exit; 700 872 end; 701 873 end; 702 874 end; 875 703 876 704 877 function THelpFile.FindTopicByTitleStartsWith( const SearchText: string ): TTopic; … … 946 1119 begin 947 1120 Result := pstring( _Dictionary[ Index ] ); 948 end;949 950 function THelpFile.GetIndexEntryPtr( Index: longint ): pstring;951 begin952 if _Index = nil then953 ReadIndex;954 Result := _Index.ValuePtrs[ Index ];955 1121 end; 956 1122
Note:
See TracChangeset
for help on using the changeset viewer.