SourceFileWinUnit.pas 21 KB

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