Diff for /Amaya/amaya/templates.c between versions 1.234 and 1.235

version 1.234, 2009/06/18 12:12:31 version 1.235, 2009/06/24 15:40:40
Line 630  void giveItems (char *text, int size, st Line 630  void giveItems (char *text, int size, st
   
 #ifdef TEMPLATES  #ifdef TEMPLATES
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
     The parameter option adds an empty string
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 static char *createMenuString (const struct menuType* items, const int nbItems)  static char *createMenuString (const struct menuType* items, const int nbItems,
                                  ThotBool option)
 {  {
   char *result, *iter;    char *result, *iter;
   int   size = 0;    int   size = 0;
   int   i;    int   i;
   
   for (i=0; i < nbItems; i++)    if (option)
       size += 3;
     for (i = 0; i < nbItems; i++)
     size += 2 + strlen (items[i].label);      size += 2 + strlen (items[i].label);
   
   result = (char *) TtaGetMemory (size);    result = (char *) TtaGetMemory (size);
   iter = result;    iter = result;
   for (i=0; i < nbItems; i++)    if (option)
       {
         strcpy (iter, "B ");
         iter +=  3;
       }
     for (i = 0; i < nbItems; i++)
     {      {
       *iter = 'B';        *iter = 'B';
       ++iter;        ++iter;
   
       strcpy (iter, items[i].label);        strcpy (iter, items[i].label);
       iter += strlen (items[i].label)+1;        iter += strlen (items[i].label)+1;
     }      }
Line 784  ThotBool Template_CanInsertRepeatChild(E Line 792  ThotBool Template_CanInsertRepeatChild(E
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
   QueryStringFromMenu    QueryStringFromMenu
   Show a context menu to query a choice.    Show a context menu to query a choice.
   @param items space-separated choice list string.    The parameter items is a space-separated choice list string.
   @return The choosed item string or NULL if none.    The parameter option adds an empty string
     Return The choosed item string or NULL if none.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
 static char* QueryStringFromMenu (Document doc, char* items)  static char *QueryStringFromMenu (Document doc, char* items, ThotBool option)
 {  {
   int nbitems, size;    int              nbitems, size;
   struct menuType *itemlist;    struct menuType *itemlist;
   char *menuString;    char            *menuString;
   char *result = NULL;    char            *result = NULL;
   
   if (!TtaGetDocumentAccessMode (doc))    if (!TtaGetDocumentAccessMode (doc))
     return NULL;      return NULL;
Line 802  static char* QueryStringFromMenu (Docume Line 811  static char* QueryStringFromMenu (Docume
   if (size == 0)    if (size == 0)
     return NULL;      return NULL;
   giveItems (items, size, &itemlist, &nbitems);    giveItems (items, size, &itemlist, &nbitems);
   menuString = createMenuString (itemlist, nbitems);    menuString = createMenuString (itemlist, nbitems, option);
   TtaNewScrollPopup (BaseDialog + OptionMenu, TtaGetViewFrame (doc, 1), NULL,    TtaNewScrollPopup (BaseDialog + OptionMenu, TtaGetViewFrame (doc, 1), NULL,
                      nbitems, menuString , NULL, false, 'L');                       nbitems, menuString , NULL, false, 'L');
   TtaFreeMemory (menuString);    TtaFreeMemory (menuString);
Line 812  static char* QueryStringFromMenu (Docume Line 821  static char* QueryStringFromMenu (Docume
   TtaDestroyDialogue (BaseDialog + OptionMenu);    TtaDestroyDialogue (BaseDialog + OptionMenu);
   
   if (ReturnOption != -1)    if (ReturnOption != -1)
     result = TtaStrdup(itemlist[ReturnOption].label);      {
         if (option)
           {
             if (ReturnOption == 0)
               result = TtaStrdup(" ");
             else
               result = TtaStrdup(itemlist[ReturnOption-1].label);
           }
         else
           result = TtaStrdup(itemlist[ReturnOption].label);
       }
   
   TtaFreeMemory (itemlist);    TtaFreeMemory (itemlist);
   return result;    return result;
Line 892  ThotBool BagButtonClicked (NotifyElement Line 911  ThotBool BagButtonClicked (NotifyElement
       listtypes = Template_GetListTypes (t, bagEl);        listtypes = Template_GetListTypes (t, bagEl);
       if (listtypes)        if (listtypes)
         {          {
           result = QueryStringFromMenu (doc, listtypes);            result = QueryStringFromMenu (doc, listtypes, FALSE);
           TtaFreeMemory (listtypes);            TtaFreeMemory (listtypes);
           if (result)            if (result)
             {              {
Line 1052  ThotBool RepeatButtonClicked (NotifyElem Line 1071  ThotBool RepeatButtonClicked (NotifyElem
 #ifdef TEMPLATE_DEBUG  #ifdef TEMPLATE_DEBUG
               printf("RepeatButtonClicked : \n  > %s\n", listtypes);                printf("RepeatButtonClicked : \n  > %s\n", listtypes);
 #endif /* TEMPLATE_DEBUG */  #endif /* TEMPLATE_DEBUG */
               result = QueryStringFromMenu (doc, listtypes);                result = QueryStringFromMenu (doc, listtypes, FALSE);
               TtaFreeMemory (listtypes);                TtaFreeMemory (listtypes);
               if (result)                if (result)
                 DoReplicateUseElement (t, doc, view, el, repeatEl, result);                  DoReplicateUseElement (t, doc, view, el, repeatEl, result);
Line 1070  ThotBool RepeatButtonClicked (NotifyElem Line 1089  ThotBool RepeatButtonClicked (NotifyElem
 }  }
   
 /*----------------------------------------------------------------------  /*----------------------------------------------------------------------
     ElementIsOptional
     Return TRUE if the element is optional
     ----------------------------------------------------------------------*/
   ThotBool ElementIsOptional (Element el)
   {
     ElementType        elType;
           AttributeType    attType;
     Attribute        att;
   
     elType = TtaGetElementType (el);
     attType.AttrSSchema = elType.ElSSchema;
     attType.AttrTypeNum = Template_ATTR_types;
     att = TtaGetAttribute (el, attType);
     return (att != NULL);
   }
   
   /*----------------------------------------------------------------------
   UseButtonClicked    UseButtonClicked
   Shows a menu with all the types that can be used in a use element.    Shows a menu with all the types that can be used in a use element.
   ----------------------------------------------------------------------*/    ----------------------------------------------------------------------*/
Line 1085  ThotBool UseButtonClicked (NotifyElement Line 1121  ThotBool UseButtonClicked (NotifyElement
   Declaration     decl;    Declaration     decl;
   Element         firstEl, newEl = NULL;    Element         firstEl, newEl = NULL;
   char           *types, *listtypes = NULL, *result = NULL;    char           *types, *listtypes = NULL, *result = NULL;
   ThotBool        oldStructureChecking;    ThotBool        oldStructureChecking, option;
   
   if (!TtaGetDocumentAccessMode (doc))    if (!TtaGetDocumentAccessMode (doc))
     return TRUE;      return TRUE;
Line 1118  ThotBool UseButtonClicked (NotifyElement Line 1154  ThotBool UseButtonClicked (NotifyElement
 #ifdef TEMPLATE_DEBUG  #ifdef TEMPLATE_DEBUG
           printf("UseButtonClicked : \n  > %s\n", listtypes);            printf("UseButtonClicked : \n  > %s\n", listtypes);
 #endif /* TEMPLATE_DEBUG */  #endif /* TEMPLATE_DEBUG */
             option = ElementIsOptional(el);
           result = QueryStringFromMenu(doc, listtypes);            result = QueryStringFromMenu(doc, listtypes, option);
           if (result)            if (result)
             {              {
               decl = Template_GetDeclaration(t, result);                decl = Template_GetDeclaration(t, result);
               if (decl)                if (decl || !strcmp (result, " "))
                 {                  {
                   /* Prepare insertion.*/                    /* Prepare insertion.*/
                   oldStructureChecking = TtaGetStructureChecking (doc);                    oldStructureChecking = TtaGetStructureChecking (doc);
Line 1140  ThotBool UseButtonClicked (NotifyElement Line 1176  ThotBool UseButtonClicked (NotifyElement
                             
                   // look for the enclosing target element                    // look for the enclosing target element
                   parent = GetParentLine (el, elType.ElSSchema);                    parent = GetParentLine (el, elType.ElSSchema);
                   /* Insert */                    if (decl)
                   newEl = Template_InsertUseChildren(doc, el, decl, parent, TRUE);                      /* Insert */
                       newEl = Template_InsertUseChildren(doc, el, decl, parent, TRUE);
                     else
                       {
                       newEl = Template_GetNewSimpleTypeInstance(doc, el, decl);
                       newEl = InsertWithNotify (newEl, NULL, el, doc);
                       }
                   for (child = TtaGetFirstChild(newEl); child; TtaNextSibling(&child))                    for (child = TtaGetFirstChild(newEl); child; TtaNextSibling(&child))
                       TtaRegisterElementCreate (child, doc);                        TtaRegisterElementCreate (child, doc);
                   //TtaChangeTypeOfElement(el, doc, Template_EL_useSimple);  
                   //TtaRegisterElementTypeChange (el, Template_EL_useEl, doc);  
   
                   /* xt:currentType attribute.*/                    /* xt:currentType attribute.*/
                   SetAttributeStringValueWithUndo(el, Template_ATTR_currentType, result);                    SetAttributeStringValueWithUndo(el, Template_ATTR_currentType, result);

Removed from v.1.234  
changed lines
  Added in v.1.235


Webmaster