fpmsrch.inc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. S: PSortedSymbolCollection;
  39. Overflow: boolean;
  40. ProcS : string;
  41. Level : longint;
  42. function NameMatches(const St : string) : boolean;
  43. begin
  44. NameMatches:=(ProcS='') or (Pos(ProcS,UpcaseStr(St)) > 0);
  45. end;
  46. procedure InsertInS(P: PSymbol);
  47. procedure InsertItemsInS(P: PSymbolCollection);
  48. var I: Sw_integer;
  49. begin
  50. for I:=0 to P^.Count-1 do
  51. InsertInS(P^.At(I));
  52. end;
  53. begin
  54. Inc(level);
  55. if S^.Count=MaxCollectionSize then
  56. begin Overflow:=true; Exit; end;
  57. if {(P^.typ = procsym) this needs symconst unit which I prefer to avoid }
  58. ((P^.GetTypeName='proc') or (P^.GetTypeName='func'))
  59. and NameMatches(P^.GetName) then
  60. S^.Insert(P);
  61. { this is wrong because it inserted args or locals of proc
  62. in the globals list !! PM}
  63. if (P^.Items<>nil) and (level=1) then
  64. InsertItemsInS(P^.Items);
  65. Dec(level);
  66. end;
  67. var
  68. EditorWindow : PSourceWindow;
  69. begin
  70. level:=0;
  71. if BrowCol.Modules=nil then
  72. begin ErrorBox(msg_nodebuginfoavailable,nil); Exit; end;
  73. EditorWindow:=FirstEditorWindow;
  74. If assigned(EditorWindow) then
  75. ProcS:=LowerCaseStr(EditorWindow^.Editor^.GetCurrentWord)
  76. else
  77. ProcS:='';
  78. if ExecuteDialog(ProcedureDialog(ProcS),@ProcS)=cmCancel then
  79. exit;
  80. ProcS:=UpcaseStr(ProcS);
  81. Overflow:=false;
  82. if assigned(ProcedureCollection) then
  83. begin
  84. ProcedureCollection^.deleteAll;
  85. Dispose(ProcedureCollection,done);
  86. end;
  87. New(S, Init(500,500));
  88. ProcedureCollection:=S;
  89. BrowCol.Modules^.ForEach(TCallbackProcParam(@InsertInS));
  90. if Overflow then
  91. WarningBox(msg_toomanysymbolscantdisplayall,nil);
  92. Desktop^.GetExtent(R); R.A.X:=R.B.X-35;
  93. Desktop^.Insert(New(PBrowserWindow, Init(R,
  94. label_sym_findprocedure,SearchFreeWindowNo,nil,label_sym_findprocedure2+ProcS,'',S,nil,nil,nil)));
  95. end;
  96. procedure TIDEApp.Objects;
  97. begin
  98. if ObjectTree=nil then
  99. begin ErrorBox(msg_nodebuginfoavailable,nil); Exit; end;
  100. OpenSymbolBrowser(0,0,label_sym_objects,label_sym_globalscope,nil,nil,nil,nil,ObjectTree,nil);
  101. end;
  102. procedure TIDEApp.Globals;
  103. var R: TRect;
  104. S: PSortedSymbolCollection;
  105. Overflow: boolean;
  106. Level : longint;
  107. procedure InsertInS(P: PSymbol);
  108. procedure InsertItemsInS(P: PSymbolCollection);
  109. var I: Sw_integer;
  110. begin
  111. for I:=0 to P^.Count-1 do
  112. InsertInS(P^.At(I));
  113. end;
  114. begin
  115. Inc(level);
  116. if S^.Count=MaxCollectionSize then
  117. begin Overflow:=true; Exit; end;
  118. S^.Insert(P);
  119. { this is wrong because it inserted args or locals of proc
  120. in the globals list !! PM}
  121. if (P^.Items<>nil) and (level=1) then
  122. InsertItemsInS(P^.Items);
  123. Dec(level);
  124. end;
  125. begin
  126. level:=0;
  127. if BrowCol.Modules=nil then
  128. begin ErrorBox(msg_nodebuginfoavailable,nil); Exit; end;
  129. Overflow:=false;
  130. if assigned(GlobalsCollection) then
  131. begin
  132. GlobalsCollection^.deleteAll;
  133. Dispose(GlobalsCollection,done);
  134. end;
  135. New(S, Init(500,500));
  136. GlobalsCollection:=S;
  137. BrowCol.Modules^.ForEach(TCallbackProcParam(@InsertInS));
  138. if Overflow then
  139. WarningBox(msg_toomanysymbolscantdisplayall,nil);
  140. Desktop^.GetExtent(R); R.A.X:=R.B.X-35;
  141. Desktop^.Insert(New(PBrowserWindow, Init(R,
  142. label_sym_globals,SearchFreeWindowNo,nil,label_sym_globalscope,'',S,nil,nil,nil)));
  143. end;
  144. procedure TIDEApp.Modules;
  145. var
  146. R: TRect;
  147. S: PSortedSymbolCollection;
  148. procedure InsertInS(P: PSymbol);
  149. begin
  150. S^.Insert(P);
  151. end;
  152. begin
  153. if BrowCol.Modules=nil then
  154. begin ErrorBox(msg_nodebuginfoavailable,nil); Exit; end;
  155. if assigned(ModulesCollection) then
  156. begin
  157. ModulesCollection^.deleteAll;
  158. Dispose(ModulesCollection,done);
  159. end;
  160. New(S, Init(500,500));
  161. ModulesCollection:=S;
  162. BrowCol.Modules^.ForEach(TCallbackProcParam(@InsertInS));
  163. Desktop^.GetExtent(R); R.A.X:=R.B.X-35;
  164. Desktop^.Insert(New(PBrowserWindow, Init(R,
  165. dialog_units,SearchFreeWindowNo,nil,label_sym_globalscope,'',S,nil,nil,nil)));
  166. end;
  167. function SymbolDialog(S : string) : PDialog;
  168. var D: PDialog;
  169. R,R1,R2: TRect;
  170. IL: PEditorInputLine;
  171. begin
  172. R.Assign(0,0,40,8);
  173. New(D, Init(R, dialog_browsesymbol));
  174. with D^ do
  175. begin
  176. Options:=Options or ofCentered;
  177. GetExtent(R); R.Grow(-3,-2); R.B.Y:=R.A.Y+1;
  178. R1.Copy(R);
  179. R2.Copy(R); Inc(R2.A.Y);Inc(R2.B.Y);
  180. New(IL, Init(R2,255));
  181. Insert(IL);
  182. IL^.SetData(S);
  183. Insert(New(PLabel, Init(R1, label_entersymboltobrowse, IL)));
  184. GetExtent(R); R.Grow(-8,-1); R.A.Y:=R.B.Y-2; R.B.X:=R.A.X+10;
  185. Insert(New(PButton, Init(R, button_OK, cmOK, bfDefault)));
  186. R.Move(15,0);
  187. Insert(New(PButton, Init(R, button_Cancel, cmCancel, bfNormal)));
  188. end;
  189. IL^.Select;
  190. SymbolDialog:=D;
  191. end;
  192. procedure TIDEApp.SearchSymbol;
  193. var
  194. EditorWindow : PSourceWindow;
  195. S : string;
  196. begin
  197. EditorWindow:=FirstEditorWindow;
  198. If assigned(EditorWindow) then
  199. S:=LowerCaseStr(EditorWindow^.Editor^.GetCurrentWord)
  200. else
  201. S:='';
  202. if ExecuteDialog(SymbolDialog(S),@S)<>cmCancel then
  203. OpenOneSymbolBrowser(S);
  204. end;