fptemplt.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. {
  2. $Id$
  3. This file is part of the Free Pascal Integrated Development Environment
  4. Copyright (c) 1998 by Berczi Gabor
  5. Template support routines for the IDE
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit FPTemplt;
  13. interface
  14. uses FPViews;
  15. function GetTemplateCount: integer;
  16. function GetTemplateName(Index: integer): string;
  17. function StartTemplate(Index: integer; Editor: PSourceEditor): boolean;
  18. procedure InitTemplates;
  19. procedure DoneTemplates;
  20. implementation
  21. uses
  22. Dos,Objects,
  23. {$ifdef EDITORS}
  24. Editors,
  25. {$else}
  26. WEditor,
  27. {$endif}
  28. FPVars,FPUtils;
  29. type
  30. PTemplate = ^TTemplate;
  31. TTemplate = record
  32. Name : PString;
  33. Path : PString;
  34. end;
  35. PTemplateCollection = ^TTemplateCollection;
  36. TTemplateCollection = object(TSortedCollection)
  37. function At(Index: Integer): PTemplate;
  38. procedure FreeItem(Item: Pointer); virtual;
  39. function Compare(Key1, Key2: Pointer): Sw_Integer; virtual;
  40. end;
  41. const Templates : PTemplateCollection = nil;
  42. function NewTemplate(const Name, Path: string): PTemplate;
  43. var P: PTemplate;
  44. begin
  45. New(P);
  46. FillChar(P^,SizeOf(P^),0);
  47. P^.Name:=NewStr(Name);
  48. P^.Path:=NewStr(Path);
  49. NewTemplate:=P;
  50. end;
  51. procedure DisposeTemplate(P: PTemplate);
  52. begin
  53. if assigned(P) then
  54. begin
  55. if assigned(P^.Name) then
  56. DisposeStr(P^.Name);
  57. if assigned(P^.Path) then
  58. DisposeStr(P^.Path);
  59. Dispose(P);
  60. end;
  61. end;
  62. function TTemplateCollection.At(Index: Integer): PTemplate;
  63. begin
  64. At:=inherited At(Index);
  65. end;
  66. procedure TTemplateCollection.FreeItem(Item: Pointer);
  67. begin
  68. if assigned(Item) then
  69. DisposeTemplate(Item);
  70. end;
  71. function TTemplateCollection.Compare(Key1, Key2: Pointer): Sw_Integer;
  72. var R: Sw_integer;
  73. K1: PTemplate absolute Key1;
  74. K2: PTemplate absolute Key2;
  75. begin
  76. if K1^.Name^<K2^.Name^ then R:=-1 else
  77. if K1^.Name^>K2^.Name^ then R:= 1 else
  78. R:=0;
  79. Compare:=R;
  80. end;
  81. function GetTemplateCount: integer;
  82. var Count: integer;
  83. begin
  84. if Templates=nil then Count:=0 else Count:=Templates^.Count;
  85. GetTemplateCount:=Count;
  86. end;
  87. function GetTemplateName(Index: integer): string;
  88. begin
  89. GetTemplateName:=Templates^.At(Index)^.Name^;
  90. end;
  91. function StartTemplate(Index: integer; Editor: PSourceEditor): boolean;
  92. var
  93. T: PTemplate;
  94. OK: boolean;
  95. begin
  96. T:=Templates^.At(Index);
  97. OK:=StartEditor(Editor,T^.Path^);
  98. StartTemplate:=OK;
  99. end;
  100. {*****************************************************************************
  101. InitTemplates
  102. *****************************************************************************}
  103. procedure InitTemplates;
  104. procedure ScanDir(Dir: PathStr);
  105. var SR: SearchRec;
  106. S: string;
  107. PT : PTemplate;
  108. i : sw_integer;
  109. begin
  110. if copy(Dir,length(Dir),1)<>DirSep then Dir:=Dir+DirSep;
  111. FindFirst(Dir+'*.pt',AnyFile,SR);
  112. while (DosError=0) do
  113. begin
  114. S:=NameOf(SR.Name);
  115. S:=LowerCaseStr(S);
  116. S[1]:=Upcase(S[1]);
  117. PT:=NewTemplate(S,FExpand(Dir+SR.Name));
  118. if not Templates^.Search(PT,i) then
  119. Templates^.Insert(PT)
  120. else
  121. DisposeTemplate(PT);
  122. FindNext(SR);
  123. end;
  124. {$ifdef FPC}
  125. FindClose(SR);
  126. {$endif def FPC}
  127. end;
  128. begin
  129. New(Templates, Init(10,10));
  130. ScanDir('.');
  131. ScanDir(IDEDir);
  132. end;
  133. procedure DoneTemplates;
  134. begin
  135. if assigned(Templates) then
  136. begin
  137. Dispose(Templates, Done);
  138. Templates:=nil;
  139. end;
  140. end;
  141. END.
  142. {
  143. $Log$
  144. Revision 1.8 1999-06-25 00:33:40 pierre
  145. * avoid lost memory on duplicate Template Items
  146. Revision 1.7 1999/03/08 14:58:11 peter
  147. + prompt with dialogs for tools
  148. Revision 1.6 1999/03/01 15:42:03 peter
  149. + Added dummy entries for functions not yet implemented
  150. * MenuBar didn't update itself automatically on command-set changes
  151. * Fixed Debugging/Profiling options dialog
  152. * TCodeEditor converts spaces to tabs at save only if efUseTabChars is
  153. set
  154. * efBackSpaceUnindents works correctly
  155. + 'Messages' window implemented
  156. + Added '$CAP MSG()' and '$CAP EDIT' to available tool-macros
  157. + Added TP message-filter support (for ex. you can call GREP thru
  158. GREP2MSG and view the result in the messages window - just like in TP)
  159. * A 'var' was missing from the param-list of THelpFacility.TopicSearch,
  160. so topic search didn't work...
  161. * In FPHELP.PAS there were still context-variables defined as word instead
  162. of THelpCtx
  163. * StdStatusKeys() was missing from the statusdef for help windows
  164. + Topic-title for index-table can be specified when adding a HTML-files
  165. Revision 1.5 1999/02/18 13:44:35 peter
  166. * search fixed
  167. + backward search
  168. * help fixes
  169. * browser updates
  170. Revision 1.4 1999/02/16 17:13:56 pierre
  171. + findclose added for FPC
  172. Revision 1.3 1999/01/21 11:54:24 peter
  173. + tools menu
  174. + speedsearch in symbolbrowser
  175. * working run command
  176. Revision 1.2 1998/12/28 15:47:52 peter
  177. + Added user screen support, display & window
  178. + Implemented Editor,Mouse Options dialog
  179. + Added location of .INI and .CFG file
  180. + Option (INI) file managment implemented (see bottom of Options Menu)
  181. + Switches updated
  182. + Run program
  183. Revision 1.2 1998/12/22 10:39:51 peter
  184. + options are now written/read
  185. + find and replace routines
  186. }