gitkrrenderer.c

Go to the documentation of this file.
00001 
00012 #define GITK_RENDERER_C
00013 #define GITKR_RENDERER_C
00014 
00015 #include "gitkrincludes.h"
00016 
00020 void gitkr_render(void) {
00021   gitk_log_intro();
00022   if(gitk_dialog_list) {
00023     GitkDialogPtr cur_context/*=gitk_context_get_current()*/;
00024     //-- let the user choose one context or just return one if there is only one
00026     cur_context=gitkr_set_context(); // select a context
00027     //-- now process that context
00028     if(cur_context) {
00029       //-- is context not yet layouted, or modified ?
00030       if(cur_context->changed) {
00031         //-- yes: layout context
00032         gitkr_dialog_generate_layout(cur_context);
00033         cur_context->changed=FALSE;
00034       }
00035       //-- display layout
00036       gitkr_dialog_output_layout(cur_context);
00037     }
00038     else { gitk_err("no context available!"); }
00039   }
00040   else { gitk_err("empty context list!"); }
00041   gitk_log_outro();
00042 }
00043 
00047 GitkDialogPtr gitkr_set_context(void) {
00048   GitkDialogPtr cur_context=NULL;
00049   //gitk_log_intro();
00050   if((cur_context=gitk_context_activate())==NULL) {
00051     cur_context=gitkr_select_context();
00052   }
00053   return(cur_context);
00054 }
00055 
00059 GitkDialogPtr gitkr_select_context(void) {
00060   GList* node;
00061   GitkDialogPtr dialog;
00062   gint i;
00063   gchar *context_name;
00064   static gchar *dialog_desc_pre=\
00065   "<?xml version=\"1.0\" ?>"\
00066   "<!DOCTYPE giml SYSTEM \"http://gitk.sourceforge.net/giml.dtd\">"\
00067   "<giml xmlns=\""GITK_NS_URL"\""\
00068   " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""\
00069   " xmlns:i18n=\""I18N_NS_URL"\""\
00070   " >"\
00071   "  <dialog>"\
00072   "    <meta>"\
00073   "      <dc:title><i18n:text>context menu</i18n:text></dc:title"\
00074   "    </meta>"\
00075   "    <widgetgroup>";
00077   static gchar *widget_desc_fmt=\
00078   "      <widget id=\"Menu%03d\" type=\"action_action\">"\
00079   "        <label>%s</label>"\
00080   "      </widget>";
00081   static gchar *dialog_desc_post=\
00082   "    </widgetgroup>"\
00083   "  </dialog>"\
00084   "</giml>";
00085   gchar *widget_desc=NULL;
00086   gchar *dialog_desc=NULL;
00087 
00088   g_assert(gitk_dialog_list!=NULL);
00089 
00090   gitk_log_intro();
00091   node=g_list_first(gitk_dialog_list);
00092   //-- iterate of contexts and build a menu which the dialog module of the renderer can display
00093   i=0;
00094   dialog_desc=strdup(dialog_desc_pre);
00095   while(node) {
00096     dialog=(GitkDialogPtr)node->data;
00097     //gitk_log1("processing node : 0x%08lx",node);
00098     //gitk_log1("dialog=0x%08lx",dialog);
00099     context_name=gitkr_cxpath_get_string(dialog,xpath_get_dialog_name,NULL);
00100     //-- length is : fmtlen+namelen+numberlen - fmtcharslen
00101     widget_desc=g_new(gchar,strlen(widget_desc_fmt)+strlen(context_name)+3-6);
00102     sprintf(widget_desc,widget_desc_fmt,i,context_name);
00103     //-- allocate new space, copy old data and append new
00104     dialog_desc=strapp(dialog_desc,widget_desc);
00105     g_free(widget_desc);
00106     free(context_name);
00107     node=g_list_next(node);
00108     i++;
00109   }
00110   dialog_desc=strapp(dialog_desc,dialog_desc_post);
00111 
00112   //-- hide and free old context selecting context
00113   if(context_selection_dialog) {
00114     gitk_dialog_hide(context_selection_dialog);
00115     gitk_dialog_free(context_selection_dialog);
00116     context_selection_dialog=NULL;
00117   }
00118   //-- init and show the new context selecting dialog
00119   if((context_selection_dialog=gitk_dialog_new_from_string(dialog_desc))) {
00120     gitk_dialog_show(context_selection_dialog,TRUE);
00121     gitk_context_set_current(context_selection_dialog);
00122   }
00123 
00124   g_free(dialog_desc);
00125 
00126   gitk_log_outro();
00127 
00128   return(context_selection_dialog);
00129 }
00130 
00137 gchar *strapp(gchar *src1,gchar *src2) {
00138   gchar *ret;
00139 
00140   g_assert(src2!=NULL);
00141 
00142   if(src1==NULL) ret=strdup(src2);
00143   else {
00144     ret=g_new(gchar,strlen(src1)+strlen(src2)-1);
00145     strcpy(ret,src1);
00146     strcat(ret,src2);
00147     g_free(src1);
00148   }
00149   return(ret);
00150 }

Generated on Thu Oct 28 10:59:12 2004 for gitk by doxygen 1.3.6