[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-cvs: CVS update: g_funcs.nw



  User: danmc   
  Date: 06/05/16 18:31:02

  Modified:    .        g_funcs.nw g_register.nw x_dialog.nw
  Log:
  Add a (gschem-filesel) guile function which gives a generic file open
  
  and save as dialog box.  Add some placeholder code to the pcb major
  
  mode showing how this routine is used.  While here update the pcb
  
  major mode TODO list a bit.
  
  
  
  
  Revision  Changes    Path
  1.11      +63 -1     eda/geda/devel/gschem/noweb/g_funcs.nw
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: g_funcs.nw
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/g_funcs.nw,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- g_funcs.nw	25 Apr 2006 22:26:56 -0000	1.10
  +++ g_funcs.nw	16 May 2006 22:31:01 -0000	1.11
  @@ -1,5 +1,5 @@
   @c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-
  -@c $Id: g_funcs.nw,v 1.10 2006/04/25 22:26:56 danmc Exp $
  +@c $Id: g_funcs.nw,v 1.11 2006/05/16 22:31:01 danmc Exp $
   
   @node File g_funcs.c,,,Top
   @chapter File @file{g_funcs.c}
  @@ -18,6 +18,7 @@
   <<g_funcs.c : g_funcs_log()>>
   <<g_funcs.c : g_funcs_msg()>>
   <<g_funcs.c : g_funcs_confirm()>>
  +<<g_funcs.c : g_funcs_filesel()>>
   <<g_funcs.c : g_funcs_use_rc_values()>>
   <<g_funcs.c : g_funcs_key_name()>>
   <<g_funcs.c : g_funcs_key_value()>>
  @@ -71,6 +72,7 @@
   
   #include "../include/globals.h"
   #include "../include/prototype.h"
  +#include "../include/x_dialog.h"
   
   #ifdef HAVE_LIBDMALLOC
   #include <dmalloc.h>
  @@ -206,6 +208,66 @@
   
   @ %def g_funcs_confirm
   
  +@section Function @code{g_funcs_filesel()}
  +
  +@defun g_funcs_filesel message
  +@end defun
  +
  +<<g_funcs.c : g_funcs_filesel()>>=
  +SCM g_funcs_filesel(SCM msg, SCM templ, SCM flags)
  +{
  +  int c_flags;
  +  char * r;
  +  SCM v;
  +
  +  SCM_ASSERT (SCM_NIMP (msg) && SCM_STRINGP (msg), msg,
  +	      SCM_ARG1, "gschem-filesel");
  +  
  +  SCM_ASSERT (SCM_NIMP (templ) && SCM_STRINGP (templ), templ,
  +	      SCM_ARG1, "gschem-filesel");
  +  
  +  /* FIXME -- figure out the magic SCM_ASSERT for the flags */
  +
  +  /* 
  +   * FIXME -- how to deal with conflicting flags? 
  +   * Should I throw a scheme error?  Just deal in the c code?
  +   */
  +  for (c_flags = 0; scm_pair_p (flags) == SCM_BOOL_T; flags = SCM_CDR (flags)) {
  +    SCM f = SCM_CAR (flags);
  +    if (strcmp (SCM_STRING_CHARS (f), "may_exist") == 0) {
  +      c_flags |= FSB_MAY_EXIST;
  +
  +    } else if (strcmp (SCM_STRING_CHARS (f), "must_exist") == 0) {
  +      c_flags |= FSB_MUST_EXIST;
  +      
  +    } else if (strcmp (SCM_STRING_CHARS (f), "must_not_exist") == 0) {
  +      c_flags |= FSB_SHOULD_NOT_EXIST;
  +
  +    } else if (strcmp (SCM_STRING_CHARS (f), "save") == 0) {
  +      c_flags |= FSB_SAVE;
  +
  +    } else if (strcmp (SCM_STRING_CHARS (f), "open") == 0) {
  +      c_flags |= FSB_LOAD;
  +
  +    } else {
  +      scm_wrong_type_arg ("gschem-filesel", 1, f);
  +    }
  +  }
  +
  +  r = generic_filesel_dialog (SCM_STRING_CHARS (msg),
  +			      SCM_STRING_CHARS (templ),
  +			      c_flags
  +			      );
  +
  +  v = scm_makfrom0str (r);
  +  g_free (r);
  +
  +  return v;
  +}
  +
  +
  +@ %def g_funcs_filesel
  +
   
   @section Function @code{g_funcs_use_rc_values()}
   
  
  
  
  1.32      +4 -2      eda/geda/devel/gschem/noweb/g_register.nw
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: g_register.nw
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/g_register.nw,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -b -r1.31 -r1.32
  --- g_register.nw	25 Apr 2006 22:26:56 -0000	1.31
  +++ g_register.nw	16 May 2006 22:31:01 -0000	1.32
  @@ -1,6 +1,6 @@
   @c -*- mode: Noweb; noweb-doc-mode: texinfo-mode; noweb-code-mode: c-mode -*-
   @c 
  -@c $Id: g_register.nw,v 1.31 2006/04/25 22:26:56 danmc Exp $
  +@c $Id: g_register.nw,v 1.32 2006/05/16 22:31:01 danmc Exp $
   @c
   
   @node File g_register.c,,,Top
  @@ -190,6 +190,8 @@
     { "gschem-log",                1, 0, 0, g_funcs_log },
     { "gschem-msg",                1, 0, 0, g_funcs_msg },
     { "gschem-confirm",            1, 0, 0, g_funcs_confirm },
  +  { "gschem-filesel",            2, 0, 1, g_funcs_filesel },
  +
     /* keymapping callbacks */
     { "file-new-window",           0, 0, 0, g_keys_file_new_window },
     { "file-new",                  0, 0, 0, g_keys_file_new },
  
  
  
  1.41      +100 -2    eda/geda/devel/gschem/noweb/x_dialog.nw
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: x_dialog.nw
  ===================================================================
  RCS file: /home/cvspsrv/cvsroot/eda/geda/devel/gschem/noweb/x_dialog.nw,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -b -r1.40 -r1.41
  --- x_dialog.nw	25 Apr 2006 22:26:56 -0000	1.40
  +++ x_dialog.nw	16 May 2006 22:31:01 -0000	1.41
  @@ -132,14 +132,18 @@
   <<x_dialog.c : x_dialog_raise_all()>>
   /*********** End of misc support functions for dialog boxes *******/
   
  -/***************** Start of generic message dialog box ********************/
  +/***************** Start of generic message dialog box *******************/
   <<x_dialog.c : generic_msg_dialog()>>
   /***************** End of generic message dialog box *********************/
   
  -/***************** Start of generic confirm dialog box ********************/
  +/***************** Start of generic confirm dialog box *******************/
   <<x_dialog.c : generic_confirm_dialog()>>
   /***************** End of generic confirm dialog box *********************/
   
  +/***************** Start of generic file select dialog box ***************/
  +<<x_dialog.c : generic_filesel_dialog()>>
  +/***************** End of generic file select dialog box *****************/
  +
   /*********** Start of generic text input dialog box *******/
   <<x_dialog.c : generic_text_input_ok()>>
   <<x_dialog.c : generic_text_input_dialog()>>
  @@ -226,6 +230,7 @@
   #include "../include/i_vars.h"
   #include "../include/globals.h"
   #include "../include/prototype.h"
  +#include "../include/x_dialog.h"
   
   #ifdef HAVE_LIBDMALLOC
   #include <dmalloc.h>
  @@ -4111,6 +4116,99 @@
   
   @ %def generic_confirm_dialog
   
  +@defun generic_filesel_dialog const char *
  +@end defun
  +
  +<<x_dialog.c : generic_filesel_dialog()>>=
  +/* Caller should free result */
  +
  +char *
  +generic_filesel_dialog (const char *msg, const char *templ, gint flags)
  +{
  +  GtkWidget *dialog;
  +  gchar *result = NULL, *folder, *seed;
  +  char *title;
  +  static gchar *path = NULL;
  +  static gchar *shortcuts = NULL;
  +
  +  /* Default to load if not specified.  Maybe this should cause an error. */ 
  +  if (! (flags & (FSB_LOAD | FSB_SAVE))) {
  +    flags = flags | FSB_LOAD;
  +  }
  +
  +  if (flags & FSB_LOAD) {
  +    title = g_strdup_printf("%s: Open", msg);
  +    dialog = gtk_file_chooser_dialog_new (title,
  +					  NULL,
  +					  GTK_FILE_CHOOSER_ACTION_OPEN,
  +					  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  +					  GTK_STOCK_OPEN, GTK_RESPONSE_OK,
  +					  NULL);
  +    /* Since this is a load dialog box, the file must exist! */
  +    flags = flags | FSB_MUST_EXIST;
  +
  +  } else {
  +    title = g_strdup_printf("%s: Save", msg);
  +    dialog = gtk_file_chooser_dialog_new (title,
  +					  NULL,
  +					  GTK_FILE_CHOOSER_ACTION_SAVE,
  +					  GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
  +					  GTK_STOCK_OPEN, GTK_RESPONSE_OK,
  +					  NULL);
  +  }
  +
  +  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
  +
  +  /* Pick the current default folder to look for files in */
  +  if (path && *path) {
  +    gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), path);
  +  }
  +
  +
  +  /* Pick the current template (*.rc) or default file name */
  +  if (templ && *templ) {
  +    if (flags & FSB_SAVE)  {
  +      gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), templ);
  +    } else {
  +      gtk_file_chooser_select_filename (GTK_FILE_CHOOSER (dialog), templ);
  +    }
  +  }
  +
  +  
  +  if (shortcuts && *shortcuts) {
  +    printf ("shortcuts = \"%s\"\n", shortcuts);
  +    folder = g_strdup (shortcuts);
  +    seed = folder;
  +    while ((folder = strtok (seed, ":")) != NULL) {
  +      gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog),
  +					    folder, NULL);
  +      seed = NULL;
  +    }
  +  
  +    g_free (folder);
  +  }
  +
  +  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
  +    result = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  +    folder = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
  +    /* FIXME
  +    if (folder && path) {
  +      dup_string (path, folder);
  +      g_free (folder);
  +    }
  +    */
  +  }
  +  gtk_widget_destroy (dialog);
  +
  +  g_free (title);
  +
  +  return result;
  +
  +}
  +
  +
  +@ %def generic_filesel_dialog
  +
   
   
   @section Function @code{ generic_text_input_ok()}