Procedure

TdmodShared.Resync

Module

dShared

Last Modified

7/15/2014 3:26:36 PM

Comments

SelNode,

Visibility

Public

Owner

TdmodShared

Declaration

procedure Resync(SyncNode: TTreeNode; AllowInactive: boolean;
                            var EmptyCount: integer);

Calls Hierarchy


TdmodShared.Resync
 ├InSyncNode
 ├GetID
 │ └..(rec)..
 ├TTemplate.RemoveNode
 ├BuildNodes
 │ ├TTemplate.AddNode
 │ ├TTemplate.GetItems
 │ │ └ExpandTemplate
 │ │   ├TTemplate.GetChildren
 │ │   ├GetTemplateChildren
 │ │   ├AddTemplate
 │ │   │ ├TTemplate.Create
 │ │   │ │ └TTemplate.ReminderDialogIEN
 │ │   │ └TTemplate.AddChild
 │ │   │   └TTemplate.GetItems...
 │ │   └TTemplate.ItemIENs
 │ │     └TTemplate.GetItems...
 │ ├..(rec)..
 │ └TTemplate.GetChildren
 └GetNode
   └GetID...

Called-By Hierarchy


                              TdmodShared.Resync
              TfrmTemplateEditor.cbShHideClick┤ 
            TfrmTemplateEditor.cbActiveClick┘ │ 
             TfrmTemplateEditor.cbPerHideClick┤ 
            TfrmTemplateEditor.cbActiveClick┘ │ 
                     TfrmTemplateEditor.Resync┘ 
              TfrmTemplateEditor.btnNewClick┤   
                             EditTemplates┤ │   
     TfrmDCSumm.popSummMemoTemplateClick┤ │ │   
          TfrmDCSumm.mnuNewTemplateClick┤ │ │   
        TfrmDCSumm.mnuEditTemplatesClick┤ │ │   
  TfrmDCSumm.mnuEditSharedTemplatesClick┤ │ │   
    TfrmDCSumm.mnuNewSharedTemplateClick┤ │ │   
   TfrmConsults.popNoteMemoTemplateClick┤ │ │   
      TfrmConsults.mnuEditTemplatesClick┤ │ │   
        TfrmConsults.mnuNewTemplateClick┤ │ │   
TfrmConsults.mnuEditSharedTemplatesClick┤ │ │   
  TfrmConsults.mnuNewSharedTemplateClick┤ │ │   
       TfrmDrawers.mnuEditTemplatesClick┤ │ │   
         TfrmDrawers.mnuNewTemplateClick┤ │ │   
    TfrmSurgery.popNoteMemoTemplateClick┤ │ │   
       TfrmSurgery.mnuEditTemplatesClick┤ │ │   
         TfrmSurgery.mnuNewTemplateClick┤ │ │   
 TfrmSurgery.mnuEditSharedTemplatesClick┤ │ │   
   TfrmSurgery.mnuNewSharedTemplateClick┤ │ │   
      TfrmNotes.popNoteMemoTemplateClick┤ │ │   
         TfrmNotes.mnuEditTemplatesClick┤ │ │   
           TfrmNotes.mnuNewTemplateClick┤ │ │   
   TfrmNotes.mnuEditSharedTemplatesClick┤ │ │   
     TfrmNotes.mnuNewSharedTemplateClick┘ │ │   
        TfrmTemplateEditor.mnuAutoGenClick┤ │   
 TfrmTemplateEditor.mnuImportTemplateClick┘ │   
            TfrmTemplateEditor.sbMoveUpClick┤   
          TfrmTemplateEditor.sbMoveDownClick┤   
            TfrmTemplateEditor.sbDeleteClick┤   
     TfrmTemplateEditor.mnuNodeDeleteClick┤ │   
          TfrmTemplateEditor.tvTreeKeyDown┘ │   
           TfrmTemplateEditor.tvTreeDragDrop┤   
        TfrmTemplateEditor.sbCopyLeftClick┤ │   
       TfrmTemplateEditor.sbCopyRightClick┤ │   
      TfrmTemplateEditor.mnuNodePasteClick┘ │   
             TfrmTemplateEditor.mnuSortClick┤   
           TfrmTemplateEditor.TemplateLocked┘   
             TfrmTemplateEditor.FormCreate┘     

Calls

Name Declaration Comments
BuildNodes procedure BuildNodes(tmpl: TTemplate; Owner: TTreeNode); -
GetID function GetID(Node: TTreeNode): string; -
GetNode function GetNode(ID: string): TTreeNode; -
InSyncNode function InSyncNode(Node: TTreeNode): boolean; -
TTemplate.RemoveNode procedure RemoveNode(Node: Pointer); -

Called-By

Name Declaration Comments
TfrmTemplateEditor.cbPerHideClick procedure cbPerHideClick(Sender: TObject); -
TfrmTemplateEditor.cbShHideClick procedure cbShHideClick(Sender: TObject); -
TfrmTemplateEditor.Resync procedure Resync(const Templates: array of TTemplate); -


Source

238   procedure TdmodShared.Resync(SyncNode: TTreeNode; AllowInactive: boolean;
239                                   var EmptyCount: integer);
240   var
241     FromGet: boolean;
242     IDCount, SyncLevel, i: integer;
243     SyncExpanded: boolean;
244     //SelNode,
245     Node: TTreeNode;
246     Template: TTemplate;
247     IDSort, CurExp: TStringList;
248     SelID, TopID: string;
249     DoSel, DoTop: boolean;
250     Tree: TTreeView;
251     First: boolean;
252     TagCount: longint;
253   
254     function InSyncNode(Node: TTreeNode): boolean;
255     var
256       TmpNode: TTreeNode;
257   
258     begin
259       Result := FALSE;
260       TmpNode := Node;
261       while((not Result) and assigned(TmpNode)) do
262       begin
263         if(TmpNode = SyncNode) then
264           Result := TRUE
265         else
266           TmpNode := TmpNode.Parent;
267       end;
268     end;
269   
270     function GetID(Node: TTreeNode): string;
271     var
272       tmpl: TTemplate;
273       IDX: string;
274       
275     begin
276       inc(IDCount);
277       Result := '';
278       if(assigned(Node) and assigned(Node.Data)) then
279       begin
280         tmpl := TTemplate(Node.Data);
281         if((tmpl.ID = '') or (tmpl.ID = '0')) then
282         begin
283           if(tmpl.LastTagIndex <> FTagIndex) then
284           begin
285             tmpl.LastTagIndex := FTagIndex;
286             inc(TagCount);
287             tmpl.tag := TagCount;
288           end;
289           IDX := '<'+IntToStr(tmpl.Tag)+'>';
290         end
291         else
292           IDX := tmpl.ID;
293         if(Node <> SyncNode) and (assigned(Node.Parent)) then
294           Result := U + GetID(Node.Parent);
295         Result := IDX + Result;
296       end;
297       dec(IDCount);
298       if((not FromGet) and (IDCount = 0) and (Result <> '')) then
299         Result := IntToStr(Node.AbsoluteIndex) + U + Result;
300     end;
301   
302     function GetNode(ID: string): TTreeNode;
303     var
304       idx, i :integer;
305       TrueID, TmpStr: string;
306       TmpNode: TTreeNode;
307   
308     begin
309       Result := nil;
310       if(ID <> '') then
311       begin
312         idx := StrToIntDef(Piece(ID,U,1),0);
313         i := pos(U,ID);
314         if(i > 0) then
315         begin
316           delete(ID,1,i);
317           FromGet := TRUE;
318           try
319             TmpNode := SyncNode.GetFirstChild;
320             while ((not assigned(Result)) and (assigned(TmpNode)) and
321                    (TmpNode.Level > SyncLevel)) do
322             begin
323               if(GetID(TmpNode) = ID) then
324                 Result := TmpNode
325               else
326                 TmpNode := TmpNode.GetNext;
327             end;
328             if(not assigned(Result)) then
329             begin
330               TrueID := piece(ID,U,1);
331               TmpNode := SyncNode.GetFirstChild;
332               while ((not assigned(Result)) and (assigned(TmpNode)) and
333                      (TmpNode.Level > SyncLevel)) do
334               begin
335                 if(assigned(TmpNode.Data) and (TTemplate(TmpNode.Data).ID = TrueID)) then
336                 begin
337                   TmpStr := IntToStr(abs(idx-TmpNode.AbsoluteIndex));
338                   TmpStr := copy('000000',1,7-length(TmpStr))+TmpStr;
339                   IDSort.AddObject(TmpStr,TmpNode);
340                 end;
341                 TmpNode := TmpNode.GetNext;
342               end;
343               if(IDSort.Count > 0) then
344               begin
345                 IDSort.Sort;
346                 Result := TTreeNode(IDSort.Objects[0]);
347                 IDSort.Clear;
348               end;
349             end;
350           finally
351             FromGet := FALSE;
352           end;
353         end;
354       end;
355     end;
356   
357     procedure BuildNodes(tmpl: TTemplate; Owner: TTreeNode);
358     var
359       i: integer;
360       TmpNode: TTreeNode;
361   
362     begin
363       if(tmpl.Active or AllowInactive) then
364       begin
365         if(First) then
366         begin
367           First := FALSE;
368           TmpNode := Owner;
369         end
370         else
371         begin
372           TmpNode := Tree.Items.AddChildObject(Owner, tmpl.PrintName, tmpl);
373           TORTreeNode(TmpNode).StringData := tmpl.ID + U + tmpl.PrintName;
374           TmpNode.Cut := not tmpl.Active;
375           tmpl.AddNode(TmpNode);
376         end;
377         if(tmpl.Expanded) then
378         begin
379           for i := 0 to tmpl.Items.Count-1 do
380             BuildNodes(TTemplate(tmpl.Items[i]), TmpNode);
381         end
382         else
383         if(InEditor or (not tmpl.HideItems)) and
384            ((tmpl.Children in [tcActive, tcBoth]) or
385            (AllowInactive and (tmpl.Children = tcInactive))) then
386         begin
387           Tree.Items.AddChild(TmpNode, EmptyNodeText);
388           inc(EmptyCount);
389         end;
390       end;
391     end;
392   
393   begin
394     if(assigned(SyncNode)) then
395     begin
396       TagCount := 0;
397       inc(FTagIndex);
398       Tree := TTreeView(SyncNode.TreeView);
399       Tree.Items.BeginUpdate;
400       try
401         SyncExpanded := SyncNode.Expanded;
402         Template := TTemplate(SyncNode.Data);
403         SyncLevel := SyncNode.Level;
404         FromGet := FALSE;
405         IDCount := 0;
406         IDSort := TStringList.Create;
407         try
408         {-- Get the Current State of the tree --}
409           CurExp := TStringList.Create;
410           try
411             Node := Tree.TopItem;
412             DoTop := InSyncNode(Node);
413             if(DoTop) then
414               TopID := GetID(Node);
415   
416             Node := Tree.Selected;
417             DoSel := InSyncNode(Node);
418             if(DoSel) then
419               SelID := GetID(Node);
420   
421             Node := SyncNode.GetFirstChild;
422             while ((assigned(Node)) and (Node.Level > SyncLevel)) do
423             begin
424               if(Node.Text = EmptyNodeText) then
425                 dec(EmptyCount)
426               else
427               if(Node.Expanded) then
428                 CurExp.Add(GetID(Node));
429               if(assigned(Node.Data)) then
430                 TTemplate(Node.Data).RemoveNode(Node);
431               Node := Node.GetNext;
432             end;
433   
434           {-- Recursively Rebuild the Tree --}
435             SyncNode.DeleteChildren;
436             First := TRUE;
437             BuildNodes(Template, SyncNode);
438   
439           {-- Attempt to restore Tree to it's former State --}
440             SyncNode.Expanded := SyncExpanded;
441             for i := 0 to CurExp.Count-1 do
442             begin
443               Node := GetNode(CurExp[i]);
444               if(assigned(Node)) then
445                 Node.Expand(FALSE);
446             end;
447   
448             if(DoTop) and (TopID <> '') then
449             begin
450               Node := GetNode(TopID);
451               if(assigned(Node)) then
452                 Tree.TopItem := Node;
453             end;
454   
455             if(DoSel) and (SelID <> '') then
456             begin
457               Node := GetNode(SelID);
458               if(assigned(Node)) then
459               begin
460                 Tree.Selected := Node;
461                 Node.MakeVisible;
462               end;
463             end;
464   
465           finally
466             CurExp.Free;
467           end;
468   
469         finally
470           IDSort.Free;
471         end;
472   
473       finally
474         Tree.Items.EndUpdate;
475       end;
476     end;
477   end;