gattrib
|
00001 /* gEDA - GPL Electronic Design Automation 00002 * gattrib -- gEDA component and net attribute manipulation using spreadsheet. 00003 * Copyright (C) 2003-2010 Stuart D. Brorson. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 /*------------------------------------------------------------------*/ 00027 #ifdef HAVE_CONFIG_H 00028 #include "config.h" 00029 #endif 00030 00031 #include <version.h> 00032 00033 /*------------------------------------------------------------------ 00034 * Includes required to run graphical widgets. 00035 *------------------------------------------------------------------*/ 00036 #include <stdio.h> 00037 #include <stdlib.h> 00038 #include <gtk/gtk.h> 00039 #include <gdk/gdk.h> 00040 #include <gdk/gdkkeysyms.h> 00041 00042 #include <glib.h> 00043 #include <glib-object.h> 00044 00045 00046 #ifdef HAVE_STRING_H 00047 #include <string.h> 00048 #endif 00049 00050 00051 /*------------------------------------------------------------------ 00052 * Gattrib specific includes 00053 *------------------------------------------------------------------*/ 00054 #include <libgeda/libgeda.h> /* geda library fcns */ 00055 #include "../include/struct.h" /* typdef and struct declarations */ 00056 #include "../include/prototype.h" /* function prototypes */ 00057 #include "../include/globals.h" 00058 00059 #ifdef HAVE_LIBDMALLOC 00060 #include <dmalloc.h> 00061 #endif 00062 00063 00069 void x_dialog_newattrib() 00070 { 00071 GtkWidget *dialog; 00072 GtkWidget *label; 00073 GtkWidget *attrib_entry; 00074 gchar *entry_text; 00075 00076 /* Create the dialog */ 00077 dialog = gtk_dialog_new_with_buttons("Add new attribute", NULL, 00078 GTK_DIALOG_MODAL, 00079 GTK_STOCK_OK, GTK_RESPONSE_OK, 00080 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 00081 NULL); 00082 00083 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); 00084 00085 /* Create a text label for the dialog window */ 00086 label = gtk_label_new ("Enter new attribute name"); 00087 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, 00088 FALSE, FALSE, 0); 00089 00090 /* Create the "attrib" text entry area */ 00091 attrib_entry = gtk_entry_new_with_max_length(1024); 00092 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), attrib_entry, TRUE, TRUE, 5); 00093 gtk_widget_set_size_request (dialog, 260, 140); 00094 00095 gtk_widget_show_all(dialog); 00096 00097 switch(gtk_dialog_run(GTK_DIALOG(dialog))) { 00098 case GTK_RESPONSE_OK: 00099 entry_text = g_strdup( gtk_entry_get_text(GTK_ENTRY(attrib_entry)) ); 00100 00101 /* Perhaps do some other checks . . . . */ 00102 if (entry_text != NULL) { 00103 s_toplevel_add_new_attrib(entry_text); 00104 g_free(entry_text); 00105 } 00106 break; 00107 00108 case GTK_RESPONSE_CANCEL: 00109 default: 00110 /* do nothing */ 00111 break; 00112 } 00113 00114 gtk_widget_destroy(dialog); 00115 } 00116 00117 00123 void x_dialog_delattrib() 00124 { 00125 GtkWidget *dialog; 00126 gint mincol, maxcol; 00127 GtkSheet *sheet; 00128 gint cur_page; 00129 00130 /* First verify that exactly one column is selected. */ 00131 cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); 00132 sheet = GTK_SHEET(sheets[cur_page]); 00133 if (sheet == NULL) { 00134 return; 00135 } 00136 00137 mincol = x_gtksheet_get_min_col(sheet); 00138 maxcol = x_gtksheet_get_max_col(sheet); 00139 00140 if ( (mincol != maxcol) || (mincol == -1) || (maxcol == -1) ) { 00141 /* Improper selection -- maybe throw up error box? */ 00142 return; 00143 } 00144 00145 /* Create the dialog */ 00146 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 00147 GTK_MESSAGE_QUESTION, 00148 GTK_BUTTONS_YES_NO, 00149 "Are you sure you want to delete this attribute?"); 00150 00151 gtk_window_set_title(GTK_WINDOW(dialog), "Delete attribute"); 00152 switch(gtk_dialog_run(GTK_DIALOG(dialog))) { 00153 case GTK_RESPONSE_YES: 00154 /* call the fcn to actually delete the attrib column. */ 00155 s_toplevel_delete_attrib_col(); /* this fcn figures out 00156 * which col to delete. */ 00157 break; 00158 00159 default: 00160 break; 00161 } 00162 00163 gtk_widget_destroy(dialog); 00164 } 00165 00173 void x_dialog_missing_sym() 00174 { 00175 GtkWidget *dialog; 00176 const char *string = "One or more components have been found with missing symbol files!\n\n" 00177 "This probably happened because gattrib couldn't find your component libraries, " 00178 "perhaps because your gafrc or gattribrc files are misconfigured.\n\n" 00179 "Chose \"Quit\" to leave gattrib and fix the problem, or\n" 00180 "\"Forward\" to continue working with gattrib.\n"; 00181 00182 /* Create the dialog */ 00183 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 00184 GTK_MESSAGE_WARNING, 00185 GTK_BUTTONS_NONE, 00186 "%s", string); 00187 00188 gtk_dialog_add_buttons(GTK_DIALOG(dialog), 00189 GTK_STOCK_QUIT, GTK_RESPONSE_REJECT, 00190 GTK_STOCK_GO_FORWARD, GTK_RESPONSE_ACCEPT, 00191 NULL); 00192 00193 gtk_window_set_title(GTK_WINDOW(dialog), "Missing symbol file found for component!"); 00194 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT); 00195 00196 switch(gtk_dialog_run(GTK_DIALOG(dialog))) { 00197 case GTK_RESPONSE_ACCEPT: 00198 /* Continue with the execution */ 00199 break; 00200 00201 default: 00202 /* Terminate */ 00203 exit(0); 00204 break; 00205 } 00206 00207 gtk_widget_destroy(dialog); 00208 } 00209 00215 void x_dialog_unsaved_data() 00216 { 00217 GtkWidget *dialog; 00218 gchar *tmp; 00219 gchar *str; 00220 00221 tmp = "Save the changes before closing?"; 00222 str = g_strconcat ("<big><b>", tmp, "</b></big>", NULL); 00223 00224 tmp = "If you don't save, all your changes will be permanently lost."; 00225 str = g_strconcat (str, "\n\n", tmp, NULL); 00226 00227 dialog = gtk_message_dialog_new (GTK_WINDOW (window), 00228 GTK_DIALOG_MODAL | 00229 GTK_DIALOG_DESTROY_WITH_PARENT, 00230 GTK_MESSAGE_WARNING, 00231 GTK_BUTTONS_NONE, NULL); 00232 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), str); 00233 gtk_dialog_add_buttons (GTK_DIALOG (dialog), 00234 "Close without saving", GTK_RESPONSE_NO, 00235 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 00236 GTK_STOCK_SAVE, GTK_RESPONSE_YES, 00237 NULL); 00238 00239 /* Set the alternative button order (ok, cancel, help) for other systems */ 00240 gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog), 00241 GTK_RESPONSE_YES, 00242 GTK_RESPONSE_NO, 00243 GTK_RESPONSE_CANCEL, 00244 -1); 00245 00246 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES); 00247 00248 switch (gtk_dialog_run (GTK_DIALOG (dialog))) 00249 { 00250 case GTK_RESPONSE_NO: 00251 { 00252 gattrib_quit(0); 00253 break; 00254 } 00255 case GTK_RESPONSE_YES: 00256 { 00257 s_toplevel_gtksheet_to_toplevel(pr_current); /* Dumps sheet data into TOPLEVEL */ 00258 s_page_save_all(pr_current); /* saves all pages in design */ 00259 sheet_head->CHANGED = FALSE; 00260 gattrib_quit(0); 00261 break; 00262 } 00263 case GTK_RESPONSE_CANCEL: 00264 default: 00265 { 00266 break; 00267 } 00268 } 00269 gtk_widget_destroy (dialog); 00270 return; 00271 } 00272 00278 void x_dialog_unimplemented_feature() 00279 { 00280 GtkWidget *dialog; 00281 const char *string = "Sorry -- you have chosen a feature which has net been\n" 00282 "implemented yet.\n\nGattrib is an open-source program which\n" 00283 "I work on as a hobby. It is still a work in progress.\n" 00284 "If you wish to contribute (perhaps by implementing this\n" 00285 "feature), please do so! Please send patches to gattrib\n" 00286 "to Stuart Brorson: sdb@cloud9.net.\n\n" 00287 "Otherwise, just hang tight -- I'll implement this feature soon!\n"; 00288 00289 /* Create the dialog */ 00290 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 00291 GTK_MESSAGE_INFO, 00292 GTK_BUTTONS_OK, 00293 "%s", string); 00294 00295 gtk_window_set_title(GTK_WINDOW(dialog), "Unimplemented feature!"); 00296 00297 gtk_dialog_run(GTK_DIALOG(dialog)); 00298 gtk_widget_destroy(dialog); 00299 } 00300 00310 void x_dialog_fatal_error(gchar *string, gint return_code) 00311 { 00312 GtkWidget *dialog; 00313 00314 fprintf(stderr, "%s\n", string); 00315 00316 /* Create the dialog */ 00317 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 00318 GTK_MESSAGE_ERROR, 00319 GTK_BUTTONS_OK, 00320 "%s", string); 00321 00322 gtk_window_set_title(GTK_WINDOW(dialog), "Fatal error"); 00323 00324 gtk_dialog_run(GTK_DIALOG(dialog)); 00325 gtk_widget_destroy(dialog); 00326 00327 exit(GPOINTER_TO_INT(return_code)); 00328 } 00329 00334 void x_dialog_about_dialog() 00335 { 00336 GtkWidget *dialog; 00337 const char *string = "gEDA : GPL Electronic Design Automation\n\n" 00338 "This is gattrib -- gEDA's attribute editor\n\n" 00339 "Gattrib version: %s%s.%s\n\n" 00340 "Gattrib is written by: Stuart Brorson (sdb@cloud9.net)\n" 00341 "with generous helpings of code from gschem, gnetlist, \n" 00342 "and gtkextra, as well as support from the gEDA community."; 00343 00344 00345 /* Create the dialog */ 00346 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, 00347 GTK_MESSAGE_INFO, 00348 GTK_BUTTONS_OK, 00349 string, PREPEND_VERSION_STRING, 00350 PACKAGE_DOTTED_VERSION, 00351 PACKAGE_DATE_VERSION); 00352 00353 gtk_window_set_title(GTK_WINDOW(dialog), "About..."); 00354 00355 gtk_dialog_run(GTK_DIALOG(dialog)); 00356 gtk_widget_destroy(dialog); 00357 } 00358 00364 void x_dialog_export_file() 00365 { 00366 gchar *filename; 00367 GtkWidget *dialog; 00368 00369 dialog = gtk_file_chooser_dialog_new("Export CSV", NULL, 00370 GTK_FILE_CHOOSER_ACTION_SAVE, 00371 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, 00372 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, 00373 NULL); 00374 00375 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); 00376 00377 switch(gtk_dialog_run(GTK_DIALOG(dialog))) { 00378 case GTK_RESPONSE_ACCEPT: 00379 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); 00380 if(filename != NULL) { 00381 f_export_components(filename); 00382 g_free(filename); 00383 } 00384 break; 00385 00386 default: 00387 break; 00388 } 00389 00390 gtk_widget_destroy(dialog); 00391 } 00392