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

Last change on this file since 1710 was 1679, checked in by healthsevak, 10 years ago

Updating the working copy to CPRS version 28

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