[459] | 1 | unit fTemplateFields;
|
---|
| 2 |
|
---|
| 3 | interface
|
---|
| 4 |
|
---|
| 5 | uses
|
---|
| 6 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
| 7 | ORCtrls, ComCtrls, StdCtrls, ExtCtrls;
|
---|
| 8 |
|
---|
| 9 | type
|
---|
| 10 | TfrmTemplateFields = class(TForm)
|
---|
| 11 | pnlBottom: TPanel;
|
---|
| 12 | btnCancel: TButton;
|
---|
| 13 | cboObjects: TORComboBox;
|
---|
| 14 | btnInsert: TButton;
|
---|
| 15 | lblReq: TStaticText;
|
---|
| 16 | btnPreview: TButton;
|
---|
| 17 | procedure FormShow(Sender: TObject);
|
---|
| 18 | procedure FormCreate(Sender: TObject);
|
---|
| 19 | procedure cboObjectsNeedData(Sender: TObject; const StartFrom: String;
|
---|
| 20 | Direction, InsertAt: Integer);
|
---|
| 21 | procedure cboObjectsDblClick(Sender: TObject);
|
---|
| 22 | procedure btnCancelClick(Sender: TObject);
|
---|
| 23 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
| 24 | procedure btnInsertClick(Sender: TObject);
|
---|
| 25 | procedure btnPreviewClick(Sender: TObject);
|
---|
| 26 | procedure cboObjectsChange(Sender: TObject);
|
---|
| 27 | private
|
---|
| 28 | { Fre: TRichEdit;}
|
---|
| 29 | Fre: TCustomEdit;
|
---|
| 30 | FAutoLongLines: TNotifyEvent;
|
---|
| 31 | procedure InsertField;
|
---|
| 32 | { procedure Setre(const Value: TRichEdit);}
|
---|
| 33 | procedure Setre(const Value: TCustomEdit);
|
---|
| 34 | public
|
---|
| 35 | procedure UpdateStatus;
|
---|
| 36 | { property re: TRichEdit read Fre write Setre;}
|
---|
| 37 | property re: TCustomEdit read Fre write Setre;
|
---|
| 38 | property AutoLongLines: TNotifyEvent read FAutoLongLines write FAutoLongLines;
|
---|
| 39 | end;
|
---|
| 40 |
|
---|
| 41 | implementation
|
---|
| 42 |
|
---|
| 43 | uses
|
---|
| 44 | ORFn, rTemplates, uTemplateFields, fTemplateDialog, ORClasses;
|
---|
| 45 |
|
---|
| 46 | {$R *.DFM}
|
---|
| 47 |
|
---|
| 48 | procedure TfrmTemplateFields.FormShow(Sender: TObject);
|
---|
| 49 | begin
|
---|
| 50 | cboObjects.SelectAll;
|
---|
| 51 | cboObjects.SetFocus;
|
---|
| 52 | end;
|
---|
| 53 |
|
---|
| 54 | procedure TfrmTemplateFields.FormCreate(Sender: TObject);
|
---|
| 55 | begin
|
---|
| 56 | cboObjects.InitLongList('');
|
---|
| 57 | cboObjects.ItemHeight := 15;
|
---|
| 58 | ResizeAnchoredFormToFont(self);
|
---|
| 59 | //ResizeAnchoredFormToFont doesn't work right on the button positions for some reason.
|
---|
| 60 | btnCancel.Left := pnlBottom.ClientWidth - btnCancel.Width;
|
---|
| 61 | btnInsert.Left := btnCancel.Left - btnInsert.Width - 8;
|
---|
| 62 | end;
|
---|
| 63 |
|
---|
| 64 | procedure TfrmTemplateFields.cboObjectsNeedData(Sender: TObject;
|
---|
| 65 | const StartFrom: String; Direction, InsertAt: Integer);
|
---|
| 66 | var
|
---|
| 67 | tmp: TStrings;
|
---|
| 68 |
|
---|
| 69 | begin
|
---|
| 70 | tmp := SubSetOfTemplateFields(StartFrom, Direction);
|
---|
| 71 | ConvertCodes2Text(tmp, FALSE);
|
---|
| 72 | cboObjects.ForDataUse(tmp);
|
---|
| 73 | end;
|
---|
| 74 |
|
---|
| 75 | procedure TfrmTemplateFields.InsertField;
|
---|
| 76 | var
|
---|
| 77 | cnt: integer;
|
---|
| 78 |
|
---|
| 79 | begin
|
---|
| 80 | if assigned(Fre) and (not TORExposedCustomEdit(Fre).ReadOnly) and (cboObjects.ItemIndex >= 0) then
|
---|
| 81 | begin
|
---|
| 82 | if Fre is TRichEdit then
|
---|
| 83 | cnt := TRichEdit(FRe).Lines.Count
|
---|
| 84 | else
|
---|
| 85 | cnt :=0;
|
---|
| 86 | Fre.SelText := TemplateFieldBeginSignature +
|
---|
| 87 | Piece(cboObjects.Items[cboObjects.ItemIndex],U,2)+
|
---|
| 88 | TemplateFieldEndSignature;
|
---|
| 89 | if Fre is TRichEdit then
|
---|
| 90 | if(assigned(FAutoLongLines) and (cnt <> TRichEdit(FRe).Lines.Count)) then
|
---|
| 91 | FAutoLongLines(Self);
|
---|
| 92 | end;
|
---|
| 93 | end;
|
---|
| 94 |
|
---|
| 95 | procedure TfrmTemplateFields.cboObjectsDblClick(Sender: TObject);
|
---|
| 96 | begin
|
---|
| 97 | if btnInsert.Enabled then
|
---|
| 98 | InsertField;
|
---|
| 99 | end;
|
---|
| 100 |
|
---|
| 101 | procedure TfrmTemplateFields.btnCancelClick(Sender: TObject);
|
---|
| 102 | begin
|
---|
| 103 | Close;
|
---|
| 104 | end;
|
---|
| 105 |
|
---|
| 106 | procedure TfrmTemplateFields.FormClose(Sender: TObject;
|
---|
| 107 | var Action: TCloseAction);
|
---|
| 108 | begin
|
---|
| 109 | Action := caHide;
|
---|
| 110 | end;
|
---|
| 111 |
|
---|
| 112 | procedure TfrmTemplateFields.Setre(const Value: TCustomEdit);
|
---|
| 113 | begin
|
---|
| 114 | Fre := Value;
|
---|
| 115 | UpdateStatus;
|
---|
| 116 | end;
|
---|
| 117 |
|
---|
| 118 | procedure TfrmTemplateFields.UpdateStatus;
|
---|
| 119 | begin
|
---|
| 120 | btnInsert.Enabled := (not TORExposedCustomEdit(re).ReadOnly);
|
---|
| 121 | end;
|
---|
| 122 |
|
---|
| 123 | procedure TfrmTemplateFields.btnInsertClick(Sender: TObject);
|
---|
| 124 | begin
|
---|
| 125 | InsertField;
|
---|
| 126 | end;
|
---|
| 127 |
|
---|
| 128 | procedure TfrmTemplateFields.btnPreviewClick(Sender: TObject);
|
---|
| 129 | var
|
---|
| 130 | tmp, txt: string;
|
---|
| 131 |
|
---|
| 132 |
|
---|
| 133 | begin
|
---|
| 134 | if(cboObjects.ItemIndex >= 0) then
|
---|
| 135 | begin
|
---|
| 136 | FormStyle := fsNormal;
|
---|
| 137 | try
|
---|
| 138 | txt := Piece(cboObjects.Items[cboObjects.ItemIndex],U,2);
|
---|
| 139 | tmp := TemplateFieldBeginSignature + txt + TemplateFieldEndSignature;
|
---|
| 140 | CheckBoilerplate4Fields(tmp, 'Preview Template Field: ' + txt, TRUE);
|
---|
| 141 | finally
|
---|
| 142 | FormStyle := fsStayOnTop;
|
---|
| 143 | end;
|
---|
| 144 | end;
|
---|
| 145 | end;
|
---|
| 146 |
|
---|
| 147 | procedure TfrmTemplateFields.cboObjectsChange(Sender: TObject);
|
---|
| 148 | begin
|
---|
| 149 | btnPreview.Enabled := (cboObjects.ItemIndex >= 0)
|
---|
| 150 | end;
|
---|
| 151 |
|
---|
| 152 | end.
|
---|