FunctionList.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. unit FunctionList;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, JvExStdCtrls, JvListBox, JvDotNetControls, ShellAPI,
  6. JvComponent, JvDockControlForm, ComCtrls, JvExComCtrls, JvListView,
  7. ImgList, ToolWin;
  8. type
  9. TfrmFunctionList = class(TForm)
  10. JvDockClient1: TJvDockClient;
  11. lvwFunctions: TJvDotNetListView;
  12. tblFunctionList: TToolBar;
  13. tbtnRefresh: TToolButton;
  14. imlFunctionList: TImageList;
  15. ToolButton1: TToolButton;
  16. tbtnGotoDef: TToolButton;
  17. procedure lvwFunctionsDblClick(Sender: TObject);
  18. procedure tbtnRefreshClick(Sender: TObject);
  19. procedure tbtnGotoDefClick(Sender: TObject);
  20. private
  21. { Private declarations }
  22. public
  23. { Public declarations }
  24. procedure RefreshList(sFileName: String);
  25. end;
  26. var
  27. frmFunctionList: TfrmFunctionList;
  28. implementation
  29. uses Main;
  30. {$R *.dfm}
  31. procedure TfrmFunctionList.RefreshList(sFileName: String);
  32. var
  33. CTagAppPath, TagFile, CTagParams: String;
  34. sTag: String;
  35. cmdLine: String;
  36. x: Integer;
  37. lstTags: TStringList;
  38. pFctInfo: TFctInfo;
  39. pItem: TListItem;
  40. si: TStartupInfo;
  41. pi: TProcessInformation;
  42. begin
  43. // Free previously created TFctInfo objects...
  44. for x := 0 to lvwFunctions.Items.Count - 1 do
  45. TFctInfo(lvwFunctions.Items[x].Data).Free;
  46. lstTags := TStringList.Create;
  47. lvwFunctions.Items.Clear;
  48. lvwFunctions.Items.BeginUpdate;
  49. // Build executable and its parameters strings
  50. CTagAppPath := '"' + ExtractFilePath(Application.ExeName) + 'ctags.exe"';
  51. TagFile := ChangeFileExt(sFileName, '.tag');
  52. CTagParams := '"-f' + TagFile + '" "--fields=+n+S+K" "' + sFileName + '"';
  53. // Initialize createprocess variables for call
  54. FillChar(si, sizeof(si), 0);
  55. si.cb := sizeof(si);
  56. cmdLine := CTagAppPath + ' ' + CTagParams;
  57. // get the tags from the source
  58. CreateProcess(nil, PChar(cmdLine), nil, nil, True, CREATE_NO_WINDOW, nil, nil, si, pi);
  59. // Wait until the process is done
  60. WaitForSingleObject(pi.hProcess, INFINITE);
  61. // Closing handles
  62. CloseHandle(pi.hProcess);
  63. CloseHandle(pi.hThread);
  64. // Read the created tag file
  65. lstTags.LoadFromFile(TagFile);
  66. // searching for tags
  67. for x := 0 to lstTags.Count - 1 do
  68. begin
  69. sTag := lstTags.Strings[x];
  70. // make sure this line is not a comment
  71. if Pos('!_', sTag) <> 1 then
  72. begin
  73. pFctInfo := TFctInfo.Create;
  74. // Get the definition
  75. pFctInfo.FctDef := StringReplace(Copy(sTag, Pos('/^', sTag) + 2, Pos('$/;"', sTag) - Pos('/^', sTag) - 2), 'function ', '', [rfReplaceAll, rfIgnoreCase]);
  76. // Get the function's parameters
  77. pFctInfo.Params := Copy(pFctInfo.FctDef, Pos('(', pFctInfo.FctDef) + 1, Length(pFctInfo.FctDef) - 1 - Pos('(', pFctInfo.FctDef));
  78. // Get the line definition
  79. pFctInfo.Line := StrToInt(Copy(sTag, Pos('line:', sTag) + 5, Length(sTag) - Pos('line:', sTag) - 4));
  80. // Add function definition in list
  81. pItem := lvwFunctions.Items.Add;
  82. pItem.Caption := pFctInfo.FctDef;
  83. pItem.Data := pFctInfo;
  84. pItem.SubItems.Add(IntToStr(pFctInfo.Line));
  85. end;
  86. end;
  87. lvwFunctions.Items.EndUpdate;
  88. lstTags.Free;
  89. end;
  90. procedure TfrmFunctionList.lvwFunctionsDblClick(Sender: TObject);
  91. begin
  92. tbtnGotoDef.Click;
  93. end;
  94. procedure TfrmFunctionList.tbtnRefreshClick(Sender: TObject);
  95. begin
  96. if Assigned(frmMain.jvUnitBar.SelectedTab) then
  97. begin
  98. if Assigned(frmMain.jvUnitBar.SelectedTab.Data) then
  99. begin
  100. RefreshList(TLuaUnit(frmMain.jvUnitBar.SelectedTab.Data).sUnitPath);
  101. end;
  102. end;
  103. end;
  104. procedure TfrmFunctionList.tbtnGotoDefClick(Sender: TObject);
  105. begin
  106. if Assigned(lvwFunctions.Selected) then
  107. frmMain.PopUpUnitToScreen(TLuaUnit(frmMain.jvUnitBar.SelectedTab.Data).sUnitPath, TFctInfo(lvwFunctions.Selected.Data).Line, False, HIGHLIGHT_STACK)
  108. end;
  109. end.