SourceFileWinUnit.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2000-2004 Sebastian Reichelt
  4. Copyright (C) 2006 Kevin Kofler
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. }
  17. unit SourceFileWinUnit;
  18. interface
  19. uses
  20. SourceFileUnit,
  21. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  22. ComCtrls, Menus, ActnList, ToolWin, MemoComponentUnit, ExtCtrls{$IFDEF CODINGEXT}, CompletionForm{$ENDIF};
  23. type
  24. TSourceFileForm = class(TForm)
  25. Actions: TActionList;
  26. ActionFilePrint: TAction;
  27. ActionFilePrintQuickly: TAction;
  28. ActionFileClose: TAction;
  29. ActionEditUndo: TAction;
  30. ActionEditRedo: TAction;
  31. ActionEditDelete: TAction;
  32. ActionEditCut: TAction;
  33. ActionEditCopy: TAction;
  34. ActionEditPaste: TAction;
  35. ActionEditSelectAll: TAction;
  36. ActionFindFind: TAction;
  37. ActionFindReplace: TAction;
  38. ActionFindOpenFile: TAction;
  39. ActionFindFunctions: TAction;
  40. ActionEditIncreaseIndent: TAction;
  41. ActionEditDecreaseIndent: TAction;
  42. MainMenu: TMainMenu;
  43. File1: TMenuItem;
  44. Print1: TMenuItem;
  45. Edit1: TMenuItem;
  46. Undo1: TMenuItem;
  47. Redo1: TMenuItem;
  48. N2: TMenuItem;
  49. Delete1: TMenuItem;
  50. Cut1: TMenuItem;
  51. Copy1: TMenuItem;
  52. Paste1: TMenuItem;
  53. N9: TMenuItem;
  54. SelectAll1: TMenuItem;
  55. N18: TMenuItem;
  56. IncreaseIndent1: TMenuItem;
  57. DecreaseIndent1: TMenuItem;
  58. Find1: TMenuItem;
  59. Find2: TMenuItem;
  60. Replace1: TMenuItem;
  61. N13: TMenuItem;
  62. Functions1: TMenuItem;
  63. N15: TMenuItem;
  64. OpenFileAtCursor1: TMenuItem;
  65. ActionFileSave: TAction;
  66. ActionFileSaveAs: TAction;
  67. ActionFileCompile: TAction;
  68. Save1: TMenuItem;
  69. SaveAs1: TMenuItem;
  70. N1: TMenuItem;
  71. Compile1: TMenuItem;
  72. N3: TMenuItem;
  73. N4: TMenuItem;
  74. Close1: TMenuItem;
  75. StatusBar: TStatusBar;
  76. EditorToolBar: TToolBar;
  77. ToolButton3: TToolButton;
  78. ToolButton4: TToolButton;
  79. ToolButton23: TToolButton;
  80. ToolButton24: TToolButton;
  81. ToolButton6: TToolButton;
  82. ToolButton7: TToolButton;
  83. ToolButton8: TToolButton;
  84. ToolButton9: TToolButton;
  85. ToolButton10: TToolButton;
  86. ToolButton5: TToolButton;
  87. ToolButton19: TToolButton;
  88. ToolButton11: TToolButton;
  89. ToolButton20: TToolButton;
  90. ToolButton21: TToolButton;
  91. ToolButton25: TToolButton;
  92. ToolButton22: TToolButton;
  93. ToolButton13: TToolButton;
  94. ToolBarBevel: TBevel;
  95. ToolButton1: TToolButton;
  96. EditorPopup: TPopupMenu;
  97. Undo2: TMenuItem;
  98. Redo2: TMenuItem;
  99. N16: TMenuItem;
  100. Clear1: TMenuItem;
  101. Cut2: TMenuItem;
  102. Copy2: TMenuItem;
  103. Paste2: TMenuItem;
  104. N17: TMenuItem;
  105. SelectAll2: TMenuItem;
  106. N20: TMenuItem;
  107. IncreaseIndent2: TMenuItem;
  108. DecreaseIndent2: TMenuItem;
  109. N5: TMenuItem;
  110. OpenFileatCursor2: TMenuItem;
  111. FindDlg: TFindDialog;
  112. ReplaceDlg: TReplaceDialog;
  113. FunctionPopup: TPopupMenu;
  114. NoFunctionsItem: TMenuItem;
  115. ActionFileAddToProject: TAction;
  116. AddtoProject1: TMenuItem;
  117. N6: TMenuItem;
  118. ToolButton2: TToolButton;
  119. procedure FormClose(Sender: TObject; var Action: TCloseAction);
  120. procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  121. procedure FormCreate(Sender: TObject);
  122. procedure ActionFileCloseExecute(Sender: TObject);
  123. procedure FileSave(Sender: TObject);
  124. procedure FileSaveAs(Sender: TObject);
  125. procedure FileCompile(Sender: TObject);
  126. procedure FilePrint(Sender: TObject);
  127. procedure FilePrintQuickly(Sender: TObject);
  128. procedure EditorChange(Sender: TObject);
  129. procedure EditUndo(Sender: TObject);
  130. procedure EditRedo(Sender: TObject);
  131. procedure EditDelete(Sender: TObject);
  132. procedure EditCut(Sender: TObject);
  133. procedure EditCopy(Sender: TObject);
  134. procedure EditPaste(Sender: TObject);
  135. procedure EditSelectAll(Sender: TObject);
  136. procedure EditIncreaseIndent(Sender: TObject);
  137. procedure EditDecreaseIndent(Sender: TObject);
  138. procedure FindDlgFind(Sender: TObject);
  139. procedure ReplaceDlgReplace(Sender: TObject);
  140. procedure FindString(Sender: TObject);
  141. procedure FindFind(Sender: TObject);
  142. procedure FindReplace(Sender: TObject);
  143. procedure FindOpenFile(Sender: TObject);
  144. procedure FunctionPopupPopup(Sender: TObject);
  145. procedure FindFunctions(Sender: TObject);
  146. procedure FindFunctionFromPopup(Sender: TObject);
  147. procedure FileAddToProject(Sender: TObject);
  148. procedure FormEnable(Sender: TObject);
  149. procedure FormShow(Sender: TObject);
  150. procedure FindDlgClose(Sender: TObject);
  151. private
  152. FSourceFile: TSourceFile;
  153. procedure SetSourceFile(const Value: TSourceFile);
  154. function GetEditor: TMemoComponent;
  155. protected
  156. procedure CreateParams(var Params: TCreateParams); override;
  157. public
  158. OriginalCaption: string;
  159. EnableTimer: TTimer;
  160. Funcs: TSourceFileFunctions;
  161. procedure UpdateCaption;
  162. procedure UpdateEditButtons;
  163. procedure UpdateStatusBar;
  164. procedure UpdateFuncs;
  165. property SourceFile: TSourceFile read FSourceFile write SetSourceFile;
  166. property Editor: TMemoComponent read GetEditor;
  167. {$IFDEF CODINGEXT}
  168. procedure InitCodingExt;
  169. procedure ActionFindSymbolExecute(Sender: TObject);
  170. {$ENDIF}
  171. end;
  172. implementation
  173. {$R *.DFM}
  174. uses
  175. Printers,
  176. UtilsDos, UtilsWin,
  177. MasterUnit,
  178. MainUnit, FunctionsWinUnit;
  179. procedure TSourceFileForm.SetSourceFile(const Value: TSourceFile);
  180. begin
  181. FSourceFile := Value;
  182. UpdateCaption;
  183. if Assigned (SourceFile) and (SourceFile is TTextSourceFile) then
  184. with SourceFile as TTextSourceFile do
  185. if Assigned (TextEditor) then
  186. with TextEditor do begin
  187. OnKeyDown := MainForm.EditorKeyDown;
  188. OnChange := EditorChange;
  189. OnSelectionChange := EditorChange;
  190. PopupMenu := EditorPopup;
  191. end;
  192. ActionFileCompile.Enabled := Assigned (SourceFile) and SourceFile.Compilable;
  193. ActionFilePrint.Enabled := Assigned (SourceFile) and SourceFile.Printable and (Printer.Printers.Count > 0);
  194. ActionFilePrintQuickly.Enabled := ActionFilePrint.Enabled;
  195. ActionFindFunctions.Enabled := Assigned (SourceFile) and (SourceFile is TSourceTextSourceFile);
  196. EditorChange (Editor);
  197. end;
  198. procedure TSourceFileForm.UpdateCaption;
  199. begin
  200. if Assigned (SourceFile) then begin
  201. Caption := OriginalCaption + ' - ' + SourceFile.SourceName;
  202. if (MainForm.ProjectFile = '') and (ExtractFilePath (SourceFile.FileName) = 'C:\') then
  203. StatusBar.Panels.Items[5].Text := ExtractFileName (SourceFile.FileName)
  204. else
  205. StatusBar.Panels.Items[5].Text := SourceFile.FileName;
  206. end else
  207. Caption := OriginalCaption;
  208. end;
  209. function TSourceFileForm.GetEditor: TMemoComponent;
  210. begin
  211. if Assigned (SourceFile) and (SourceFile is TTextSourceFile) then
  212. Result := (SourceFile as TTextSourceFile).TextEditor
  213. else
  214. Result := nil;
  215. end;
  216. procedure TSourceFileForm.FormClose(Sender: TObject;
  217. var Action: TCloseAction);
  218. begin
  219. if Assigned (SourceFile) and (SourceFile.ParentForm = Self) then begin
  220. SourceFile.ParentForm := nil;
  221. SourceFile.Free;
  222. end;
  223. Action := caFree;
  224. end;
  225. procedure TSourceFileForm.FormCloseQuery(Sender: TObject;
  226. var CanClose: Boolean);
  227. begin
  228. if Compiling then
  229. CanClose := False
  230. else if Assigned (SourceFile) and (SourceFile.ParentForm = Self) then
  231. SourceFile.WarnIfModified;
  232. end;
  233. procedure TSourceFileForm.FormCreate(Sender: TObject);
  234. begin
  235. OriginalCaption := Caption;
  236. {$IFDEF CODINGEXT}
  237. InitCodingExt;
  238. {$ENDIF}
  239. end;
  240. procedure TSourceFileForm.ActionFileCloseExecute(Sender: TObject);
  241. begin
  242. if not Compiling then
  243. Close;
  244. end;
  245. procedure TSourceFileForm.FileSave(Sender: TObject);
  246. begin
  247. if Assigned (SourceFile) then begin
  248. SourceFile.Save;
  249. UpdateCaption;
  250. end;
  251. end;
  252. procedure TSourceFileForm.FileSaveAs(Sender: TObject);
  253. begin
  254. if Assigned (SourceFile) then begin
  255. SourceFile.SaveAs;
  256. UpdateCaption;
  257. UpdateStatusBar;
  258. end;
  259. end;
  260. procedure TSourceFileForm.FileCompile(Sender: TObject);
  261. begin
  262. if (not Compiling) and Assigned (SourceFile) then
  263. with MainForm do begin
  264. BeginCompilation;
  265. CopyHeaders;
  266. Self.SourceFile.Compile;
  267. DeleteHeaders;
  268. EndCompilation;
  269. end;
  270. end;
  271. procedure TSourceFileForm.FilePrint(Sender: TObject);
  272. var
  273. Cp: Integer;
  274. begin
  275. if Assigned (SourceFile) and (Printer.Printers.Count > 0) then
  276. with MainForm do try
  277. PrintDlg.PrintRange := prAllPages;
  278. PrintDlg.MaxPage := TSourceFile(ProjectTree.Selected.Data).CountPages;
  279. PrintDlg.ToPage := PrintDlg.MaxPage;
  280. if Assigned (CurrentEditor) then begin
  281. if CurrentEditor.Selection.RLength > 0 then
  282. PrintDlg.Options := PrintDlg.Options + [poSelection]
  283. else
  284. PrintDlg.Options := PrintDlg.Options - [poSelection];
  285. end;
  286. if Assigned (Sender) then begin
  287. if not PrintDlg.Execute then
  288. Abort;
  289. Cp := PrintDlg.Copies;
  290. if Cp < 1 then
  291. Cp := 1;
  292. end else
  293. Cp := 1;
  294. SourceFile.Print (Cp, PrintDlg.PrintRange, PrintDlg.FromPage, PrintDlg.ToPage);
  295. except
  296. Abort;
  297. end;
  298. end;
  299. procedure TSourceFileForm.FilePrintQuickly(Sender: TObject);
  300. begin
  301. FilePrint (nil);
  302. end;
  303. procedure TSourceFileForm.EditorChange(Sender: TObject);
  304. begin
  305. UpdateEditButtons;
  306. UpdateStatusBar;
  307. end;
  308. procedure TSourceFileForm.UpdateEditButtons;
  309. var
  310. TextSel: Boolean;
  311. begin
  312. if Assigned (Editor) then begin
  313. TextSel := Editor.SelLength > 0;
  314. ActionEditDelete.Enabled := TextSel;
  315. ActionEditCut.Enabled := TextSel;
  316. ActionEditCopy.Enabled := TextSel;
  317. ActionEditUndo.Enabled := Editor.CanUndo;
  318. ActionEditRedo.Enabled := Editor.CanRedo;
  319. end;
  320. end;
  321. procedure TSourceFileForm.UpdateStatusBar;
  322. var
  323. S: string;
  324. I: Integer;
  325. Cell: TTextCell;
  326. begin
  327. with StatusBar.Panels do begin
  328. if Assigned (Editor) then begin
  329. with Editor do begin
  330. if Enabled then begin
  331. if Selection.RLength > 0 then begin
  332. I := Selection.RLength + Selection.StartRowCol.Row - Selection.EndRowCol.Row;
  333. if Selection.EndRowCol.Col > LineLength [Selection.EndRowCol.Row] then
  334. Dec (I);
  335. S := IntToStr (I);
  336. if Items[0].Text <> S then
  337. Items[0].Text := S;
  338. if Items[1].Text <> '' then
  339. Items[1].Text := '';
  340. if Items[0].Width <> 60 then
  341. Items[0].Width := 60;
  342. if Items[1].Width <> 0 then
  343. Items[1].Width := 0;
  344. end else begin
  345. Cell := Selection.StartRowCol;
  346. S := IntToStr (Cell.Row);
  347. if Items[0].Text <> S then
  348. Items[0].Text := S;
  349. S := IntToStr (Cell.Col);
  350. if Items[1].Text <> S then
  351. Items[1].Text := S;
  352. if Items[0].Width <> 30 then
  353. Items[0].Width := 30;
  354. if Items[1].Width <> 30 then
  355. Items[1].Width := 30;
  356. end;
  357. I := TextLength - LineCount + 1;
  358. S := IntToStr (I) + ' Character';
  359. if I <> 1 then
  360. S := S + 's';
  361. if Items[3].Text <> S then
  362. Items[3].Text := S;
  363. if Items[2].Width <> 1 then
  364. Items[2].Width := 1;
  365. if Items[3].Width <> 93 then
  366. Items[3].Width := 93;
  367. if Items[2].Width <> 1 then
  368. Items[2].Width := 1;
  369. end;
  370. end;
  371. end else begin
  372. if Items[0].Text <> '' then
  373. Items[0].Text := '';
  374. if Items[1].Text <> '' then
  375. Items[1].Text := '';
  376. if Items[3].Text <> '' then
  377. Items[3].Text := '';
  378. if Items[0].Width <> 0 then
  379. Items[0].Width := 0;
  380. if Items[1].Width <> 0 then
  381. Items[1].Width := 0;
  382. if Items[2].Width <> 0 then
  383. Items[2].Width := 0;
  384. if Items[3].Width <> 0 then
  385. Items[3].Width := 0;
  386. if Items[4].Width <> 0 then
  387. Items[4].Width := 0;
  388. end;
  389. end;
  390. Update;
  391. end;
  392. procedure TSourceFileForm.EditUndo(Sender: TObject);
  393. begin
  394. if Assigned (Editor) then
  395. Editor.Undo;
  396. end;
  397. procedure TSourceFileForm.EditRedo(Sender: TObject);
  398. begin
  399. if Assigned (Editor) then
  400. Editor.Redo;
  401. end;
  402. procedure TSourceFileForm.EditDelete(Sender: TObject);
  403. begin
  404. if Assigned (Editor) then
  405. Editor.ClearSelection;
  406. end;
  407. procedure TSourceFileForm.EditCut(Sender: TObject);
  408. begin
  409. if Assigned (Editor) then
  410. Editor.CutToClipboard;
  411. end;
  412. procedure TSourceFileForm.EditCopy(Sender: TObject);
  413. begin
  414. if Assigned (Editor) then
  415. Editor.CopyToClipboard;
  416. end;
  417. procedure TSourceFileForm.EditPaste(Sender: TObject);
  418. begin
  419. if Assigned (Editor) then
  420. Editor.PasteFromClipboard;
  421. end;
  422. procedure TSourceFileForm.EditSelectAll(Sender: TObject);
  423. begin
  424. if Assigned (Editor) then
  425. Editor.SelectAll;
  426. end;
  427. procedure TSourceFileForm.EditIncreaseIndent(Sender: TObject);
  428. begin
  429. if Assigned (Editor) then
  430. Editor.ChangeIndent (1);
  431. end;
  432. procedure TSourceFileForm.EditDecreaseIndent(Sender: TObject);
  433. begin
  434. if Assigned (Editor) then
  435. Editor.ChangeIndent (-1);
  436. end;
  437. procedure TSourceFileForm.FindDlgFind(Sender: TObject);
  438. begin
  439. try
  440. FindString (Sender);
  441. except
  442. ShowDefaultMessageBox ('Text ''' + (Sender as TFindDialog).FindText + ''' not found.', 'Search Failed', mtProgramError);
  443. end;
  444. end;
  445. procedure TSourceFileForm.ReplaceDlgReplace(Sender: TObject);
  446. begin
  447. if Assigned (Editor) then
  448. with Sender as TReplaceDialog do
  449. repeat
  450. if UpperCase (Editor.Selection.Text) = UpperCase (FindText) then
  451. Editor.Selection.Text := ReplaceText;
  452. Options := Options + [frFindNext];
  453. FindString (Sender);
  454. until not (frReplaceAll in Options);
  455. end;
  456. procedure TSourceFileForm.FindString(Sender: TObject);
  457. var
  458. P: Integer;
  459. S,
  460. T: string;
  461. Valid: Boolean;
  462. FPos: Integer;
  463. begin
  464. if Assigned (Editor) then begin
  465. with Sender as TFindDialog do begin
  466. if frFindNext in Options then
  467. P := Editor.SelStart + 1
  468. else
  469. if frDown in Options then
  470. P := 1
  471. else
  472. P := Length (Editor.Text);
  473. repeat
  474. Valid := False;
  475. if frDown in Options then
  476. T := Copy (Editor.Text, P + 1, Length (Editor.Text))
  477. else
  478. T := Copy (Editor.Text, 1, P - 1);
  479. if frMatchCase in Options then
  480. S := FindText
  481. else begin
  482. S := UpperCase (FindText);
  483. T := UpperCase (T);
  484. end;
  485. if frDown in Options then
  486. FPos := Pos (S, T)
  487. else
  488. FPos := LastPos (S, T);
  489. if FPos > 0 then begin
  490. Valid := True;
  491. if frWholeWord in Options then begin
  492. if ((FPos > 1) and (T <> '') and (T [FPos - 1] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$'])) then
  493. Valid := False;
  494. if ((FPos + Length (S) < Length (T)) and (T <> '') and (T [FPos + Length (S)] in ['A'..'Z', 'a'..'z', '0'..'9', '_', '$'])) then
  495. Valid := False;
  496. end;
  497. if not (frDown in Options) then
  498. P := 0;
  499. if not Valid then
  500. Inc (P, FPos);
  501. end;
  502. until Valid or (FPos <= 0);
  503. if Valid then begin
  504. with Editor.Selection do begin
  505. DoChanging;
  506. RStart := P + FPos;
  507. RLength := Length (S);
  508. DoChange;
  509. ScrollInView (2);
  510. end;
  511. SetFocus;
  512. end else
  513. Abort;
  514. end;
  515. end;
  516. end;
  517. procedure TSourceFileForm.FindFind(Sender: TObject);
  518. begin
  519. FindDlg.Execute;
  520. SetFocus;
  521. end;
  522. procedure TSourceFileForm.FindReplace(Sender: TObject);
  523. begin
  524. ReplaceDlg.Execute;
  525. SetFocus;
  526. end;
  527. procedure TSourceFileForm.FindOpenFile(Sender: TObject);
  528. var
  529. I: Integer;
  530. S: string;
  531. QuotesInLine: Boolean;
  532. SourceFile: TSourceFile;
  533. begin
  534. if Assigned (Editor) then begin
  535. QuotesInLine := Pos ('"', Editor.Lines [Editor.Selection.StartRowCol.Row - 1]) > 0;
  536. S := '';
  537. for I := Editor.Selection.RStart - 1 downto 1 do begin
  538. if (not QuotesInLine) and (Editor.Text [I] = ' ') then
  539. Break;
  540. if Editor.Text [I] in [' ', 'A'..'Z', 'a'..'z', '0'..'9', '_', '-', '.', '\', ':'] then
  541. S := Editor.Text [I] + S
  542. else
  543. Break;
  544. end;
  545. for I := Editor.Selection.RStart to Length (Editor.Text) do begin
  546. if (not QuotesInLine) and (Editor.Text [I] = ' ') then
  547. Break;
  548. if Editor.Text [I] in [' ', 'A'..'Z', 'a'..'z', '0'..'9', '_', '-', '.', '\', ':'] then
  549. S := S + Editor.Text [I]
  550. else
  551. Break;
  552. end;
  553. S := Trim (S);
  554. if Length (S) > 0 then begin
  555. SourceFile := MainForm.SourceFiles.FindFileNameOnly (S);
  556. if Assigned (SourceFile) then
  557. SourceFile.Edit
  558. else begin
  559. SourceFile := Self.SourceFile;
  560. if FileExists (ExpandFileName (S)) then
  561. MainForm.AddSourceFile (ExpandFileName (S), True)
  562. else if Assigned (SourceFile) and (SourceFile is TGNUAsmSourceFile) and FileExists (WithBackslash (TIGCCFolder) + GASIncludeLocation + S) then
  563. MainForm.AddSourceFile (WithBackslash (TIGCCFolder) + GASIncludeLocation + S, True)
  564. else if Assigned (SourceFile) and (SourceFile is TAsmSourceFile) and FileExists (WithBackslash (TIGCCFolder) + ASMIncludeLocation + S) then
  565. MainForm.AddSourceFile (WithBackslash (TIGCCFolder) + ASMIncludeLocation + S, True)
  566. else if FileExists (WithBackslash (TIGCCFolder) + CIncludeLocation + S) then
  567. MainForm.AddSourceFile (WithBackslash (TIGCCFolder) + CIncludeLocation + S, True)
  568. else
  569. ShowDefaultMessageBox ('File ''' + S + ''' not found.', 'Search Failed', mtProgramError);
  570. end;
  571. end;
  572. end;
  573. end;
  574. procedure TSourceFileForm.FunctionPopupPopup(Sender: TObject);
  575. var
  576. I: Integer;
  577. M: TMenuItem;
  578. begin
  579. with (Sender as TPopupMenu).Items do begin
  580. for I := Count - 1 downto 0 do
  581. Remove (Items [I]);
  582. UpdateFuncs;
  583. for I := Low (Funcs) to High (Funcs) do begin
  584. M := TMenuItem.Create (Self);
  585. with M do begin
  586. Tag := I;
  587. Caption := Funcs[I].Name;
  588. OnClick := FindFunctionFromPopup;
  589. end;
  590. if (Pos ('main', Funcs[I].Name) > 0) and (Pos ('main', Funcs[I].Name) = Length (Funcs[I].Name) - Length ('main') + 1) then
  591. Insert (0, M)
  592. else
  593. Add (M);
  594. end;
  595. if Count <= 0 then
  596. Add (NoFunctionsItem);
  597. end;
  598. end;
  599. procedure TSourceFileForm.FindFunctions(Sender: TObject);
  600. var
  601. I: Integer;
  602. begin
  603. UpdateFuncs;
  604. with TFunctionsForm.Create (Self) do try
  605. Funcs := @Self.Funcs;
  606. with FuncList.Items do begin
  607. BeginUpdate;
  608. Clear;
  609. for I := Low (Self.Funcs) to High (Self.Funcs) do
  610. AddObject (Self.Funcs[I].Name, TObject (I));
  611. EndUpdate;
  612. end;
  613. FuncListClick (FuncList);
  614. case ShowModal of
  615. mrYes: begin
  616. if Assigned (Editor) then begin
  617. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (Self.Funcs[Integer(FuncList.Items.Objects[FuncList.ItemIndex])].PrototypeLine, 1)));
  618. Editor.Selection.ScrollInView (5);
  619. end;
  620. end;
  621. mrNo: begin
  622. if Assigned (Editor) then begin
  623. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (Self.Funcs[Integer(FuncList.Items.Objects[FuncList.ItemIndex])].ImplementationLine, 1)));
  624. Editor.Selection.ScrollInView (5);
  625. end;
  626. end;
  627. end;
  628. with FuncList.Items do begin
  629. BeginUpdate;
  630. for I := Count - 1 downto 0 do begin
  631. Objects [I] := nil;
  632. Delete (I);
  633. end;
  634. EndUpdate;
  635. end;
  636. finally
  637. Free;
  638. end;
  639. end;
  640. procedure TSourceFileForm.UpdateFuncs;
  641. begin
  642. if Assigned (SourceFile) and (SourceFile is TSourceTextSourceFile) then
  643. with SourceFile as TSourceTextSourceFile do
  644. Funcs := GetFunctions
  645. else
  646. SetLength (Funcs, 0);
  647. end;
  648. procedure TSourceFileForm.FindFunctionFromPopup(Sender: TObject);
  649. var
  650. L: Integer;
  651. begin
  652. if Sender is TMenuItem then
  653. with Sender as TMenuItem do begin
  654. if Funcs[Tag].ImplementationLine > 0 then
  655. L := Funcs[Tag].ImplementationLine
  656. else
  657. L := Funcs[Tag].PrototypeLine;
  658. if L > 0 then begin
  659. if Assigned (Editor) then begin
  660. Editor.Selection.NoSelAtPos (Editor.CellToCharIdx (TextCell (L, 1)));
  661. Editor.Selection.ScrollInView (5);
  662. end;
  663. end;
  664. end;
  665. end;
  666. procedure TSourceFileForm.FileAddToProject(Sender: TObject);
  667. var
  668. N: TTreeNode;
  669. begin
  670. if (not Compiling) and Assigned (SourceFile) then
  671. with MainForm, SourceFile do begin
  672. ParentForm := nil;
  673. N := ProjectTree.Items.AddChildObject (TopNode.Item [ClassTreeIndex], SourceName, Pointer (SourceFile));
  674. with N do begin
  675. ImageIndex := ClassImageIndex;
  676. SelectedIndex := ImageIndex;
  677. end;
  678. TreeItem := N;
  679. if Assigned (Editor) then
  680. with Editor do begin
  681. Hide;
  682. Parent := EditorPanel;
  683. Align := alClient;
  684. end;
  685. if SourceFile is TTextSourceFile then
  686. with SourceFile as TTextSourceFile do
  687. if Assigned (TextEditor) then
  688. with TextEditor do begin
  689. OnEnter := EditorEnter;
  690. OnExit := EditorExit;
  691. OnKeyDown := EditorKeyDown;
  692. OnChange := EditorChange;
  693. OnSelectionChange := EditorChange;
  694. PopupMenu := EditorPopup;
  695. end;
  696. SortFiles;
  697. MainForm.Modify;
  698. ProjectTree.Selected := N;
  699. SourceFile := nil;
  700. Self.Close;
  701. end;
  702. end;
  703. procedure TSourceFileForm.FormEnable(Sender: TObject);
  704. begin
  705. if Assigned (EnableTimer) then begin
  706. EnableTimer.Free;
  707. EnableTimer := nil;
  708. end;
  709. Enabled := True;
  710. if Assigned (Editor) then begin
  711. Editor.Enabled := False;
  712. Editor.Enabled := True;
  713. ActiveControl := Editor;
  714. end;
  715. SetFocus;
  716. end;
  717. procedure TSourceFileForm.FormShow(Sender: TObject);
  718. begin
  719. if not (Enabled or Assigned (EnableTimer)) then begin
  720. EnableTimer := TTimer.Create (Self);
  721. EnableTimer.OnTimer := FormEnable;
  722. EnableTimer.Interval := 100;
  723. EnableTimer.Enabled := True;
  724. end;
  725. end;
  726. procedure TSourceFileForm.CreateParams(var Params: TCreateParams);
  727. begin
  728. inherited;
  729. Params.WndParent := GetDesktopWindow;
  730. end;
  731. {$IFDEF CODINGEXT}
  732. procedure TSourceFileForm.InitCodingExt;
  733. var
  734. ActionFindSymbol: TAction;
  735. begin
  736. // Find Symbol declaration tool
  737. ActionFindSymbol := TAction.Create(Self);
  738. with ActionFindSymbol do begin
  739. ActionList := Actions;
  740. Caption := 'F&ind Symbol Declaration';
  741. Category := 'Extension';
  742. OnExecute := ActionFindSymbolExecute;
  743. end;
  744. InsertsAction(Self, [OpenFileAtCursor1, OpenFileatCursor2], ActionFindSymbol);
  745. end;
  746. procedure TSourceFileForm.ActionFindSymbolExecute(Sender: TObject);
  747. begin
  748. CompForm.FindSymbolDecl;
  749. end;
  750. {$ENDIF}
  751. procedure TSourceFileForm.FindDlgClose(Sender: TObject);
  752. begin
  753. SetFocus;
  754. end;
  755. end.