source: cprs/trunk/CPRS-Chart/Templates/fTemplateEditor.pas@ 1154

Last change on this file since 1154 was 829, checked in by Kevin Toppenberg, 14 years ago

Upgrade to version 27

File size: 126.6 KB
Line 
1unit fTemplateEditor;
2{The OwnerScan conditional compile varaible was created because there were too
3 many things that needed to be done to incorporate the viewing of other user's
4 personal templates by clinical coordinators. These include:
5 Changing the Personal tree.
6 expanding entirely new personal list when personal list changes
7 when click on stop editing shared button, and personal is for someone else,
8 need to resync to personal list.
9
10HOT HEYS NOT YET ASSIGNED:
11JFKQRUVZ
12}
13{$DEFINE OwnerScan}
14{$UNDEF OwnerScan}
15interface
16
17uses
18 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
19 ExtCtrls, StdCtrls, ComCtrls, ORCtrls, Buttons, Mask, ORFn, ORNet,
20 uTemplates, Menus, ImgList, Clipbrd, ToolWin, MenuBar, TypInfo, MSXML_TLB, fBase508Form,
21 VA508AccessibilityManager, VA508ImageListLabeler;
22
23type
24 TTemplateTreeControl = (tcDel, tcUp, tcDown, tcLbl, tcCopy);
25 TTemplateTreeType = (ttShared, ttPersonal);
26
27 TfrmTemplateEditor = class(TfrmBase508Form)
28 splMain: TSplitter;
29 pnlBottom: TPanel;
30 btnApply: TButton;
31 btnCancel: TButton;
32 btnOK: TButton;
33 pnlBoilerplate: TPanel;
34 reBoil: TRichEdit;
35 pnlTop: TPanel;
36 pnlRightTop: TPanel;
37 splProperties: TSplitter;
38 pnlCopyBtns: TPanel;
39 sbCopyLeft: TBitBtn;
40 sbCopyRight: TBitBtn;
41 lblCopy: TLabel;
42 splMiddle: TSplitter;
43 pnlShared: TPanel;
44 lblShared: TLabel;
45 tvShared: TORTreeView;
46 pnlSharedBottom: TPanel;
47 sbShUp: TBitBtn;
48 sbShDown: TBitBtn;
49 sbShDelete: TBitBtn;
50 cbShHide: TCheckBox;
51 pnlSharedGap: TPanel;
52 pnlPersonal: TPanel;
53 lblPersonal: TLabel;
54 tvPersonal: TORTreeView;
55 pnlPersonalBottom: TPanel;
56 sbPerUp: TBitBtn;
57 sbPerDown: TBitBtn;
58 sbPerDelete: TBitBtn;
59 cbPerHide: TCheckBox;
60 pnlPersonalGap: TPanel;
61 popTemplates: TPopupMenu;
62 mnuCollapseTree: TMenuItem;
63 mnuFindTemplates: TMenuItem;
64 popBoilerplate: TPopupMenu;
65 mnuBPInsertObject: TMenuItem;
66 mnuBPErrorCheck: TMenuItem;
67 mnuBPSpellCheck: TMenuItem;
68 pnlGroupBP: TPanel;
69 reGroupBP: TRichEdit;
70 lblGroupBP: TLabel;
71 splBoil: TSplitter;
72 pnlGroupBPGap: TPanel;
73 tmrAutoScroll: TTimer;
74 popGroup: TPopupMenu;
75 mnuGroupBPCopy: TMenuItem;
76 mnuBPCut: TMenuItem;
77 N2: TMenuItem;
78 mnuBPCopy: TMenuItem;
79 mnuBPPaste: TMenuItem;
80 N4: TMenuItem;
81 mnuGroupBPSelectAll: TMenuItem;
82 mnuBPSelectAll: TMenuItem;
83 N6: TMenuItem;
84 mnuNodeCopy: TMenuItem;
85 mnuNodePaste: TMenuItem;
86 mnuNodeDelete: TMenuItem;
87 N8: TMenuItem;
88 mnuBPUndo: TMenuItem;
89 cbEditShared: TCheckBox;
90 pnlProperties: TPanel;
91 gbProperties: TGroupBox;
92 lblName: TLabel;
93 lblLines: TLabel;
94 cbExclude: TORCheckBox;
95 cbActive: TCheckBox;
96 edtGap: TCaptionEdit;
97 udGap: TUpDown;
98 edtName: TCaptionEdit;
99 mnuMain: TMainMenu;
100 mnuEdit: TMenuItem;
101 mnuUndo: TMenuItem;
102 N9: TMenuItem;
103 mnuCut: TMenuItem;
104 mnuCopy: TMenuItem;
105 mnuPaste: TMenuItem;
106 mnuSelectAll: TMenuItem;
107 N11: TMenuItem;
108 mnuInsertObject: TMenuItem;
109 mnuErrorCheck: TMenuItem;
110 mnuSpellCheck: TMenuItem;
111 N13: TMenuItem;
112 mnuGroupBoilerplate: TMenuItem;
113 mnuGroupCopy: TMenuItem;
114 mnuGroupSelectAll: TMenuItem;
115 mnuTemplate: TMenuItem;
116 mnuTCopy: TMenuItem;
117 mnuTPaste: TMenuItem;
118 mnuTDelete: TMenuItem;
119 N12: TMenuItem;
120 pnlShSearch: TPanel;
121 btnShFind: TORAlignButton;
122 edtShSearch: TCaptionEdit;
123 cbShMatchCase: TCheckBox;
124 cbShWholeWords: TCheckBox;
125 pnlPerSearch: TPanel;
126 btnPerFind: TORAlignButton;
127 edtPerSearch: TCaptionEdit;
128 cbPerMatchCase: TCheckBox;
129 cbPerWholeWords: TCheckBox;
130 mnuFindShared: TMenuItem;
131 mnuFindPersonal: TMenuItem;
132 N3: TMenuItem;
133 mnuShCollapse: TMenuItem;
134 mnuPerCollapse: TMenuItem;
135 pnlMenuBar: TPanel;
136 lblPerOwner: TLabel;
137 cboOwner: TORComboBox;
138 btnNew: TORAlignButton;
139 pnlMenu: TPanel;
140 mbMain: TMenuBar;
141 mnuNewTemplate: TMenuItem;
142 Bevel1: TBevel;
143 mnuNodeNew: TMenuItem;
144 mnuBPCheckGrammar: TMenuItem;
145 mnuCheckGrammar: TMenuItem;
146 N1: TMenuItem;
147 N7: TMenuItem;
148 N14: TMenuItem;
149 mnuSort: TMenuItem;
150 N15: TMenuItem;
151 mnuNodeSort: TMenuItem;
152 mnuTry: TMenuItem;
153 mnuBPTry: TMenuItem;
154 mnuAutoGen: TMenuItem;
155 mnuNodeAutoGen: TMenuItem;
156 pnlNotes: TPanel;
157 reNotes: TRichEdit;
158 splNotes: TSplitter;
159 lblNotes: TLabel;
160 popNotes: TPopupMenu;
161 mnuNotesUndo: TMenuItem;
162 MenuItem2: TMenuItem;
163 mnuNotesCut: TMenuItem;
164 mnuNotesCopy: TMenuItem;
165 mnuNotesPaste: TMenuItem;
166 MenuItem6: TMenuItem;
167 mnuNotesSelectAll: TMenuItem;
168 MenuItem8: TMenuItem;
169 mnuNotesGrammar: TMenuItem;
170 mnuNotesSpelling: TMenuItem;
171 cbNotes: TCheckBox;
172 gbDialogProps: TGroupBox;
173 cbDisplayOnly: TCheckBox;
174 cbOneItemOnly: TCheckBox;
175 cbHideItems: TORCheckBox;
176 cbFirstLine: TCheckBox;
177 cbHideDlgItems: TCheckBox;
178 cbIndent: TCheckBox;
179 mnuTools: TMenuItem;
180 mnuEditTemplateFields: TMenuItem;
181 N16: TMenuItem;
182 mnuImportTemplate: TMenuItem;
183 mnuExportTemplate: TMenuItem;
184 mnuBPInsertField: TMenuItem;
185 mnuInsertField: TMenuItem;
186 cbEditUser: TCheckBox;
187 dlgImport: TOpenDialog;
188 dlgExport: TSaveDialog;
189 cbxType: TCaptionComboBox;
190 lblType: TLabel;
191 cbxRemDlgs: TORComboBox;
192 lblRemDlg: TLabel;
193 N17: TMenuItem;
194 mnuTemplateIconLegend: TMenuItem;
195 pnlBP: TPanel;
196 lblBoilerplate: TLabel;
197 cbLongLines: TCheckBox;
198 cbLock: TORCheckBox;
199 mnuRefresh: TMenuItem;
200 lblBoilRow: TLabel;
201 lblGroupRow: TLabel;
202 lblBoilCol: TLabel;
203 lblGroupCol: TLabel;
204 pnlCOM: TPanel;
205 lblCOMParam: TLabel;
206 edtCOMParam: TCaptionEdit;
207 cbxCOMObj: TORComboBox;
208 lblCOMObj: TLabel;
209 pnlLink: TPanel;
210 cbxLink: TORComboBox;
211 lblLink: TLabel;
212 imgLblTemplates: TVA508ImageListLabeler;
213 procedure btnNewClick(Sender: TObject);
214 procedure btnApplyClick(Sender: TObject);
215 procedure FormCreate(Sender: TObject);
216 procedure cboOwnerNeedData(Sender: TObject; const StartFrom: String;
217 Direction, InsertAt: Integer);
218 procedure cboOwnerChange(Sender: TObject);
219 procedure tvPersonalExpanding(Sender: TObject; Node: TTreeNode;
220 var AllowExpansion: Boolean);
221 procedure tvSharedExpanding(Sender: TObject; Node: TTreeNode;
222 var AllowExpansion: Boolean);
223 procedure tvTreeGetImageIndex(Sender: TObject; Node: TTreeNode);
224 procedure tvTreeGetSelectedIndex(Sender: TObject; Node: TTreeNode);
225 procedure tvTreeChange(Sender: TObject; Node: TTreeNode);
226 procedure splMainMoved(Sender: TObject);
227 procedure pnlBoilerplateResize(Sender: TObject);
228 procedure edtNameOldChange(Sender: TObject);
229 procedure cbActiveClick(Sender: TObject);
230 procedure cbExcludeClick(Sender: TObject);
231 procedure edtGapChange(Sender: TObject);
232 procedure tvTreeEnter(Sender: TObject);
233 procedure tvTreeNodeEdited(Sender: TObject; Node: TTreeNode;
234 var S: String);
235 procedure cbShHideClick(Sender: TObject);
236 procedure cbPerHideClick(Sender: TObject);
237 procedure FormDestroy(Sender: TObject);
238 procedure sbMoveUpClick(Sender: TObject);
239 procedure sbMoveDownClick(Sender: TObject);
240 procedure sbDeleteClick(Sender: TObject);
241 procedure tvTreeDragging(Sender: TObject; Node: TTreeNode;
242 var CanDrag: Boolean);
243 procedure tvTreeDragOver(Sender, Source: TObject; X, Y: Integer;
244 State: TDragState; var Accept: Boolean);
245 procedure tvTreeDragDrop(Sender, Source: TObject; X, Y: Integer);
246 procedure sbCopyLeftClick(Sender: TObject);
247 procedure sbCopyRightClick(Sender: TObject);
248 procedure reBoilChange(Sender: TObject);
249 procedure cbEditSharedClick(Sender: TObject);
250 procedure popTemplatesPopup(Sender: TObject);
251 procedure mnuCollapseTreeClick(Sender: TObject);
252 procedure mnuFindTemplatesClick(Sender: TObject);
253 procedure btnFindClick(Sender: TObject);
254 procedure edtSearchChange(Sender: TObject);
255 procedure edtShSearchEnter(Sender: TObject);
256 procedure edtShSearchExit(Sender: TObject);
257 procedure edtPerSearchEnter(Sender: TObject);
258 procedure edtPerSearchExit(Sender: TObject);
259 procedure btnOKClick(Sender: TObject);
260 procedure FormShow(Sender: TObject);
261 procedure mnuBPInsertObjectClick(Sender: TObject);
262 procedure mnuBPErrorCheckClick(Sender: TObject);
263 procedure popBoilerplatePopup(Sender: TObject);
264 procedure btnCancelClick(Sender: TObject);
265 procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
266 procedure mnuBPSpellCheckClick(Sender: TObject);
267 procedure splBoilMoved(Sender: TObject);
268 procedure edtGapKeyPress(Sender: TObject; var Key: Char);
269 procedure edtNameExit(Sender: TObject);
270 procedure tmrAutoScrollTimer(Sender: TObject);
271 procedure tvTreeStartDrag(Sender: TObject;
272 var DragObject: TDragObject);
273 procedure tvTreeEndDrag(Sender, Target: TObject; X, Y: Integer);
274 procedure mnuGroupBPCopyClick(Sender: TObject);
275 procedure popGroupPopup(Sender: TObject);
276 procedure mnuBPCutClick(Sender: TObject);
277 procedure mnuBPCopyClick(Sender: TObject);
278 procedure mnuBPPasteClick(Sender: TObject);
279 procedure mnuGroupBPSelectAllClick(Sender: TObject);
280 procedure mnuBPSelectAllClick(Sender: TObject);
281 procedure mnuNodeDeleteClick(Sender: TObject);
282 procedure mnuNodeCopyClick(Sender: TObject);
283 procedure mnuNodePasteClick(Sender: TObject);
284 procedure mnuBPUndoClick(Sender: TObject);
285 procedure tvTreeKeyDown(Sender: TObject; var Key: Word;
286 Shift: TShiftState);
287 procedure mnuEditClick(Sender: TObject);
288 procedure mnuGroupBoilerplateClick(Sender: TObject);
289 procedure cbShFindOptionClick(Sender: TObject);
290 procedure cbPerFindOptionClick(Sender: TObject);
291 procedure mnuTemplateClick(Sender: TObject);
292 procedure mnuFindSharedClick(Sender: TObject);
293 procedure mnuFindPersonalClick(Sender: TObject);
294 procedure mnuShCollapseClick(Sender: TObject);
295 procedure mnuPerCollapseClick(Sender: TObject);
296 procedure pnlShSearchResize(Sender: TObject);
297 procedure pnlPerSearchResize(Sender: TObject);
298 procedure pnlPropertiesResize(Sender: TObject);
299 procedure mbMainResize(Sender: TObject);
300 procedure mnuBPCheckGrammarClick(Sender: TObject);
301 procedure mnuSortClick(Sender: TObject);
302 procedure pnlBoilerplateCanResize(Sender: TObject; var NewWidth,
303 NewHeight: Integer; var Resize: Boolean);
304 procedure mnuBPTryClick(Sender: TObject);
305 procedure mnuAutoGenClick(Sender: TObject);
306 procedure reNotesChange(Sender: TObject);
307 procedure mnuNotesUndoClick(Sender: TObject);
308 procedure mnuNotesCutClick(Sender: TObject);
309 procedure mnuNotesCopyClick(Sender: TObject);
310 procedure mnuNotesPasteClick(Sender: TObject);
311 procedure mnuNotesSelectAllClick(Sender: TObject);
312 procedure mnuNotesGrammarClick(Sender: TObject);
313 procedure mnuNotesSpellingClick(Sender: TObject);
314 procedure popNotesPopup(Sender: TObject);
315 procedure cbNotesClick(Sender: TObject);
316 procedure cbDisplayOnlyClick(Sender: TObject);
317 procedure cbFirstLineClick(Sender: TObject);
318 procedure cbOneItemOnlyClick(Sender: TObject);
319 procedure cbHideDlgItemsClick(Sender: TObject);
320 procedure cbHideItemsClick(Sender: TObject);
321 procedure cbIndentClick(Sender: TObject);
322 procedure mnuToolsClick(Sender: TObject);
323 procedure mnuEditTemplateFieldsClick(Sender: TObject);
324 procedure mnuBPInsertFieldClick(Sender: TObject);
325 procedure mnuExportTemplateClick(Sender: TObject);
326 procedure mnuImportTemplateClick(Sender: TObject);
327 procedure cbxTypeDrawItem(Control: TWinControl; Index: Integer;
328 Rect: TRect; State: TOwnerDrawState);
329 procedure cbxTypeChange(Sender: TObject);
330 procedure cbxRemDlgsChange(Sender: TObject);
331 procedure mnuTemplateIconLegendClick(Sender: TObject);
332 procedure cbLongLinesClick(Sender: TObject);
333 procedure cbLockClick(Sender: TObject);
334 procedure mnuRefreshClick(Sender: TObject);
335 procedure reResizeRequest(Sender: TObject; Rect: TRect);
336 procedure reBoilSelectionChange(Sender: TObject);
337 procedure reGroupBPSelectionChange(Sender: TObject);
338 procedure cbxCOMObjChange(Sender: TObject);
339 procedure edtCOMParamChange(Sender: TObject);
340 procedure cbxLinkNeedData(Sender: TObject; const StartFrom: String;
341 Direction, InsertAt: Integer);
342 procedure cbxLinkChange(Sender: TObject);
343 procedure reBoilKeyUp(Sender: TObject; var Key: Word;
344 Shift: TShiftState);
345 procedure reBoilKeyPress(Sender: TObject; var Key: Char);
346 procedure reBoilKeyDown(Sender: TObject; var Key: Word;
347 Shift: TShiftState);
348 procedure FormClose(Sender: TObject; var Action: TCloseAction);
349 private
350 FLastRect: TRect;
351 FForceContainer: boolean;
352 FSavePause: integer;
353 FCopyNode: TTreeNode;
354 FPasteNode: TTreeNode;
355 FCopying: boolean;
356 FDropNode: TTreeNode;
357 FDropInto: boolean;
358 FDragNode: TTreeNode;
359 FPersonalEmptyNodeCount: integer;
360 FSharedEmptyNodeCount: integer;
361// FOldPersonalTemplate: TTemplate;
362 FCurrentPersonalUser: Int64;
363 FCanEditPersonal: boolean;
364 FCanEditShared: boolean;
365 FUpdating: boolean;
366 FCurTree: TTreeView;
367 FTreeControl: array[TTemplateTreeType, TTemplateTreeControl] of TControl;
368 FInternalHiddenExpand :boolean;
369 FFindShOn: boolean;
370 FFindShNext: boolean;
371 FLastFoundShNode: TTreeNode;
372 FFindPerOn: boolean;
373 FFindPerNext: boolean;
374 FLastFoundPerNode: TTreeNode;
375 FFirstShow: boolean;
376 FFocusName: boolean;
377 FOK2Close: boolean;
378 FBtnNewNode: TTreeNode;
379 FLastDropNode: TTreeNode;
380 FFromMainMenu: boolean;
381 FMainMenuTree: TTreeView;
382 FDragOverCount: integer;
383 FBPOK: boolean;
384 FImportingFromXML: boolean;
385 FXMLTemplateElement: IXMLDOMNode;
386 FXMLFieldElement: IXMLDOMNode;
387 FCanDoReminders: boolean;
388 FCanDoCOMObjects: boolean;
389 //FPersonalObjects: TStringList;
390 FShowingTemplate: TTemplate;
391 FConsultServices: TStringList;
392 FNavigatingTab: boolean;
393 protected
394 procedure UpdateXY(re: TRichEdit; lblX, lblY: TLabel);
395 function IsTemplateLocked(Node: TTreeNode): boolean;
396 procedure RefreshData;
397 procedure ShowTemplateType(Template: TTemplate);
398 procedure DisplayBoilerplate(Node: TTreeNode);
399 procedure NewPersonalUser(UsrIEN: Int64);
400 procedure HideControls;
401 procedure EnableControls(ok, Root: boolean);
402 procedure EnableNavControls;
403 procedure MoveCopyButtons;
404 procedure ShowInfo(Node: TTreeNode);
405 function ChangeTree(NewTree: TTreeView): boolean;
406 procedure Resync(const Templates: array of TTemplate);
407 function AllowMove(ADropNode, ADragNode: TTreeNode): boolean;
408 function CanClone(const Node: TTreeNode): boolean;
409 function Clone(Node: TTreeNode): boolean;
410 procedure SharedEditing;
411 function GetTree: TTreeView;
412 procedure SetFindNext(const Tree: TTreeView; const Value: boolean);
413 function ScanNames: boolean;
414 function PasteOK: boolean;
415 function AutoDel(Template: TTemplate): boolean;
416 procedure cbClick(Sender: TCheckBox; Index: integer);
417 procedure UpdateInsertsDialogs;
418 procedure AutoLongLines(Sender: TObject);
419 //procedure UpdatePersonalObjects;
420 procedure UpdateApply(Template: TTemplate);
421 procedure TemplateLocked(Sender: TObject);
422 procedure InitTrees;
423 procedure AdjustControls4FontChange;
424 procedure ShowGroupBoilerplate(Visible: boolean);
425 function GetLinkType(const ANode: TTreeNode): TTemplateLinkType;
426 end;
427
428procedure EditTemplates(Form: TForm; NewTemplate: boolean = FALSE; CopiedText: string = ''; Shared: boolean = FALSE);
429
430const
431 TemplateEditorSplitters = 'frmTempEditSplitters';
432 TemplateEditorSplitters2 = 'frmTempEditSplitters2';
433
434var
435 tmplEditorSplitterMiddle: integer = 0;
436 tmplEditorSplitterProperties: integer = 0;
437 tmplEditorSplitterMain: integer = 0;
438 tmplEditorSplitterBoil: integer = 0;
439 tmplEditorSplitterNotes: integer = 0;
440
441implementation
442
443{$R *.DFM}
444
445uses dShared, uCore, rTemplates, fTemplateObjects, uSpell, fTemplateView,
446 fTemplateAutoGen, fDrawers, fTemplateFieldEditor, fTemplateFields, XMLUtils,
447 fIconLegend, uReminders, uConst, rCore, rEventHooks, rConsults, VAUtils,
448 rMisc, fFindingTemplates;
449
450const
451 PropText = ' Template Properties ';
452// GroupTag = 5;
453 BPDisplayOnlyFld = 0;
454 BPFirstLineFld = 1;
455 BPOneItemOnlyFld = 2;
456 BPHideDlgItemsFld = 3;
457 BPHideItemsFld = 4;
458 BPIndentFld = 5;
459 BPLockFld = 6;
460 NoIE5 = 'You must have Internet Explorer 5 or better installed to %s Templates';
461 NoIE5Header = 'Need Internet Explorer 5';
462 VK_A = Ord('A');
463 VK_C = Ord('C');
464 VK_E = Ord('E');
465 VK_F = Ord('F');
466 VK_G = Ord('G');
467 VK_I = Ord('I');
468 VK_S = Ord('S');
469 VK_T = Ord('T');
470 VK_V = Ord('V');
471 VK_X = Ord('X');
472 VK_Z = Ord('Z');
473
474type
475 TTypeIndex = (tiTemplate, tiFolder, tiGroup, tiDialog, tiRemDlg, tiCOMObj);
476
477const
478 tiNone = TTypeIndex(-1);
479// TypeTag: array[TTypeIndex] of integer = (7, 6, 8, -8, 7, 7);
480 ttDialog = TTemplateType(-ord(ttGroup));
481
482 TypeTag: array[TTypeIndex] of TTemplateType = (ttDoc, ttClass, ttGroup, ttDialog, ttDoc, ttDoc);
483 ForcedIdx: array[boolean, TTypeIndex] of integer = ((0,1,2,3,4,5),(-1,0,1,2,-1,-1));
484 IdxForced: array[boolean, 0..5] of TTypeIndex = ((tiTemplate, tiFolder, tiGroup, tiDialog, tiRemDlg, tiCOMObj),
485 (tiFolder, tiGroup, tiDialog, tiNone, tiNone, tiNone));
486 iMessage = 'This template has one or more new fields, and you are not authorized to create new fields. ' +
487 'If you continue, the program will import the new template without the new fields. Do you wish ' +
488 'to do this?';
489 iMessage2 = 'The imported template fields had XML errors. ';
490 iMessage3 = 'No Fields were imported.';
491
492var
493 frmTemplateObjects: TfrmTemplateObjects = nil;
494 frmTemplateFields: TfrmTemplateFields = nil;
495
496procedure EditTemplates(Form: TForm; NewTemplate: boolean = FALSE;
497 CopiedText: string = ''; Shared: boolean = FALSE);
498var
499 frmTemplateEditor: TfrmTemplateEditor;
500 Drawers: TFrmDrawers;
501 ExpandStr, SelectStr: string;
502 SelNode: TTreeNode;
503 SelShared: boolean;
504
505begin
506 if(UserTemplateAccessLevel in [taReadOnly, taNone]) then exit;
507
508 ExpandStr := '';
509 SelectStr := '';
510 Drawers := nil;
511 if(not NewTemplate) and (CopiedText = '') then
512 begin
513 if Form is TfrmDrawers then
514 Drawers := TFrmDrawers(Form)
515 else
516 if IsPublishedProp(Form, DrawersProperty) then
517 Drawers := TFrmDrawers(GetOrdProp(Form, DrawersProperty));
518 end;
519
520 if assigned(Drawers) then
521 begin
522 ExpandStr := Drawers.tvTemplates.GetExpandedIDStr(1, ';');
523 SelectStr := Drawers.tvTemplates.GetNodeID(TORTreeNode(Drawers.tvTemplates.Selected),1,';');
524 end;
525
526 frmTemplateEditor := TfrmTemplateEditor.Create(Application);
527 try
528 with frmTemplateEditor do
529 begin
530 Font := Form.Font;
531 reBoil.Font.Size := Form.Font.Size;
532 reGroupBP.Font.Size := Form.Font.Size;
533 reNotes.Font.Size := Form.Font.Size;
534 dmodShared.ExpandTree(tvShared, ExpandStr, FSharedEmptyNodeCount);
535 SelNode := tvShared.FindPieceNode(SelectStr,1,';');
536 SelShared := assigned(SelNode);
537 dmodShared.ExpandTree(tvPersonal, ExpandStr, FPersonalEmptyNodeCount);
538 if not SelShared then
539 SelNode := tvPersonal.FindPieceNode(SelectStr,1,';');
540
541 if(SelShared and (not Shared)) then
542 Shared := TRUE;
543
544 if(Shared and (UserTemplateAccessLevel = taEditor)) then
545 begin
546 cbEditShared.Checked := TRUE;
547 ActiveControl := tvShared;
548 if SelShared then
549 tvShared.Selected := SelNode
550 else
551 tvShared.Selected := tvShared.Items.GetFirstNode;
552 end
553 else
554 if(not SelShared) and (assigned(SelNode)) then
555 tvPersonal.Selected := SelNode;
556 if(NewTemplate) then
557 begin
558 btnNewClick(frmTemplateEditor);
559 if(CopiedText <> '') then
560 begin
561 TTemplate(FBtnNewNode.Data).Boilerplate := CopiedText;
562 ShowInfo(FBtnNewNode);
563 end;
564 end;
565 ShowModal;
566 end;
567 finally
568 frmTemplateEditor.Free;
569 end;
570end;
571
572procedure TfrmTemplateEditor.btnNewClick(Sender: TObject);
573var
574 idx: integer;
575 Tmp, Owner: TTemplate;
576 Node, PNode: TTreeNode;
577 ownr: string;
578 ok: boolean;
579 ACheckBox: TCheckBox;
580
581begin
582 if((assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
583 begin
584 if(FCurTree = tvShared) and (FCanEditShared) then
585 ok := TRUE
586 else
587 if(FCurTree = tvPersonal) and (FCanEditPersonal) then
588 ok := TRUE
589 else
590 ok := FALSE;
591 if(ok) then
592 begin
593 Node := FCurTree.Selected;
594 PNode := Node;
595 if(TTemplate(Node.Data).RealType = ttDoc) then
596 PNode := Node.Parent;
597 if CanClone(PNode) then
598 begin
599 Clone(PNode);
600 Owner := TTemplate(PNode.Data);
601 if assigned(Owner) and Owner.CanModify then
602 begin
603 if Node = PNode then
604 idx := 0
605 else
606 idx := Owner.Items.IndexOf(Node.Data) + 1;
607 if(FCurTree = tvShared) then
608 begin
609 ownr := '';
610 ACheckBox := cbShHide;
611 end
612 else
613 begin
614 ownr := IntToStr(User.DUZ);
615 ACheckBox := cbPerHide;
616 end;
617 if FImportingFromXML then
618 begin
619 Tmp := TTemplate.CreateFromXML(FXMLTemplateElement, ownr);
620 ACheckBox.Checked := ACheckBox.Checked and Tmp.Active;
621 end
622 else
623 begin
624 Tmp := TTemplate.Create('0^T^A^'+NewTemplateName+'^^^'+ownr);
625 Tmp.BackupItems;
626 Templates.AddObject(Tmp.ID, Tmp);
627 end;
628 btnApply.Enabled := TRUE;
629 if(idx >= Owner.Items.Count) then
630 Owner.Items.Add(Tmp)
631 else
632 Owner.Items.Insert(idx, Tmp);
633 Resync([Owner]);
634 Node := FCurTree.Selected;
635 if(Node.Data <> Tmp) then
636 begin
637 if(TTemplate(Node.Data).RealType = ttDoc) then
638 Node := Node.GetNextSibling
639 else
640 begin
641 Node.Expand(FALSE);
642 Node := Node.GetFirstChild;
643 end;
644 FCurTree.Selected := Node;
645 end;
646 FBtnNewNode := Node;
647 if(FFirstShow) then
648 FFocusName := TRUE
649 else
650 begin
651 edtName.SetFocus;
652 edtName.SelectAll;
653 end;
654 end;
655 end;
656 end;
657 end;
658end;
659
660procedure TfrmTemplateEditor.btnApplyClick(Sender: TObject);
661begin
662 if(ScanNames) then
663 begin
664 SaveAllTemplates;
665 BtnApply.Enabled := BackupDiffers;
666 if not BtnApply.Enabled then
667 UnlockAllTemplates;
668 end;
669end;
670
671procedure TfrmTemplateEditor.FormCreate(Sender: TObject);
672begin
673 ResizeAnchoredFormToFont(self);
674 //Now fix everything the resize messed up
675 lblLines.Width := cbLock.Left - lblLines.Left - 15;
676 sbPerDelete.Left := pnlPersonalBottom.ClientWidth - sbPerDelete.Width - 1;
677 sbPerDown.Left := sbPerDelete.Left - sbPerDown.Width - 2;
678 sbPerUp.Left := sbPerDown.Left - sbPerUp.Width - 2;
679 cbPerHide.Width := sbPerUp.Left - 3;
680 btnPerFind.Left := pnlPerSearch.ClientWidth - btnPerFind.Width;
681
682 FSavePause := Application.HintHidePause;
683 Application.HintHidePause := FSavePause*2;
684 if InteractiveRemindersActive then
685 begin
686 QuickCopy(GetTemplateAllowedReminderDialogs, cbxRemDlgs.Items);
687 FCanDoReminders := (cbxRemDlgs.Items.Count > 0);
688 end
689 else
690 FCanDoReminders := FALSE;
691
692 QuickCopy(GetAllActiveCOMObjects, cbxCOMObj.Items);
693 FCanDoCOMObjects := (cbxCOMObj.Items.Count > 0);
694
695 FUpdating := TRUE;
696 FFirstShow := TRUE;
697
698 FTreeControl[ttShared, tcDel] := sbShDelete;
699 FTreeControl[ttShared, tcUp] := sbShUp;
700 FTreeControl[ttShared, tcDown] := sbShDown;
701 FTreeControl[ttShared, tcLbl] := lblCopy;
702 FTreeControl[ttShared, tcCopy] := sbCopyRight;
703 FTreeControl[ttPersonal, tcDel] := sbPerDelete;
704 FTreeControl[ttPersonal, tcUp] := sbPerUp;
705 FTreeControl[ttPersonal, tcDown] := sbPerDown;
706 FTreeControl[ttPersonal, tcLbl] := lblCopy;
707 FTreeControl[ttPersonal, tcCopy] := sbCopyLeft;
708 dmodShared.InEditor := TRUE;
709 dmodShared.OnTemplateLock := TemplateLocked;
710
711 gbProperties.Caption := PropText;
712 pnlShSearch.Visible := FALSE;
713 pnlPerSearch.Visible := FALSE;
714 FCanEditPersonal := TRUE;
715
716{ Don't mess with the order of the following commands! }
717 InitTrees;
718
719 tvPersonal.Selected := tvPersonal.Items.GetFirstNode;
720
721 ClearBackup;
722
723 cboOwner.SelText := MixedCase(User.Name);
724 NewPersonalUser(User.DUZ);
725
726 cbEditShared.Visible := (UserTemplateAccessLevel = taEditor);
727 FCanEditShared := FALSE;
728 SharedEditing;
729
730 HideControls;
731
732 lblCopy.AutoSize := TRUE;
733 lblCopy.AutoSize := FALSE; // resets height based on font
734 lblCopy.Width := pnlCopyBtns.Width + splMiddle.Width;
735 MoveCopyButtons;
736
737 cbShHide.Checked := TRUE;
738 cbPerHide.Checked := TRUE;
739
740 BtnApply.Enabled := BackupDiffers;
741 SetFormPosition(Self);
742end;
743
744procedure TfrmTemplateEditor.HideControls;
745begin
746 sbCopyRight.Visible := FCanEditPersonal;
747 if(not FCanEditPersonal) then
748 cbPerHide.Checked := TRUE;
749 cbPerHide.Visible := FCanEditPersonal;
750 sbPerDelete.Visible := FCanEditPersonal;
751 sbPerUp.Visible := FCanEditPersonal;
752 sbPerDown.Visible := FCanEditPersonal;
753 tvPersonal.ReadOnly := not FCanEditPersonal;
754 MoveCopyButtons;
755end;
756
757procedure TfrmTemplateEditor.cboOwnerNeedData(Sender: TObject;
758 const StartFrom: String; Direction, InsertAt: Integer);
759begin
760// cboOwner.ForDataUse(SubSetOfTemplateOwners(StartFrom, Direction));
761end;
762
763procedure TfrmTemplateEditor.cboOwnerChange(Sender: TObject);
764begin
765 NewPersonalUser(cboOwner.ItemIEN);
766end;
767
768procedure TfrmTemplateEditor.NewPersonalUser(UsrIEN: Int64);
769var
770 NewEdit: boolean;
771
772begin
773 FCurrentPersonalUser := UsrIEN;
774 NewEdit := (FCurrentPersonalUser = User.DUZ);
775 if(FCanEditPersonal <> NewEdit) then
776 begin
777 FCanEditPersonal := NewEdit;
778 HideControls;
779 end;
780end;
781
782procedure TfrmTemplateEditor.tvPersonalExpanding(Sender: TObject;
783 Node: TTreeNode; var AllowExpansion: Boolean);
784begin
785 AllowExpansion := dmodShared.ExpandNode(tvPersonal, Node,
786 FPersonalEmptyNodeCount, not cbPerHide.Checked);
787 if(AllowExpansion and FInternalHiddenExpand) then
788 AllowExpansion := FALSE;
789end;
790
791procedure TfrmTemplateEditor.tvSharedExpanding(Sender: TObject;
792 Node: TTreeNode; var AllowExpansion: Boolean);
793begin
794 AllowExpansion := dmodShared.ExpandNode(tvShared, Node,
795 FSharedEmptyNodeCount, not cbShHide.Checked);
796 if(AllowExpansion and FInternalHiddenExpand) then
797 AllowExpansion := FALSE;
798end;
799
800procedure TfrmTemplateEditor.tvTreeGetImageIndex(Sender: TObject;
801 Node: TTreeNode);
802begin
803 Node.ImageIndex := dmodShared.ImgIdx(Node);
804end;
805
806procedure TfrmTemplateEditor.tvTreeGetSelectedIndex(Sender: TObject;
807 Node: TTreeNode);
808begin
809 Node.SelectedIndex := dmodShared.ImgIdx(Node);
810end;
811
812function TfrmTemplateEditor.IsTemplateLocked(Node: TTreeNode): boolean;
813var
814 Template: TTemplate;
815
816begin
817 Result := FALSE;
818 if assigned(Node) then
819 begin
820 Template := TTemplate(Node.Data);
821 if Template.AutoLock then
822 Result := TRUE
823 else
824 if (Template.PersonalOwner = 0) then
825 begin
826 if RootTemplate.IsLocked then
827 Result := TRUE
828 else
829 begin
830 Result := TTemplate(Node.Data).IsLocked;
831 if (not Result) and assigned(Node.Parent) and
832 (TTemplate(Node.Parent).PersonalOwner = 0) then
833 Result := IsTemplateLocked(Node.Parent);
834 end;
835 end;
836 end;
837end;
838
839procedure TfrmTemplateEditor.tvTreeChange(Sender: TObject;
840 Node: TTreeNode);
841var
842 ok, Something: boolean;
843 Template: TTemplate;
844
845begin
846 ChangeTree(TTreeView(Sender));
847 Something := assigned(Node);
848 if Something then
849 begin
850 Template := TTemplate(Node.Data);
851 Something := assigned(Template);
852 if Something then
853 begin
854 if(Sender = tvPersonal) then
855 begin
856 ok := FCanEditPersonal;
857 if ok and (Template.PersonalOwner = 0) and IsTemplateLocked(Node) then
858 ok := FALSE;
859 end
860 else
861 ok := FCanEditShared;
862 EnableControls(ok, (Template.RealType in AllTemplateRootTypes));
863 ShowInfo(Node);
864 end;
865 end;
866 if not Something then
867 begin
868 gbProperties.Caption := PropText;
869 EnableControls(FALSE, FALSE);
870 ShowInfo(nil);
871 end;
872end;
873
874procedure TfrmTemplateEditor.EnableControls(ok, Root: boolean);
875begin
876 cbLock.Enabled := ok and (FCurTree = tvShared);
877 if(ok and Root) then
878 begin
879 ok := FALSE;
880 lblName.Enabled := TRUE;
881 edtName.Enabled := TRUE;
882 reNotes.ReadOnly := FALSE;
883 end
884 else
885 begin
886 lblName.Enabled := ok;
887 edtName.Enabled := ok;
888 reNotes.ReadOnly := not ok;
889 end;
890 lblNotes.Enabled := (not reNotes.ReadOnly);
891 UpdateReadOnlyColorScheme(reNotes, reNotes.ReadOnly);
892 cbxType.Enabled := ok;
893 lblType.Enabled := ok;
894 lblRemDlg.Enabled := ok;
895 cbxRemDlgs.Enabled := ok and FCanDoReminders;
896 cbActive.Enabled := ok;
897 cbExclude.Enabled := ok;
898 cbDisplayOnly.Enabled := ok;
899 cbFirstLine.Enabled := ok;
900 cbOneItemOnly.Enabled := ok;
901 cbHideDlgItems.Enabled := ok;
902 cbHideItems.Enabled := ok;
903 cbIndent.Enabled := ok;
904 edtGap.Enabled := ok;
905 udGap.Enabled := ok;
906 udGap.Invalidate;
907 lblLines.Enabled := ok;
908 reBoil.ReadOnly := not ok;
909 UpdateReadOnlyColorScheme(reBoil, not ok);
910 lblLink.Enabled := ok;
911 cbxLink.Enabled := ok;
912 ok := ok and FCanDoCOMObjects;
913 cbxCOMObj.Enabled := ok;
914 lblCOMObj.Enabled := ok;
915 edtCOMParam.Enabled := ok;
916 lblCOMParam.Enabled := ok;
917 UpdateInsertsDialogs;
918 EnableNavControls;
919end;
920
921procedure TfrmTemplateEditor.MoveCopyButtons;
922var
923 tmpHeight: integer;
924
925begin
926 tmpHeight := tvShared.Height;
927 dec(tmpHeight,lblCopy.Height);
928 if(sbCopyLeft.Visible) then
929 dec(tmpHeight, sbCopyLeft.Height+5);
930 if(sbCopyRight.Visible) then
931 dec(tmpHeight, sbCopyRight.Height+5);
932 tmpHeight := (tmpHeight div 2) + tvShared.Top;
933 lblCopy.Top := tmpHeight;
934 inc(tmpHeight,lblCopy.height+5);
935 if(sbCopyLeft.Visible) then
936 begin
937 sbCopyLeft.Top := tmpHeight;
938 inc(tmpHeight, sbCopyLeft.Height+5);
939 end;
940 if(sbCopyRight.Visible) then
941 sbCopyRight.Top := tmpHeight;
942end;
943
944procedure TfrmTemplateEditor.splMainMoved(Sender: TObject);
945begin
946 MoveCopyButtons;
947end;
948
949procedure TfrmTemplateEditor.ShowGroupBoilerplate(Visible: boolean);
950begin
951 pnlGroupBP.Visible := Visible;
952 splBoil.Visible := Visible;
953 if Visible then
954 begin
955 reBoil.Align := alTop;
956 pnlGroupBP.Align := alClient;
957 reBoil.Height := tmplEditorSplitterBoil;
958 splBoil.Top := pnlGroupBP.Top - splBoil.Height;
959 end
960 else
961 begin
962 pnlGroupBP.Align := alBottom;
963 reBoil.Align := alClient;
964 end;
965end;
966
967procedure TfrmTemplateEditor.ShowInfo(Node: TTreeNode);
968var
969 OldUpdating, ClearName, ClearRB, ClearAll: boolean;
970 Idx: TTypeIndex;
971 CanDoCOM: boolean;
972 lt: TTemplateLinkType;
973 lts: string;
974
975begin
976 OldUpdating := FUpdating;
977 FUpdating := TRUE;
978 try
979 if(assigned(Node)) then
980 begin
981 FShowingTemplate := TTemplate(Node.Data);
982 with FShowingTemplate do
983 begin
984 ClearName := FALSE;
985 ClearRB := FALSE;
986 ClearAll := FALSE;
987 ShowTemplateType(TTemplate(Node.Data));
988 lt := GetLinkType(Node);
989 if(lt = ltNone) or (IsReminderDialog and (not (lt in [ltNone, ltTitle]))) then
990 pnlLink.Visible := FALSE
991 else
992 begin
993 pnlLink.Visible := TRUE;
994 pnlLink.Tag := ord(lt);
995 case lt of
996 ltTitle: lts := 'Title';
997 ltConsult: lts := 'Consult Service';
998 ltProcedure: lts := 'Procedure';
999 else lts := '';
1000 end;
1001 cbxLink.Clear;
1002 if lt = ltConsult then
1003 begin
1004 cbxLink.LongList := FALSE;
1005 if not assigned(FConsultServices) then
1006 begin
1007 FConsultServices := TStringList.Create;
1008 FastAssign(LoadServiceListWithSynonyms(1), FConsultServices);
1009 SortByPiece(FConsultServices, U, 2);
1010 end;
1011 FastAssign(FConsultServices, cbxLink.Items);
1012 end
1013 else
1014 begin
1015 cbxLink.LongList := TRUE;
1016 cbxLink.HideSynonyms := TRUE;
1017 cbxLink.InitLongList(LinkName);
1018 end;
1019 cbxLink.SelectByID(LinkIEN);
1020 lblLink.Caption := ' Associated ' + lts + ': ';
1021 cbxLink.Caption := lblLink.Caption;
1022 end;
1023
1024 edtName.Text := PrintName;
1025 reNotes.Lines.Text := Description;
1026 if(PersonalOwner = 0) and (FCurTree = tvShared) and (cbEditShared.Checked) then
1027 begin
1028 cbLock.Checked := IsLocked;
1029 if AutoLock then
1030 cbLock.Enabled := FALSE;
1031 end
1032 else
1033 begin
1034 cbLock.Checked := IsTemplateLocked(Node);
1035 cbLock.Enabled := FALSE;
1036 end;
1037 CanDoCom := FCanDoCOMObjects and (PersonalOwner = 0);
1038 if(RealType in AllTemplateRootTypes) then
1039 begin
1040 ClearRB := TRUE;
1041 ClearAll := TRUE;
1042 end
1043 else
1044 begin
1045 case RealType of
1046 ttDoc: begin
1047 if IsReminderDialog then
1048 Idx := tiRemDlg
1049 else
1050 if IsCOMObject then
1051 Idx := tiCOMObj
1052 else
1053 Idx := tiTemplate;
1054 end;
1055 ttGroup: begin
1056 if(Dialog) then
1057 Idx := tiDialog
1058 else
1059 Idx := tiGroup;
1060 end;
1061 ttClass: Idx := tiFolder;
1062 else Idx := tiNone;
1063 end;
1064 FForceContainer := ((RealType in [ttGroup, ttClass]) and (Children <> tcNone));
1065 cbxType.Items.Clear;
1066 if not FForceContainer then
1067 cbxType.Items.Add('Template');
1068 cbxType.Items.Add('Folder');
1069 cbxType.Items.Add('Group Template');
1070 cbxType.Items.Add('Dialog');
1071 if (not FForceContainer) then
1072 begin
1073 if(FCanDoReminders or CanDoCOM) then
1074 cbxType.Items.Add('Reminder Dialog');
1075 if(CanDoCOM) then
1076 cbxType.Items.Add('COM Object');
1077 end;
1078 cbxType.ItemIndex := ForcedIdx[FForceContainer, Idx];
1079 if(Idx = tiRemDlg) and FCanDoReminders then
1080 cbxRemDlgs.SelectByID(ReminderDialogIEN)
1081 else
1082 begin
1083 lblRemDlg.Enabled := FALSE;
1084 cbxRemDlgs.Enabled := FALSE;
1085 cbxRemDlgs.ItemIndex := -1;
1086 end;
1087 if (Idx = tiCOMObj) and CanDoCOM then
1088 begin
1089 pnlCOM.Visible := TRUE;
1090 cbxCOMObj.SelectByIEN(COMObject);
1091 edtCOMParam.Text := COMParam;
1092 end
1093 else
1094 begin
1095 pnlCOM.Visible := FALSE;
1096 cbxCOMObj.ItemIndex := -1;
1097 edtCOMParam.Text := '';
1098 end;
1099 cbActive.Checked := Active;
1100 if(RealType in [ttClass, ttGroup]) then
1101 cbHideItems.Checked := HideItems
1102 else
1103 begin
1104 cbHideItems.Checked := FALSE;
1105 cbHideItems.Enabled := FALSE;
1106 end;
1107 if((RealType in [ttDoc, ttGroup]) and (assigned(Node.Parent)) and
1108 (TTemplate(Node.Parent.Data).RealType = ttGroup) and
1109 (not IsReminderDialog) and (not IsCOMObject)) then
1110 cbExclude.Checked := Exclude
1111 else
1112 begin
1113 cbExclude.Checked := FALSE;
1114 cbExclude.Enabled := FALSE;
1115 end;
1116 if dmodShared.InDialog(Node) and (not IsReminderDialog) and (not IsCOMObject) then
1117 begin
1118 cbDisplayOnly.Checked := DisplayOnly;
1119 cbFirstLine.Checked := FirstLine;
1120 end
1121 else
1122 begin
1123 cbDisplayOnly.Checked := FALSE;
1124 cbDisplayOnly.Enabled := FALSE;
1125 cbFirstLine.Checked := FALSE;
1126 cbFirstLine.Enabled := FALSE;
1127 end;
1128 if(RealType in [ttGroup, ttClass]) and (Children <> tcNone) and
1129 (dmodShared.InDialog(Node)) then
1130 begin
1131 cbOneItemOnly.Checked := OneItemOnly;
1132 cbIndent.Checked := IndentItems;
1133 if(RealType = ttGroup) and (Boilerplate <> '') then
1134 begin
1135 cbHideDlgItems.Checked := HideDlgItems;
1136 end
1137 else
1138 begin
1139 cbHideDlgItems.Checked := FALSE;
1140 cbHideDlgItems.Enabled := FALSE;
1141 end;
1142 end
1143 else
1144 begin
1145 cbOneItemOnly.Checked := FALSE;
1146 cbOneItemOnly.Enabled := FALSE;
1147 cbHideDlgItems.Checked := FALSE;
1148 cbHideDlgItems.Enabled := FALSE;
1149 cbIndent.Checked := FALSE;
1150 cbIndent.Enabled := FALSE;
1151 end;
1152 if(RealType = ttGroup) then
1153 edtGap.Text := IntToStr(Gap)
1154 else
1155 begin
1156 edtGap.Text := '0';
1157 edtGap.Enabled := FALSE;
1158 udGap.Enabled := FALSE;
1159 udGap.Invalidate;
1160 lblLines.Enabled := FALSE;
1161 end;
1162 DisplayBoilerPlate(Node);
1163 end;
1164 end;
1165 end
1166 else
1167 begin
1168 ClearAll := TRUE;
1169 ClearRB := TRUE;
1170 ClearName := TRUE;
1171 gbProperties.Caption := PropText;
1172 end;
1173 if(ClearName) then
1174 begin
1175 edtName.Text := '';
1176 reNotes.Clear;
1177 end;
1178 if(ClearRB) then
1179 begin
1180 cbxType.ItemIndex := Ord(tiNone);
1181 end;
1182 if(ClearAll) then
1183 begin
1184 cbActive.Checked := FALSE;
1185 cbExclude.Checked := FALSE;
1186 cbDisplayOnly.Checked := FALSE;
1187 cbFirstLine.Checked := FALSE;
1188 cbOneItemOnly.Checked := FALSE;
1189 cbHideDlgItems.Checked := FALSE;
1190 cbHideItems.Checked := FALSE;
1191 cbIndent.Checked := FALSE;
1192 edtGap.Text := '0';
1193 reBoil.Clear;
1194 ShowGroupBoilerplate(False);
1195 pnlBoilerplateResize(Self);
1196 pnlCOM.Visible := FALSE;
1197 pnlLink.Visible := FALSE;
1198 end;
1199 if cbDisplayOnly.Enabled or
1200 cbFirstLine.Enabled or
1201 cbIndent.Enabled or
1202 cbOneItemOnly.Enabled or
1203 cbHideDlgItems.Enabled then
1204 gbDialogProps.Font.Color := clWindowText
1205 else
1206 gbDialogProps.Font.Color := clInactiveCaption;
1207 finally
1208 FUpdating := OldUpdating;
1209 end;
1210end;
1211
1212procedure TfrmTemplateEditor.pnlBoilerplateResize(Sender: TObject);
1213var
1214 Max: integer;
1215
1216begin
1217 if(pnlGroupBP.Visible) and (pnlGroupBP.Height > (pnlBoilerplate.Height-29)) then
1218 begin
1219 pnlGroupBP.Height := pnlBoilerplate.Height-29;
1220 end;
1221 if cbLongLines.checked then
1222 Max := 240
1223 else
1224 Max := MAX_ENTRY_WIDTH;
1225 LimitEditWidth(reBoil, Max);
1226 LimitEditWidth(reNotes, MAX_ENTRY_WIDTH);
1227end;
1228
1229procedure TfrmTemplateEditor.edtNameOldChange(Sender: TObject);
1230var
1231 i: integer;
1232 Template: TTemplate;
1233 DoRefresh: boolean;
1234
1235begin
1236 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
1237 begin
1238 if CanClone(FCurTree.Selected) then
1239 begin
1240 DoRefresh := Clone(FCurTree.Selected);
1241 Template := TTemplate(FCurTree.Selected.Data);
1242 if assigned(Template) and Template.CanModify then
1243 begin
1244 Template.PrintName := edtName.Text;
1245 UpdateApply(Template);
1246 for i := 0 to Template.Nodes.Count-1 do
1247 TTreeNode(Template.Nodes.Objects[i]).Text := Template.PrintName;
1248 if(DoRefresh) then
1249 begin
1250 tvShared.Invalidate;
1251 tvPersonal.Invalidate;
1252 end;
1253 end;
1254 end;
1255 end;
1256end;
1257
1258procedure TfrmTemplateEditor.cbActiveClick(Sender: TObject);
1259var
1260 i: integer;
1261 Template: TTemplate;
1262 Node: TTreeNode;
1263
1264begin
1265 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
1266 begin
1267 if CanClone(FCurTree.Selected) then
1268 begin
1269 Clone(FCurTree.Selected);
1270 Template := TTemplate(FCurTree.Selected.Data);
1271 if assigned(Template) and Template.CanModify then
1272 begin
1273 Template.Active := cbActive.Checked;
1274 UpdateApply(Template);
1275 for i := 0 to Template.Nodes.Count-1 do
1276 begin
1277 Node := TTreeNode(Template.Nodes.Objects[i]);
1278 Node.Cut := not Template.Active;
1279 end;
1280 if(FCurTree = tvShared) then
1281 begin
1282 cbPerHideClick(Sender);
1283 cbShHideClick(Sender);
1284 end
1285 else
1286 begin
1287 cbShHideClick(Sender);
1288 cbPerHideClick(Sender);
1289 end;
1290 tvTreeChange(FCurTree, FCurTree.Selected);
1291 EnableNavControls;
1292 if cbActive.CanFocus then
1293 cbActive.SetFocus;
1294 end;
1295 end;
1296 end;
1297end;
1298
1299procedure TfrmTemplateEditor.cbExcludeClick(Sender: TObject);
1300var
1301 i: integer;
1302 Template: TTemplate;
1303 Node: TTreeNode;
1304
1305begin
1306 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
1307 begin
1308 if CanClone(FCurTree.Selected) then
1309 begin
1310 Clone(FCurTree.Selected);
1311 Template := TTemplate(FCurTree.Selected.Data);
1312 if assigned(Template) and Template.CanModify then
1313 begin
1314 Template.Exclude := cbExclude.Checked;
1315 UpdateApply(Template);
1316 for i := 0 to Template.Nodes.Count-1 do
1317 begin
1318 Node := TTreeNode(Template.Nodes.Objects[i]);
1319 Node.ImageIndex := dmodShared.ImgIdx(Node);
1320 Node.SelectedIndex := dmodShared.ImgIdx(Node);
1321 end;
1322 tvShared.Invalidate;
1323 tvPersonal.Invalidate;
1324 end;
1325 end;
1326 end;
1327end;
1328
1329procedure TfrmTemplateEditor.edtGapChange(Sender: TObject);
1330var
1331 DoRefresh: boolean;
1332 Template: TTemplate;
1333
1334begin
1335 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
1336 begin
1337 if CanClone(FCurTree.Selected) then
1338 begin
1339 DoRefresh := Clone(FCurTree.Selected);
1340 Template := TTemplate(FCurTree.Selected.Data);
1341 if assigned(Template) and Template.CanModify then
1342 begin
1343 Template.Gap := StrToIntDef(edtGap.Text, 0);
1344 UpdateApply(Template);
1345 DisplayBoilerPlate(FCurTree.Selected);
1346 if(DoRefresh) then
1347 begin
1348 tvShared.Invalidate;
1349 tvPersonal.Invalidate;
1350 end;
1351 end;
1352 end;
1353 end;
1354end;
1355
1356function TfrmTemplateEditor.ChangeTree(NewTree: TTreeView): boolean;
1357var
1358 i: TTemplateTreeControl;
1359
1360begin
1361 Result := FALSE;
1362 tvShared.HideSelection := TRUE;
1363 tvPersonal.HideSelection := TRUE;
1364 if(NewTree <> FCurTree) then
1365 begin
1366 Result := TRUE;
1367 if(assigned(FCurTree)) then
1368 begin
1369 for i := low(TTemplateTreeControl) to high(TTemplateTreeControl) do
1370 FTreeControl[TTemplateTreeType(FCurTree.Tag), i].Enabled := FALSE;
1371 end;
1372 FCurTree := NewTree;
1373 end;
1374 if(assigned(FCurTree)) then
1375 begin
1376 FCurTree.HideSelection := FALSE;
1377 if(FCurTree = tvPersonal) and (Screen.ActiveControl = tvShared) then
1378 tvPersonal.SetFocus
1379 else
1380 if(FCurTree = tvShared) and (Screen.ActiveControl = tvPersonal) then
1381 tvShared.SetFocus;
1382 end;
1383end;
1384
1385procedure TfrmTemplateEditor.tvTreeEnter(Sender: TObject);
1386begin
1387 if((Sender is TTreeView) and (ChangeTree(TTreeView(Sender)))) then
1388 tvTreeChange(Sender, TTreeView(Sender).Selected);
1389end;
1390
1391procedure TfrmTemplateEditor.tvTreeNodeEdited(Sender: TObject;
1392 Node: TTreeNode; var S: String);
1393begin
1394 FUpdating := TRUE;
1395 try
1396 edtName.Text := S;
1397 finally
1398 FUpdating := FALSE;
1399 end;
1400 edtNameOldChange(edtName);
1401end;
1402
1403procedure TfrmTemplateEditor.cbShHideClick(Sender: TObject);
1404var
1405 Node: TTreeNode;
1406
1407begin
1408 Node := tvShared.Items.GetFirstNode;
1409 while assigned(Node) do
1410 begin
1411 dmodShared.Resync(Node, not cbShHide.Checked, FSharedEmptyNodeCount);
1412 Node := Node.getNextSibling;
1413 end;
1414 tvTreeChange(tvShared, tvShared.Selected);
1415 EnableNavControls;
1416end;
1417
1418procedure TfrmTemplateEditor.cbPerHideClick(Sender: TObject);
1419begin
1420 dmodShared.Resync(tvPersonal.Items.GetFirstNode, not cbPerHide.Checked,
1421 FPersonalEmptyNodeCount);
1422 tvTreeChange(tvPersonal, tvPersonal.Selected);
1423 EnableNavControls;
1424end;
1425
1426procedure TfrmTemplateEditor.DisplayBoilerplate(Node: TTreeNode);
1427var
1428 OldUpdating, ItemOK, BPOK, LongLines: boolean;
1429 i: integer;
1430 TmpSL: TStringList;
1431
1432begin
1433 OldUpdating := FUpdating;
1434 FUpdating := TRUE;
1435 try
1436 pnlBoilerplateResize(pnlBoilerplate);
1437 reBoil.Clear;
1438 ItemOK := FALSE;
1439 BPOK := TRUE;
1440 with Node, TTemplate(Node.Data) do
1441 begin
1442 if(RealType in [ttDoc, ttGroup]) then
1443 begin
1444 TmpSL := TStringList.Create;
1445 try
1446 if(RealType = ttGroup) and (not reBoil.ReadOnly) then
1447 begin
1448 ItemOK := TRUE;
1449 TmpSL.Text := Boilerplate;
1450 reGroupBP.Clear;
1451 reGroupBP.SelText := FullBoilerplate;
1452 end
1453 else
1454 TmpSL.Text := FullBoilerplate;
1455 LongLines := FALSE;
1456 for i := 0 to TmpSL.Count-1 do
1457 begin
1458 if length(TmpSL[i]) > MAX_ENTRY_WIDTH then
1459 begin
1460 LongLines := TRUE;
1461 break;
1462 end;
1463 end;
1464 cbLongLines.Checked := LongLines;
1465 reBoil.SelText := TmpSL.Text;
1466 finally
1467 TmpSL.Free;
1468 end;
1469 end
1470 else
1471 begin
1472 reBoil.ReadOnly := TRUE;
1473 UpdateReadOnlyColorScheme(reBoil, TRUE);
1474 UpdateInsertsDialogs;
1475 end;
1476 ShowGroupBoilerplate(ItemOK);
1477 if(not ItemOK) and (IsReminderDialog or IsCOMObject) then
1478 BPOK := FALSE;
1479 pnlBoilerplateResize(Self);
1480 pnlBoilerplate.Visible := BPOK;
1481 lblBoilerplate.Visible := BPOK;
1482 pnlCOM.Visible := (not BPOK) and IsCOMObject;
1483 end;
1484 finally
1485 FUpdating := OldUpdating;
1486 end;
1487end;
1488
1489procedure TfrmTemplateEditor.FormDestroy(Sender: TObject);
1490begin
1491 KillObj(@FConsultServices);
1492 Application.HintHidePause := FSavePause;
1493 if(assigned(frmTemplateObjects)) then
1494 begin
1495 frmTemplateObjects.Free;
1496 frmTemplateObjects := nil;
1497 end;
1498 if(assigned(frmTemplateFields)) then
1499 begin
1500 frmTemplateFields.Free;
1501 frmTemplateFields := nil;
1502 end;
1503 //---------- CQ #8665 - RV --------
1504 //KillObj(@FPersonalObjects);
1505 if (assigned(uPersonalObjects)) then
1506 begin
1507 KillObj(@uPersonalObjects);
1508 uPersonalObjects.Free;
1509 uPersonalObjects := nil;
1510 end;
1511 // ---- end CQ #8665 -------------
1512 dmodShared.OnTemplateLock := nil;
1513 dmodShared.InEditor := FALSE;
1514 RemoveAllNodes;
1515 ClearBackup;
1516 UnlockAllTemplates;
1517 dmodShared.Reload;
1518end;
1519
1520procedure TfrmTemplateEditor.sbMoveUpClick(Sender: TObject);
1521var
1522 idx: integer;
1523 ChangeLevel: boolean;
1524 ParentsParent, ParentNode, Node: TTreeNode;
1525 NodeTemplate, ParentTemplate, Template: TTemplate;
1526 Hide, First, ok: boolean;
1527
1528begin
1529 if((assigned(FCurTree)) and (assigned(FCurTree.Selected)) and
1530 (assigned(FCurTree.Selected.Parent))) then
1531 begin
1532 Node := FCurTree.Selected;
1533 NodeTemplate := TTemplate(Node.Data);
1534 ParentNode := Node.Parent;
1535 Template := TTemplate(ParentNode.Data);
1536 idx := Template.Items.IndexOf(NodeTemplate);
1537 ChangeLevel := (idx < 1);
1538 if(not ChangeLevel) then
1539 begin
1540 if(TTemplateTreeType(TBitBtn(Sender).Tag) = ttShared) then
1541 Hide := cbShHide.Checked
1542 else
1543 Hide := cbPerHide.Checked;
1544 First := TRUE;
1545 while(idx > 0) do
1546 begin
1547 if First then
1548 begin
1549 ok := FALSE;
1550 First := FALSE;
1551 if CanClone(ParentNode) then
1552 begin
1553 if(Clone(ParentNode)) then
1554 Template := TTemplate(ParentNode.Data);
1555 if Template.CanModify then
1556 ok := TRUE;
1557 end;
1558 end
1559 else
1560 ok := TRUE;
1561 if ok then
1562 begin
1563 Template.Items.Exchange(idx-1, idx);
1564 if(Hide and (not TTemplate(Template.Items[idx]).Active)) then
1565 begin
1566 dec(idx);
1567 ChangeLevel := (idx < 1);
1568 end
1569 else
1570 idx := 0;
1571 end
1572 else
1573 idx := 0;
1574 end;
1575 end;
1576 if(ChangeLevel) then
1577 begin
1578 ParentsParent := ParentNode.Parent;
1579 if(assigned(ParentsParent)) then
1580 begin
1581 ParentTemplate := TTemplate(ParentsParent.Data);
1582 if(ParentTemplate.Items.IndexOf(NodeTemplate) >= 0) then
1583 InfoBox(ParentsParent.Text + ' already contains the ' +
1584 NodeTemplate.PrintName + ' template.',
1585 'Error', MB_OK or MB_ICONERROR)
1586 else
1587 begin
1588 if CanClone(ParentNode) then
1589 begin
1590 if(Clone(ParentNode)) then
1591 Template := TTemplate(ParentNode.Data);
1592 if Template.CanModify and CanClone(ParentsParent) then
1593 begin
1594 if(Clone(ParentsParent)) then
1595 ParentTemplate := TTemplate(ParentsParent.Data);
1596 if ParentTemplate.CanModify then
1597 begin
1598 Template.Items.Delete(idx);
1599 idx := ParentTemplate.Items.IndexOf(Template);
1600 if(idx >= 0) then
1601 begin
1602 ParentTemplate.Items.Insert(idx, NodeTemplate);
1603 Resync([ParentTemplate, Template]);
1604 btnApply.Enabled := TRUE;
1605 end;
1606 end;
1607 end;
1608 end;
1609 end;
1610 end;
1611 end
1612 else
1613 begin
1614 Resync([Template]);
1615 btnApply.Enabled := TRUE;
1616 end;
1617 end;
1618end;
1619
1620procedure TfrmTemplateEditor.sbMoveDownClick(Sender: TObject);
1621var
1622 max, idx: integer;
1623 ChangeLevel: boolean;
1624 ParentsParent, ParentNode, Node: TTreeNode;
1625 NodeTemplate, ParentTemplate, Template: TTemplate;
1626 Hide, First, ok: boolean;
1627
1628begin
1629 if((assigned(FCurTree)) and (assigned(FCurTree.Selected)) and
1630 (assigned(FCurTree.Selected.Parent))) then
1631 begin
1632 Node := FCurTree.Selected;
1633 NodeTemplate := TTemplate(Node.Data);
1634 ParentNode := Node.Parent;
1635 Template := TTemplate(ParentNode.Data);
1636 idx := Template.Items.IndexOf(NodeTemplate);
1637 max := Template.Items.Count-1;
1638 ChangeLevel := (idx >= max);
1639 if(not ChangeLevel) then
1640 begin
1641 if(TTemplateTreeType(TBitBtn(Sender).Tag) = ttShared) then
1642 Hide := cbShHide.Checked
1643 else
1644 Hide := cbPerHide.Checked;
1645 First := TRUE;
1646 while(idx < max) do
1647 begin
1648 if First then
1649 begin
1650 ok := FALSE;
1651 First := FALSE;
1652 if CanClone(ParentNode) then
1653 begin
1654 if(Clone(ParentNode)) then
1655 Template := TTemplate(ParentNode.Data);
1656 if Template.CanModify then
1657 ok := TRUE;
1658 end;
1659 end
1660 else
1661 ok := TRUE;
1662 if ok then
1663 begin
1664 Template.Items.Exchange(idx, idx+1);
1665 if(Hide and (not TTemplate(Template.Items[idx]).Active)) then
1666 begin
1667 inc(idx);
1668 ChangeLevel := (idx >= max);
1669 end
1670 else
1671 idx := max;
1672 end
1673 else
1674 idx := max;
1675 end;
1676 end;
1677 if(ChangeLevel) then
1678 begin
1679 ParentsParent := ParentNode.Parent;
1680 if(assigned(ParentsParent)) then
1681 begin
1682 ParentTemplate := TTemplate(ParentsParent.Data);
1683 if(ParentTemplate.Items.IndexOf(NodeTemplate) >= 0) then
1684 InfoBox(ParentsParent.Text + ' already contains the ' +
1685 NodeTemplate.PrintName + ' template.',
1686 'Error', MB_OK or MB_ICONERROR)
1687 else
1688 begin
1689 if CanClone(ParentNode) then
1690 begin
1691 if(Clone(ParentNode)) then
1692 Template := TTemplate(ParentNode.Data);
1693 if Template.CanModify and CanClone(ParentsParent) then
1694 begin
1695 if(Clone(ParentsParent)) then
1696 ParentTemplate := TTemplate(ParentsParent.Data);
1697 if ParentTemplate.CanModify then
1698 begin
1699 Template.Items.Delete(idx);
1700 idx := ParentTemplate.Items.IndexOf(Template);
1701 if(idx >= 0) then
1702 begin
1703 if(idx = (ParentTemplate.Items.Count-1)) then
1704 ParentTemplate.Items.Add(NodeTemplate)
1705 else
1706 ParentTemplate.Items.Insert(idx+1, NodeTemplate);
1707 Resync([ParentTemplate, Template]);
1708 btnApply.Enabled := TRUE;
1709 end;
1710 end;
1711 end;
1712 end;
1713 end;
1714 end;
1715 end
1716 else
1717 begin
1718 Resync([Template]);
1719 btnApply.Enabled := TRUE;
1720 end;
1721 end;
1722end;
1723
1724procedure TfrmTemplateEditor.sbDeleteClick(Sender: TObject);
1725var
1726 PNode, Node: TTreeNode;
1727 Template, Parent: TTemplate;
1728 DoIt: boolean;
1729 Answer: Word;
1730
1731begin
1732 if((assigned(FCurTree)) and (assigned(FCurTree.Selected)) and
1733 (assigned(FCurTree.Selected.Parent))) then
1734 begin
1735 Node := FCurTree.Selected;
1736 Template := TTemplate(Node.Data);
1737 PNode := Node.Parent;
1738 Parent := TTemplate(PNode.Data);
1739 if(AutoDel(Template)) then
1740 DoIt := TRUE
1741 else
1742 if(Template.Active) and (cbActive.Checked) then
1743 begin
1744 DoIt := FALSE;
1745 Answer := MessageDlg('Once you delete a template you may not be able to retrieve it.' + CRLF +
1746 'Rather than deleting, you may want to inactivate a template instead.' + CRLF +
1747 'You may inactivate this template by pressing the Ignore button now.' + CRLF +
1748 'Are you sure you want to delete the "' + Node.Text +
1749 '" Template?', mtConfirmation, [mbYes, mbNo, mbIgnore], 0);
1750 if(Answer = mrYes) then
1751 DoIt := TRUE
1752 else
1753 if(Answer = mrIgnore) then
1754 cbActive.Checked := FALSE;
1755 end
1756 else
1757 DoIt := InfoBox('Are you sure you want to delete the "' + Node.Text +
1758 '" Template?', 'Confirmation', MB_YESNO or MB_ICONQUESTION) = IDYES;
1759 if(DoIt and CanClone(PNode)) then
1760 begin
1761 if(Clone(PNode)) then
1762 Parent := TTemplate(PNode.Data);
1763 if assigned(Parent) and Parent.CanModify then
1764 begin
1765 btnApply.Enabled := TRUE;
1766 Parent.RemoveChild(Template);
1767 MarkDeleted(Template);
1768 Resync([Parent]);
1769 tvTreeChange(FCurTree, FCurTree.Selected);
1770 end;
1771 end;
1772 end;
1773end;
1774
1775procedure TfrmTemplateEditor.EnableNavControls;
1776var
1777 i: TTemplateTreeControl;
1778 AllowUp, AllowDown, AllowSet: boolean;
1779 Node: TTreeNode;
1780 Tree: TTemplateTreeType;
1781 Curok: boolean;
1782 OldActiveControl: TControl;
1783begin
1784 if(Assigned(FCurTree)) then
1785 begin
1786 Tree := TTemplateTreeType(FCurTree.Tag);
1787 Node := FCurTree.Selected;
1788 if(Assigned(Node)) then
1789 Curok := (TTemplate(Node.Data).RealType in [ttDoc, ttGroup, ttClass])
1790 else
1791 Curok := FALSE;
1792 if(Curok) then
1793 begin
1794 OldActiveControl := ActiveControl;
1795 FTreeControl[Tree, tcDel].Enabled := TRUE;
1796 AllowSet := FALSE;
1797 if(Node.Index > 0) then
1798 AllowUp := TRUE
1799 else
1800 begin
1801 AllowUp := AllowMove(Node.Parent.Parent, Node);
1802 AllowSet := TRUE;
1803 end;
1804 FTreeControl[Tree, tcUp].Enabled := AllowUp;
1805 AllowDown := AllowUp;
1806 if(Node.Index < (Node.Parent.Count-1)) then
1807 AllowDown := TRUE
1808 else
1809 begin
1810 if(not AllowSet) then
1811 AllowDown := AllowMove(Node.Parent.Parent, Node);
1812 end;
1813 FTreeControl[Tree, tcDown].Enabled := AllowDown;
1814 if not AllowUp and (OldActiveControl = FTreeControl[Tree, tcUp]) then
1815 (FTreeControl[Tree, tcDown] as TWinControl).SetFocus;
1816 if not AllowDown and (OldActiveControl = FTreeControl[Tree, tcDown]) then
1817 (FTreeControl[Tree, tcUp] as TWinControl).SetFocus;
1818 FTreeControl[Tree, tcCopy].Enabled := FTreeControl[TTemplateTreeType(1-ord(Tree)), tcDel].Visible;
1819 if(FTreeControl[Tree, tcCopy].Enabled) then
1820 begin
1821 if(Tree = ttShared) then
1822 Node := tvPersonal.Selected
1823 else
1824 Node := tvShared.Selected;
1825 if(assigned(Node)) then
1826 begin
1827 if(TTemplate(Node.Data).RealType = ttDoc) then
1828 Node := Node.Parent;
1829 FTreeControl[Tree, tcCopy].Enabled := AllowMove(Node, FCurTree.Selected);
1830 end
1831 else
1832 FTreeControl[Tree, tcCopy].Enabled := FALSE;
1833 end;
1834 FTreeControl[Tree, tcLbl].Enabled := FTreeControl[Tree, tcCopy].Enabled;
1835 end
1836 else
1837 begin
1838 for i := low(TTemplateTreeControl) to high(TTemplateTreeControl) do
1839 FTreeControl[Tree, i].Enabled := FALSE;
1840 end;
1841 if(FCurTree = tvShared) and (FCanEditShared) then
1842 btnNew.Enabled := TRUE
1843 else
1844 if(FCurTree = tvPersonal) and (FCanEditPersonal) then
1845 btnNew.Enabled := TRUE
1846 else
1847 btnNew.Enabled := FALSE;
1848 end
1849 else
1850 btnNew.Enabled := FALSE;
1851end;
1852
1853procedure TfrmTemplateEditor.tvTreeDragging(Sender: TObject;
1854 Node: TTreeNode; var CanDrag: Boolean);
1855
1856begin
1857 CanDrag := (TTemplate(Node.Data).RealType in [ttDoc, ttGroup, ttClass]);
1858 if(CanDrag) then
1859 FDragNode := Node
1860 else
1861 FDragNode := nil;
1862end;
1863
1864procedure TfrmTemplateEditor.tvTreeDragOver(Sender, Source: TObject; X,
1865 Y: Integer; State: TDragState; var Accept: Boolean);
1866var
1867 TmpNode: TTreeNode;
1868 Tree: TTreeView;
1869
1870begin
1871 FDropNode := nil;
1872 Accept := FALSE;
1873 if(Source is TTreeView) and (assigned(FDragNode)) then
1874 begin
1875 Tree := TTreeView(Sender);
1876 FDropNode := Tree.GetNodeAt(X,Y);
1877 if(((Tree = tvShared) and (FCanEditShared)) or
1878 ((Tree = tvPersonal) and (FCanEditPersonal))) then
1879 begin
1880 if(assigned(FDropNode)) then
1881 begin
1882 FDropInto := (TTemplate(FDropNode.Data).RealType in AllTemplateFolderTypes);
1883 if(FDropInto) then
1884 TmpNode := FDropNode
1885 else
1886 TmpNode := FDropNode.Parent;
1887 Accept := AllowMove(TmpNode, FDragNode);
1888 end;
1889 end;
1890 end;
1891end;
1892
1893procedure TfrmTemplateEditor.tvTreeDragDrop(Sender, Source: TObject; X,
1894 Y: Integer);
1895var
1896 Src, Template, Item: TTemplate;
1897 SIdx, idx: integer;
1898 TmpNode: TTreeNode;
1899
1900begin
1901 if(assigned(FDragNode)) and (assigned(FDropNode)) and (FDragNode <> FDropNode) then
1902 begin
1903 Item := TTemplate(FDragNode.Data);
1904 if(FDropInto) then
1905 begin
1906 TmpNode := FDropNode;
1907 idx := 0;
1908 end
1909 else
1910 begin
1911 TmpNode := FDropNode.Parent;
1912 idx := TTemplate(FDropNode.Parent.Data).Items.IndexOf(FDropNode.Data);
1913 end;
1914 if(AllowMove(TmpNode, FDragNode) and (idx >= 0)) then
1915 begin
1916 Template := TTemplate(TmpNode.Data);
1917 if(Template <> FDragNode.Parent.Data) and
1918 (Template.Items.IndexOf(Item) >= 0) then
1919 InfoBox(Template.PrintName + ' already contains the ' +
1920 Item.PrintName + ' template.',
1921 'Error', MB_OK or MB_ICONERROR)
1922 else
1923 begin
1924 Src := TTemplate(FDragNode.Parent.Data);
1925 Sidx := Src.Items.IndexOf(Item);
1926 if CanClone(TmpNode) then
1927 begin
1928 if(Clone(TmpNode)) then
1929 Template := TTemplate(TmpNode.Data);
1930 if assigned(Template) and Template.CanModify then
1931 begin
1932 if(Sidx >= 0) and (FDragNode.TreeView = FDropNode.TreeView) and
1933 (not FCopying) then // if same tree delete source
1934 begin
1935 if CanClone(FDragNode.Parent) then
1936 begin
1937 if(Clone(FDragNode.Parent)) then
1938 Src := TTemplate(FDragNode.Parent.Data);
1939 if assigned(Src) and Src.CanModify then
1940 begin
1941 Src.Items.Delete(Sidx);
1942 if(Template = Src) then
1943 Src := nil;
1944 end
1945 else
1946 Src := nil;
1947 end
1948 else
1949 Src := nil;
1950 end
1951 else
1952 Src := nil;
1953 if(idx > 0) then
1954 idx := TTemplate(FDropNode.Parent.Data).Items.IndexOf(FDropNode.Data);
1955 Template.Items.Insert(idx, Item);
1956 if(TTreeView(FDropNode.TreeView) = tvShared) then
1957 begin
1958 Item.PersonalOwner := 0;
1959 tvPersonal.Invalidate;
1960 end;
1961 TTreeView(FDragNode.TreeView).Selected := FDragNode;
1962 TTreeView(FDragNode.TreeView).SetFocus;
1963 Resync([Src, Template]);
1964 btnApply.Enabled := TRUE;
1965 end;
1966 end;
1967 end;
1968 end;
1969 end;
1970end;
1971
1972procedure TfrmTemplateEditor.Resync(const Templates: array of TTemplate);
1973var
1974 i, j: integer;
1975 NodeList: TStringList;
1976 TemplateList: TStringList;
1977 Node: TTreeNode;
1978 tmpl: TTemplate;
1979 NodeID: string;
1980
1981begin
1982 NodeList := TStringList.Create;
1983 try
1984 TemplateList := TStringList.Create;
1985 try
1986 for i := low(Templates) to high(Templates) do
1987 begin
1988 tmpl := Templates[i];
1989 if(assigned(tmpl)) then
1990 begin
1991 for j := 0 to tmpl.Nodes.Count-1 do
1992 begin
1993 Node := TTreeNode(tmpl.Nodes.Objects[j]);
1994 if(NodeList.IndexOfObject(Node) < 0) then
1995 begin
1996 NodeID := IntToStr(Node.Level);
1997 NodeID := copy('000',1,4-length(NodeID))+NodeID+U+tmpl.Nodes[j];
1998 TemplateList.AddObject(NodeID,tmpl);
1999 NodeList.AddObject(NodeId,Node);
2000 end;
2001 end;
2002 end;
2003 end;
2004
2005 { By Sorting by Node Level, we prevent a Resync
2006 of nodes deeper within the heirchary }
2007
2008 NodeList.Sort;
2009
2010 for i := 0 to NodeList.Count-1 do
2011 begin
2012 NodeID := NodeList[i];
2013 Node := TTreeNode(NodeList.Objects[i]);
2014 j := TemplateList.IndexOf(NodeID);
2015 if(j >= 0) then
2016 begin
2017 tmpl := TTemplate(TemplateList.Objects[j]);
2018 NodeID := Piece(NodeID,U,2);
2019 if(tmpl.Nodes.IndexOf(NodeID) >= 0) then
2020 begin
2021 if(Node.TreeView = tvShared) then
2022 dmodShared.Resync(Node, not cbShHide.Checked, FSharedEmptyNodeCount)
2023 else
2024 if(Node.TreeView = tvPersonal) then
2025 dmodShared.Resync(Node, not cbPerHide.Checked, FPersonalEmptyNodeCount);
2026 end;
2027 end;
2028 end;
2029 finally
2030 TemplateList.Free;
2031 end;
2032 finally
2033 NodeList.Free;
2034 end;
2035 EnableNavControls;
2036 if((assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
2037 tvTreeChange(FCurTree, FCurTree.Selected)
2038 else
2039 tvPersonal.Selected := tvPersonal.Items.GetFirstNode;
2040 FCopyNode := nil;
2041end;
2042
2043procedure TfrmTemplateEditor.sbCopyLeftClick(Sender: TObject);
2044begin
2045 if(assigned(tvPersonal.Selected)) then
2046 begin
2047 if(not assigned(tvShared.Selected)) then
2048 tvShared.Selected := tvShared.Items.GetFirstNode;
2049 FDragNode := tvPersonal.Selected;
2050 FDropNode := tvShared.Selected;
2051 FDropInto := (TTemplate(FDropNode.Data).RealType in AllTemplateFolderTypes);
2052 tvTreeDragDrop(tvPersonal, tvShared, 0,0);
2053 end;
2054end;
2055
2056procedure TfrmTemplateEditor.sbCopyRightClick(Sender: TObject);
2057begin
2058 if(assigned(tvShared.Selected)) then
2059 begin
2060 if(not assigned(tvPersonal.Selected)) then
2061 tvPersonal.Selected := tvPersonal.Items.GetFirstNode;
2062 FDragNode := tvShared.Selected;
2063 FDropNode := tvPersonal.Selected;
2064 FDropInto := (TTemplate(FDropNode.Data).RealType in AllTemplateFolderTypes);
2065 tvTreeDragDrop(tvShared, tvPersonal, 0,0);
2066 end;
2067end;
2068
2069procedure TfrmTemplateEditor.AdjustControls4FontChange;
2070var
2071 x: integer;
2072
2073 procedure Adjust(Control: TWinControl);
2074 begin
2075 x := x - Control.Width - 2;
2076 Control.Left := x;
2077 end;
2078
2079begin
2080 if FCanEditShared then
2081 begin
2082 x := pnlSharedBottom.Width;
2083 Adjust(sbSHDelete);
2084 Adjust(sbSHDown);
2085 Adjust(sbSHUp);
2086 cbSHHide.Width := x;
2087 end;
2088 x := pnlBottom.Width;
2089 Adjust(btnApply);
2090 Adjust(btnCancel);
2091 Adjust(btnOK);
2092 cbEditShared.Width := TextWidthByFont(cbEditShared.Font.Handle, cbEditShared.Caption) + 25;
2093 cbNotes.Left := cbEditShared.Left + cbEditShared.Width + 60;
2094 cbNotes.Width := TextWidthByFont(cbNotes.Font.Handle, cbNotes.Caption) + 25;
2095end;
2096
2097function TfrmTemplateEditor.AllowMove(ADropNode, ADragNode: TTreeNode): boolean;
2098var
2099 i: integer;
2100 TmpNode: TTreeNode;
2101 DragTemplate, DropTemplate: TTemplate;
2102
2103begin
2104 if(assigned(ADropNode) and assigned(ADragNode)) then
2105 begin
2106 DropTemplate := TTemplate(ADropNode.Data);
2107 DragTemplate := TTemplate(ADragNode.Data);
2108 if IsTemplateLocked(ADropNode) then
2109 Result := FALSE
2110 else
2111 Result := (DragTemplate.RealType in [ttDoc, ttGroup, ttClass]);
2112 if(Result) then
2113 begin
2114 if(FCopying) then
2115 begin
2116 if(DropTemplate.Items.IndexOf(DragTemplate) >= 0) then
2117 Result := FALSE;
2118 end
2119 else
2120 if((assigned(ADragNode.Parent)) and (ADropNode <> ADragNode.Parent) and
2121 (DropTemplate.Items.IndexOf(DragTemplate) >= 0)) then
2122 Result := FALSE;
2123 end;
2124 if(Result) then
2125 begin
2126 for i := 0 to DropTemplate.Nodes.Count-1 do
2127 begin
2128 TmpNode := TTreeNode(DropTemplate.Nodes.Objects[i]);
2129 while (Result and (assigned(TmpNode.Parent))) do
2130 begin
2131 if(TmpNode.Data = DragTemplate) then
2132 Result := FALSE
2133 else
2134 TmpNode := TmpNode.Parent;
2135 end;
2136 if(not Result) then break;
2137 end;
2138 end;
2139 end
2140 else
2141 Result := FALSE;
2142end;
2143
2144function TfrmTemplateEditor.Clone(Node: TTreeNode): boolean;
2145var
2146 idx: integer;
2147 Prnt, OldT, NewT: TTemplate;
2148 PNode: TTreeNode;
2149 ok: boolean;
2150
2151begin
2152 Result := FALSE;
2153 if((assigned(Node)) and (TTreeView(Node.TreeView) = tvPersonal)) then
2154 begin
2155 OldT := TTemplate(Node.Data);
2156 if(OldT.PersonalOwner <> User.DUZ) then
2157 begin
2158 PNode := Node.Parent;
2159 Prnt := nil;
2160 if (assigned(PNode)) then
2161 begin
2162 ok := CanClone(PNode);
2163 if ok then
2164 begin
2165 Clone(PNode);
2166 Prnt := TTemplate(PNode.Data);
2167 ok := Prnt.CanModify;
2168 end;
2169 end
2170 else
2171 ok := TRUE;
2172 if ok then
2173 begin
2174 BtnApply.Enabled := TRUE;
2175 Result := TRUE;
2176 NewT := OldT.Clone(User.DUZ);
2177 OldT.RemoveNode(Node);
2178 MarkDeleted(OldT);
2179 Node.Data := NewT;
2180 NewT.AddNode(Node);
2181 if(assigned(Prnt)) then
2182 begin
2183 idx := Prnt.Items.IndexOf(OldT);
2184 if(idx >= 0) then
2185 Prnt.Items[idx] := NewT;
2186 end;
2187 tvPersonal.Invalidate;
2188 ShowTemplateType(NewT);
2189 end;
2190 end;
2191 end;
2192end;
2193
2194procedure TfrmTemplateEditor.reBoilChange(Sender: TObject);
2195var
2196 DoInfo, DoRefresh: boolean;
2197 TmpBPlate: string;
2198 Template: TTemplate;
2199 x: integer;
2200
2201begin
2202 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
2203 begin
2204 Template := TTemplate(FCurTree.Selected.Data);
2205 TmpBPlate := reBoil.Lines.Text;
2206 if(Template.Boilerplate <> TmpBPlate) then
2207 begin
2208 if CanClone(FCurTree.Selected) then
2209 begin
2210 DoRefresh := Clone(FCurTree.Selected);
2211 if(DoRefresh) then
2212 Template := TTemplate(FCurTree.Selected.Data);
2213 if assigned(Template) and Template.CanModify then
2214 begin
2215 DoInfo := FALSE;
2216 if(Template.Boilerplate = '') or (TmpBPlate = '') then
2217 DoInfo := TRUE;
2218 Template.Boilerplate := TmpBPlate;
2219 TTemplate(FCurTree.Selected.Data).Gap := StrToIntDef(edtGap.Text, 0);
2220 if(Template.RealType = ttGroup) then
2221 begin
2222 reGroupBP.Text := Template.FullBoilerplate;
2223 end;
2224 if(DoRefresh) then
2225 begin
2226 tvShared.Invalidate;
2227 tvPersonal.Invalidate;
2228 end;
2229 if(DoInfo) then
2230 begin
2231 x := reBoil.SelStart;
2232 ShowInfo(FCurTree.Selected);
2233 reBoil.SelStart := x;
2234 end;
2235 end;
2236 end;
2237 btnApply.Enabled := TRUE;
2238// reBoil.Lines.Text := Template.Boilerplate;
2239 end;
2240 end;
2241end;
2242
2243procedure TfrmTemplateEditor.SharedEditing;
2244begin
2245{$IFDEF OwnerScan}
2246 lblPerOwner.Visible := FCanEditShared;
2247 cboOwner.Visible := FCanEditShared;
2248{$ELSE}
2249 lblPerOwner.Visible := FALSE;
2250 cboOwner.Visible := FALSE;
2251{$ENDIF}
2252 sbCopyLeft.Visible := FCanEditShared;
2253 if(not FCanEditShared) then
2254 cbShHide.Checked := TRUE;
2255 cbShHide.Visible := FCanEditShared;
2256 sbShDelete.Visible := FCanEditShared;
2257 sbShUp.Visible := FCanEditShared;
2258 sbShDown.Visible := FCanEditShared;
2259 tvShared.ReadOnly := not FCanEditShared;
2260 MoveCopyButtons;
2261 tvTreeChange(FCurTree, FCurTree.Selected);
2262 if FCanEditShared then
2263 AdjustControls4FontChange;
2264end;
2265
2266procedure TfrmTemplateEditor.cbEditSharedClick(Sender: TObject);
2267begin
2268 FCanEditShared := cbEditShared.Checked;
2269 SharedEditing;
2270end;
2271
2272procedure TfrmTemplateEditor.popTemplatesPopup(Sender: TObject);
2273var
2274 Tree: TTreeView;
2275 Node: TTreeNode;
2276 FindOn: boolean;
2277 Txt: string;
2278
2279begin
2280 FFromMainMenu := FALSE;
2281 Tree := GetTree;
2282 Node := Tree.Selected;
2283 Tree.Selected := Node; // This line prevents selected from changing after menu closes
2284 mnuCollapseTree.Enabled := dmodShared.NeedsCollapsing(Tree);
2285 if(Tree = tvShared) then
2286 begin
2287 Txt := 'Shared';
2288 FindOn := FFindShOn;
2289 mnuNodeDelete.Enabled := ((sbShDelete.Visible) and (sbShDelete.Enabled));
2290 end
2291 else
2292 begin
2293 Txt := 'Personal';
2294 FindOn := FFindPerOn;
2295 mnuNodeDelete.Enabled := ((sbPerDelete.Visible) and (sbPerDelete.Enabled));
2296 end;
2297 mnuFindTemplates.Checked := FindOn;
2298 mnuCollapseTree.Caption := 'Collapse '+Txt+' &Tree';
2299 mnuFindTemplates.Caption := '&Find '+Txt+' Templates';
2300
2301 if(assigned(Tree) and assigned(Tree.Selected) and assigned(Tree.Selected.Data)) then
2302 begin
2303 mnuNodeCopy.Enabled := (TTemplate(Tree.Selected.Data).RealType in [ttDoc, ttGroup, ttClass]);
2304 mnuNodeSort.Enabled := (TTemplate(Tree.Selected.Data).RealType in AllTemplateFolderTypes) and
2305 (Tree.Selected.HasChildren) and
2306 (Tree.Selected.GetFirstChild.GetNextSibling <> nil);
2307 end
2308 else
2309 begin
2310 mnuNodeCopy.Enabled := FALSE;
2311 mnuNodeSort.Enabled := FALSE;
2312 end;
2313 FPasteNode := Tree.Selected;
2314 mnuNodePaste.Enabled := PasteOK;
2315 mnuNodeNew.Enabled := btnNew.Enabled;
2316 mnuNodeAutoGen.Enabled := btnNew.Enabled;
2317end;
2318
2319procedure TfrmTemplateEditor.mnuCollapseTreeClick(Sender: TObject);
2320begin
2321 if(GetTree = tvShared) then
2322 begin
2323 tvShared.Selected := tvShared.Items.GetFirstNode;
2324 tvShared.FullCollapse;
2325 end
2326 else
2327 begin
2328 tvPersonal.Selected := tvShared.Items.GetFirstNode;
2329 tvPersonal.FullCollapse;
2330 end;
2331end;
2332
2333procedure TfrmTemplateEditor.mnuFindTemplatesClick(Sender: TObject);
2334var
2335 Tree: TTreeView;
2336
2337begin
2338 Tree := GetTree;
2339 if(Tree = tvShared) then
2340 begin
2341 FFindShOn := not FFindShOn;
2342 pnlShSearch.Visible := FFindShOn;
2343 if(FFindShOn) then
2344 begin
2345 edtShSearch.SetFocus;
2346 btnShFind.Enabled := (edtShSearch.Text <> '');
2347 end;
2348 end
2349 else
2350 begin
2351 FFindPerOn := not FFindPerOn;
2352 pnlPerSearch.Visible := FFindPerOn;
2353 if(FFindPerOn) then
2354 begin
2355 edtPerSearch.SetFocus;
2356 btnPerFind.Enabled := (edtPerSearch.Text <> '');
2357 end;
2358 end;
2359 SetFindNext(Tree, FALSE);
2360end;
2361
2362procedure TfrmTemplateEditor.ShowTemplateType(Template: TTemplate);
2363begin
2364 if(Template.PersonalOwner > 0) then
2365 gbProperties.Caption := 'Personal'
2366 else
2367 gbProperties.Caption := 'Shared';
2368 gbProperties.Caption := gbProperties.Caption + PropText;
2369end;
2370
2371function TfrmTemplateEditor.GetTree: TTreeView;
2372begin
2373 if(FFromMainMenu) then
2374 Result := FMainMenuTree
2375 else
2376 begin
2377 if(TTemplateTreeType(PopupComponent(popTemplates, popTemplates).Tag) = ttShared) then
2378 Result := tvShared
2379 else
2380 Result := tvPersonal;
2381 end;
2382end;
2383
2384procedure TfrmTemplateEditor.btnFindClick(Sender: TObject);
2385var
2386 Found: TTreeNode;
2387 edtSearch: TEdit;
2388 IsNext: boolean;
2389 FindNext: boolean;
2390 FindWholeWords: boolean;
2391 FindCase: boolean;
2392 Tree: TTreeView;
2393 LastFoundNode, TmpNode: TTreeNode;
2394// S1,S2: string;
2395
2396begin
2397 if(TTemplateTreeType(TButton(Sender).Tag) = ttShared) then
2398 begin
2399 Tree := tvShared;
2400 edtSearch := edtShSearch;
2401 FindNext := FFindShNext;
2402 FindWholeWords := cbShWholeWords.Checked;
2403 FindCase := cbShMatchCase.Checked;
2404 LastFoundNode := FLastFoundShNode;
2405 end
2406 else
2407 begin
2408 Tree := tvPersonal;
2409 edtSearch := edtPerSearch;
2410 FindNext := FFindPerNext;
2411 FindWholeWords := cbPerWholeWords.Checked;
2412 FindCase := cbPerMatchCase.Checked;
2413 LastFoundNode := FLastFoundPerNode;
2414 end;
2415 if(edtSearch.text <> '') then
2416 begin
2417 IsNext := ((FindNext) and assigned (LastFoundNode));
2418 if IsNext then
2419
2420 TmpNode := LastFoundNode
2421 else
2422 TmpNode := Tree.Items.GetFirstNode;
2423 FInternalHiddenExpand := TRUE;
2424 try
2425 Found := FindTemplate(edtSearch.Text, Tree, Self, TmpNode,
2426 IsNext, not FindCase, FindWholeWords);
2427 finally
2428 FInternalHiddenExpand := FALSE;
2429 end;
2430 if Assigned(Found) then
2431 begin
2432 Tree.Selected := Found;
2433 if(Tree = tvShared) then
2434 FLastFoundShNode := Found
2435 else
2436 FLastFoundPerNode := Found;
2437 SetFindNext(Tree, TRUE);
2438 end;
2439 end;
2440 edtSearch.SetFocus;
2441end;
2442
2443procedure TfrmTemplateEditor.edtSearchChange(Sender: TObject);
2444begin
2445 if(TTemplateTreeType(TEdit(Sender).Tag) = ttShared) then
2446 begin
2447 btnShFind.Enabled := (edtShSearch.Text <> '');
2448 SetFindNext(tvShared, FALSE);
2449 end
2450 else
2451 begin
2452 btnPerFind.Enabled := (edtPerSearch.Text <> '');
2453 SetFindNext(tvPersonal, FALSE);
2454 end;
2455end;
2456
2457procedure TfrmTemplateEditor.SetFindNext(const Tree: TTreeView; const Value: boolean);
2458begin
2459 if(Tree = tvShared) then
2460 begin
2461 if(FFindShNext <> Value) then
2462 begin
2463 FFindShNext := Value;
2464 if(FFindShNext) then btnShFind.Caption := 'Find Next'
2465 else btnShFind.Caption := 'Find';
2466 end;
2467 end
2468 else
2469 begin
2470 if(FFindPerNext <> Value) then
2471 begin
2472 FFindPerNext := Value;
2473 if(FFindPerNext) then btnPerFind.Caption := 'Find Next'
2474 else btnPerFind.Caption := 'Find';
2475 end;
2476 end;
2477end;
2478
2479procedure TfrmTemplateEditor.edtShSearchEnter(Sender: TObject);
2480begin
2481 btnShFind.Default := TRUE;
2482end;
2483
2484procedure TfrmTemplateEditor.edtShSearchExit(Sender: TObject);
2485begin
2486 btnShFind.Default := FALSE;
2487end;
2488
2489procedure TfrmTemplateEditor.edtPerSearchEnter(Sender: TObject);
2490begin
2491 btnPerFind.Default := TRUE;
2492end;
2493
2494procedure TfrmTemplateEditor.edtPerSearchExit(Sender: TObject);
2495begin
2496 btnPerFind.Default := FALSE;
2497end;
2498
2499procedure TfrmTemplateEditor.btnOKClick(Sender: TObject);
2500begin
2501 if(ScanNames) then
2502 begin
2503 if(SaveAllTemplates) then
2504 begin
2505 FOK2Close := TRUE;
2506 ModalResult := mrOK;
2507 end
2508 else
2509 BtnApply.Enabled := BackupDiffers;
2510 end;
2511end;
2512
2513procedure TfrmTemplateEditor.FormShow(Sender: TObject);
2514begin
2515 if(FFirstShow) then
2516 begin
2517 FUpdating := FALSE;
2518 FFirstShow := FALSE;
2519 if(FFocusName) then
2520 begin
2521 edtName.SetFocus;
2522 edtName.SelectAll;
2523 end;
2524 pnlBoilerplateResize(Self);
2525 AdjustControls4FontChange;
2526 MoveCopyButtons;
2527 end;
2528end;
2529
2530procedure TfrmTemplateEditor.mnuBPInsertObjectClick(Sender: TObject);
2531var
2532 i: integer;
2533 DoIt: boolean;
2534
2535begin
2536 if(not assigned(frmTemplateObjects)) then
2537 begin
2538 dmodShared.LoadTIUObjects;
2539 frmTemplateObjects := TfrmTemplateObjects.Create(Self);
2540 DoIt := TRUE;
2541 if (UserTemplateAccessLevel <> taEditor) then
2542 begin
2543 UpdatePersonalObjects;
2544 if uPersonalObjects.Count > 0 then // -------- CQ #8665 - RV ------------
2545 begin
2546 DoIt := FALSE;
2547 for i := 0 to dmodShared.TIUObjects.Count-1 do
2548 if uPersonalObjects.IndexOf(Piece(dmodShared.TIUObjects[i],U,2)) >= 0 then // -------- CQ #8665 - RV ------------
2549 frmTemplateObjects.cboObjects.Items.Add(dmodShared.TIUObjects[i]);
2550 end;
2551 end;
2552 if DoIt then
2553 FastAssign(dmodShared.TIUObjects, frmTemplateObjects.cboObjects.Items);
2554 frmTemplateObjects.Font := Font;
2555 frmTemplateObjects.re := reBoil;
2556 frmTemplateObjects.AutoLongLines := AutoLongLines;
2557 end;
2558 frmTemplateObjects.Show;
2559end;
2560
2561procedure TfrmTemplateEditor.mnuBPErrorCheckClick(Sender: TObject);
2562begin
2563 FBPOK := FALSE;
2564 if(reBoil.Lines.Count > 0) then
2565 begin
2566 if(dmodShared.TemplateOK(FCurTree.Selected.Data,'OK')) then
2567 begin
2568 TestBoilerplate(reBoil.Lines);
2569 if(RPCBrokerV.Results.Count > 0) then
2570 InfoBox('Boilerplate Contains Errors:'+CRLF+CRLF+
2571 RPCBrokerV.Results.Text, 'Error', MB_OK or MB_ICONERROR)
2572 else
2573 begin
2574 FBPOK := TRUE;
2575 if(assigned(Sender)) then
2576 InfoBox('No Errors Found in Boilerplate.', 'Information', MB_OK or MB_ICONINFORMATION);
2577 end;
2578 end;
2579 end;
2580end;
2581
2582procedure TfrmTemplateEditor.popBoilerplatePopup(Sender: TObject);
2583var
2584 tryOK, ok: boolean;
2585
2586begin
2587 ok := not reBoil.ReadOnly;
2588 mnuBPInsertObject.Enabled := ok;
2589 mnuBPInsertField.Enabled := ok;
2590
2591 mnuBPPaste.Enabled := (ok and Clipboard.HasFormat(CF_TEXT));
2592 if(ok) then
2593 ok := (reBoil.Lines.Count > 0);
2594 tryOK := (reBoil.Lines.Count > 0) or ((pnlGroupBP.Visible) and (reGroupBP.Lines.Count > 0));
2595 mnuBPErrorCheck.Enabled := tryOK;
2596 mnuBPTry.Enabled := tryOK;
2597 mnuBPSpellCheck.Enabled := ok and SpellCheckAvailable;
2598 mnuBPCheckGrammar.Enabled := ok and SpellCheckAvailable;
2599
2600 mnuBPCopy.Enabled := (reBoil.SelLength > 0);
2601 mnuBPCut.Enabled := (ok and (reBoil.SelLength > 0));
2602 mnuBPSelectAll.Enabled := (reBoil.Lines.Count > 0);
2603 mnuBPUndo.Enabled := (reBoil.Perform(EM_CANUNDO, 0, 0) <> 0);
2604end;
2605
2606function TfrmTemplateEditor.ScanNames: boolean;
2607var
2608 Errors: TList;
2609 msg: string;
2610 i: integer;
2611 Node: TTreeNode;
2612
2613 procedure ScanTree(Tree: TTreeView);
2614 begin
2615 Node := Tree.Items.GetFirstNode;
2616 while (assigned(Node)) do
2617 begin
2618 if(Node.Text <> EmptyNodeText) and (assigned(Node.Data)) then
2619 begin
2620 if(BadTemplateName(Node.Text)) then
2621 Errors.Add(Node);
2622 end;
2623 Node := Node.GetNext;
2624 end;
2625 end;
2626
2627begin
2628 Errors := TList.Create;
2629 try
2630 ScanTree(tvShared);
2631 ScanTree(tvPersonal);
2632 if(Errors.Count > 0) then
2633 begin
2634 if(Errors.Count > 1) then
2635 msg := IntToStr(Errors.Count) + ' Templates have invalid names'
2636 else
2637 msg := 'Template has an invalid name';
2638 msg := msg + ': ';
2639 for i := 0 to Errors.Count-1 do
2640 begin
2641 if(i > 0) then msg := msg + ', ';
2642 Node := TTreeNode(Errors[i]);
2643 msg := msg + Node.Text;
2644 Node.MakeVisible;
2645 end;
2646 msg := msg + '.' + BadNameText;
2647 InfoBox(msg, 'Error', MB_OK or MB_ICONERROR);
2648 TTreeView(Node.TreeView).Selected := TTreeNode(Errors[0]);
2649 end;
2650 finally
2651 Result := (Errors.Count = 0);
2652 Errors.Free;
2653 end;
2654end;
2655
2656procedure TfrmTemplateEditor.btnCancelClick(Sender: TObject);
2657begin
2658 FOK2Close := TRUE;
2659end;
2660
2661procedure TfrmTemplateEditor.FormClose(Sender: TObject;
2662 var Action: TCloseAction);
2663begin
2664 SaveUserBounds(Self);
2665end;
2666
2667procedure TfrmTemplateEditor.FormCloseQuery(Sender: TObject;
2668 var CanClose: Boolean);
2669var
2670 ans: word;
2671
2672begin
2673 if(not FOK2Close) and (BackupDiffers) then
2674 begin
2675 ans := InfoBox('Save Changes?', 'Confirmation', MB_YESNOCANCEL or MB_ICONQUESTION);
2676 if(ans = IDCANCEL) then
2677 CanClose := FALSE
2678 else
2679 if(ans = IDYES) then
2680 begin
2681 CanClose := FALSE;
2682 if(ScanNames) then
2683 begin
2684 if(SaveAllTemplates) then
2685 CanClose := TRUE
2686 else
2687 BtnApply.Enabled := BackupDiffers;
2688 end;
2689 end;
2690 end;
2691end;
2692
2693procedure TfrmTemplateEditor.mnuBPSpellCheckClick(Sender: TObject);
2694begin
2695 SpellCheckForControl(reBoil);
2696end;
2697
2698procedure TfrmTemplateEditor.splBoilMoved(Sender: TObject);
2699begin
2700 if pnlBoilerplate.Visible and pnlGroupBP.Visible then
2701 tmplEditorSplitterBoil := reBoil.Height;
2702 if pnlNotes.Visible then
2703 tmplEditorSplitterNotes := pnlNotes.Height;
2704 pnlBoilerplateResize(Self);
2705end;
2706
2707procedure TfrmTemplateEditor.edtGapKeyPress(Sender: TObject;
2708 var Key: Char);
2709begin
2710 if(not (Key in ['0','1','2','3'])) then Key := #0;
2711end;
2712
2713procedure TfrmTemplateEditor.edtNameExit(Sender: TObject);
2714var
2715 Warn: boolean;
2716
2717begin
2718 Warn := (ActiveControl <> btnCancel) and (BadTemplateName(edtName.Text));
2719 if(Warn and ((ActiveControl = sbShDelete) or (ActiveControl = sbPerDelete))) then
2720 begin
2721 if((assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
2722 Warn := not AutoDel(TTemplate(FCurTree.Selected.Data));
2723 end;
2724 if(Warn) then
2725 begin
2726 InfoBox('Template has an invalid name: ' + edtName.Text + '.' + BadNameText, 'Error', MB_OK or MB_ICONERROR);
2727 edtName.SetFocus;
2728 end;
2729end;
2730
2731procedure TfrmTemplateEditor.tmrAutoScrollTimer(Sender: TObject);
2732const
2733 EdgeScroll = 16;
2734
2735var
2736 TopNode: TTreeNode;
2737 Redraw: boolean;
2738 TmpPt: TPoint;
2739 ht: THitTests;
2740 HPos, RMax: integer;
2741
2742begin
2743 if(assigned(FDropNode)) then
2744 begin
2745 TopNode := FDropNode.TreeView.TopItem;
2746 Redraw := FALSE;
2747 TmpPt := FDropNode.TreeView.ScreenToClient(Mouse.CursorPos);
2748 if(TopNode = FDropNode) and (TopNode <> TTreeView(FDropNode.TreeView).Items.GetFirstNode) then
2749 begin
2750 FDropNode.TreeView.TopItem := TopNode.GetPrevVisible;
2751 Redraw := TRUE;
2752 end
2753 else
2754 begin
2755 RMax := FDropNode.TreeView.ClientHeight - EdgeScroll;
2756 if((TmpPt.Y > RMax) and (FDropNode.GetNextVisible <> nil)) then
2757 begin
2758 TORTreeView(FDropNode.TreeView).VertScrollPos :=
2759 TORTreeView(FDropNode.TreeView).VertScrollPos + 1;
2760 Redraw := TRUE;
2761 end;
2762 end;
2763 if(FLastDropNode <> FDropNode) then
2764 begin
2765 if((assigned(FDropNode)) and (FDropNode.GetNext = nil)) then
2766 Redraw := TRUE
2767 else
2768 if((assigned(FLastDropNode)) and (FLastDropNode.GetNext = nil)) then
2769 Redraw := TRUE;
2770 FLastDropNode := FDropNode;
2771 FDragOverCount := 0;
2772 end
2773 else
2774 begin
2775 if(FDropNode.HasChildren) and (not FDropNode.Expanded) then
2776 begin
2777 ht := FDropNode.TreeView.GetHitTestInfoAt(TmpPt.X, TmpPt.Y);
2778 if(htOnButton in ht) then
2779 begin
2780 inc(FDragOverCount);
2781 if(FDragOverCount > 4) then
2782 begin
2783 TopNode := FDropNode.TreeView.TopItem;
2784 FDropNode.Expand(FALSE);
2785 FDropNode.TreeView.TopItem := TopNode;
2786 FDragOverCount := 0;
2787 Redraw := TRUE;
2788 end;
2789 end
2790 else
2791 FDragOverCount := 0;
2792 end;
2793 if(not Redraw) then
2794 begin
2795 HPos := TORTreeView(FDropNode.TreeView).HorzScrollPos;
2796 if(HPos > 0) and (TmpPt.X < EdgeScroll) then
2797 begin
2798 TORTreeView(FDropNode.TreeView).HorzScrollPos :=
2799 TORTreeView(FDropNode.TreeView).HorzScrollPos - EdgeScroll;
2800 Redraw := TRUE;
2801 end
2802 else
2803 begin
2804 RMax := FDropNode.TreeView.ClientWidth - EdgeScroll;
2805 if(TmpPt.X > RMax) then
2806 begin
2807 TORTreeView(FDropNode.TreeView).HorzScrollPos :=
2808 TORTreeView(FDropNode.TreeView).HorzScrollPos + EdgeScroll;
2809 Redraw := TRUE;
2810 end;
2811 end;
2812 end;
2813 end;
2814 if(Redraw) then
2815 begin
2816 TmpPt := Mouse.CursorPos; // Wiggling the mouse causes needed windows messages to fire
2817 inc(TmpPt.X);
2818 Mouse.CursorPos := TmpPt;
2819 dec(TmpPt.X);
2820 Mouse.CursorPos := TmpPt;
2821 FDropNode.TreeView.Invalidate;
2822 end;
2823 end;
2824end;
2825
2826procedure TfrmTemplateEditor.tvTreeStartDrag(Sender: TObject;
2827 var DragObject: TDragObject);
2828begin
2829 FDropNode := nil;
2830 FLastDropNode := nil;
2831 FDragOverCount := 0;
2832 tmrAutoScroll.Enabled := TRUE;
2833end;
2834
2835procedure TfrmTemplateEditor.tvTreeEndDrag(Sender, Target: TObject; X,
2836 Y: Integer);
2837begin
2838 tmrAutoScroll.Enabled := FALSE;
2839end;
2840
2841procedure TfrmTemplateEditor.mnuGroupBPCopyClick(Sender: TObject);
2842begin
2843 reGroupBP.CopyToClipboard;
2844end;
2845
2846procedure TfrmTemplateEditor.popGroupPopup(Sender: TObject);
2847begin
2848 mnuGroupBPCopy.Enabled := (pnlGroupBP.Visible and (reGroupBP.SelLength > 0));
2849 mnuGroupBPSelectAll.Enabled := (pnlGroupBP.Visible and (reGroupBP.Lines.Count > 0));
2850end;
2851
2852procedure TfrmTemplateEditor.mnuBPCutClick(Sender: TObject);
2853begin
2854 reBoil.CutToClipboard;
2855end;
2856
2857procedure TfrmTemplateEditor.mnuBPCopyClick(Sender: TObject);
2858begin
2859 reBoil.CopyToClipboard;
2860end;
2861
2862procedure TfrmTemplateEditor.mnuBPPasteClick(Sender: TObject);
2863begin
2864 reBoil.SelText := Clipboard.AsText;
2865end;
2866
2867procedure TfrmTemplateEditor.mnuGroupBPSelectAllClick(Sender: TObject);
2868begin
2869 reGroupBP.SelectAll;
2870end;
2871
2872procedure TfrmTemplateEditor.mnuBPSelectAllClick(Sender: TObject);
2873begin
2874 reBoil.SelectAll;
2875end;
2876
2877procedure TfrmTemplateEditor.mnuNodeDeleteClick(Sender: TObject);
2878begin
2879 if(FCurTree = tvShared) and (sbShDelete.Visible) and (sbShDelete.Enabled) then
2880 sbDeleteClick(sbShDelete)
2881 else
2882 if(FCurTree = tvPersonal) and (sbPerDelete.Visible) and (sbPerDelete.Enabled) then
2883 sbDeleteClick(sbPerDelete);
2884end;
2885
2886procedure TfrmTemplateEditor.mnuNodeCopyClick(Sender: TObject);
2887begin
2888 if(assigned(FCurTree)) then
2889 FCopyNode := FCurTree.Selected
2890 else
2891 FCopyNode := nil;
2892end;
2893
2894procedure TfrmTemplateEditor.mnuNodePasteClick(Sender: TObject);
2895begin
2896 if(PasteOK) then
2897 begin
2898 FDragNode := FCopyNode;
2899 FDropNode := FPasteNode;
2900 FDropInto := (TTemplate(FDropNode.Data).RealType in AllTemplateFolderTypes);
2901 FCopying := TRUE;
2902 try
2903 tvTreeDragDrop(tvShared, tvPersonal, 0, 0);
2904 finally
2905 FCopying := FALSE;
2906 end;
2907 end;
2908 FCopyNode := nil;
2909end;
2910
2911function TfrmTemplateEditor.PasteOK: boolean;
2912var
2913 OldCopying: boolean;
2914 Node: TTreeNode;
2915
2916begin
2917 Result := assigned(FCopyNode) and assigned(FPasteNode);
2918 if(Result) then
2919 Result := (FTreeControl[TTemplateTreeType(FPasteNode.TreeView.Tag), tcDel].Visible);
2920 if(Result) then
2921 begin
2922 OldCopying := FCopying;
2923 FCopying := TRUE;
2924 try
2925 Node := FPasteNode;
2926 if(TTemplate(Node.Data).RealType = ttDoc) then
2927 Node := Node.Parent;
2928 Result := AllowMove(Node, FCopyNode);
2929 finally
2930 FCopying := OldCopying;
2931 end;
2932 end;
2933end;
2934
2935procedure TfrmTemplateEditor.mnuBPUndoClick(Sender: TObject);
2936begin
2937 reBoil.Perform(EM_UNDO, 0, 0);
2938end;
2939
2940procedure TfrmTemplateEditor.tvTreeKeyDown(Sender: TObject;
2941 var Key: Word; Shift: TShiftState);
2942begin
2943
2944 if(Key = VK_DELETE) then
2945 begin
2946 if(Sender = tvShared) then
2947 begin
2948 if(sbShDelete.Visible and sbShDelete.Enabled) then
2949 sbDeleteClick(sbShDelete);
2950 end
2951 else
2952 begin
2953 if(sbPerDelete.Visible and sbPerDelete.Enabled) then
2954 sbDeleteClick(sbPerDelete);
2955 end;
2956 end;
2957 //Code Added to provide CTRL Key access for 508 compliance GRE 3/03
2958 if (ssCtrl in Shift) and (Key = VK_A) then
2959 reBoil.SelectAll
2960 else
2961 if (ssCtrl in Shift) and (Key = VK_C) then
2962 reBoil.CopyToClipboard
2963 else
2964 if (ssCtrl in Shift) and (Key = VK_E) then
2965 mnuBPErrorCheckClick(Self)
2966 else
2967 if (ssCtrl in Shift) and (Key = VK_F) then
2968 mnuBPInsertFieldClick(Self)
2969 else
2970 if (ssCtrl in Shift) and (Key = VK_G) then
2971 GrammarCheckForControl(reBoil)
2972 else
2973 if (ssCtrl in Shift) and (Key = VK_I) then
2974 mnuBPInsertObjectClick(Self)
2975 else
2976 if (ssCtrl in Shift) and (Key = VK_S) then
2977 SpellCheckForControl(reBoil)
2978 else
2979 if (ssCtrl in Shift) and (Key = VK_T) then
2980 mnuBPTryClick(Self)
2981 else
2982 if (ssCtrl in Shift) and (Key = VK_V) then
2983 reBoil.SelText := Clipboard.AsText
2984 else
2985 if (ssCtrl in Shift) and (Key = VK_X) then
2986 reBoil.CutToClipboard
2987 else
2988 if (ssCtrl in Shift) and (Key = VK_Z) then
2989 reBoil.Perform(EM_UNDO, 0, 0);
2990 //End of ---- Code Added to provide CTRL Key access for 508 compliance GRE 3/03
2991end;
2992
2993procedure TfrmTemplateEditor.mnuEditClick(Sender: TObject);
2994var
2995 tryOK, ok: boolean;
2996
2997begin
2998 if pnlBoilerplate.Visible then
2999 begin
3000 ok := (not reBoil.ReadOnly);
3001 mnuInsertObject.Enabled := ok;
3002 mnuInsertField.Enabled := ok;
3003 mnuPaste.Enabled := (ok and Clipboard.HasFormat(CF_TEXT));
3004 if(ok) then
3005 ok := (reBoil.Lines.Count > 0);
3006 tryOK := (reBoil.Lines.Count > 0) or ((pnlGroupBP.Visible) and (reGroupBP.Lines.Count > 0));
3007 mnuErrorCheck.Enabled := tryOK;
3008 mnuTry.Enabled := tryOK;
3009 mnuSpellCheck.Enabled := ok and SpellCheckAvailable;
3010 mnuCheckGrammar.Enabled := ok and SpellCheckAvailable;
3011
3012 mnuCopy.Enabled := (reBoil.SelLength > 0);
3013 mnuCut.Enabled := (ok and (reBoil.SelLength > 0));
3014 mnuSelectAll.Enabled := (reBoil.Lines.Count > 0);
3015 mnuUndo.Enabled := (reBoil.Perform(EM_CANUNDO, 0, 0) <> 0);
3016 mnuGroupBoilerplate.Enabled := pnlGroupBP.Visible;
3017 end
3018 else
3019 begin
3020 mnuInsertObject.Enabled := FALSE;
3021 mnuInsertField.Enabled := FALSE;
3022 mnuPaste.Enabled := FALSE;
3023 mnuErrorCheck.Enabled := FALSE;
3024 mnuTry.Enabled := FALSE;
3025 mnuSpellCheck.Enabled := FALSE;
3026 mnuCheckGrammar.Enabled := FALSE;
3027 mnuCopy.Enabled := FALSE;
3028 mnuCut.Enabled := FALSE;
3029 mnuSelectAll.Enabled := FALSE;
3030 mnuUndo.Enabled := FALSE;
3031 mnuGroupBoilerplate.Enabled := FALSE;
3032 end;
3033end;
3034
3035procedure TfrmTemplateEditor.mnuGroupBoilerplateClick(Sender: TObject);
3036begin
3037 mnuGroupCopy.Enabled := (pnlGroupBP.Visible and (reGroupBP.SelLength > 0));
3038 mnuGroupSelectAll.Enabled := (pnlGroupBP.Visible and (reGroupBP.Lines.Count > 0));
3039end;
3040
3041procedure TfrmTemplateEditor.cbShFindOptionClick(Sender: TObject);
3042begin
3043 SetFindNext(tvShared, FALSE);
3044 if(pnlShSearch.Visible) then edtShSearch.SetFocus;
3045end;
3046
3047procedure TfrmTemplateEditor.cbPerFindOptionClick(Sender: TObject);
3048begin
3049 SetFindNext(tvPersonal, FALSE);
3050 if(pnlPerSearch.Visible) then edtPerSearch.SetFocus;
3051end;
3052
3053procedure TfrmTemplateEditor.mnuTemplateClick(Sender: TObject);
3054var
3055 Tree: TTreeView;
3056
3057begin
3058 FFromMainMenu := TRUE;
3059 Tree := FCurTree;
3060 if(assigned(Tree) and assigned(Tree.Selected)) then
3061 begin
3062 if(Tree = tvShared) then
3063 mnuTDelete.Enabled := ((sbShDelete.Visible) and (sbShDelete.Enabled))
3064 else
3065 mnuTDelete.Enabled := ((sbPerDelete.Visible) and (sbPerDelete.Enabled));
3066 if(assigned(Tree) and assigned(Tree.Selected) and assigned(Tree.Selected.Data)) then
3067 begin
3068 mnuTCopy.Enabled := (TTemplate(Tree.Selected.Data).RealType in [ttDoc, ttGroup, ttClass]);
3069 mnuSort.Enabled := (TTemplate(Tree.Selected.Data).RealType in AllTemplateFolderTypes) and
3070 (Tree.Selected.HasChildren) and
3071 (Tree.Selected.GetFirstChild.GetNextSibling <> nil);
3072 end
3073 else
3074 begin
3075 mnuTCopy.Enabled := FALSE;
3076 mnuSort.Enabled := FALSE;
3077 end;
3078 FPasteNode := Tree.Selected;
3079 mnuTPaste.Enabled := PasteOK;
3080 end
3081 else
3082 begin
3083 mnuTCopy.Enabled := FALSE;
3084 mnuTPaste.Enabled := FALSE;
3085 mnuTDelete.Enabled := FALSE;
3086 mnuSort.Enabled := FALSE;
3087 end;
3088 mnuNewTemplate.Enabled := btnNew.Enabled;
3089 mnuAutoGen.Enabled := btnNew.Enabled;
3090 mnuFindShared.Checked := FFindShOn;
3091 mnuFindPersonal.Checked := FFindPerOn;
3092 mnuShCollapse.Enabled := dmodShared.NeedsCollapsing(tvShared);
3093 mnuPerCollapse.Enabled := dmodShared.NeedsCollapsing(tvPersonal);
3094end;
3095
3096procedure TfrmTemplateEditor.mnuFindSharedClick(Sender: TObject);
3097begin
3098 FMainMenuTree := tvShared;
3099 mnuFindTemplatesClick(tvShared);
3100end;
3101
3102procedure TfrmTemplateEditor.mnuFindPersonalClick(Sender: TObject);
3103begin
3104 FMainMenuTree := tvPersonal;
3105 mnuFindTemplatesClick(tvPersonal);
3106end;
3107
3108procedure TfrmTemplateEditor.mnuShCollapseClick(Sender: TObject);
3109begin
3110 FMainMenuTree := tvShared;
3111 mnuCollapseTreeClick(tvShared);
3112end;
3113
3114procedure TfrmTemplateEditor.mnuPerCollapseClick(Sender: TObject);
3115begin
3116 FMainMenuTree := tvPersonal;
3117 mnuCollapseTreeClick(tvPersonal);
3118end;
3119
3120procedure TfrmTemplateEditor.pnlShSearchResize(Sender: TObject);
3121begin
3122 if((cbShMatchCase.Width + cbShWholeWords.Width) > pnlShSearch.Width) then
3123 cbShWholeWords.Left := cbShMatchCase.Width
3124 else
3125 cbShWholeWords.Left := pnlShSearch.Width - cbShWholeWords.Width;
3126end;
3127
3128procedure TfrmTemplateEditor.pnlPerSearchResize(Sender: TObject);
3129begin
3130 if((cbPerMatchCase.Width + cbPerWholeWords.Width) > pnlPerSearch.Width) then
3131 cbPerWholeWords.Left := cbPerMatchCase.Width
3132 else
3133 cbPerWholeWords.Left := pnlPerSearch.Width - cbPerWholeWords.Width;
3134end;
3135
3136procedure TfrmTemplateEditor.pnlPropertiesResize(Sender: TObject);
3137begin
3138 btnNew.Width := pnlProperties.Width;
3139end;
3140
3141procedure TfrmTemplateEditor.mbMainResize(Sender: TObject);
3142begin
3143 pnlMenu.Width := mbMain.Width + 4;
3144 mbMain.Width := pnlMenu.Width - 3;
3145end;
3146
3147procedure TfrmTemplateEditor.mnuBPCheckGrammarClick(Sender: TObject);
3148begin
3149 GrammarCheckForControl(reBoil);
3150end;
3151
3152procedure TfrmTemplateEditor.mnuSortClick(Sender: TObject);
3153var
3154 Tree: TTreeView;
3155
3156begin
3157 Tree := FCurTree;
3158 if(assigned(Tree) and assigned(Tree.Selected) and Tree.Selected.HasChildren) then
3159 begin
3160 TTemplate(Tree.Selected.Data).SortChildren;
3161 Resync([TTemplate(Tree.Selected.Data)]);
3162 btnApply.Enabled := TRUE;
3163 end;
3164end;
3165
3166procedure TfrmTemplateEditor.pnlBoilerplateCanResize(Sender: TObject;
3167 var NewWidth, NewHeight: Integer; var Resize: Boolean);
3168begin
3169 if(NewHeight < 40) then Resize := FALSE;
3170end;
3171
3172function TfrmTemplateEditor.AutoDel(Template: TTemplate): boolean;
3173begin
3174 if(assigned(Template)) then
3175 Result := (((Template.ID = '0') or (Template.ID = '')) and
3176 (Template.PrintName = NewTemplateName) and
3177 (Template.Boilerplate = ''))
3178 else
3179 Result := FALSE;
3180end;
3181
3182procedure TfrmTemplateEditor.mnuBPTryClick(Sender: TObject);
3183var
3184 R: TRect;
3185 Move: boolean;
3186 tmpl: TTemplate;
3187 txt: String;
3188
3189begin
3190 mnuBPErrorCheckClick(nil);
3191 if(FBPOK) or (reBoil.Lines.Count = 0) then
3192 begin
3193 Move := assigned(frmTemplateView);
3194 if(Move) then
3195 begin
3196 R := frmTemplateView.BoundsRect;
3197 frmTemplateView.Free;
3198 frmTemplateView := nil;
3199 end;
3200 tmpl := TTemplate(FCurTree.Selected.Data);
3201 tmpl.TemplatePreviewMode := TRUE; // Prevents "Are you sure?" dialog when canceling
3202 txt := tmpl.Text;
3203 if(not tmpl.DialogAborted) then
3204 ShowTemplateData(Self, tmpl.PrintName ,txt);
3205 if(Move) then
3206 frmTemplateView.BoundsRect := R;
3207 tmpl.TemplatePreviewMode := FALSE;
3208 end;
3209end;
3210
3211procedure TfrmTemplateEditor.mnuAutoGenClick(Sender: TObject);
3212var
3213 AName, AText: string;
3214
3215begin
3216 dmodShared.LoadTIUObjects;
3217 UpdatePersonalObjects;
3218 GetAutoGenText(AName, AText, uPersonalObjects); // -------- CQ #8665 - RV ------------
3219 if(AName <> '') and (AText <> '') then
3220 begin
3221 btnNewClick(Self);
3222 TTemplate(FBtnNewNode.Data).PrintName := AName;
3223 TTemplate(FBtnNewNode.Data).Boilerplate := AText;
3224 ShowInfo(FBtnNewNode);
3225 edtNameOldChange(Self);
3226 end;
3227end;
3228
3229procedure TfrmTemplateEditor.reNotesChange(Sender: TObject);
3230var
3231 Template: TTemplate;
3232 DoRefresh: boolean;
3233
3234begin
3235 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
3236 begin
3237 if CanClone(FCurTree.Selected) then
3238 begin
3239 DoRefresh := Clone(FCurTree.Selected);
3240 Template := TTemplate(FCurTree.Selected.Data);
3241 if assigned(Template) and Template.CanModify then
3242 begin
3243 Template.Description := reNotes.Lines.Text;
3244 UpdateApply(Template);
3245 if(DoRefresh) then
3246 begin
3247 tvShared.Invalidate;
3248 tvPersonal.Invalidate;
3249 end;
3250 end;
3251 end;
3252 btnApply.Enabled := TRUE;
3253// reNotes.Lines.Text := Template.Description;
3254 end;
3255end;
3256
3257procedure TfrmTemplateEditor.mnuNotesUndoClick(Sender: TObject);
3258begin
3259 reNotes.Perform(EM_UNDO, 0, 0);
3260end;
3261
3262procedure TfrmTemplateEditor.mnuNotesCutClick(Sender: TObject);
3263begin
3264 reNotes.CutToClipboard;
3265end;
3266
3267procedure TfrmTemplateEditor.mnuNotesCopyClick(Sender: TObject);
3268begin
3269 reNotes.CopyToClipboard;
3270end;
3271
3272procedure TfrmTemplateEditor.mnuNotesPasteClick(Sender: TObject);
3273begin
3274 reNotes.SelText := Clipboard.AsText;
3275end;
3276
3277procedure TfrmTemplateEditor.mnuNotesSelectAllClick(Sender: TObject);
3278begin
3279 reNotes.SelectAll;
3280end;
3281
3282procedure TfrmTemplateEditor.mnuNotesGrammarClick(Sender: TObject);
3283begin
3284 GrammarCheckForControl(reNotes);
3285end;
3286
3287procedure TfrmTemplateEditor.mnuNotesSpellingClick(Sender: TObject);
3288begin
3289 SpellCheckForControl(reNotes);
3290end;
3291
3292procedure TfrmTemplateEditor.popNotesPopup(Sender: TObject);
3293var
3294 ok: boolean;
3295
3296begin
3297 ok := not reNotes.ReadOnly;
3298 mnuNotesPaste.Enabled := (ok and Clipboard.HasFormat(CF_TEXT));
3299 if(ok) then
3300 ok := (reNotes.Lines.Count > 0);
3301 mnuNotesSpelling.Enabled := ok and SpellCheckAvailable;
3302 mnuNotesGrammar.Enabled := ok and SpellCheckAvailable;
3303 mnuNotesCopy.Enabled := (reNotes.SelLength > 0);
3304 mnuNotesCut.Enabled := (ok and (reNotes.SelLength > 0));
3305 mnuNotesSelectAll.Enabled := (reNotes.Lines.Count > 0);
3306 mnuNotesUndo.Enabled := (reNotes.Perform(EM_CANUNDO, 0, 0) <> 0);
3307end;
3308
3309procedure TfrmTemplateEditor.cbNotesClick(Sender: TObject);
3310begin
3311 pnlNotes.Visible := cbNotes.Checked;
3312 splNotes.Visible := cbNotes.Checked;
3313 if cbNotes.Checked then
3314 begin
3315 pnlNotes.Height := tmplEditorSplitterNotes;
3316 pnlNotes.Top := pnlBottom.Top - pnlNotes.Height;
3317 splNotes.Top := pnlNotes.Top-3;
3318 end;
3319 pnlBoilerplateResize(Self);
3320end;
3321
3322procedure TfrmTemplateEditor.cbDisplayOnlyClick(Sender: TObject);
3323begin
3324 cbClick(TCheckBox(Sender), BPDisplayOnlyFld);
3325end;
3326
3327procedure TfrmTemplateEditor.cbFirstLineClick(Sender: TObject);
3328begin
3329 cbClick(TCheckBox(Sender), BPFirstLineFld);
3330end;
3331
3332procedure TfrmTemplateEditor.cbOneItemOnlyClick(Sender: TObject);
3333begin
3334 cbClick(TCheckBox(Sender), BPOneItemOnlyFld);
3335end;
3336
3337procedure TfrmTemplateEditor.cbHideDlgItemsClick(Sender: TObject);
3338begin
3339 cbClick(TCheckBox(Sender), BPHideDlgItemsFld);
3340end;
3341
3342procedure TfrmTemplateEditor.cbHideItemsClick(Sender: TObject);
3343begin
3344 cbClick(TCheckBox(Sender), BPHideItemsFld);
3345end;
3346
3347procedure TfrmTemplateEditor.cbClick(Sender: TCheckBox; Index: integer);
3348var
3349 Template: TTemplate;
3350
3351begin
3352 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
3353 begin
3354 if CanClone(FCurTree.Selected) then
3355 begin
3356 Clone(FCurTree.Selected);
3357 Template := TTemplate(FCurTree.Selected.Data);
3358 if assigned(Template) and Template.CanModify then
3359 begin
3360 case Index of
3361 BPDisplayOnlyFld: Template.DisplayOnly := Sender.Checked;
3362 BPFirstLineFld: Template.FirstLine := Sender.Checked;
3363 BPOneItemOnlyFld: Template.OneItemOnly := Sender.Checked;
3364 BPHideDlgItemsFld: Template.HideDlgItems := Sender.Checked;
3365 BPHideItemsFld: Template.HideItems := Sender.Checked;
3366 BPIndentFld: Template.IndentItems := Sender.Checked;
3367 BPLockFld: Template.Lock := Sender.Checked;
3368 end;
3369 UpdateApply(Template);
3370 end;
3371 end;
3372 end;
3373end;
3374
3375procedure TfrmTemplateEditor.cbIndentClick(Sender: TObject);
3376begin
3377 cbClick(TCheckBox(Sender), BPIndentFld);
3378end;
3379
3380procedure TfrmTemplateEditor.mnuToolsClick(Sender: TObject);
3381begin
3382 mnuEditTemplateFields.Enabled := CanEditTemplateFields;
3383 mnuImportTemplate.Enabled := btnNew.Enabled;
3384 mnuExportTemplate.Enabled := (assigned(FCurTree) and assigned(FCurTree.Selected) and
3385 assigned(FCurTree.Selected.Data));
3386end;
3387
3388procedure TfrmTemplateEditor.mnuEditTemplateFieldsClick(Sender: TObject);
3389begin
3390 if assigned(frmTemplateObjects) then
3391 frmTemplateObjects.Hide;
3392 if assigned(frmTemplateFields) then
3393 frmTemplateFields.Hide;
3394 if EditDialogFields and assigned(frmTemplateFields) then
3395 FreeAndNil(frmTemplateFields);
3396end;
3397
3398procedure TfrmTemplateEditor.mnuBPInsertFieldClick(Sender: TObject);
3399begin
3400 if(not assigned(frmTemplateFields)) then
3401 begin
3402 frmTemplateFields := TfrmTemplateFields.Create(Self);
3403 frmTemplateFields.Font := Font;
3404 frmTemplateFields.re := reBoil;
3405 frmTemplateFields.AutoLongLines := AutoLongLines;
3406 end;
3407 frmTemplateFields.Show;
3408end;
3409
3410procedure TfrmTemplateEditor.UpdateInsertsDialogs;
3411begin
3412 if assigned(frmTemplateObjects) then
3413 frmTemplateObjects.UpdateStatus;
3414 if assigned(frmTemplateFields) then
3415 frmTemplateFields.UpdateStatus;
3416end;
3417
3418procedure TfrmTemplateEditor.mnuExportTemplateClick(Sender: TObject);
3419var
3420 Tmpl, Flds: TStringList;
3421 i: integer;
3422 XMLDoc: IXMLDOMDocument;
3423 err: boolean;
3424
3425begin
3426 err := FALSE;
3427 if(assigned(FCurTree) and assigned(FCurTree.Selected) and assigned(FCurTree.Selected.Data)) then
3428 begin
3429 dlgExport.FileName := ValidFileName(TTemplate(FCurTree.Selected.Data).PrintName);
3430 if dlgExport.Execute then
3431 begin
3432 Tmpl := TStringList.Create;
3433 try
3434 Flds := TStringList.Create;
3435 try
3436 Tmpl.Add('<'+XMLHeader+'>');
3437 if TTemplate(FCurTree.Selected.Data).CanExportXML(Tmpl, Flds, 2) then
3438 begin
3439 if (Flds.Count > 0) then begin
3440 ExpandEmbeddedFields(Flds);
3441 FastAssign(ExportTemplateFields(Flds), Flds);
3442 for i := 0 to Flds.Count-1 do
3443 Flds[i] := ' ' + Flds[i];
3444 FastAddStrings(Flds, Tmpl);
3445 end; {if}
3446 Tmpl.Add('</'+XMLHeader+'>');
3447 try
3448 XMLDoc := CoDOMDocument.Create;
3449 try
3450 XMLDoc.preserveWhiteSpace := TRUE;
3451 XMLDoc.LoadXML(Tmpl.Text);
3452 XMLDoc.Save(dlgExport.FileName);
3453 finally
3454 XMLDoc := nil;
3455 end;
3456 except
3457 InfoBox(Format(NoIE5, ['Export']), NoIE5Header, MB_OK);
3458 err := TRUE;
3459 end;
3460 if not err then
3461 InfoBox('Template ' + TTemplate(FCurTree.Selected.Data).PrintName +
3462 ' Exported.', 'Template Exported', MB_OK);
3463 end;
3464 finally
3465 Flds.Free;
3466 end;
3467 finally
3468 Tmpl.Free;
3469 end;
3470 end;
3471 end;
3472end;
3473
3474procedure TfrmTemplateEditor.mnuImportTemplateClick(Sender: TObject);
3475const
3476 Filter1 = 'Template Files|*.txml';
3477 WordFilter = '|Word Documents|*.doc;*.dot';
3478 Filter2 = '|XML Files|*.xml|All Files|*.*';
3479
3480var
3481 XMLDoc: IXMLDOMDocument;
3482 RootElement: IXMLDOMElement;
3483 ImportedTemplate: TTemplate;
3484 AppData, Flds, ResultSet: TStringList;
3485 tmp,j,p3: string;
3486 err, ok, changes, xmlerr: boolean;
3487 i: integer;
3488 choice: word;
3489
3490 procedure ClearFields;
3491 begin
3492 Flds.Text := '';
3493 ResultSet.Text := '';
3494 end;
3495
3496begin
3497 tmp := Filter1;
3498 err := FALSE;
3499 if WordImportActive then
3500 tmp := tmp + WordFilter;
3501 tmp := tmp + Filter2;
3502 dlgImport.Filter := tmp;
3503 if btnNew.Enabled and dlgImport.Execute then
3504 begin
3505 tmp := ExtractFileExt(dlgImport.FileName);
3506 if(WordImportActive and ((CompareText(tmp,'.doc') = 0) or
3507 (CompareText(tmp,'.dot') = 0))) then
3508 AppData := TStringList.Create
3509 else
3510 AppData := nil;
3511 try
3512 try
3513 XMLDoc := CoDOMDocument.Create;
3514 except
3515 InfoBox(Format(NoIE5, ['Import']), NoIE5Header, MB_OK);
3516 exit;
3517 end;
3518 try
3519 if assigned(AppData) then
3520 begin
3521 try
3522 ok := GetXMLFromWord(dlgImport.FileName, AppData);
3523 except
3524 ok := FALSE;
3525 err := TRUE;
3526 end;
3527 end
3528 else
3529 ok := TRUE;
3530 if ok and assigned(XMLDoc) then
3531 begin
3532 XMLDoc.preserveWhiteSpace := TRUE;
3533 if assigned(AppData) then
3534 XMLDoc.LoadXML(AppData.Text)
3535 else
3536 XMLDoc.Load(dlgImport.FileName);
3537 RootElement := XMLDoc.DocumentElement;
3538 if not assigned(RootElement) then
3539 XMLImportError(0);
3540 try
3541 if(RootElement.tagName <> XMLHeader)then
3542 XMLImportError(0)
3543 else
3544 begin
3545 ImportedTemplate := nil;
3546 FXMLTemplateElement := FindXMLElement(RootElement, XMLTemplateTag);
3547 if assigned(FXMLTemplateElement) then
3548 begin
3549 FXMLFieldElement := FindXMLElement(RootElement, XMLTemplateFieldsTag);
3550 if(assigned(FXMLFieldElement)) then
3551 begin
3552 Flds := TStringList.Create;
3553 ResultSet := TStringList.Create;
3554 try
3555 Flds.Text := FXMLFieldElement.Get_XML;
3556 choice := IDOK;
3557 changes := FALSE;
3558 Application.ProcessMessages;
3559 if not BuildTemplateFields(Flds) then //Calls RPC to transfer all field XML
3560 choice := IDCANCEL; //for processing
3561 Flds.Text := '';
3562 Application.ProcessMessages;
3563 if choice = IDOK then
3564 CheckTemplateFields(Flds);
3565 if Flds.Count > 0 then
3566 begin
3567 for i := 1 to Flds.Count do
3568 begin
3569 j := piece(Flds[i-1],U,2);
3570 if (j = '0') or (j = '2') then
3571 begin
3572 p3 := piece(Flds[i-1],U,3);
3573 if p3 = 'XML FORMAT ERROR' then
3574 choice := IDCANCEL;
3575 changes := TRUE;
3576 if j = '2' then begin
3577 j := Flds[i-1];
3578 SetPiece(j,U,2,'1');
3579 Flds[i-1] := j
3580 end;
3581 end;
3582 end;
3583 end
3584 else
3585 choice := IDCANCEL;
3586 if choice <> IDOK then
3587 InfoBox(iMessage2+iMessage3, 'Error', MB_OK or MB_ICONERROR)
3588 else
3589 if (not CanEditTemplateFields) AND
3590 changes {(there is at least one new field)} then
3591 begin
3592 choice := InfoBox(iMessage, 'Warning', MB_OKCANCEL or MB_ICONWARNING);
3593 Flds.Text := '';
3594 end;
3595 if choice <> IDCANCEL then
3596 begin
3597 FImportingFromXML := TRUE;
3598 try
3599 btnNewClick(Self);
3600 ImportedTemplate := TTemplate(FBtnNewNode.Data);
3601 finally
3602 FImportingFromXML := FALSE;
3603 end; {try}
3604 Application.ProcessMessages;
3605 if assigned(ImportedTemplate) and (Flds.Count > 0) then
3606 if not ImportLoadedFields(ResultSet) then begin
3607 InfoBox(iMessage2+iMessage3, 'Error', MB_OK or MB_ICONERROR);
3608 ClearFields;
3609 choice := IDCANCEL;
3610 end;//if
3611 if Flds.Count = 0 then
3612 choice := IDCANCEL;
3613 end {if choice <> mrCancel}
3614 else
3615 ClearFields;
3616
3617 xmlerr := FALSE;
3618 if (Flds.Count > 0) and
3619 (ResultSet.Count > 0) and
3620 (Flds.Count = ResultSet.Count) then
3621 for i := 0 to Flds.Count-1 do begin
3622 if piece(ResultSet[i],U,2) = '0' then begin
3623 j := piece(Flds[i],U,1) + U + '0' + U + piece(ResultSet[i],U,3);
3624 Flds[i] := j;
3625 end
3626 end
3627 else
3628 xmlerr := TRUE;
3629
3630 if xmlerr and (choice <> IDCANCEL) then begin
3631 InfoBox(iMessage2, 'Warning', MB_OK or MB_ICONWARNING);
3632 ClearFields;
3633 end;
3634
3635 i := 0;
3636 while (i < Flds.Count) do begin
3637 if Piece(Flds[i], U, 2) <> '0' then
3638 Flds.Delete(i)
3639 else
3640 inc(i);
3641 end;//while
3642 if(Flds.Count > 0) then
3643 begin
3644 if assigned(frmTemplateFields) then
3645 FreeAndNil(frmTemplateFields);
3646 ImportedTemplate.UpdateImportedFieldNames(Flds);
3647 if not assigned(AppData) then
3648 begin
3649 for i := 0 to Flds.Count-1 do
3650 Flds[i] := ' Field "' + Piece(Flds[i],U,1) + '" has been renamed to "'+
3651 Piece(Flds[i],U,3) + '"';
3652 if Flds.Count = 1 then
3653 tmp := 'A template field has'
3654 else
3655 tmp := IntToStr(Flds.Count) + ' template fields have';
3656 Flds.Insert(0,tmp + ' been imported with the same name as');
3657 Flds.Insert(1,'existing template fields, but with different field definitions.');
3658 Flds.Insert(2,'These imported template fields have been renamed as follows:');
3659 Flds.Insert(3,'');
3660 InfoBox(Flds.Text, 'Information', MB_OK or MB_ICONINFORMATION);
3661 end;
3662 end;
3663 finally
3664 Flds.Free;
3665 ResultSet.Free;
3666 end;
3667 end
3668 else {There are no fields to consider...}
3669 begin
3670 FImportingFromXML := TRUE;
3671 try
3672 btnNewClick(Self);
3673 ImportedTemplate := TTemplate(FBtnNewNode.Data);
3674 finally
3675 FImportingFromXML := FALSE;
3676 end; {try}
3677 end;
3678 end;
3679 if assigned(ImportedTemplate) then
3680 ShowInfo(FBtnNewNode);
3681 end;
3682 finally
3683 RootElement := nil;
3684 end;
3685 end;
3686 finally
3687 XMLDoc := nil;
3688 end;
3689 finally
3690 if assigned(AppData) then
3691 begin
3692 AppData.Free;
3693 if err then
3694 InfoBox('An error occured while Importing Word Document. Make sure Word is closed and try again.','Import Error', MB_OK);
3695 end;
3696 end;
3697 end;
3698end;
3699
3700procedure TfrmTemplateEditor.cbxTypeDrawItem(Control: TWinControl;
3701 Index: Integer; Rect: TRect; State: TOwnerDrawState);
3702var
3703 ImgIdx: integer;
3704
3705begin
3706 cbxType.Canvas.FillRect(Rect);
3707 case IdxForced[FForceContainer, Index] of
3708 tiTemplate: ImgIdx := 4;
3709 tiFolder: ImgIdx := 3;
3710 tiGroup: ImgIdx := 5;
3711 tiDialog: ImgIdx := 23;
3712 tiRemDlg: ImgIdx := 27;
3713 tiCOMObj: ImgIdx := 28;
3714 else
3715 ImgIdx := ord(tiNone);
3716 end;
3717 if ImgIdx >= 0 then
3718 dmodShared.imgTemplates.Draw(cbxType.Canvas, Rect.Left+1, Rect.Top+1, ImgIdx);
3719 if Index >= 0 then
3720 cbxType.Canvas.TextOut(Rect.Left+21, Rect.Top+2, cbxType.Items[Index]);
3721end;
3722
3723procedure TfrmTemplateEditor.cbxTypeChange(Sender: TObject);
3724var
3725 i,tg: integer;
3726 Template: TTemplate;
3727 ttyp: TTemplateType;
3728 Node: TTreeNode;
3729 idx: TTypeIndex;
3730
3731begin
3732 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected))) then
3733 begin
3734 tg := cbxType.ItemIndex;
3735 if tg >= 0 then
3736 begin
3737 if CanClone(FCurTree.Selected) then
3738 begin
3739 idx := IdxForced[FForceContainer, tg];
3740 if(idx = tiRemDlg) and (not (GetLinkType(FCurTree.Selected) in [ltNone, ltTitle])) then
3741 begin
3742 FUpdating := TRUE;
3743 try
3744 cbxType.ItemIndex := ord(tiTemplate);
3745 finally
3746 FUpdating := FALSE;
3747 end;
3748 ShowMsg('Can not assign a Reminder Dialog to a Reason for Request');
3749 end
3750 else
3751 begin
3752 Clone(FCurTree.Selected);
3753 Template := TTemplate(FCurTree.Selected.Data);
3754 if assigned(Template) and Template.CanModify then
3755 begin
3756 ttyp := TypeTag[idx];
3757 if(not FForceContainer) or (not (idx in [tiTemplate, tiRemDlg])) then
3758 begin
3759 if(ttyp = ttDialog) then
3760 begin
3761 Template.Dialog := TRUE;
3762 ttyp := ttGroup;
3763 end
3764 else
3765 Template.Dialog := FALSE;
3766 Template.RealType := ttyp;
3767 if(Template.RealType = ttDoc) and (idx = tiRemDlg) then
3768 Template.IsReminderDialog := TRUE
3769 else
3770 Template.IsReminderDialog := FALSE;
3771 if(Template.RealType = ttDoc) and (idx = tiCOMObj) then
3772 Template.IsCOMObject := TRUE
3773 else
3774 Template.IsCOMObject := FALSE;
3775 UpdateApply(Template);
3776 end;
3777 for i := 0 to Template.Nodes.Count-1 do
3778 begin
3779 Node := TTreeNode(Template.Nodes.Objects[i]);
3780 Node.ImageIndex := dmodShared.ImgIdx(Node);
3781 Node.SelectedIndex := dmodShared.ImgIdx(Node);
3782 end;
3783 tvShared.Invalidate;
3784 tvPersonal.Invalidate;
3785 Node := FCurTree.Selected;
3786 tvTreeChange(TTreeView(Node.TreeView), Node);
3787 end;
3788 end;
3789 end;
3790 end;
3791 end;
3792end;
3793
3794procedure TfrmTemplateEditor.cbxRemDlgsChange(Sender: TObject);
3795var
3796 Template: TTemplate;
3797
3798begin
3799 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected)) and
3800 FCanDoReminders) then
3801 begin
3802 if CanClone(FCurTree.Selected) then
3803 begin
3804 Clone(FCurTree.Selected);
3805 Template := TTemplate(FCurTree.Selected.Data);
3806 if assigned(Template) and Template.CanModify then
3807 begin
3808 if cbxRemDlgs.ItemIndex < 0 then
3809 Template.ReminderDialog := ''
3810 else
3811 Template.ReminderDialog := cbxRemDlgs.Items[cbxRemDlgs.ItemIndex];
3812 UpdateApply(Template);
3813 end;
3814 end;
3815 end;
3816end;
3817
3818procedure TfrmTemplateEditor.mnuTemplateIconLegendClick(Sender: TObject);
3819begin
3820 ShowIconLegend(ilTemplates, TRUE);
3821end;
3822
3823procedure TfrmTemplateEditor.cbLongLinesClick(Sender: TObject);
3824begin
3825 pnlBoilerplateResize(Self);
3826 pnlBoilerplateResize(Self); // Second Call is Needed!
3827end;
3828
3829procedure TfrmTemplateEditor.AutoLongLines(Sender: TObject);
3830begin
3831 cbLongLines.Checked := TRUE;
3832end;
3833
3834(*procedure TfrmTemplateEditor.UpdatePersonalObjects;
3835var
3836 i: integer;
3837
3838begin
3839 if not assigned(FPersonalObjects) then
3840 begin
3841 FPersonalObjects := TStringList.Create;
3842 GetAllowedPersonalObjects;
3843 for i := 0 to RPCBrokerV.Results.Count-1 do
3844 FPersonalObjects.Add(Piece(RPCBrokerV.Results[i],U,1));
3845 FPersonalObjects.Sorted := TRUE;
3846 end;
3847end;*)
3848
3849(*function TfrmTemplateEditor.ModifyAllowed(const Node: TTreeNode): boolean;
3850var
3851 tmpl: TTemplate;
3852
3853 function GetFirstPersonalNode(Node: TTreeNode): TTreeNode;
3854 begin
3855 Result := Node;
3856 if assigned(Node.Parent) and (TTemplate(Node.Data).PersonalOwner <> User.DUZ) then
3857 Result := GetFirstPersonalNode(Node.Parent);
3858 end;
3859
3860begin
3861 if(assigned(Node)) then
3862 begin
3863 if (TTreeView(Node.TreeView) = tvPersonal) then
3864 Result := TTemplate(GetFirstPersonalNode(Node).Data).CanModify
3865 else
3866 Result := TRUE;
3867 end
3868 else
3869 Result := FALSE;
3870 if Result then
3871 begin
3872 tmpl := TTemplate(Node.Data);
3873 if (tmpl.PersonalOwner = 0) or (tmpl.PersonalOwner = User.DUZ) then
3874 Result := tmpl.CanModify;
3875 end;
3876end;
3877*)
3878
3879{ Returns TRUE if Cloning is not needed or if Cloning is needed and
3880 the top personal Node in the tree is locked. }
3881function TfrmTemplateEditor.CanClone(const Node: TTreeNode): boolean;
3882var
3883 Template: TTemplate;
3884
3885 function GetFirstPersonalNode(Node: TTreeNode): TTreeNode;
3886 begin
3887 Result := Node;
3888 if assigned(Node.Parent) and (TTemplate(Node.Data).PersonalOwner <> User.DUZ) then
3889 Result := GetFirstPersonalNode(Node.Parent);
3890 end;
3891
3892begin
3893 if(assigned(Node)) and assigned(Node.Data) then
3894 begin
3895 if (TTreeView(Node.TreeView) = tvPersonal) then
3896 begin
3897 Template := TTemplate(Node.Data);
3898 if Template.IsCOMObject or (Template.FileLink <> '') then
3899 Result := FALSE
3900 else
3901 Result := TTemplate(GetFirstPersonalNode(Node).Data).CanModify
3902 end
3903 else
3904 Result := TRUE;
3905 end
3906 else
3907 Result := FALSE;
3908end;
3909
3910procedure TfrmTemplateEditor.UpdateApply(Template: TTemplate);
3911begin
3912 if(not btnApply.Enabled) then
3913 btnApply.Enabled := Template.Changed;
3914end;
3915
3916procedure TfrmTemplateEditor.TemplateLocked(Sender: TObject);
3917begin
3918 Resync([TTemplate(Sender)]);
3919 ShowMsg(Format(TemplateLockedText, [TTemplate(Sender).PrintName]));
3920end;
3921
3922procedure TfrmTemplateEditor.cbLockClick(Sender: TObject);
3923begin
3924 cbClick(TCheckBox(Sender), BPLockFLD);
3925end;
3926
3927procedure TfrmTemplateEditor.mnuRefreshClick(Sender: TObject);
3928begin
3929 if btnApply.Enabled then
3930 begin
3931 if InfoBox('All changes must be saved before you can Refresh. Save Changes?',
3932 'Confirmation', MB_YESNO or MB_ICONQUESTION) <> IDYES then
3933 exit;
3934 end;
3935 btnApplyClick(Sender);
3936 if BtnApply.Enabled then
3937 InfoBox('Save not completed - unable to refresh.', 'Error', MB_OK or MB_ICONERROR)
3938 else
3939 RefreshData;
3940end;
3941
3942procedure TfrmTemplateEditor.RefreshData;
3943var
3944 exp1, exp2, s1, s2, t1, t2: string;
3945 focus: TWinControl;
3946
3947begin
3948 focus := FCurTree;
3949 exp1 := tvShared.GetExpandedIDStr(1, ';');
3950 exp2 := tvPersonal.GetExpandedIDStr(1, ';');
3951 s1 := tvShared.GetNodeID(TORTreeNode(tvShared.Selected),1,';');
3952 s2 := tvPersonal.GetNodeID(TORTreeNode(tvPersonal.Selected),1,';');
3953 t1 := tvShared.GetNodeID(TORTreeNode(tvShared.TopItem),1,';');
3954 t2 := tvPersonal.GetNodeID(TORTreeNode(tvPersonal.TopItem),1,';');
3955 tvPersonal.Items.BeginUpdate;
3956 try
3957 tvShared.Items.BeginUpdate;
3958 try
3959 ReleaseTemplates;
3960 tvPersonal.Items.Clear;
3961 tvShared.Items.Clear;
3962 InitTrees;
3963 tvShared.SetExpandedIDStr(1, ';', exp1);
3964 tvShared.TopItem := tvShared.FindPieceNode(t1,1,';');
3965 tvShared.Selected := tvShared.FindPieceNode(s1,1,';');
3966 tvPersonal.SetExpandedIDStr(1, ';', exp2);
3967 tvPersonal.TopItem := tvPersonal.FindPieceNode(t2,1,';');
3968 tvPersonal.Selected := tvPersonal.FindPieceNode(s2,1,';');
3969 finally
3970 tvShared.Items.EndUpdate;
3971 end;
3972 finally
3973 tvPersonal.Items.EndUpdate;
3974 end;
3975 ActiveControl := focus;
3976end;
3977
3978procedure TfrmTemplateEditor.InitTrees;
3979begin
3980 LoadTemplateData;
3981 if(not assigned(RootTemplate)) then
3982 SaveTemplate(AddTemplate('0^R^A^Shared Templates'),-1);
3983 if(not assigned(MyTemplate)) then
3984 AddTemplate('0^P^A^My Templates^^^'+IntToStr(User.DUZ));
3985 dmodShared.AddTemplateNode(tvPersonal, FPersonalEmptyNodeCount, MyTemplate);
3986 dmodShared.AddTemplateNode(tvShared, FSharedEmptyNodeCount, RootTemplate);
3987 if (UserTemplateAccessLevel = taEditor) then
3988 begin
3989 if CanEditLinkType(ttTitles) then
3990 dmodShared.AddTemplateNode(tvShared, FSharedEmptyNodeCount, TitlesTemplate);
3991 if CanEditLinkType(ttConsults) then
3992 dmodShared.AddTemplateNode(tvShared, FSharedEmptyNodeCount, ConsultsTemplate);
3993 if CanEditLinkType(ttProcedures) then
3994 dmodShared.AddTemplateNode(tvShared, FSharedEmptyNodeCount, ProceduresTemplate);
3995 end;
3996end;
3997
3998procedure TfrmTemplateEditor.reResizeRequest(Sender: TObject;
3999 Rect: TRect);
4000var
4001 R: TRect;
4002
4003begin
4004 R := TRichEdit(Sender).ClientRect;
4005 if (FLastRect.Right <> R.Right) or
4006 (FLastRect.Bottom <> R.Bottom) or
4007 (FLastRect.Left <> R.Left) or
4008 (FLastRect.Top <> R.Top) then
4009 begin
4010 FLastRect := R;
4011 pnlBoilerplateResize(Self);
4012 end;
4013end;
4014
4015procedure TfrmTemplateEditor.reBoilSelectionChange(Sender: TObject);
4016begin
4017 UpdateXY(reBoil, lblBoilCol, lblBoilRow);
4018end;
4019
4020procedure TfrmTemplateEditor.reGroupBPSelectionChange(Sender: TObject);
4021begin
4022 UpdateXY(reGroupBP, lblGroupCol, lblGroupRow);
4023end;
4024
4025procedure TfrmTemplateEditor.UpdateXY(re: TRichEdit; lblX, lblY: TLabel);
4026var
4027 p: TPoint;
4028
4029begin
4030 p := re.CaretPos;
4031 lblY.Caption := 'Line: ' + inttostr(p.y + 1);
4032 lblX.Caption := 'Column: ' + inttostr(p.x + 1);
4033end;
4034
4035procedure TfrmTemplateEditor.cbxCOMObjChange(Sender: TObject);
4036var
4037 Template: TTemplate;
4038
4039begin
4040 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected)) and
4041 FCanDoCOMObjects and (FCurTree = tvShared)) then
4042 begin
4043 Template := TTemplate(FCurTree.Selected.Data);
4044 if assigned(Template) and Template.CanModify then
4045 begin
4046 if cbxCOMObj.ItemIndex < 0 then
4047 Template.COMObject := 0
4048 else
4049 Template.COMObject := cbxCOMObj.ItemID;
4050 UpdateApply(Template);
4051 end;
4052 end;
4053end;
4054
4055procedure TfrmTemplateEditor.edtCOMParamChange(Sender: TObject);
4056var
4057 Template: TTemplate;
4058
4059begin
4060 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected)) and
4061 FCanDoCOMObjects and (FCurTree = tvShared)) then
4062 begin
4063 Template := TTemplate(FCurTree.Selected.Data);
4064 if assigned(Template) and Template.CanModify then
4065 begin
4066 Template.COMParam := edtCOMParam.Text;
4067 UpdateApply(Template);
4068 end;
4069 end;
4070end;
4071
4072function TfrmTemplateEditor.GetLinkType(const ANode: TTreeNode): TTemplateLinkType;
4073var
4074 Node: TTreeNode;
4075
4076begin
4077 Result := ltNone;
4078 if assigned(ANode) then
4079 begin
4080 if(not assigned(ANode.Data)) or (TTemplate(ANode.Data).RealType <> ttClass) then
4081 begin
4082 Node := ANode.Parent;
4083 repeat
4084 if assigned(Node) and assigned(Node.Data) then
4085 begin
4086 if (TTemplate(Node.Data).FileLink <> '') then
4087 Node := nil
4088 else
4089 if (TTemplate(Node.Data).RealType in AllTemplateLinkTypes) then
4090 begin
4091 case TTemplate(Node.Data).RealType of
4092 ttTitles: Result := ltTitle;
4093 ttConsults: Result := ltConsult;
4094 ttProcedures: Result := ltProcedure;
4095 end;
4096 end
4097 else
4098 Node := Node.Parent;
4099 end
4100 else
4101 Node := nil;
4102 until(Result <> ltNone) or (not assigned(Node));
4103 end;
4104 end;
4105end;
4106
4107procedure TfrmTemplateEditor.cbxLinkNeedData(Sender: TObject;
4108 const StartFrom: String; Direction, InsertAt: Integer);
4109var
4110 tmpSL: TStringList;
4111 i: integer;
4112 tmp: string;
4113
4114begin
4115 tmpSL := TStringList.Create;
4116 try
4117 case TTemplateLinkType(pnlLink.Tag) of
4118 ltTitle: FastAssign(SubSetOfAllTitles(StartFrom, Direction), tmpSL);
4119// ltConsult:
4120 ltProcedure:
4121 begin
4122 FastAssign(SubSetOfProcedures(StartFrom, Direction), tmpSL);
4123 for i := 0 to tmpSL.Count-1 do
4124 begin
4125 tmp := tmpSL[i];
4126 setpiece(tmp,U,1,piece(piece(tmp,U,4),';',1));
4127 tmpSL[i] := tmp;
4128 end;
4129 end;
4130 end;
4131 cbxLink.ForDataUse(tmpSL);
4132 finally
4133 tmpSL.Free;
4134 end;
4135end;
4136
4137procedure TfrmTemplateEditor.cbxLinkChange(Sender: TObject);
4138var
4139 Template,LinkTemplate: TTemplate;
4140 update: boolean;
4141
4142begin
4143 if((not FUpdating) and (assigned(FCurTree)) and (assigned(FCurTree.Selected)) and
4144 (FCurTree = tvShared)) then
4145 begin
4146 Template := TTemplate(FCurTree.Selected.Data);
4147 if assigned(Template) and Template.CanModify then
4148 begin
4149 update := true;
4150 if cbxLink.ItemIEN > 0 then
4151 begin
4152 LinkTemplate := GetLinkedTemplate(cbxLink.ItemID, TTemplateLinkType(pnlLink.tag));
4153 if (assigned(LinkTemplate) and (LinkTemplate <> Template)) then
4154 begin
4155 ShowMsg(GetLinkName(cbxLink.ItemID, TTemplateLinkType(pnlLink.tag)) +
4156 ' is already assigned to another template.');
4157 cbxLink.SelectByID(Template.LinkIEN);
4158 update := False;
4159 end
4160 else
4161 begin
4162 Template.FileLink := ConvertFileLink(cbxLink.ItemID, TTemplateLinkType(pnlLink.tag));
4163 if Template.LinkName <> '' then
4164 edtName.Text := copy(Template.LinkName,1,edtName.MaxLength);
4165 end;
4166 end
4167 else
4168 Template.FileLink := '';
4169 if update then
4170 UpdateApply(Template);
4171 end;
4172 end;
4173end;
4174
4175procedure TfrmTemplateEditor.reBoilKeyUp(Sender: TObject; var Key: Word;
4176 Shift: TShiftState);
4177begin
4178 if FNavigatingTab then
4179 begin
4180 if ssShift in Shift then
4181 FindNextControl(Sender as TWinControl, False, True, False).SetFocus //previous control
4182 else if ssCtrl in Shift then
4183 FindNextControl(Sender as TWinControl, True, True, False).SetFocus; //next control
4184 FNavigatingTab := False;
4185 end;
4186 if (key = VK_ESCAPE) then begin
4187 FindNextControl(Sender as TWinControl, False, True, False).SetFocus; //previous control
4188 key := 0;
4189 end;
4190end;
4191
4192procedure TfrmTemplateEditor.reBoilKeyPress(Sender: TObject;
4193 var Key: Char);
4194begin
4195 if FNavigatingTab then
4196 Key := #0; //Disable shift-tab processinend;
4197end;
4198
4199procedure TfrmTemplateEditor.reBoilKeyDown(Sender: TObject; var Key: Word;
4200 Shift: TShiftState);
4201begin
4202 //The navigating tab controls were inadvertantently adding tab characters
4203 //This should fix it
4204 FNavigatingTab := (Key = VK_TAB) and ([ssShift,ssCtrl] * Shift <> []);
4205 if FNavigatingTab then
4206 Key := 0;
4207end;
4208
4209end.
4210
Note: See TracBrowser for help on using the repository browser.