FindInFiles.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. unit FindInFiles;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, Mask, JvExMask, JvToolEdit, ExtCtrls, JvExStdCtrls,
  6. JvRadioButton;
  7. type
  8. TfrmFindInFiles = class(TForm)
  9. cboSearchInFilesText: TComboBox;
  10. Label1: TLabel;
  11. gbSearchOptions: TGroupBox;
  12. chkSearchCaseSensitive: TCheckBox;
  13. chkSearchWholeWords: TCheckBox;
  14. chkRegularExpression: TCheckBox;
  15. fraDirectory: TGroupBox;
  16. jvdirDirectory: TJvDirectoryEdit;
  17. Label2: TLabel;
  18. optOutput: TRadioGroup;
  19. btnOK: TButton;
  20. btnCancel: TButton;
  21. chkIncludeSubdir: TCheckBox;
  22. fraWhere: TGroupBox;
  23. jvoptFilesInDir: TJvRadioButton;
  24. jvoptActiveProject: TJvRadioButton;
  25. jvoptOpenFiles: TJvRadioButton;
  26. procedure btnOKClick(Sender: TObject);
  27. procedure optWhereClick(Sender: TObject);
  28. procedure btnCancelClick(Sender: TObject);
  29. procedure FormShow(Sender: TObject);
  30. private
  31. { Private declarations }
  32. public
  33. { Public declarations }
  34. SearchText: String;
  35. SearchDirectory: String;
  36. function IsCaseSensitive: Boolean;
  37. function IsWholeWordOnly: Boolean;
  38. function IsResgularExpression: Boolean;
  39. function IsSubDir: Boolean;
  40. function GetSearchMode: Integer;
  41. procedure SetSearchMode(Index: Integer);
  42. function GetOutput: Integer;
  43. end;
  44. var
  45. frmFindInFiles: TfrmFindInFiles;
  46. implementation
  47. uses Main;
  48. {$R *.dfm}
  49. procedure TfrmFindInFiles.btnOKClick(Sender: TObject);
  50. begin
  51. if cboSearchInFilesText.Text <> '' then
  52. begin
  53. SearchText := cboSearchInFilesText.Text;
  54. SearchDirectory := jvdirDirectory.Text;
  55. Self.Close;
  56. end
  57. else
  58. begin
  59. Application.MessageBox('The search string cannot be blank.', 'LuaEdit', MB_OK+MB_ICONERROR);
  60. end;
  61. end;
  62. procedure TfrmFindInFiles.btnCancelClick(Sender: TObject);
  63. begin
  64. SearchText := '';
  65. SearchDirectory := '';
  66. Self.Close;
  67. end;
  68. procedure TfrmFindInFiles.optWhereClick(Sender: TObject);
  69. begin
  70. fraDirectory.Enabled := (GetSearchMode = 2);
  71. jvdirDirectory.Enabled := (GetSearchMode = 2);
  72. chkIncludeSubdir.Enabled := (GetSearchMode = 2);
  73. end;
  74. function TfrmFindInFiles.IsCaseSensitive: Boolean;
  75. begin
  76. Result := chkSearchCaseSensitive.Checked;
  77. end;
  78. function TfrmFindInFiles.IsWholeWordOnly: Boolean;
  79. begin
  80. Result := chkSearchWholeWords.Checked;
  81. end;
  82. function TfrmFindInFiles.IsResgularExpression: Boolean;
  83. begin
  84. Result := chkRegularExpression.Checked;
  85. end;
  86. function TfrmFindInFiles.IsSubDir: Boolean;
  87. begin
  88. Result := chkIncludeSubdir.Checked;
  89. end;
  90. function TfrmFindInFiles.GetSearchMode: Integer;
  91. begin
  92. // Retreive mode through radio buttons
  93. if jvoptActiveProject.Checked then
  94. Result := 0
  95. else if jvoptOpenFiles.Checked then
  96. Result := 1
  97. else
  98. Result := 2;
  99. end;
  100. procedure TfrmFindInFiles.SetSearchMode(Index: Integer);
  101. begin
  102. // Set mode through radio buttons
  103. case Index of
  104. 0:
  105. begin
  106. if jvoptActiveProject.Enabled then
  107. jvoptActiveProject.Checked := True
  108. else
  109. SetSearchMode(2);
  110. end;
  111. 1:
  112. begin
  113. if jvoptOpenFiles.Enabled then
  114. jvoptOpenFiles.Checked := True
  115. else
  116. SetSearchMode(2);
  117. end;
  118. 2: jvoptFilesInDir.Checked := True;
  119. end;
  120. end;
  121. function TfrmFindInFiles.GetOutput: Integer;
  122. begin
  123. Result := optOutput.ItemIndex;
  124. end;
  125. procedure TfrmFindInFiles.FormShow(Sender: TObject);
  126. begin
  127. optWhereClick(nil);
  128. end;
  129. end.