PrefFrame.pas 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. unit PrefFrame;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, TmpltForm;
  6. type
  7. TCodingExt = class(TFrame)
  8. TemplateBox: TGroupBox;
  9. CompBox: TGroupBox;
  10. CompEditor: TButton;
  11. TmpltList: TListBox;
  12. IdLbl: TLabel;
  13. CodeLbl: TLabel;
  14. IdEdit: TEdit;
  15. CodeMemo: TMemo;
  16. ClearBtn: TButton;
  17. ApplyBtn: TButton;
  18. procedure CompEditorClick(Sender: TObject);
  19. procedure TmpltListData(Control: TWinControl; Index: Integer;
  20. var Data: string);
  21. procedure ApplyBtnClick(Sender: TObject);
  22. procedure ClearBtnClick(Sender: TObject);
  23. procedure TmpltListClick(Sender: TObject);
  24. procedure OnShow(Sender: TObject);
  25. public
  26. { Déclarations publiques }
  27. end;
  28. implementation
  29. {$R *.dfm}
  30. uses uEditor;
  31. procedure TCodingExt.CompEditorClick(Sender: TObject);
  32. var
  33. Form: TCEditorForm;
  34. begin
  35. Form := TCEditorForm.Create(Self);
  36. Form.ShowModal;
  37. Form.Free;
  38. end;
  39. procedure TCodingExt.TmpltListData(Control: TWinControl; Index: Integer;
  40. var Data: string);
  41. begin
  42. if (Index >= 0) and (Index < TemplateForm.Templates.Count) then
  43. Data := TemplateForm.Templates[Index];
  44. end;
  45. procedure TCodingExt.ApplyBtnClick(Sender: TObject);
  46. var
  47. Id: string;
  48. T: TTemplate;
  49. i: Integer;
  50. begin
  51. Id := Trim(IdEdit.Text);
  52. if Id <> '' then
  53. begin
  54. if TemplateForm.Templates.Find(Id, i) then
  55. TTemplate(TemplateForm.Templates.Objects[i]).Text := CodeMemo.Text
  56. else
  57. begin
  58. T := TTemplate.Create;
  59. T.Text := CodeMemo.Text;
  60. TemplateForm.Templates.AddObject(Id, T);
  61. end;
  62. end;
  63. TmpltList.Count := TemplateForm.Templates.Count;
  64. end;
  65. procedure TCodingExt.ClearBtnClick(Sender: TObject);
  66. var
  67. i: Integer;
  68. begin
  69. for i := TemplateForm.Templates.Count - 1 downto 0 do
  70. if TmpltList.Selected[i] then
  71. begin
  72. TemplateForm.Templates.Objects[i].Free;
  73. TemplateForm.Templates.Delete(i);
  74. end;
  75. TmpltList.Count := TemplateForm.Templates.Count;
  76. end;
  77. procedure TCodingExt.TmpltListClick(Sender: TObject);
  78. var
  79. Index: Integer;
  80. begin
  81. if TmpltList.SelCount > 0 then
  82. begin
  83. Index := TmpltList.ItemIndex;
  84. IdEdit.Text := TemplateForm.Templates[Index];
  85. CodeMemo.Text := TTemplate(TemplateForm.Templates.Objects[Index]).Text;
  86. end;
  87. end;
  88. procedure TCodingExt.OnShow(Sender: TObject);
  89. begin
  90. if TmpltList.Count <> TemplateForm.Templates.Count then
  91. TmpltList.Count := TemplateForm.Templates.Count;
  92. end;
  93. end.