#include #include #include #include #include #include #include #include "../framework/framework.h" #include "tledit.h" #include "tledit.m" #define TLEDIT_VERSION "TLMPWORK_VERSION" "." "TLMPWORK_RELEASE" struct EDIT_NODE{ TLNODE *node; bool viewsub; EDIT_NODE(TLNODE *_node, bool _viewsub){ node = _node; viewsub = _viewsub; } }; static bool tledit_pickfile (SSTRING &path, const char *init) { path.setfrom (init); bool ret = false; DIALOG dia; dia.settype (DIATYPE_POPUP); dia.newf_str ("File path",path); dia.last_noempty(); int nof = 0; while (1){ MENU_STATUS code = dia.edit ("","",help_nil,nof); if (code == MENU_ESCAPE || code == MENU_CANCEL){ break; }else{ ret = true; break; } } return ret; } int main (int argc, char *argv[]) { glocal SSTRING status; glocal PRIVATE_MESSAGE status_update; glocal PRIVATE_MESSAGE endsplash,showsplash; int ret = (argc, argv,"tlmpwork"); xconf_error(msg); char buf[1000]; snprintf (buf,sizeof(buf)-1,MSG_U(N_USAGE,"tledit version %s\n\nUsage: tledit fichier") ,TLEDIT_VERSION); xconf_notice (buf); return main (0,NULL); glocal int argc = argc; glocal char **argv = argv; glocal PRIVATE_MESSAGE msg; (MSG_U(T_TLEDIT,"TLEDIT 1.0"),glocal.msg); layout_area1(true); //layout_area2(false); ("tledit",TLMPWORK_VERSION,TLMPWORK_RELEASE); printf (MSG_U(I_ABOUT ,"Experimental TLMP editor\n")); printf ("Jacques Gélinas jack@solucorp.qc.ca\n"); setgpl(); printf ("http://www.solucorp.qc.ca/tlmp\n"); topmenu (MSG_U(M_FILE,"File")); menuentry (1,MSG_U(M_OPEN,"Open")); menuentry (2,MSG_U(M_SAVE,"Save")); menuentry (3,MSG_U(M_SAVEAS,"Save as")); menuentry (4,MSG_U(M_CLOSE,"Close")); menuentry (99,MSG_U(M_QUIT,"Quit")); endmenu(); topmenu (MSG_U(M_OPTIONS,"Options")); menuentry (901,MSG_U(M_PREFER,"Preferences")); endmenu(); helpmenu(); endmenu(); if (id == 99){ end(); }else if (id == 1){ SSTRING path; if (tledit_pickfile (path,"")){ newdocument ((void*)path.get()); } }else if (id == 2){ dialog_sendmessage (focus[0]->docmsgs.save); }else if (id == 3){ dialog_sendmessage (focus[0]->docmsgs.saveas); }else if (id == 4){ dialog_sendmessage (focus[0]->docmsgs.close); } newbutton (1,"floppy",MSG_U(B_SAVE,"Save"),""); newbutton (2,"folder",MSG_U(B_OPEN,"Open"),""); if (id == 1){ dialog_sendmessage (focus[0]->docmsgs.save); }else if (id == 2){ SSTRING path; if (tledit_pickfile (path,"")){ newdocument ((void*)path.get()); } } fprintf (stderr,"nodocument\n"); dialog_sendmessage (glocal.showsplash); glocal TLNODE *mainnode; glocal bool viewsub; glocal PRIVATE_MESSAGE upddoc; glocal PRIVATE_MESSAGE dump; glocal PRIVATE_MESSAGE dumpdone; glocal SSTRING file; glocal FRAMEWORK_INFO *info = &info; glocal.file.setfrom ((const char *)info.data); dialog_sendmessage (glocal.endsplash); (glocal.file.get(),info); if (dialog_testmessage(glocal.info->docmsgs.save)){ glocal.mainnode->write (glocal.file.get()); glocal.status.setfromf (MSG_U(I_FILESAVE,"File %s was save") ,glocal.file.get()); dialog_sendmessage (glocal.status_update); }else if (dialog_testmessage(glocal.info->docmsgs.saveas)){ fprintf (stderr,"Saveas %s\n",glocal.file.get()); SSTRING newfile; if (tledit_pickfile (newfile,glocal.file.get())){ glocal.mainnode->write (newfile.get()); glocal.status.setfromf (MSG_R(I_FILESAVE),newfile.get()); dialog_sendmessage (glocal.status_update); } }else if (dialog_testmessage(glocal.info->docmsgs.close)){ end(); } layout_area1(false); layout_area2(true); glocal _F_FRAMEWORK *framework = this; glocal FRAMEWORK_INFO *info = &info; TLNODE node (TLNODE_TEXT,"","","",""); glocal.mainnode = &node; const char *fname = glocal.file.get(); node.read (fname); (fname,"",help_nil); setvsize (23); newf_clist(); newf_head ("a\tb"); waitfor (glocal.upddoc); waitfor (glocal.info->msgs.mayend); waitfor (glocal.info->msgs.ending); glocal _F_editrecords *editr = this; (glocal.mainnode); const char *title = node->title.get(); char buf[200]; memset (buf,'.',100); sprintf (buf+level*2+2,"%s %s",title,node->comment.get()); buf[level*2] = ' '; buf[level*2+1] = ' '; //printf ("menu :%s: :%s:\n",buf,title); glocal.editr->new_menuitem ("",buf); nobutton(); glocal.mainnode->write ("/tmp/toto.tlcc"); glocal int no = no; glocal bool viewsub = uistate.rightb != 0; dialog_sendmessage (glocal.dump); dialog_waitformessage (glocal.dumpdone); (glocal.mainnode); if (count == glocal.no){ glocal.framework->newdocument (new EDIT_NODE(node,glocal.viewsub),2); } if (glocal.framework->must_end(glocal.info->msgs)){ endedit(); } // upddoc just force a call to the functag load if (info.nbdocument==1){ DIALOG dia; SSTRING tmp; glocal.mainnode->gettext (tmp); dia.newf_textarea (NULL,tmp,70,25); int nof = 0; dia.waitfor (glocal.upddoc); dia.waitfor (glocal.dump); info.msgs.waitfor(dia); while (1){ MENU_STATUS code = dia.edit (MSG_U(T_SOURCEFILE,"Full text"),"",help_nil,nof,0); if (code == MENU_MESSAGE){ if (must_end(info.msgs)){ break; }else if (dialog_testmessage(glocal.upddoc)){ glocal.mainnode->gettext (tmp); dia.reload(); }else if (dialog_testmessage(glocal.dump)){ dia.request_dump(); } }else if (code == MENU_DUMP){ dia.save(); glocal.mainnode->replace (tmp.get(),true); dialog_sendmessage (glocal.dumpdone); } } }else{ EDIT_NODE *edit = (EDIT_NODE*)info.data; if (edit->node->nodeedit(edit->viewsub,info) != -1){ dialog_sendmessage (glocal.upddoc); } delete edit; } framesrc.newdocument((void*)NULL,2); framesrc.loop(); DIALOG dia; dia.newf_str (NULL,glocal.status,80); dia.set_lastreadonly(); dia.waitfor (glocal.status_update); int nof=0; while (true){ MENU_STATUS code = dia.edit ("","",help_nil,nof,0); if (code == MENU_MESSAGE){ dia.reload(); } } // Use to present the default splash screen when // there is no document // ... does not work DIALOG dia; char sent[100]; diagui_sendxpm("tlmp",sent); //dia.gui_passthrough (P_Icon_xpm,"%s",sent); SSTRING s; dia.waitfor (glocal.endsplash); dia.waitfor (glocal.showsplash); int nof = 0; while (1){ MENU_STATUS code = dia.edit ("","",help_nil,nof,0); if (code == MENU_MESSAGE){ if (dialog_testmessage (glocal.showsplash)){ dia.remove_all(); dia.newf_str ("c1",s); }else if (dialog_testmessage(glocal.endsplash)){ dia.remove_all(); } } } if (argc > 0){ for (int i=0; i return ret; }