source: cprs/branches/HealthSevak-CPRS/CPRS-Chart/Templates/fTemplateEditor.pas@ 1719

Last change on this file since 1719 was 1699, checked in by healthsevak, 10 years ago

Implemented the OpenSource based spell check feature

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