gschem

x_script.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * gschem - gEDA Schematic Capture
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00021 #include <config.h>
00022 
00023 #include <stdio.h>
00024 #ifdef HAVE_STDLIB_H
00025 #include <stdlib.h>
00026 #endif
00027 #ifdef HAVE_STRING_H
00028 #include <string.h>
00029 #endif
00030 
00031 #include "gschem.h"
00032 
00033 #ifdef HAVE_LIBDMALLOC
00034 #include <dmalloc.h>
00035 #endif
00036 
00042 void setup_script_selector (GSCHEM_TOPLEVEL *w_current)
00043 {
00044   char *filename;
00045 
00046   w_current->sowindow =
00047     gtk_file_chooser_dialog_new (_("Execute Script..."),
00048                  GTK_WINDOW(w_current->main_window),
00049                  GTK_FILE_CHOOSER_ACTION_OPEN,
00050                  GTK_STOCK_CANCEL, 
00051                  GTK_RESPONSE_CANCEL,
00052                  GTK_STOCK_EXECUTE, 
00053                  GTK_RESPONSE_ACCEPT,
00054                  NULL);
00055 
00056   /* Set the alternative button order (ok, cancel, help) for other systems */
00057   gtk_dialog_set_alternative_button_order(GTK_DIALOG(w_current->sowindow),
00058                       GTK_RESPONSE_ACCEPT,
00059                       GTK_RESPONSE_CANCEL,
00060                       -1);
00061 
00062   if (gtk_dialog_run (GTK_DIALOG (w_current->sowindow)) == GTK_RESPONSE_ACCEPT) {
00063     filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (w_current->sowindow));
00064 
00065     if (!(g_file_test(filename, G_FILE_TEST_IS_DIR))) {
00066       s_log_message(_("Executing guile script [%s]\n"), filename);
00067       g_read_file(w_current->toplevel, filename, NULL);
00068     }
00069     g_free (filename);
00070   }
00071 
00072   gtk_widget_destroy (GTK_WIDGET(w_current->sowindow));
00073   w_current->sowindow = NULL;
00074 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines