source: cprs/branches/foia-cprs/CPRS-Chart/Templates/fTemplateFieldEditor.pas@ 697

Last change on this file since 697 was 459, checked in by Kevin Toppenberg, 16 years ago

Adding foia-cprs branch

File size: 37.2 KB
Line 
1unit fTemplateFieldEditor;
2
3interface
4
5uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 ORCtrls, StdCtrls, ExtCtrls, Menus, ComCtrls, uTemplateFields, ORFn,
8 ToolWin, MenuBar, ORClasses, ORDtTm;
9
10type
11 TfrmTemplateFieldEditor = class(TForm)
12 pnlBottom: TPanel;
13 btnOK: TButton;
14 btnCancel: TButton;
15 pnlObjs: TPanel;
16 cbxObjs: TORComboBox;
17 lblObjs: TLabel;
18 splLeft: TSplitter;
19 pnlRight: TPanel;
20 pnlPreview: TPanel;
21 lblNotes: TLabel;
22 pnlObjInfo: TPanel;
23 lblName: TLabel;
24 lblS2: TLabel;
25 lblLM: TLabel;
26 edtName: TCaptionEdit;
27 splBottom: TSplitter;
28 lblS1: TLabel;
29 edtLMText: TCaptionEdit;
30 cbxType: TORComboBox;
31 lblType: TLabel;
32 reNotes: TRichEdit;
33 btnApply: TButton;
34 btnPreview: TButton;
35 mnuMain: TMainMenu;
36 mnuAction: TMenuItem;
37 mnuNew: TMenuItem;
38 mnuCopy: TMenuItem;
39 cbHide: TCheckBox;
40 pnlTop: TPanel;
41 MenuBar1: TMenuBar;
42 btnNew: TButton;
43 btnCopy: TButton;
44 mnuDelete: TMenuItem;
45 btnDelete: TButton;
46 mnuPreview: TMenuItem;
47 popText: TPopupMenu;
48 mnuBPUndo: TMenuItem;
49 N8: TMenuItem;
50 mnuBPCut: TMenuItem;
51 mnuBPCopy: TMenuItem;
52 mnuBPPaste: TMenuItem;
53 mnuBPSelectAll: TMenuItem;
54 N2: TMenuItem;
55 mnuBPCheckGrammar: TMenuItem;
56 mnuBPSpellCheck: TMenuItem;
57 lblTextLen: TLabel;
58 edtTextLen: TCaptionEdit;
59 udTextLen: TUpDown;
60 pnlSwap: TPanel;
61 edtDefault: TCaptionEdit;
62 pnlNum: TPanel;
63 edtURL: TCaptionEdit;
64 udDefNum: TUpDown;
65 edtDefNum: TCaptionEdit;
66 udMinVal: TUpDown;
67 edtMinVal: TCaptionEdit;
68 lblMin: TLabel;
69 udInc: TUpDown;
70 edtInc: TCaptionEdit;
71 lblInc: TLabel;
72 lblMaxVal: TLabel;
73 edtMaxVal: TCaptionEdit;
74 udMaxVal: TUpDown;
75 reItems: TRichEdit;
76 lblLength: TLabel;
77 edtLen: TCaptionEdit;
78 udLen: TUpDown;
79 cbxDefault: TORComboBox;
80 lblS3: TLabel;
81 gbIndent: TGroupBox;
82 lblIndent: TLabel;
83 edtIndent: TCaptionEdit;
84 udIndent: TUpDown;
85 udPad: TUpDown;
86 edtPad: TCaptionEdit;
87 lblPad: TLabel;
88 gbMisc: TGroupBox;
89 cbActive: TCheckBox;
90 cbRequired: TCheckBox;
91 cbSepLines: TCheckBox;
92 pnlDate: TPanel;
93 edtDateDef: TCaptionEdit;
94 cbxDateType: TORComboBox;
95 lblDateType: TLabel;
96 cbExclude: TCheckBox;
97 lblReq: TStaticText;
98 lblLine: TLabel;
99 lblCol: TLabel;
100 N14: TMenuItem;
101 mnuInsertTemplateField: TMenuItem;
102 procedure cbxObjsNeedData(Sender: TObject; const StartFrom: String;
103 Direction, InsertAt: Integer);
104 procedure FormCreate(Sender: TObject);
105 procedure cbxObjsChange(Sender: TObject);
106 procedure edtNameChange(Sender: TObject);
107 procedure cbxTypeChange(Sender: TObject);
108 procedure edtLenChange(Sender: TObject);
109 procedure edtDefaultChange(Sender: TObject);
110 procedure cbxDefaultChange(Sender: TObject);
111 procedure edtLMTextChange(Sender: TObject);
112 procedure cbActiveClick(Sender: TObject);
113 procedure mnuNewClick(Sender: TObject);
114 procedure btnOKClick(Sender: TObject);
115 procedure btnApplyClick(Sender: TObject);
116 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
117 procedure btnCancelClick(Sender: TObject);
118 procedure reItemsChange(Sender: TObject);
119 procedure cbHideClick(Sender: TObject);
120 procedure edtNameExit(Sender: TObject);
121 procedure mnuCopyClick(Sender: TObject);
122 procedure mnuDeleteClick(Sender: TObject);
123 procedure btnPreviewClick(Sender: TObject);
124 procedure mnuActionClick(Sender: TObject);
125 procedure cbRequiredClick(Sender: TObject);
126 procedure pnlObjsResize(Sender: TObject);
127 procedure FormDestroy(Sender: TObject);
128 procedure cbxObjsSynonymCheck(Sender: TObject; const Text: String;
129 var IsSynonym: Boolean);
130 procedure popTextPopup(Sender: TObject);
131 procedure mnuBPUndoClick(Sender: TObject);
132 procedure mnuBPCutClick(Sender: TObject);
133 procedure mnuBPCopyClick(Sender: TObject);
134 procedure mnuBPPasteClick(Sender: TObject);
135 procedure mnuBPSelectAllClick(Sender: TObject);
136 procedure mnuBPCheckGrammarClick(Sender: TObject);
137 procedure mnuBPSpellCheckClick(Sender: TObject);
138 procedure cbSepLinesClick(Sender: TObject);
139 procedure edtpopControlEnter(Sender: TObject);
140 procedure cbxObjsKeyDown(Sender: TObject; var Key: Word;
141 Shift: TShiftState);
142 procedure edtTextLenChange(Sender: TObject);
143 procedure edtDefNumChange(Sender: TObject);
144 procedure edtMinValChange(Sender: TObject);
145 procedure edtMaxValChange(Sender: TObject);
146 procedure edtIncChange(Sender: TObject);
147 procedure edtURLChange(Sender: TObject);
148 procedure edtPadChange(Sender: TObject);
149 procedure edtIndentChange(Sender: TObject);
150 procedure reNotesChange(Sender: TObject);
151 procedure cbxDateTypeChange(Sender: TObject);
152 procedure cbExcludeClick(Sender: TObject);
153 procedure FormResize(Sender: TObject);
154 procedure reItemsResizeRequest(Sender: TObject; Rect: TRect);
155 procedure reItemsSelectionChange(Sender: TObject);
156 procedure mnuInsertTemplateFieldClick(Sender: TObject);
157 procedure ControlExit(Sender: TObject);
158 procedure reNotesKeyUp(Sender: TObject; var Key: Word;
159 Shift: TShiftState);
160 private
161 CopyFld, FFld: TTemplateField;
162 FUpdating: boolean;
163 FReloadChanges: boolean;
164 FChangesPending: boolean;
165 FDeleted: TORStringList;
166 FHideSynonyms: boolean;
167 FLastRect: TRect;
168 procedure UpdateControls;
169 procedure SyncItems(DoUpdate: boolean = TRUE);
170 function SaveChanges: boolean;
171 procedure ResetListEntry;
172 procedure VerifyName;
173 procedure EnableButtons;
174 procedure SetFld(const Value: TTemplateField);
175 procedure SetHideSynonyms(const Value: boolean);
176 function GetPopupControl: TCustomEdit;
177 public
178 { Public declarations }
179 end;
180
181function EditDialogFields: boolean;
182
183implementation
184
185uses rTemplates, fTemplateDialog, Clipbrd, uSpell, uConst,
186 fTemplateFields;
187
188{$R *.DFM}
189
190{ TfrmDlgObjEditor }
191
192var
193 frmTemplateFields: TfrmTemplateFields = nil;
194
195
196function EditDialogFields: boolean;
197var
198 frmTemplateFieldEditor: TfrmTemplateFieldEditor;
199
200begin
201 frmTemplateFieldEditor := TfrmTemplateFieldEditor.Create(Application);
202 try
203 frmTemplateFieldEditor.ShowModal;
204 Result := frmTemplateFieldEditor.FReloadChanges;
205 finally
206 frmTemplateFieldEditor.Free;
207 end;
208end;
209
210procedure TfrmTemplateFieldEditor.UpdateControls;
211const
212 DefTxt = 'Default:';
213
214var
215 ok, edt, txt, tmp: boolean;
216 Y, idx, Max: integer;
217 wpTxt: string;
218
219 procedure SetLbl(const Text: string);
220 var
221 lbl: TLabel;
222
223 begin
224 inc(idx);
225 case idx of
226 1: lbl := lblS1;
227 2: lbl := lblS2;
228 3: lbl := lblS3;
229 else
230 lbl := nil;
231 end;
232 if assigned(lbl) then
233 lbl.Caption := Text;
234 end;
235
236 procedure SetY(Control: TControl; const Text: string);
237 begin
238 if (Control.Visible) then
239 begin
240 Control.Top := Y;
241 inc(Y, Control.Height);
242 SetLbl(Text);
243 end;
244 end;
245
246begin
247 if(not FUpdating) then
248 begin
249 FUpdating := TRUE;
250 try
251 Y := 0;
252 idx := 0;
253 ok := assigned(FFld);
254 if(ok) then
255 begin
256 edt := (FFld.FldType in EditLenTypes);
257 txt := (FFld.FldType in EditDfltTypes);
258 end
259 else
260 begin
261 edt := FALSE;
262 txt := FALSE;
263 end;
264 lblName.Enabled := ok;
265 edtName.Enabled := ok;
266 lblType.Enabled := ok;
267 cbxType.Enabled := ok;
268 lblLM.Enabled := ok;
269 edtLMText.Enabled := ok;
270 cbActive.Enabled := ok;
271
272 gbMisc.Enabled := ok;
273 lblNotes.Enabled := ok;
274 reNotes.Enabled := ok;
275 if(ok) then
276 begin
277 edtName.Text := FFld.FldName;
278 cbxType.ItemIndex := ord(FFld.FldType);
279 edtLMText.Text := FFld.LMText;
280 cbActive.Checked := FFld.Inactive;
281 reNotes.Lines.Text := FFld.Notes;
282 end
283 else
284 begin
285 edtName.Text := '';
286 cbxType.ItemIndex := -1;
287 edtLMText.Text := '';
288 cbActive.Checked := FALSE;
289 reNotes.Clear;
290 end;
291
292 tmp := ok and (not (FFld.FldType in NoRequired));
293 cbRequired.Enabled := tmp;
294 if tmp then
295 cbRequired.Checked := FFld.Required
296 else
297 cbRequired.Checked := FALSE;
298
299 pnlSwap.DisableAlign;
300 try
301 tmp := ok and (FFld.FldType in SepLinesTypes);
302 cbSepLines.Enabled := tmp;
303 if tmp then
304 cbSepLines.Checked := FFld.SepLines
305 else
306 cbSepLines.Checked := FALSE;
307
308 tmp := ok and (FFld.FldType in ExcludeText);
309 cbExclude.Enabled := tmp;
310 if tmp then
311 cbExclude.Checked := FFld.SepLines
312 else
313 cbExclude.Checked := FALSE;
314
315 lblLength.Enabled := edt;
316 if ok and (FFld.FldType = dftWP) then
317 begin
318 lblTextLen.Caption := 'Num Lines:';
319 udLen.Min := 5;
320 udLen.Max := 74;
321 udTextLen.Min := 2;
322 udTextLen.Max := MaxTFWPLines;
323 end
324 else
325 begin
326 udLen.Min := 1;
327 udLen.Max := 70;
328 udTextLen.Min := 0;
329 udTextLen.Max := 240;
330 lblTextLen.Caption := 'Text Len:';
331 end;
332
333 lblTextLen.Enabled := edt;
334 edtTextLen.Enabled := edt;
335 udTextLen.Enabled := edt;
336 edtLen.Enabled := edt;
337 udLen.Enabled := edt;
338
339 edtDefault.Visible := txt;
340 SetY(edtDefault, DefTxt);
341 Max := MaxTFEdtLen;
342
343 if(edt) then
344 begin
345 udLen.Associate := edtLen;
346 udLen.Position := FFld.MaxLen;
347 udTextLen.Associate := edtTextLen;
348 udTextLen.Position := FFld.TextLen;
349 if txt then
350 Max := FFld.MaxLen;
351 end
352 else
353 begin
354 udLen.Associate := nil;
355 edtLen.Text := '';
356 udTextLen.Associate := nil;
357 edtTextLen.Text := '';
358 end;
359
360 if txt then
361 begin
362 edtDefault.MaxLength := Max;
363 edtDefault.Text := copy(FFld.EditDefault, 1, Max);
364 end;
365
366 gbIndent.Enabled := ok;
367 lblIndent.Enabled := ok;
368 edtIndent.Enabled := ok;
369 udIndent.Enabled := ok;
370 if ok then
371 begin
372 udIndent.Associate := edtIndent;
373 udIndent.Position := FFld.Indent;
374 end
375 else
376 begin
377 udIndent.Associate := nil;
378 edtIndent.Text := '';
379 end;
380
381 tmp := ok and (not cbExclude.Checked);
382 lblPad.Enabled := tmp;
383 edtPad.Enabled := tmp;
384 udPad.Enabled := tmp;
385 if tmp then
386 begin
387 udPad.Associate := edtPad;
388 udPad.Position := FFld.Pad;
389 end
390 else
391 begin
392 udPad.Associate := nil;
393 edtPad.Text := '';
394 end;
395
396 tmp := ok and (FFld.FldType = dftNumber);
397 pnlNum.Visible := tmp;
398 SetY(pnlNum, DefTxt);
399 if tmp then
400 begin
401 udDefNum.Position := StrToIntDef(FFld.EditDefault, 0);
402 udMinVal.Position := FFld.MinVal;
403 udMaxVal.Position := FFld.MaxVal;
404 udInc.Position := FFld.Increment;
405 end;
406
407 tmp := ok and (FFld.FldType = dftDate);
408 pnlDate.Visible := tmp;
409 SetY(pnlDate, DefTxt);
410 if tmp then
411 begin
412 edtDateDef.Text := FFld.EditDefault;
413 cbxDateType.SelectByID(TemplateFieldDateCodes[FFld.DateType]);
414 end;
415
416 tmp := ok and (FFld.FldType in ItemDfltTypes);
417 cbxDefault.Visible := tmp;
418 SetY(cbxDefault, DefTxt);
419
420 tmp := ok and (FFld.FldType = dftHyperlink);
421 edtURL.Visible := tmp;
422 SetY(edtURL, 'Address:');
423 if tmp then
424 edtURL.Text := FFld.URL;
425
426 tmp := ok and (FFld.FldType in FldItemTypes);
427 reItems.Visible := tmp;
428 lblLine.Visible := tmp;
429 lblCol.Visible := tmp;
430 if tmp then
431 begin
432 if FFld.FldType = dftWP then
433 wpTxt := DefTxt
434 else
435 wpTxt := 'Items:';
436 end
437 else
438 wpTxt := '';
439 SetY(reItems, wpTxt);
440 if tmp then
441 reItems.Lines.Text := FFld.Items
442 else
443 reItems.Clear;
444 finally
445 pnlSwap.EnableAlign;
446 end;
447
448 SetLbl('');
449 SetLbl('');
450 SetLbl('');
451 SyncItems(FALSE);
452 FormResize(Self);
453 finally
454 FUpdating := FALSE;
455 end;
456 end;
457end;
458
459procedure TfrmTemplateFieldEditor.SyncItems(DoUpdate: boolean = TRUE);
460var
461 i, idx, Siz, Max1, Max2: integer;
462 ChangeSizes: boolean;
463
464begin
465 if DoUpdate and FUpdating then
466 exit;
467 Max1 := 0;
468 Max2 := 0;
469 ChangeSizes := FALSE;
470 FUpdating := TRUE;
471 try
472 cbxDefault.Items.Assign(reItems.Lines);
473 idx := -1;
474 if(assigned(FFld)) and reItems.Visible and cbxDefault.Visible then
475 begin
476 ChangeSizes := TRUE;
477 for i := 0 to reItems.Lines.Count-1 do
478 begin
479 Siz := length(StripEmbedded(reItems.Lines[i]));
480 if Max1 < Siz then
481 Max1 := Siz;
482 if(idx < 0) and (FFld.ItemDefault = reItems.Lines[i]) then
483 idx := i;
484 end;
485 Max2 := Max1;
486 if Max1 > MaxTFEdtLen then
487 Max1 := MaxTFEdtLen;
488 end;
489 cbxDefault.ItemIndex := idx;
490 finally
491 FUpdating := FALSE;
492 end;
493 if ChangeSizes and DoUpdate then
494 begin
495 udLen.Position := Max1;
496 if (not udTextLen.Enabled) or
497 ((udTextLen.Position > 0) and (udTextLen.Position < Max2)) then
498 udTextLen.Position := Max2;
499 end;
500end;
501
502procedure TfrmTemplateFieldEditor.cbxObjsNeedData(Sender: TObject;
503 const StartFrom: String; Direction, InsertAt: Integer);
504var
505 tmp: TORStringList;
506 i, idx: integer;
507
508begin
509 tmp := TORStringList.Create;
510 try
511 tmp.Assign(SubSetOfTemplateFields(StartFrom, Direction));
512 for i := 0 to FDeleted.Count-1 do
513 begin
514 idx := tmp.IndexOfPiece(Piece(FDeleted[i],U,1), U, 1);
515 if(idx >= 0) then
516 tmp.delete(idx);
517 end;
518 ConvertCodes2Text(tmp, TRUE);
519 cbxObjs.ForDataUse(tmp);
520 finally
521 tmp.Free;
522 end;
523end;
524
525procedure TfrmTemplateFieldEditor.FormCreate(Sender: TObject);
526var
527 i: integer;
528 Child: TControl;
529 Overage: integer;
530begin
531 FDeleted := TORStringList.Create;
532 FHideSynonyms := TRUE;
533 cbxObjs.InitLongList('');
534 cbxObjs.ItemHeight := 15;
535 UpdateControls;
536 ResizeAnchoredFormToFont(self);
537 //ResizeAnchoredFormToFont does the pnlObjInfo panel wrong. So we fix it here.
538 gbMisc.Top := pnlObjInfo.ClientHeight - gbMisc.Height - 5;
539 gbIndent.Top := gbMisc.Top;
540 edtLMText.Top := gbMisc.Top - edtLMText.Height - 2;
541 lblLM.Top := edtLMText.Top + 5;
542 pnlSwap.Height := lblLM.Top - pnlSwap.Top;
543 Overage := edtName.Left + edtName.Width - pnlObjInfo.ClientWidth - 4;
544 for i := 0 to pnlObjInfo.ControlCount-1 do begin
545 Child := pnlObjInfo.Controls[i];
546 if (akRight in Child.Anchors) then begin
547 if (akLeft in Child.Anchors) then
548 Child.Width := Child.Width - Overage
549 else
550 Child.Left := Child.Left - Overage;
551 end;
552 end;
553end;
554
555procedure TfrmTemplateFieldEditor.cbxObjsChange(Sender: TObject);
556begin
557 if(cbxObjs.ItemIEN <> 0) then
558 SetFld(GetTemplateField(cbxObjs.ItemID, TRUE))
559 else
560 SetFld(nil);
561 UpdateControls;
562end;
563
564procedure TfrmTemplateFieldEditor.edtNameChange(Sender: TObject);
565var
566 ok: boolean;
567
568begin
569 if(not FUpdating) and (assigned(FFld)) then
570 begin
571 if (not FFld.NameChanged) and (not FFld.NewField) then
572 begin
573 ok := InfoBox('*** WARNING ***' + CRLF + CRLF +
574 'This template field has been saved, and may have been used in one or more' + CRLF +
575 'boilerplates. Boilerplates can be found in templates, titles, reasons for request' + CRLF +
576 'and reminder dialogs. Renaming this template field will cause any boilerplates' + CRLF +
577 'that use it to no longer function correctly.' + CRLF + CRLF +
578 'Are you sure you want to rename the ' + FFld.FldName + ' template field?',
579 'Warning', MB_YESNO or MB_ICONWARNING) = IDYES;
580 if ok then
581 InfoBox('Template field will be renamed when OK or Apply is pressed.', 'Information', MB_OK or MB_ICONINFORMATION)
582 else
583 begin
584 FUpdating := TRUE;
585 try
586 edtName.Text := FFld.FldName;
587 finally
588 FUpdating := FALSE;
589 end;
590 end;
591 end
592 else
593 ok := TRUE;
594 if ok then
595 begin
596 FFld.FldName := edtName.Text;
597 edtName.Text := FFld.FldName;
598 FChangesPending := TRUE;
599 ResetListEntry;
600 end;
601 end;
602end;
603
604procedure TfrmTemplateFieldEditor.cbxTypeChange(Sender: TObject);
605begin
606 if(not FUpdating) and (assigned(FFld)) then
607 begin
608 if(cbxType.ItemIndex < 0) then
609 begin
610 FUpdating := TRUE;
611 try
612 cbxType.ItemIndex := 0;
613 finally
614 FUpdating := FALSE;
615 end;
616 end;
617 FFld.FldType := TTemplateFieldType(cbxType.ItemIndex);
618 end;
619 EnableButtons;
620 UpdateControls;
621end;
622
623procedure TfrmTemplateFieldEditor.edtLenChange(Sender: TObject);
624var
625 v: integer;
626 ok: boolean;
627
628begin
629 EnsureText(edtLen, udLen);
630 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType in (EditLenTypes))) then
631 begin
632 EnsureText(edtLen, udLen);
633 FFld.MaxLen := udLen.Position;
634 udLen.Position := FFld.MaxLen;
635 if edtDefault.Visible then
636 begin
637 edtDefault.MaxLength := FFld.MaxLen;
638 edtDefault.Text := copy(edtDefault.Text,1,FFld.MaxLen);
639 end;
640 case FFLd.FldType of
641 dftEditBox: ok := TRUE;
642 dftComboBox: ok := (udTextLen.Position > 0);
643 else ok := FALSE;
644 end;
645 if ok then
646 begin
647 v := udLen.Position;
648 if udTextLen.Position < v then
649 udTextLen.Position := v;
650 end;
651 end;
652end;
653
654procedure TfrmTemplateFieldEditor.edtDefaultChange(Sender: TObject);
655begin
656 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType in EditDfltType2)) then
657 begin
658 FFld.EditDefault := TEdit(Sender).Text;
659 TEdit(Sender).Text := FFld.EditDefault;
660 end;
661end;
662
663procedure TfrmTemplateFieldEditor.cbxDefaultChange(Sender: TObject);
664begin
665 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType in ItemDfltTypes)) then
666 begin
667 FFld.ItemDefault := cbxDefault.Text;
668 SyncItems;
669 end;
670end;
671
672procedure TfrmTemplateFieldEditor.edtLMTextChange(Sender: TObject);
673begin
674 if((not FUpdating) and (assigned(FFld))) then
675 begin
676 FFld.LMText := edtLMText.Text;
677 edtLMText.Text := FFld.LMText;
678 end;
679end;
680
681procedure TfrmTemplateFieldEditor.cbActiveClick(Sender: TObject);
682begin
683 if((not FUpdating) and (assigned(FFld))) then
684 begin
685 FFld.Inactive := cbActive.Checked;
686 cbActive.Checked := FFld.Inactive;
687 FChangesPending := TRUE;
688 //ResetListEntry;
689 end;
690end;
691
692procedure TfrmTemplateFieldEditor.mnuNewClick(Sender: TObject);
693begin
694 SetFld(TTemplateField.Create(nil));
695 if(assigned(FFld)) then
696 begin
697 FChangesPending := TRUE;
698 if cbxObjs.ShortCount = 0 then
699 begin
700 cbxObjs.Items.Insert(0,LLS_LINE);
701 cbxObjs.Items.Insert(1,'');
702 end;
703 if(assigned(CopyFld)) then
704 FFld.Assign(CopyFld);
705 cbxObjs.Items.Insert(0,FFld.ID + U + FFld.FldName);
706 cbxObjs.SelectByID(FFld.ID);
707 cbxObjsChange(nil);
708 if(assigned(FFld)) then
709 edtName.SetFocus;
710 end
711 else
712 UpdateControls;
713end;
714
715procedure TfrmTemplateFieldEditor.btnOKClick(Sender: TObject);
716begin
717 SaveChanges;
718end;
719
720procedure TfrmTemplateFieldEditor.btnApplyClick(Sender: TObject);
721var
722 tmp: string;
723begin
724 SaveChanges;
725 cbxObjs.Clear;
726 if assigned(FFld) then
727 tmp := FFld.FldName
728 else
729 tmp := '';
730 cbxObjs.InitLongList(tmp);
731 cbxObjs.ItemIndex := 0;
732 cbxObjsChange(cbxObjs);
733end;
734
735procedure TfrmTemplateFieldEditor.FormCloseQuery(Sender: TObject;
736 var CanClose: Boolean);
737var
738 ans: word;
739
740begin
741 if(AnyTemplateFieldsModified) then
742 begin
743 ans := InfoBox('Save Changes?', 'Confirmation', MB_YESNOCANCEL or MB_ICONQUESTION);
744 if(ans = IDCANCEL) then
745 CanClose := FALSE
746 else
747 if(ans = IDYES) then
748 CanClose := SaveChanges;
749 end;
750end;
751
752procedure TfrmTemplateFieldEditor.btnCancelClick(Sender: TObject);
753var
754 i: integer;
755
756begin
757 for i := 0 to FDeleted.Count-1 do
758 UnlockTemplateField(Piece(FDeleted[i],U,1));
759 FDeleted.Clear;
760 ClearModifiedTemplateFields;
761end;
762
763function TfrmTemplateFieldEditor.SaveChanges: boolean;
764var
765 ans: word;
766 Errors: string;
767 i: integer;
768
769begin
770 for i := 0 to FDeleted.Count-1 do
771 DeleteTemplateField(Piece(FDeleted[i],U,1));
772 FDeleted.Clear;
773 Result := TRUE;
774 Errors := SaveTemplateFieldErrors;
775 if(Errors <> '') then
776 begin
777 ans := InfoBox(Errors + CRLF + CRLF + 'Cancel changes to these Template Fields?',
778 'Confirmation', MB_YESNO or MB_ICONQUESTION);
779 if(ans = IDYES) then
780 ClearModifiedTemplateFields
781 else
782 Result := FALSE;
783 end;
784 if(FChangesPending) then
785 FReloadChanges := TRUE;
786end;
787
788procedure TfrmTemplateFieldEditor.reItemsChange(Sender: TObject);
789begin
790 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType in FldItemTypes)) then
791 begin
792 FFld.Items := reItems.Lines.Text;
793 SyncItems;
794 end;
795end;
796
797procedure TfrmTemplateFieldEditor.cbHideClick(Sender: TObject);
798begin
799 SetHideSynonyms(cbHide.Checked);
800end;
801
802procedure TfrmTemplateFieldEditor.edtNameExit(Sender: TObject);
803begin
804 if (ActiveControl <> btnCancel) and (ActiveControl <> btnDelete) then
805 VerifyName;
806end;
807
808procedure TfrmTemplateFieldEditor.VerifyName;
809var
810 bad: boolean;
811
812begin
813 if assigned(FFld) then
814 begin
815 if FDeleted.IndexOfPiece(FFld.FldName, U, 2) >= 0 then
816 begin
817 ShowMessage('Template field can not be named the same as a deleted' + CRLF +
818 'field until OK or Apply has been pressed.');
819 bad := TRUE;
820 end
821 else
822 bad := TemplateFieldNameProblem(FFld);
823 if bad then
824 edtName.SetFocus;
825 end;
826end;
827
828procedure TfrmTemplateFieldEditor.mnuCopyClick(Sender: TObject);
829begin
830 if assigned(FFld) then
831 begin
832 CopyFld := FFld;
833 try
834 mnuNewClick(nil);
835 finally
836 CopyFld := nil;
837 end;
838 end;
839end;
840
841procedure TfrmTemplateFieldEditor.SetFld(const Value: TTemplateField);
842begin
843 FFld := Value;
844 EnableButtons;
845end;
846
847procedure TfrmTemplateFieldEditor.mnuDeleteClick(Sender: TObject);
848var
849 idx: integer;
850 ok: boolean;
851 Answer: word;
852 txt: string;
853 btns: TMsgDlgButtons;
854
855begin
856 if assigned(FFld) then
857 begin
858 ok := (FFld.NewField);
859 if not ok then
860 begin
861 btns := [mbYes, mbNo];
862 if FFld.Inactive then
863 txt := ''
864 else
865 begin
866 txt := ' Rather than deleting, you may want' + CRLF +
867 'to inactivate this template field instead. You may inactivate this template by' + CRLF +
868 'pressing the Ignore button now.';
869 include(btns, mbIgnore);
870 end;
871 Answer := MessageDlg('*** WARNING ***' + CRLF + CRLF +
872 'This template field has been saved, and may have been used in one or more' + CRLF +
873 'boilerplates. Boilerplates can be found in templates, titles, reasons for request' + CRLF +
874 'and reminder dialogs. Deleting this template field will cause any boilerplates' + CRLF +
875 'that use it to no longer function correctly.' + txt + CRLF + CRLF +
876 'Are you sure you want to delete the ' + FFld.FldName + ' template field?',
877 mtWarning, btns, 0);
878 ok := (Answer = mrYes);
879 if(Answer = mrIgnore) then
880 cbActive.Checked := TRUE;
881 end;
882 if ok then
883 begin
884 if(FFld.NewField or FFld.CanModify) then
885 begin
886 if FFld.NewField then
887 begin
888 idx := cbxObjs.ItemIndex;
889 cbxObjs.ItemIndex := -1;
890 cbxObjs.Items.Delete(idx);
891 if cbxObjs.Items[0] = LLS_LINE then
892 begin
893 cbxObjs.Items.Delete(1);
894 cbxObjs.Items.Delete(0);
895 end;
896 end
897 else
898 begin
899 FDeleted.Add(FFld.ID + U + FFld.FldName);
900 cbxObjs.ItemIndex := -1;
901 end;
902 end;
903 FFld.Free;
904 SetFld(nil);
905 UpdateControls;
906 cbxObjs.InitLongList('');
907 FChangesPending := TRUE;
908 end;
909 end;
910end;
911
912procedure TfrmTemplateFieldEditor.ResetListEntry;
913var
914 txt: string;
915
916begin
917 if(assigned(FFld) and FFld.NewField and (cbxObjs.ItemIndex >= 0)) then
918 begin
919 txt := FFld.ID + U + FFld.FldName;
920 //if(FFld.Inactive) then
921 //txt := txt + ' <Inactive>';
922 cbxObjs.Items[cbxObjs.ItemIndex] := txt;
923 cbxObjs.ItemIndex := cbxObjs.ItemIndex;
924 end;
925end;
926
927procedure TfrmTemplateFieldEditor.btnPreviewClick(Sender: TObject);
928var
929 TmpSL: TStringList;
930
931begin
932 if(assigned(FFld)) then
933 begin
934 TmpSL := TStringList.Create;
935 try
936 TmpSL.Add(TemplateFieldBeginSignature + FFld.FldName + TemplateFieldEndSignature);
937 CheckBoilerplate4Fields(TmpSL, 'Preview Template Field: ' + FFld.FldName, TRUE);
938 finally
939 TmpSL.Free;
940 end;
941 end;
942end;
943
944procedure TfrmTemplateFieldEditor.EnableButtons;
945begin
946 btnCopy.Enabled := assigned(FFld);
947 mnuCopy.Enabled := btnCopy.Enabled;
948 btnDelete.Enabled := btnCopy.Enabled; // (assigned(FFld) and FFld.NewField);
949 mnuDelete.Enabled := btnDelete.Enabled;
950 btnPreview.Enabled := assigned(FFld) and (FFld.FldType <> dftUnknown);
951 mnuPreview.Enabled := btnPreview.Enabled;
952end;
953
954procedure TfrmTemplateFieldEditor.mnuActionClick(Sender: TObject);
955begin
956 EnableButtons;
957end;
958
959procedure TfrmTemplateFieldEditor.cbRequiredClick(Sender: TObject);
960begin
961 if((not FUpdating) and (assigned(FFld))) then
962 begin
963 FFld.Required := cbRequired.Checked;
964 cbRequired.Checked := FFld.Required;
965 end;
966end;
967
968procedure TfrmTemplateFieldEditor.pnlObjsResize(Sender: TObject);
969begin
970 btnPreview.Left := pnlRight.Left;
971end;
972
973procedure TfrmTemplateFieldEditor.FormDestroy(Sender: TObject);
974begin
975 FDeleted.Free;
976 if(assigned(frmTemplateFields)) then begin
977 frmTemplateFields.FRee;
978 frmTemplateFields := nil;
979 end; {if}
980
981end;
982
983procedure TfrmTemplateFieldEditor.SetHideSynonyms(const Value: boolean);
984begin
985 FHideSynonyms := Value;
986 cbxObjs.HideSynonyms := FALSE; // Refresh Display
987 cbxObjs.HideSynonyms := TRUE;
988end;
989
990procedure TfrmTemplateFieldEditor.cbxObjsSynonymCheck(Sender: TObject;
991 const Text: String; var IsSynonym: Boolean);
992begin
993 if not FHideSynonyms then
994 IsSynonym := FALSE;
995 if(FDeleted.Count > 0) and (FDeleted.IndexOfPiece(Text,U,2) >= 0) then
996 IsSynonym := TRUE;
997end;
998
999procedure TfrmTemplateFieldEditor.popTextPopup(Sender: TObject);
1000var
1001 HasText, CanEdit, isre: boolean;
1002 ce: TCustomEdit;
1003 ShowTempField: boolean;
1004
1005begin
1006 ce := GetPopupControl;
1007 if assigned(ce) then
1008 begin
1009 isre := (ce is TRichEdit);
1010 CanEdit := (not TORExposedCustomEdit(ce).ReadOnly);
1011 mnuBPUndo.Enabled := (CanEdit and (ce.Perform(EM_CANUNDO, 0, 0) <> 0));
1012 if isre then
1013 HasText := (TRichEdit(ce).Lines.Count > 0)
1014 else
1015 HasText := (Text <> '');
1016 mnuBPSelectAll.Enabled := HasText;
1017 mnuBPCopy.Enabled := HasText and (ce.SelLength > 0);
1018 mnuBPPaste.Enabled := (CanEdit and Clipboard.HasFormat(CF_TEXT));
1019 mnuBPCut.Enabled := (CanEdit and HasText and (ce.SelLength > 0));
1020 ShowTempField := FALSE;
1021 if CanEdit then
1022 if (not assigned(frmTemplateFields)) or
1023 (assigned(frmTemplateFields) and not frmTemplateFields.Visible) then
1024 if (ce = reItems) or
1025 (ce = edtDefault) then
1026 ShowTempField := TRUE;
1027 mnuInsertTemplateField.Enabled := ShowTempField;
1028 end
1029 else
1030 begin
1031 isre := FALSE;
1032 HasText := FALSE;
1033 CanEdit := FALSE;
1034 mnuBPPaste.Enabled := FALSE;
1035 mnuBPCopy.Enabled := FALSE;
1036 mnuBPCut.Enabled := FALSE;
1037 mnuBPSelectAll.Enabled := FALSE;
1038 mnuBPUndo.Enabled := FALSE;
1039 mnuInsertTemplateField.Enabled := FALSE;
1040 end;
1041
1042 mnuBPSpellCheck.Visible := isre;
1043 mnuBPCheckGrammar.Visible := isre;
1044
1045 if isre and HasText and CanEdit then
1046 begin
1047 mnuBPSpellCheck.Enabled := SpellCheckAvailable;
1048 mnuBPCheckGrammar.Enabled := SpellCheckAvailable;
1049 end
1050 else
1051 begin
1052 mnuBPSpellCheck.Enabled := FALSE;
1053 mnuBPCheckGrammar.Enabled := FALSE;
1054 end;
1055end;
1056
1057function TfrmTemplateFieldEditor.GetPopupControl: TCustomEdit;
1058begin
1059 if assigned(popText.PopupComponent) and (popText.PopupComponent is TCustomEdit) then
1060 Result := TCustomEdit(popText.PopupComponent)
1061 else
1062 Result := nil;
1063end;
1064
1065procedure TfrmTemplateFieldEditor.mnuBPUndoClick(Sender: TObject);
1066var
1067 ce: TCustomEdit;
1068
1069begin
1070 ce := GetPopupControl;
1071 if assigned(ce) then
1072 ce.Perform(EM_UNDO, 0, 0);
1073end;
1074
1075procedure TfrmTemplateFieldEditor.mnuBPCutClick(Sender: TObject);
1076var
1077 ce: TCustomEdit;
1078
1079begin
1080 ce := GetPopupControl;
1081 if assigned(ce) then
1082 ce.CutToClipboard;
1083end;
1084
1085procedure TfrmTemplateFieldEditor.mnuBPCopyClick(Sender: TObject);
1086var
1087 ce: TCustomEdit;
1088
1089begin
1090 ce := GetPopupControl;
1091 if assigned(ce) then
1092 ce.CopyToClipboard;
1093end;
1094
1095procedure TfrmTemplateFieldEditor.mnuBPPasteClick(Sender: TObject);
1096var
1097 ce: TCustomEdit;
1098
1099begin
1100 ce := GetPopupControl;
1101 if assigned(ce) then
1102 ce.SelText := Clipboard.AsText;
1103end;
1104
1105procedure TfrmTemplateFieldEditor.mnuBPSelectAllClick(Sender: TObject);
1106var
1107 ce: TCustomEdit;
1108
1109begin
1110 ce := GetPopupControl;
1111 if assigned(ce) then
1112 ce.SelectAll;
1113end;
1114
1115procedure TfrmTemplateFieldEditor.mnuBPCheckGrammarClick(Sender: TObject);
1116var
1117 ce: TCustomEdit;
1118
1119begin
1120 ce := GetPopupControl;
1121 if(assigned(ce) and (ce is TRichEdit)) then
1122 GrammarCheckForControl(TRichEdit(ce));
1123end;
1124
1125procedure TfrmTemplateFieldEditor.mnuBPSpellCheckClick(Sender: TObject);
1126var
1127 ce: TCustomEdit;
1128
1129begin
1130 ce := GetPopupControl;
1131 if(assigned(ce) and (ce is TRichEdit)) then
1132 SpellCheckForControl(TRichEdit(ce));
1133end;
1134
1135procedure TfrmTemplateFieldEditor.cbSepLinesClick(Sender: TObject);
1136begin
1137 if((not FUpdating) and (assigned(FFld))) then
1138 begin
1139 FFld.SepLines := cbSepLines.Checked;
1140 cbSepLines.Checked := FFld.SepLines;
1141 end;
1142end;
1143
1144procedure TfrmTemplateFieldEditor.edtpopControlEnter(Sender: TObject);
1145begin
1146 popText.PopupComponent := TComponent(Sender);
1147 if assigned(frmTemplateFields) then
1148 begin
1149 if ((Sender = reItems) or (Sender = edtDefault)) then
1150 begin
1151 frmTemplateFields.btnInsert.Enabled := TRUE;
1152 if Sender = reItems then
1153 frmTemplateFields.re := reItems
1154 else
1155 frmTemplateFields.re := edtDefault;
1156 end
1157 else
1158 frmTemplateFields.btnInsert.Enabled := FALSE;
1159 end;
1160end;
1161
1162procedure TfrmTemplateFieldEditor.cbxObjsKeyDown(Sender: TObject;
1163 var Key: Word; Shift: TShiftState);
1164begin
1165 if(Key = VK_DELETE) and btnDelete.Enabled then
1166 mnuDeleteClick(btnDelete);
1167end;
1168
1169procedure TfrmTemplateFieldEditor.edtTextLenChange(Sender: TObject);
1170var
1171 v: integer;
1172
1173begin
1174 EnsureText(edtTextLen, udTextLen);
1175 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType in EditLenTypes)) then
1176 begin
1177 FFld.TextLen := udTextLen.Position;
1178 udTextLen.Position := FFld.TextLen;
1179 if FFld.FldType = dftEditBox then
1180 begin
1181 v := udTextLen.Position;
1182 if udLen.Position > v then
1183 udLen.Position := v;
1184 end;
1185 end;
1186end;
1187
1188procedure TfrmTemplateFieldEditor.edtDefNumChange(Sender: TObject);
1189var
1190 v: integer;
1191
1192begin
1193 EnsureText(edtDefNum, udDefNum);
1194 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType = dftNumber)) then
1195 begin
1196 FFld.EditDefault := IntToStr(udDefNum.Position);
1197 udDefNum.Position := StrToIntDef(FFld.EditDefault, 0);
1198 v := udDefNum.Position;
1199 if udMinVal.Position > v then
1200 udMinVal.Position := v;
1201 if udMaxVal.Position < v then
1202 udMaxVal.Position := v;
1203 end;
1204end;
1205
1206procedure TfrmTemplateFieldEditor.edtMinValChange(Sender: TObject);
1207var
1208 v: integer;
1209
1210begin
1211 EnsureText(edtMinVal, udMinVal);
1212 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType = dftNumber)) then
1213 begin
1214 FFld.MinVal := udMinVal.Position;
1215 udMinVal.Position := FFld.MinVal;
1216 v := udMinVal.Position;
1217 if udDefNum.Position < v then
1218 udDefNum.Position := v;
1219 if udMaxVal.Position < v then
1220 udMaxVal.Position := v;
1221 end;
1222end;
1223
1224procedure TfrmTemplateFieldEditor.edtMaxValChange(Sender: TObject);
1225var
1226 v: integer;
1227
1228begin
1229 EnsureText(edtMaxVal, udMaxVal);
1230 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType = dftNumber)) then
1231 begin
1232 FFld.MaxVal := udMaxVal.Position;
1233 udMaxVal.Position := FFld.MaxVal;
1234 v := udMaxVal.Position;
1235 if udDefNum.Position > v then
1236 udDefNum.Position := v;
1237 if udMinVal.Position > v then
1238 udMinVal.Position := v;
1239 end;
1240end;
1241
1242procedure TfrmTemplateFieldEditor.edtIncChange(Sender: TObject);
1243begin
1244 EnsureText(edtInc, udInc);
1245 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType = dftNumber)) then
1246 begin
1247 FFld.Increment := udInc.Position;
1248 udInc.Position := FFld.Increment;
1249 end;
1250end;
1251
1252procedure TfrmTemplateFieldEditor.edtURLChange(Sender: TObject);
1253begin
1254 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType = dftHyperlink)) then
1255 begin
1256 FFld.URL := edtURL.Text;
1257 edtURL.Text := FFld.URL;
1258 end;
1259end;
1260
1261procedure TfrmTemplateFieldEditor.edtPadChange(Sender: TObject);
1262begin
1263 EnsureText(edtPad, udPad);
1264 if((not FUpdating) and (assigned(FFld))) then
1265 begin
1266 FFld.Pad := udPad.Position;
1267 udPad.Position := FFld.Pad;
1268 end;
1269end;
1270
1271procedure TfrmTemplateFieldEditor.edtIndentChange(Sender: TObject);
1272begin
1273 EnsureText(edtIndent, udIndent);
1274 if((not FUpdating) and (assigned(FFld))) then
1275 begin
1276 FFld.Indent := udIndent.Position;
1277 udIndent.Position := FFld.Indent;
1278 end;
1279end;
1280
1281procedure TfrmTemplateFieldEditor.reNotesChange(Sender: TObject);
1282begin
1283 if((not FUpdating) and (assigned(FFld)) and FFld.CanModify) then
1284 FFld.Notes := reNotes.Lines.Text;
1285end;
1286
1287procedure TfrmTemplateFieldEditor.cbxDateTypeChange(Sender: TObject);
1288begin
1289 if((not FUpdating) and (assigned(FFld)) and (FFld.FldType = dftDate)) then
1290 begin
1291 if cbxDateType.ItemIndex >= 0 then
1292 FFld.DateType := TTmplFldDateType(cbxDateType.ItemIndex + 1)
1293 else
1294 FFld.DateType := dtDate;
1295 cbxDateType.SelectByID(TemplateFieldDateCodes[FFld.DateType]);
1296 end;
1297
1298end;
1299
1300procedure TfrmTemplateFieldEditor.cbExcludeClick(Sender: TObject);
1301begin
1302 if((not FUpdating) and (assigned(FFld))) then
1303 begin
1304 FFld.SepLines := cbExclude.Checked;
1305 cbExclude.Checked := FFld.SepLines;
1306 UpdateControls;
1307 end;
1308end;
1309
1310procedure TfrmTemplateFieldEditor.FormResize(Sender: TObject);
1311begin
1312 LimitEditWidth(reItems, 240);
1313 LimitEditWidth(reNotes, MAX_ENTRY_WIDTH);
1314end;
1315
1316procedure TfrmTemplateFieldEditor.reItemsResizeRequest(Sender: TObject;
1317 Rect: TRect);
1318var
1319 R: TRect;
1320
1321begin
1322 R := TRichEdit(Sender).ClientRect;
1323 if (FLastRect.Right <> R.Right) or
1324 (FLastRect.Bottom <> R.Bottom) or
1325 (FLastRect.Left <> R.Left) or
1326 (FLastRect.Top <> R.Top) then
1327 begin
1328 FLastRect := R;
1329 FormResize(Self);
1330 end;
1331end;
1332
1333procedure TfrmTemplateFieldEditor.reItemsSelectionChange(Sender: TObject);
1334var
1335 p: TPoint;
1336
1337begin
1338 if lblLine.Visible then
1339 begin
1340 p := reItems.CaretPos;
1341 lblLine.Caption := 'Line: ' + inttostr(p.y + 1);
1342 lblCol.Caption := 'Col: ' + inttostr(p.x + 1);
1343 end;
1344end;
1345
1346procedure TfrmTemplateFieldEditor.mnuInsertTemplateFieldClick(Sender: TObject);
1347var
1348 iCon: TCustomEdit;
1349 ShowButton: boolean;
1350begin
1351 iCon := GetPopupControl;
1352 if iCon <> nil then
1353 begin
1354 if iCon.Name <> ActiveControl.Name then
1355 begin
1356 ActiveControl := iCon;
1357 iCon.SelStart := iCon.SelLength;
1358 end;
1359 if (not assigned(frmTemplateFields)) then
1360 begin
1361 frmTemplateFields := TfrmTemplateFields.Create(Self);
1362 frmTemplateFields.Font := Font;
1363 end;
1364 ShowButton := False;
1365 if iCon = reItems then
1366 begin
1367 frmTemplateFields.re := reItems;
1368 ShowButton := TRUE;
1369 end
1370 else if iCon = edtDefault then
1371 begin
1372 frmTemplateFields.re := edtDefault;
1373 ShowButton := TRUE;
1374 end;
1375 frmTemplateFields.btnInsert.Enabled := ShowButton;
1376
1377 frmTemplateFields.Show;
1378 end
1379
1380end;
1381
1382procedure TfrmTemplateFieldEditor.ControlExit(Sender: TObject);
1383begin
1384 if assigned(frmTemplateFields) then
1385 frmTemplateFields.btnInsert.Enabled := FALSE;
1386end;
1387
1388procedure TfrmTemplateFieldEditor.reNotesKeyUp(Sender: TObject;
1389 var Key: Word; Shift: TShiftState);
1390begin
1391 if (Key = VK_TAB) then
1392 begin
1393 if ssShift in Shift then
1394 begin
1395 FindNextControl(Sender as TWinControl, False, True, False).SetFocus; //previous control
1396 Key := 0;
1397 end
1398 else if ssCtrl in Shift then
1399 begin
1400 FindNextControl(Sender as TWinControl, True, True, False).SetFocus; //next control
1401 Key := 0;
1402 end;
1403 end;
1404 if (key = VK_ESCAPE) then begin
1405 FindNextControl(Sender as TWinControl, False, True, False).SetFocus; //previous control
1406 key := 0;
1407 end;
1408end;
1409
1410end.
Note: See TracBrowser for help on using the repository browser.