#include #include #include #include "../framework/framework.h" #include "component.h" #include #include "tledit.h" #include "tledit.m" #include class PROTOTYPE: public ARRAY_OBJ{ public: SSTRING type; SSTRING desc; PARAMS params; /*~PROTOBEG~ PROTOTYPE */ public: PROTOTYPE (const char *_type, const char *_desc); PROTOTYPE (void); /*~PROTOEND~ PROTOTYPE */ }; PUBLIC PROTOTYPE::PROTOTYPE(const char *_type, const char *_desc) { type.setfrom (_type); desc.setfrom (_desc); } PUBLIC PROTOTYPE::PROTOTYPE() { } class PROTOTYPES: public ARRAY{ public: /*~PROTOBEG~ PROTOTYPES */ public: PROTOTYPE *getitem (int no)const; /*~PROTOEND~ PROTOTYPES */ }; PUBLIC PROTOTYPE *PROTOTYPES::getitem(int no) const { return (PROTOTYPE*)ARRAY::getitem(no); } /* Put the group and titles for the parameter area of a prototype, functag, fhelper dialog. */ static void compedit_introparams(DIALOG &dia) { dia.gui_group (MSG_U(T_PARAMS,"Parameters")); dia.gui_label (MSG_U(F_TYPE,"Type")); dia.gui_label (MSG_U(F_NAME,"Name")); dia.gui_label (MSG_R(F_DESCRIPTION)); dia.newline(); } static void compedit_setdiaparam(DIALOG &dia, PARAM *param) { dia.newf_str (NULL,param->type); dia.newf_str (NULL,param->name,15); dia.newf_textarea (NULL,param->desc,40,3); dia.newline(); } struct TAG{ SSTRING name; SSTRING descrip; SSTRING summary; SSTRING rettype; PARAMS params; char optional; }; /* Add a parameter and fill the dialog */ static void compedit_addparam (DIALOG &dia, PARAMS ¶ms, PARAM *param) { if (params.getnb()==0){ compedit_introparams(dia); } params.add (param); compedit_setdiaparam(dia,param); } int main (int argc, char *argv[]) { glocal SSTRINGS comps; int ret = (argc,argv,"tlmpwork"); fprintf (stderr ,MSG_U(I_USAGE ,"component_edit [ --comp compfile ... ] component ...\n")); int ret = -1; if (strcmp(opt,"--comp")==0){ if (file_exist(val)){ glocal.comps.add (new SSTRING(val)); ret = 1; }else{ xconf_error (MSG_U(E_NOCOMPFILE,"No comp file %s"),val); } } return ret; return main (0,NULL); if (glocal.comps.getnb()==0){ (); glocal.comps.add (new SSTRING (path)); } (MSG_U(T_COMPEDITOR,"Component editor")); ("component_edit",TLMPWORK_VERSION,TLMPWORK_RELEASE); printf (MSG_U(I_ABOUTEDIT ,"This is used to edit TLMP component\n" "in XML format in the various .comp files\n" "of a project\n")); printf ("Jacques Gélinas jack@solucorp.qc.ca\n"); setgpl(); printf ("http://www.solucorp.qc.ca/tlmp\n"); topmenu (MSG_R(M_FILE)); menuentry (1,MSG_U(M_OPENCOMPONENT,"Open component")); menuentry (2,MSG_U(M_NEWCOMPONENT,"New component")); menuentry (3,MSG_R(M_SAVEAS)); menuentry (4,MSG_R(M_CLOSE)); menuentry (99,MSG_R(M_QUIT)); endmenu(); topmenu (MSG_U(M_SECTIONS,"Sections")); menuentry (11,MSG_U(M_EDITSECTION,"Edit section")); helpmenu(); endmenu(); if (id == 99){ end(); }else if (id == 1){ glocal SSTRINGS tb; (MSG_U(T_COMPONENTS,"Components"),"",help_nil); newf_head (MSG_U(H_COMPONENTS,"Section\tName\tType\tSummary")); settype (DIATYPE_POPUP); glocal SSTRING last_section; (glocal.comps,0); const char *section = ""; if (glocal.last_section.cmp(info.section)!=0){ section = info.section; glocal.last_section.setfrom(section); } glocal.editrecords.new_menuitemf(section ,"%s\t%s\t%s" ,name ,is_obj ? MSG_U(I_OBJECT,"Object") : MSG_U(I_FUNCTION,"Function") ,summary); glocal.tb.add (new SSTRING(name)); glocal.FRAMEWORK.newdocument((void*)glocal.tb.getitem(no)->get()); }else if (id == 2){ (MSG_U(T_DOCUMENTS,"Documents"),"",help_nil); newf_head (MSG_U(H_DOCUMENT,"Document")); settype (DIATYPE_POPUP); for (int i=0; iget(),""); } DIALOG dia; dia.settype (DIATYPE_POPUP); glocal SSTRING name; dia.newf_str (MSG_R(F_COMPONENTNAME),glocal.name); if (dia.edit (MSG_U(T_NEWCOMPONENT,"New component"),"" ,help_nil)==MENU_ACCEPT){ (glocal.comps.getitem(no)->get()); addcomponent (glocal.name.get()); skip = true; glocal.FRAMEWORK.newdocument((void*)glocal.name.get()); } }else if (id == 3){ // Saveas dialog_sendmessage (focus[0]->docmsgs.saveas); }else if (id == 4){ // Close dialog_sendmessage (focus[0]->docmsgs.close); }else if (id == 11){ // Edit section (MSG_U(T_SECTIONS,"Sections"),"",help_nil); newf_head (MSG_U(H_SECTIONS,"Section\tSummary")); setcontext (NULL); (glocal.comps); skip = true; glocal.editrecords.new_menuitem (name,summary); glocal int no = no; (glocal.comps); skip = true; if (glocal.no == 0){ DIALOG dia; dia.newf_info (MSG_U(F_SECTIONNAME,"Section name"),name); SSTRING fsummary(summary),fdescrip(descrip); dia.newf_str (MSG_R(F_SUMMARY),fsummary,60); dia.newf_textarea (MSG_R(F_DESCRIPTION),fdescrip,60,10); dia.setcontext (NULL); if (dia.edit (MSG_U(T_ONESECTION,"One section") ,"",help_nil)==MENU_ACCEPT){ setsummary (fsummary.get()); setdescription (fdescrip.get()); } } glocal.no--; } layout_area1 (true); glocal SSTRING summary; glocal SSTRING desc; glocal char is_obj; glocal const char *comp = strdup((const char *)info.data); (glocal.comps,0); if (strcmp(glocal.comp,name)==0){ glocal.summary.setfrom (summary); glocal.desc.setfrom (descrip); glocal.is_obj = is_obj ? 1 : 0; } DIALOG dia; dia.newf_info (MSG_U(F_COMPONENTNAME,"Component name"),glocal.comp); dia.newline(); dia.newf_chk ("",glocal.is_obj,MSG_U(I_ISOBJ,"The component is a class")); dia.newline(); dia.newf_str (MSG_U(F_SUMMARY,"Summary"),glocal.summary,60); dia.newline(); dia.newf_textarea (MSG_U(F_DESCRIPTION,"Description"),glocal.desc,60,10); dia.newline(); dia.setbutinfo (MENU_USR1,MSG_U(B_FUNCTAGS,"Functags"),""); dia.setbutinfo (MENU_USR2,MSG_U(B_FHELPERS,"Helpers"),""); dia.setbutinfo (MENU_USR3,MSG_U(B_PROTOTYPES,"Prototypes"),""); dia.setbutinfo (MENU_USR4,MSG_U(B_METHOD,"Methods"),""); int nof = 0; info.msgs.waitfor(dia); dia.waitfor (info.docmsgs.close); dia.waitfor (info.docmsgs.saveas); while (1){ MENU_STATUS code = dia.edit (glocal.comp,"",help_nil,nof ,MENUBUT_CANCEL|MENUBUT_ACCEPT|MENUBUT_USR1 |MENUBUT_USR2|MENUBUT_USR3|MENUBUT_USR4); if (code == MENU_CANCEL){ break; }else if (code == MENU_MESSAGE){ if (must_end(info.msgs)){ break; }else if (dialog_testmessage(info.docmsgs.close)){ break; }else if (dialog_testmessage(info.docmsgs.saveas)){ break; } }else if (code == MENU_ACCEPT){ (glocal.comps); if (strcmp(name,glocal.comp)==0){ setdescription (glocal.desc.get()); setsummary (glocal.summary.get()); setobj (glocal.is_obj != 0); } break; }else if (code == MENU_USR1 || code == MENU_USR2 || code == MENU_USR4){ glocal int editwhat; glocal int selwhat; glocal SSTRINGS tags; // Collect the list for the copy button const char *title; if (code == MENU_USR1){ glocal.editwhat = 0; glocal.selwhat = COMPWALK_SEL_FUNCTAG; title = MSG_U(T_FUNCTAGS,"Functags"); }else if (code == MENU_USR2){ glocal.editwhat = 1; glocal.selwhat = COMPWALK_SEL_FHELPER; title = MSG_U(T_FHELPERS,"Fhelpers"); }else{ glocal.editwhat = 2; glocal.selwhat = COMPWALK_SEL_METHOD; title = MSG_U(T_METHODS,"Methods"); } (title,"",help_nil); static const char *tbh[]={ MSG_U(H_FUNCTAGS,"Name\tType\tOptional\tSummary"), MSG_U(H_FHELPERS,"Name\tType\tSummary"), MSG_R(H_FHELPERS), // Same heading for methods }; newf_head (tbh[glocal.editwhat]); settype (DIATYPE_POPUP); static const char *tbadd[]={ MSG_U(I_ADDFUNCTAG,"another functag"), MSG_U(I_ADDFHELPER,"another fhelper"), MSG_U(I_ADDMETHOD,"another method"), }; addwhat (tbadd[glocal.editwhat]); glocal.tags.remove_all(); (glocal.comps,glocal.selwhat); skip = strcmp(glocal.comp,name)!=0; glocal.tags.add (new SSTRING(name)); glocal.editrecords.new_menuitemf(name,"%s\t%s\t%s" ,rettype,optional ? MSG_U(I_YES,"Yes") : "" ,summary); glocal.tags.add (new SSTRING(name)); glocal.editrecords.new_menuitemf(name,"%s\t%s" ,rettype,summary); glocal.tags.add (new SSTRING(name)); glocal.editrecords.new_menuitemf(name,"%s\t%s" ,rettype,summary); (glocal.comps,0); skip = true; if (strcmp(glocal.comp,name)==0){ if (glocal.editwhat == 0){ addfunctag (""); }else if (glocal.editwhat == 1){ addfhelper (""); }else if (glocal.editwhat == 2){ addmethod (""); } } UISTATE st; glocal.tags.insert (0,new SSTRING); editone (0,st); glocal DIALOG dia; glocal TAG tag; glocal int no = no; glocal int insert_pos; glocal.dia.setcontext (""); (glocal.comps,glocal.selwhat); skip = strcmp(name,glocal.comp)!=0; skip = no != glocal.no; if (!skip){ glocal.tag.name.setfrom (name); glocal.tag.rettype.setfrom (rettype); glocal.tag.optional = optional ? 1 : 0; glocal.dia.gui_groupfit(""); glocal.dia.newf_str (MSG_U(F_FUNCTAG,"Tag name"),glocal.tag.name,25); glocal.dia.newf_str (MSG_U(F_RETURN,"Return"),glocal.tag.rettype,25); glocal.dia.newf_chk ("",glocal.tag.optional ,MSG_U(I_OPTIONAL,"Optional")); glocal.dia.newline(); glocal.tag.summary.setfrom (summary); glocal.tag.descrip.setfrom (descrip); glocal.dia.newf_str (MSG_R(F_SUMMARY),glocal.tag.summary,70); glocal.dia.gui_dispolast (GUI_H_LEFT,5,GUI_V_TOP,1); glocal.dia.newline(); glocal.dia.newf_textarea (MSG_R(F_DESCRIPTION),glocal.tag.descrip,70,5); glocal.dia.gui_dispolast (GUI_H_LEFT,5,GUI_V_TOP,1); glocal.dia.gui_end(); glocal.dia.newline(); } skip = no != glocal.no; if (!skip){ glocal.tag.name.setfrom (name); glocal.tag.summary.setfrom (summary); glocal.tag.descrip.setfrom (descrip); glocal.tag.rettype.setfrom (rettype); glocal.dia.gui_groupfit(""); glocal.dia.newf_str (MSG_U(F_FHELPER,"Function"),glocal.tag.name,25); glocal.dia.newf_str (MSG_R(F_RETURN),glocal.tag.rettype,25); glocal.dia.newline(); glocal.dia.newf_str (MSG_R(F_SUMMARY),glocal.tag.summary,70); glocal.dia.gui_dispolast (GUI_H_LEFT,3,GUI_V_TOP,1); glocal.dia.newline(); glocal.dia.newf_textarea (MSG_R(F_DESCRIPTION),glocal.tag.descrip,70,5); glocal.dia.gui_dispolast (GUI_H_LEFT,3,GUI_V_TOP,1); glocal.dia.gui_end(); glocal.dia.newline(); } skip = no != glocal.no; if (!skip){ glocal.tag.name.setfrom (name); glocal.tag.summary.setfrom (summary); glocal.tag.descrip.setfrom (descrip); glocal.tag.rettype.setfrom (rettype); glocal.dia.gui_group(""); glocal.dia.newf_str (MSG_U(F_METHOD,"Method"),glocal.tag.name,15); glocal.dia.newf_str (MSG_R(F_RETURN),glocal.tag.rettype); glocal.dia.newline(); glocal.dia.newf_str (MSG_R(F_SUMMARY),glocal.tag.summary,70); glocal.dia.gui_dispolast (GUI_H_LEFT,3,GUI_V_TOP,1); glocal.dia.newline(); glocal.dia.newf_textarea (MSG_R(F_DESCRIPTION),glocal.tag.descrip,70,5); glocal.dia.gui_dispolast (GUI_H_LEFT,3,GUI_V_TOP,1); glocal.dia.gui_end(); glocal.dia.newline(); } PARAM *param = new PARAM(name,type,descrip); compedit_addparam (glocal.dia,glocal.tag.params,param); // Add blanks for extra parameters for (int i=glocal.tag.params.getnb(); i<3; i++){ PARAM *param = new PARAM; compedit_addparam (glocal.dia,glocal.tag.params,param); } glocal.insert_pos = glocal.dia.getnb(); glocal.dia.gui_end(); glocal.dia.gui_dispolast (GUI_H_LEFT,2,GUI_V_CENTER,1); int nof = 0; glocal.dia.setbutinfo (MENU_USR1,MSG_U(B_MOREPARAM,"More parameters"),""); glocal.dia.setbutinfo (MENU_USR2,MSG_U(B_COPY,"Copy"),""); while (1){ static const char *tbone[]={ MSG_U(T_ONEFUNCTAG,"One functag"), MSG_U(T_ONEFHELPER,"One fhelper"), MSG_U(T_ONEMETHOD,"One method"), }; MENU_STATUS code = glocal.dia.edit ( tbone[glocal.editwhat] ,"",help_nil,nof ,MENUBUT_CANCEL|MENUBUT_ACCEPT |MENUBUT_USR1|MENUBUT_USR2); if (code == MENU_CANCEL){ break; }else if (code == MENU_USR1){ glocal.dia.set_nextfield (glocal.insert_pos); glocal.insert_pos += 4; PARAM *param = new PARAM; compedit_addparam (glocal.dia,glocal.tag.params,param); glocal.dia.set_nextfield (-1); }else if (code == MENU_USR2){ glocal.dia.save(); DIALOG_MENUPOPUP menu; for (int i=0; iget()); } glocal int sel; if (menu.editmenu ("","",help_nil,glocal.sel,0)==MENU_OK){ (glocal.comps ,glocal.selwhat); skip = strcmp(glocal.comp,name)!=0; skip = no != glocal.sel; if (!skip){ glocal.tag.summary.setfrom (summary); glocal.tag.descrip.setfrom (descrip); glocal.tag.rettype.setfrom (rettype); } skip = no != glocal.sel; if (!skip){ glocal.tag.summary.setfrom (summary); glocal.tag.descrip.setfrom (descrip); glocal.tag.rettype.setfrom (rettype); } skip = no != glocal.sel; if (!skip){ glocal.tag.summary.setfrom (summary); glocal.tag.descrip.setfrom (descrip); glocal.tag.rettype.setfrom (rettype); } PARAM *p = glocal.tag.params.getitem(no); if (p == NULL){ glocal.dia.set_nextfield (glocal.insert_pos); glocal.insert_pos += 4; p = new PARAM; compedit_addparam (glocal.dia,glocal.tag.params,p); glocal.dia.set_nextfield (-1); } p->desc.setfrom (descrip); p->type.setfrom (type); p->name.setfrom (name); glocal.dia.reload(); } }else if (code == MENU_ACCEPT){ (glocal.comps ,glocal.selwhat); skip = strcmp(name,glocal.comp)!=0; if (glocal.no == no){ setname (glocal.tag.name.get()); setoptional (glocal.tag.optional != 0); setreturn (glocal.tag.rettype.get()); setsummary (glocal.tag.summary.get()); setdescription (glocal.tag.descrip.get()); setparams (glocal.tag.params); } if (glocal.no == no){ setname (glocal.tag.name.get()); setreturn (glocal.tag.rettype.get()); setsummary (glocal.tag.summary.get()); setdescription (glocal.tag.descrip.get()); setparams (glocal.tag.params); } if (glocal.no == no){ setname (glocal.tag.name.get()); setreturn (glocal.tag.rettype.get()); setsummary (glocal.tag.summary.get()); setdescription (glocal.tag.descrip.get()); setparams (glocal.tag.params); } break; } } }else if (code == MENU_USR3){ glocal PROTOTYPES protos; (MSG_U(T_PROTOTYPES,"Prototypes"),"",help_nil); newf_head (MSG_U(H_PROTOTYPES,"Return\tParameters")); settype (DIATYPE_POPUP); addwhat (MSG_U(I_ADDPROTO,"another prototype")); glocal.protos.remove_all(); (glocal.comps,COMPWALK_SEL_PROTOTYPE); skip = strcmp(name,glocal.comp)!=0; PROTOTYPE *p = new PROTOTYPE (rettype,descrip); glocal.protos.add (p); int last = glocal.protos.getnb()-1; PROTOTYPE *p = glocal.protos.getitem(last); p->params.add (new PARAM(name,type,descrip)); for (int i=0; iparams.getnb(); j++){ if (j>0) tmp.append (','); PARAM *pp = p->params.getitem(j); tmp.appendf ("%s %s",pp->type.get(),pp->name.get()); } new_menuitem (p->type.get(),tmp.get()); } (glocal.comps,0); skip = true; if (strcmp(glocal.comp,name)==0){ addprototype (); } PROTOTYPE *p = new PROTOTYPE ("",""); glocal.protos.insert (0,p); UISTATE st; editone (0,st); PROTOTYPE *p = glocal.protos.getitem(no); DIALOG dia; dia.setcontext (""); dia.newf_textarea (MSG_R(F_DESCRIPTION),p->desc,70,5); dia.newline(); dia.newf_str (MSG_R(F_RETURN),p->type,15); dia.newline(); compedit_introparams(dia); for (int i=0; iparams.getnb(); i++){ PARAM *param = p->params.getitem(i); compedit_setdiaparam(dia,param); } // Miminally 3 parameters fields for (int i=p->params.getnb(); i<3; i++){ PARAM *param = new PARAM; p->params.add(param); compedit_setdiaparam(dia,param); } int insert_pos = dia.getnb(); dia.gui_end(); dia.gui_dispolast (GUI_H_LEFT,2,GUI_V_CENTER,1); dia.setbutinfo (MENU_USR1,MSG_R(B_MOREPARAM),""); int nof = 0; while (1){ MENU_STATUS code = dia.edit ( MSG_U(T_PROTOTYPE,"One prototype"),"" ,help_nil,nof ,MENUBUT_CANCEL|MENUBUT_ACCEPT|MENUBUT_USR1); if (code == MENU_CANCEL){ break; }else if (code == MENU_USR1){ dia.set_nextfield (insert_pos); insert_pos += 4; PARAM *param = new PARAM; p->params.add(param); compedit_setdiaparam(dia,param); dia.set_nextfield (-1); }else if (code == MENU_ACCEPT){ (glocal.comps ,COMPWALK_SEL_PROTOTYPE); skip = strcmp(glocal.comp,name)!=0; PROTOTYPE *proto = glocal.protos.getitem(no); setreturn (proto->type.get()); setdescription (proto->desc.get()); setparams (proto->params); break; } } } } free ((char*)glocal.comp); for (int i=0; i return ret; }