PrefFrame.pas 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. {
  2. TIGCC IDE
  3. Copyright (C) 2004 Fréderic Bour
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software Foundation,
  14. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. }
  16. unit PrefFrame;
  17. interface
  18. uses
  19. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  20. Dialogs, StdCtrls, TmpltForm;
  21. type
  22. TCodingExt = class(TFrame)
  23. TemplateBox: TGroupBox;
  24. CompBox: TGroupBox;
  25. CompEditor: TButton;
  26. TmpltList: TListBox;
  27. IdLbl: TLabel;
  28. CodeLbl: TLabel;
  29. IdEdit: TEdit;
  30. CodeMemo: TMemo;
  31. ClearBtn: TButton;
  32. ApplyBtn: TButton;
  33. procedure CompEditorClick(Sender: TObject);
  34. procedure TmpltListData(Control: TWinControl; Index: Integer;
  35. var Data: string);
  36. procedure ApplyBtnClick(Sender: TObject);
  37. procedure ClearBtnClick(Sender: TObject);
  38. procedure TmpltListClick(Sender: TObject);
  39. procedure OnShow(Sender: TObject);
  40. public
  41. { Déclarations publiques }
  42. end;
  43. implementation
  44. {$R *.dfm}
  45. uses uEditor;
  46. procedure TCodingExt.CompEditorClick(Sender: TObject);
  47. var
  48. Form: TCEditorForm;
  49. begin
  50. Form := TCEditorForm.Create(Self);
  51. Form.ShowModal;
  52. Form.Free;
  53. end;
  54. procedure TCodingExt.TmpltListData(Control: TWinControl; Index: Integer;
  55. var Data: string);
  56. begin
  57. if (Index >= 0) and (Index < TemplateForm.Templates.Count) then
  58. Data := TemplateForm.Templates[Index];
  59. end;
  60. procedure TCodingExt.ApplyBtnClick(Sender: TObject);
  61. var
  62. Id: string;
  63. T: TTemplate;
  64. i: Integer;
  65. begin
  66. Id := Trim(IdEdit.Text);
  67. if Id <> '' then
  68. begin
  69. if TemplateForm.Templates.Find(Id, i) then
  70. TTemplate(TemplateForm.Templates.Objects[i]).Text := CodeMemo.Text
  71. else
  72. begin
  73. T := TTemplate.Create;
  74. T.Text := CodeMemo.Text;
  75. TemplateForm.Templates.AddObject(Id, T);
  76. end;
  77. end;
  78. TmpltList.Count := TemplateForm.Templates.Count;
  79. end;
  80. procedure TCodingExt.ClearBtnClick(Sender: TObject);
  81. var
  82. i: Integer;
  83. begin
  84. for i := TemplateForm.Templates.Count - 1 downto 0 do
  85. if TmpltList.Selected[i] then
  86. begin
  87. TemplateForm.Templates.Objects[i].Free;
  88. TemplateForm.Templates.Delete(i);
  89. end;
  90. TmpltList.Count := TemplateForm.Templates.Count;
  91. end;
  92. procedure TCodingExt.TmpltListClick(Sender: TObject);
  93. var
  94. Index: Integer;
  95. begin
  96. if TmpltList.SelCount > 0 then
  97. begin
  98. Index := TmpltList.ItemIndex;
  99. IdEdit.Text := TemplateForm.Templates[Index];
  100. CodeMemo.Text := TTemplate(TemplateForm.Templates.Objects[Index]).Text;
  101. end;
  102. end;
  103. procedure TCodingExt.OnShow(Sender: TObject);
  104. begin
  105. if TmpltList.Count <> TemplateForm.Templates.Count then
  106. TmpltList.Count := TemplateForm.Templates.Count;
  107. end;
  108. end.