fpmsrch.inc 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. {
  2. This file is part of the Free Pascal Integrated Development Environment
  3. Copyright (c) 1998 by Berczi Gabor
  4. Search menu entries
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. function ProcedureDialog(S : string) : PDialog;
  12. var D: PDialog;
  13. R,R1,R2: TRect;
  14. IL: PEditorInputLine;
  15. begin
  16. R.Assign(0,0,40,8);
  17. New(D, Init(R, dialog_proceduredialog));
  18. with D^ do
  19. begin
  20. Options:=Options or ofCentered;
  21. GetExtent(R); R.Grow(-3,-2); R.B.Y:=R.A.Y+1;
  22. R1.Copy(R);
  23. R2.Copy(R); Inc(R2.A.Y);Inc(R2.B.Y);
  24. New(IL, Init(R2,255));
  25. Insert(IL);
  26. IL^.SetData(S);
  27. Insert(New(PLabel, Init(R1, label_enterproceduretofind, IL)));
  28. GetExtent(R); R.Grow(-8,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  29. Insert(New(PButton, Init(R, button_OK, cmOK, bfDefault)));
  30. R.Move(15,0);
  31. Insert(New(PButton, Init(R, button_Cancel, cmCancel, bfNormal)));
  32. end;
  33. IL^.Select;
  34. ProcedureDialog:=D;
  35. end;
  36. procedure TIDEApp.FindProcedure;
  37. var R: TRect;
  38. PB: PBrowserWindow;
  39. S: PSortedSymbolCollection;
  40. Overflow: boolean;
  41. ProcS : string;
  42. Level : longint;
  43. function NameMatches(const St : string) : boolean;
  44. begin
  45. NameMatches:=(ProcS='') or (Pos(ProcS,UpcaseStr(St)) > 0);
  46. end;
  47. procedure InsertInS(P: PSymbol);
  48. procedure InsertItemsInS(P: PSymbolCollection);
  49. var I: Sw_integer;
  50. begin
  51. for I:=0 to P^.Count-1 do
  52. InsertInS(P^.At(I));
  53. end;
  54. begin
  55. Inc(level);
  56. if S^.Count=MaxCollectionSize then
  57. begin Overflow:=true; Exit; end;
  58. if {(P^.typ = procsym) this needs symconst unit which I prefer to avoid }
  59. ((P^.GetTypeName='proc') or (P^.GetTypeName='func'))
  60. and NameMatches(P^.GetName) then
  61. S^.Insert(P);
  62. { this is wrong because it inserted args or locals of proc
  63. in the globals list !! PM}
  64. if (P^.Items<>nil) and (level=1) then
  65. InsertItemsInS(P^.Items);
  66. Dec(level);
  67. end;
  68. var
  69. EditorWindow : PSourceWindow;
  70. begin
  71. level:=0;
  72. if BrowCol.Modules=nil then
  73. begin ErrorBox(msg_nodebuginfoavailable,nil); Exit; end;
  74. EditorWindow:=FirstEditorWindow;
  75. If assigned(EditorWindow) then
  76. ProcS:=LowerCaseStr(EditorWindow^.Editor^.GetCurrentWord)
  77. else
  78. ProcS:='';
  79. if ExecuteDialog(ProcedureDialog(ProcS),@ProcS)=cmCancel then
  80. exit;
  81. ProcS:=UpcaseStr(ProcS);
  82. Overflow:=false;
  83. if assigned(ProcedureCollection) then
  84. begin
  85. ProcedureCollection^.deleteAll;
  86. Dispose(ProcedureCollection,done);
  87. end;
  88. New(S, Init(500,500));
  89. ProcedureCollection:=S;
  90. BrowCol.Modules^.ForEach(TCallbackProcParam(@InsertInS));
  91. if Overflow then
  92. WarningBox(msg_toomanysymbolscantdisplayall,nil);
  93. Desktop^.GetExtent(R); R.A.X:=R.B.X-35;
  94. PB:=New(PBrowserWindow, Init(R,
  95. label_sym_findprocedure,SearchFreeWindowNo,nil,label_sym_findprocedure2+ProcS,'',S,nil,nil,nil));
  96. Desktop^.Insert(PB);
  97. BrowserRoot^.InsertWindow(PB);
  98. end;
  99. procedure TIDEApp.Objects;
  100. var PB : PBrowserWindow;
  101. begin
  102. if ObjectTree=nil then
  103. begin ErrorBox(msg_nodebuginfoavailable,nil); Exit; end;
  104. PB:=OpenSymbolBrowser(0,0,0,0,label_sym_objects,label_sym_globalscope,nil,nil,nil,nil,ObjectTree,nil);
  105. BrowserRoot^.InsertWindow(PB);
  106. end;
  107. procedure TIDEApp.Globals;
  108. var R: TRect;
  109. S: PSortedSymbolCollection;
  110. Overflow: boolean;
  111. Level : longint;
  112. PB : PBrowserWindow;
  113. procedure InsertInS(P: PSymbol);
  114. procedure InsertItemsInS(P: PSymbolCollection);
  115. var I: Sw_integer;
  116. begin
  117. for I:=0 to P^.Count-1 do
  118. InsertInS(P^.At(I));
  119. end;
  120. begin
  121. Inc(level);
  122. if S^.Count=MaxCollectionSize then
  123. begin Overflow:=true; Exit; end;
  124. S^.Insert(P);
  125. { this is wrong because it inserted args or locals of proc
  126. in the globals list !! PM}
  127. if (P^.Items<>nil) and (level=1) then
  128. InsertItemsInS(P^.Items);
  129. Dec(level);
  130. end;
  131. begin
  132. level:=0;
  133. if BrowCol.Modules=nil then
  134. begin ErrorBox(msg_nodebuginfoavailable,nil); Exit; end;
  135. Overflow:=false;
  136. if assigned(GlobalsCollection) then
  137. begin
  138. GlobalsCollection^.deleteAll;
  139. Dispose(GlobalsCollection,done);
  140. end;
  141. New(S, Init(500,500));
  142. GlobalsCollection:=S;
  143. BrowCol.Modules^.ForEach(TCallbackProcParam(@InsertInS));
  144. if Overflow then
  145. WarningBox(msg_toomanysymbolscantdisplayall,nil);
  146. Desktop^.GetExtent(R); R.A.X:=R.B.X-35;
  147. PB:=New(PBrowserWindow, Init(R,
  148. label_sym_globals,SearchFreeWindowNo,nil,label_sym_globalscope,'',S,nil,nil,nil));
  149. Desktop^.Insert(PB);
  150. BrowserRoot^.InsertWindow(PB);
  151. end;
  152. procedure TIDEApp.Modules;
  153. var
  154. R: TRect;
  155. S: PSortedSymbolCollection;
  156. PB : PBrowserWindow;
  157. procedure InsertInS(P: PSymbol);
  158. begin
  159. S^.Insert(P);
  160. end;
  161. begin
  162. if BrowCol.Modules=nil then
  163. begin ErrorBox(msg_nodebuginfoavailable,nil); Exit; end;
  164. if assigned(ModulesCollection) then
  165. begin
  166. ModulesCollection^.deleteAll;
  167. Dispose(ModulesCollection,done);
  168. end;
  169. New(S, Init(500,500));
  170. ModulesCollection:=S;
  171. BrowCol.Modules^.ForEach(TCallbackProcParam(@InsertInS));
  172. Desktop^.GetExtent(R); R.A.X:=R.B.X-35;
  173. PB:=New(PBrowserWindow, Init(R,
  174. dialog_units,SearchFreeWindowNo,nil,label_sym_globalscope,'',S,nil,nil,nil));
  175. Desktop^.Insert(PB);
  176. BrowserRoot^.InsertWindow(PB);
  177. end;
  178. function SymbolDialog(S : string) : PDialog;
  179. var D: PDialog;
  180. R,R1,R2: TRect;
  181. IL: PEditorInputLine;
  182. begin
  183. R.Assign(0,0,40,8);
  184. New(D, Init(R, dialog_browsesymbol));
  185. with D^ do
  186. begin
  187. Options:=Options or ofCentered;
  188. GetExtent(R); R.Grow(-3,-2); R.B.Y:=R.A.Y+1;
  189. R1.Copy(R);
  190. R2.Copy(R); Inc(R2.A.Y);Inc(R2.B.Y);
  191. New(IL, Init(R2,255));
  192. Insert(IL);
  193. IL^.SetData(S);
  194. Insert(New(PLabel, Init(R1, label_entersymboltobrowse, IL)));
  195. GetExtent(R); R.Grow(-8,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  196. Insert(New(PButton, Init(R, button_OK, cmOK, bfDefault)));
  197. R.Move(15,0);
  198. Insert(New(PButton, Init(R, button_Cancel, cmCancel, bfNormal)));
  199. end;
  200. IL^.Select;
  201. SymbolDialog:=D;
  202. end;
  203. procedure TIDEApp.SearchSymbol;
  204. var
  205. EditorWindow : PSourceWindow;
  206. S : string;
  207. begin
  208. EditorWindow:=FirstEditorWindow;
  209. If assigned(EditorWindow) then
  210. S:=LowerCaseStr(EditorWindow^.Editor^.GetCurrentWord)
  211. else
  212. S:='';
  213. if ExecuteDialog(SymbolDialog(S),@S)<>cmCancel then
  214. OpenOneSymbolBrowser(S);
  215. end;