Diff for /Amaya/amaya/templates.c between versions 1.102 and 1.103

version 1.102, 2007/01/24 10:14:35 version 1.103, 2007/01/26 13:15:48
Line 710  ThotBool RepeatButtonClicked (NotifyElem Line 710  ThotBool RepeatButtonClicked (NotifyElem
       char* result = QueryStringFromMenu(doc, listtypes);        char* result = QueryStringFromMenu(doc, listtypes);
       if(result)        if(result)
       {        {
         decl = GetDeclaration(t, result);          decl = Template_GetDeclaration(t, result);
         if(decl)          if(decl)
         {          {
           /* Prepare insertion.*/                      /* Prepare insertion.*/          
Line 797  ThotBool UseButtonClicked (NotifyElement Line 797  ThotBool UseButtonClicked (NotifyElement
     char* result = QueryStringFromMenu(doc, listtypes);      char* result = QueryStringFromMenu(doc, listtypes);
     if(result)      if(result)
     {      {
       decl = GetDeclaration(t, result);        decl = Template_GetDeclaration(t, result);
       if(decl)        if(decl)
       {        {
         /* Prepare insertion.*/          /* Prepare insertion.*/
Line 813  ThotBool UseButtonClicked (NotifyElement Line 813  ThotBool UseButtonClicked (NotifyElement
           TtaRegisterElementCreate(child, doc);            TtaRegisterElementCreate(child, doc);
         }          }
                   
           TtaChangeTypeOfElement(el, doc, Template_EL_useSimple);
           TtaRegisterElementTypeChange(el, Template_EL_useEl, doc);
           
         /* Finish insertion. */          /* Finish insertion. */
         TtaCloseUndoSequence(doc);          TtaCloseUndoSequence(doc);
         TtaSetStructureChecking (oldStructureChecking, doc);          TtaSetStructureChecking (oldStructureChecking, doc);
Line 840  ThotBool UseButtonClicked (NotifyElement Line 843  ThotBool UseButtonClicked (NotifyElement
 }  }
   
   
   /*----------------------------------------------------------------------
     UseSimpleButtonClicked
     ----------------------------------------------------------------------*/
   ThotBool UseSimpleButtonClicked (NotifyElement *event)
   {
   #ifdef TEMPLATES
     ElementType parentType = TtaGetElementType(TtaGetParent(event->element));
     if(parentType.ElTypeNum == Template_EL_repeat)
       return RepeatButtonClicked(event);
   #endif /* TEMPLATES */  
     return FALSE;
   }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   OptionButtonClicked    OptionButtonClicked
Line 905  void OpeningInstance (char *fileName, Do Line 918  void OpeningInstance (char *fileName, Do
 {  {
 #ifdef TEMPLATES  #ifdef TEMPLATES
   XTigerTemplate   t;    XTigerTemplate   t;
   char            *content, *ptr;    char            *content, *ptr, *begin;
   gzFile           stream;    gzFile           stream;
   char             buffer[2000];    char             buffer[2000];
   int              res;    int              res;
Line 917  void OpeningInstance (char *fileName, Do Line 930  void OpeningInstance (char *fileName, Do
       if (res >= 0)        if (res >= 0)
         {          {
           buffer[res] = EOS;            buffer[res] = EOS;
           ptr = strstr (buffer, "<?xtiger");            begin = strstr (buffer, "<?xtiger");
           if (ptr)            
             ptr = strstr (ptr, "template");            if(begin)
           if (ptr)            {
             ptr = strstr (ptr, "=");              // Search for template version
           if (ptr)              ptr = strstr (begin, "templateVersion");
             ptr = strstr (ptr, "\"");              if (ptr)
           if (ptr)                ptr = strstr (ptr, "=");
             {              if (ptr)
               // template URI                ptr = strstr (ptr, "\"");
               content = &ptr[1];              if (ptr)
               ptr = strstr (content, "\"");                {
             }                  // template URI
           if (ptr)                  content = &ptr[1];
             {                  ptr = strstr (content, "\"");
               *ptr = EOS;                }
               //Get now the template URI              if (ptr)
               DocumentMeta[doc]->template_url = TtaStrdup (content);                {
               if (Templates_Dic == NULL)                  *ptr = EOS;
                 InitializeTemplateEnvironment ();                  //Get now the template URI
               t = (XTigerTemplate) Dictionary_Get (Templates_Dic, content);                  DocumentMeta[doc]->template_version = TtaStrdup (content);
               if (!t)                  *ptr = '"';
                 {                }
                   LoadTemplate (0, content);             
                   t = (XTigerTemplate) Dictionary_Get (Templates_Dic, content);              // Search for template uri
                 }              ptr = strstr (begin, "template");
               AddUser (t);              if (ptr && ptr[8] != 'V')
             }                ptr = strstr (ptr, "=");
               if (ptr)
                 ptr = strstr (ptr, "\"");
               if (ptr)
                 {
                   // template URI
                   content = &ptr[1];
                   ptr = strstr (content, "\"");
                 }
               if (ptr)
                 {
                   *ptr = EOS;
                   //Get now the template URI
                   DocumentMeta[doc]->template_url = TtaStrdup (content);
                   if (Templates_Dic == NULL)
                     InitializeTemplateEnvironment ();
                   t = (XTigerTemplate) Dictionary_Get (Templates_Dic, content);
                   if (!t)
                     {
                       LoadTemplate (0, content);
                       t = (XTigerTemplate) Dictionary_Get (Templates_Dic, content);
                     }
                   AddUser (t);
                   *ptr = '"';
                 }
             }
         }          }
     }      }
   TtaGZClose (stream);    TtaGZClose (stream);
Line 1009  Element GetFirstTemplateParentElement(El Line 1047  Element GetFirstTemplateParentElement(El
 #endif /* TEMPLATES */  #endif /* TEMPLATES */
 }  }
   
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   TemplateElementWillBeCreated    TemplateElementWillBeCreated
   Processed when an element will be created in a template context.    Processed when an element will be created in a template context.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 ThotBool TemplateElementWillBeCreated (NotifyElement *event)  ThotBool TemplateElementWillBeCreated (NotifyElement *event)
 {  {
 #ifdef TEMPLATES    #ifdef TEMPLATES
   Element     elem = event->element;    ElementType elType = event->elementType;
   ElementType elType;    Element     parent = event->element;
   Element     parent = TtaGetParent(elem);    ElementType parentType = TtaGetElementType(parent);
     Element     ancestor;
     ElementType ancestorType;
   
   SSchema     templateSSchema = TtaGetSSchema ("Template", event->document);    SSchema     templateSSchema = TtaGetSSchema ("Template", event->document);
   
   if (templateSSchema == NULL)    if (templateSSchema == NULL)
     return FALSE; // let Thot do the job      return FALSE; // let Thot do the job
 printf("TemplateElementWillBeCreated------------- \n");    
   while (elem)    
     {    
       elType = TtaGetElementType(elem);    
 printf(" %s_%s\n", TtaGetSSchemaName(elType.ElSSchema), TtaGetElementTypeName(elType));    printf("TemplateElementWillBeCreated %s:%s\n", TtaGetSSchemaName(elType.ElSSchema), TtaGetElementTypeName(elType));
       if (elType.ElSSchema == templateSSchema)    printf("    ^^ %s:%s\n", TtaGetSSchemaName(parentType.ElSSchema), TtaGetElementTypeName(parentType));
         {    return FALSE;
           if (elem == event->element)  
             return FALSE; // do change allowed  //
           else if (elType.ElTypeNum == Template_EL_useEl ||  //  // A xt:use within a xt:repeat
                    elType.ElTypeNum == Template_EL_useSimple)  //  if((elType.ElTypeNum==Template_EL_useSimple || elType.ElTypeNum==Template_EL_useEl) && parentType.ElTypeNum==Template_EL_repeat)
             {  //  {
               return FALSE; // let Thot do the job  //      printf("    Intend to insert xt:repeat element\n");
             }  //      return !Template_CanInsertRepeatChild(parent);
           else  if (elType.ElTypeNum == Template_EL_bag)  //  }
             return FALSE; // let Thot do the job  //  else
         }  //  {
       else  //    ancestor = parent;
         elem = TtaGetParent(elem);  //    while (ancestor)
     }  //    {
   //      ancestorType = TtaGetElementType(ancestor);
   //      printf("    >> %s:%s\n", TtaGetSSchemaName(ancestorType.ElSSchema), TtaGetElementTypeName(ancestorType));
   //      if (ancestorType.ElSSchema == templateSSchema && ancestorType.ElTypeNum == Template_EL_bag)
   //      {
   //        char* types = GetAttributeStringValue(ancestor, Template_ATTR_types, NULL);
   //        ThotBool b = Template_CanInsertElementInBag(event->document, elType, types); 
   //        printf("    Intend to insert xt:bag element : %s\n", b?"TRUE":"FALSE");
   //        return !b;
   //      }
   //      ancestor = TtaGetParent(ancestor);
   //    }
   //  }
   //  // Can not insert.
   //  return TRUE;
 #endif /* TEMPLATES*/  #endif /* TEMPLATES*/
 printf ("-------------\n");  
   return FALSE;    return FALSE;
 }  }
   
Line 1055  printf ("-------------\n"); Line 1110  printf ("-------------\n");
 ThotBool TemplateElementWillBeDeleted (NotifyElement *event)  ThotBool TemplateElementWillBeDeleted (NotifyElement *event)
 {  {
   printf("TemplateElementWillBeDeleted\n");    printf("TemplateElementWillBeDeleted\n");
     
   return FALSE;    return FALSE;
 }  }
   

Removed from v.1.102  
changed lines
  Added in v.1.103


Webmaster