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

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

Adding foia-cprs branch

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