Updated copyright text/header in most source files.
[geda-gaf.git] / gattrib / src / x_dialog.c
blob5a28cb99133cc4572900d7ce52120f63fd2f7f7e
1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2007 Stuart D. Brorson.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 /*------------------------------------------------------------------
21 * This file holds fcns used to display dialog boxes.
22 *------------------------------------------------------------------*/
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
28 /*------------------------------------------------------------------
29 * Includes required to run graphical widgets.
30 *------------------------------------------------------------------*/
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <gtk/gtk.h>
34 #include <gdk/gdk.h>
35 #include <gdk/gdkkeysyms.h>
37 #include <glib.h>
38 #include <glib-object.h>
41 #ifdef HAVE_STRING_H
42 #include <string.h>
43 #endif
46 #include "gtksheet_2_2.h"
47 #include "gtkitementry_2_2.h"
50 /*------------------------------------------------------------------
51 * Gattrib specific includes
52 *------------------------------------------------------------------*/
53 #include <libgeda/libgeda.h> /* geda library fcns */
54 #include "../include/struct.h" /* typdef and struct declarations */
55 #include "../include/prototype.h" /* function prototypes */
56 #include "../include/globals.h"
58 #ifdef HAVE_LIBDMALLOC
59 #include <dmalloc.h>
60 #endif
62 /* ========================================================= *
63 * new attrib dialog widgets
64 * ========================================================= */
66 /* --------------------------------------------------------- *
67 * This asks for the name of the attrib column to insert
68 * --------------------------------------------------------- */
69 void x_dialog_newattrib_get_name()
71 GtkWidget *dialog;
72 GtkWidget *label;
73 GtkWidget *attrib_entry;
74 gchar *entry_text;
76 #ifdef DEBUG
77 printf("In x_dialog_newattrib_get_name, creating windows.\n");
78 #endif
81 /* Create the dialog */
82 dialog = gtk_dialog_new_with_buttons("Add new attribute", NULL,
83 GTK_DIALOG_MODAL,
84 GTK_STOCK_OK, GTK_RESPONSE_OK,
85 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
86 NULL);
88 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
90 /* Create a text label for the dialog window */
91 label = gtk_label_new ("Enter new attribute name");
92 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label,
93 FALSE, FALSE, 0);
95 /* Create the "attrib" text entry area */
96 attrib_entry = gtk_entry_new_with_max_length(1024);
97 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), attrib_entry, TRUE, TRUE, 5);
98 gtk_widget_set_size_request (dialog, 260, 140);
100 gtk_widget_show_all(dialog);
102 switch(gtk_dialog_run(GTK_DIALOG(dialog))) {
103 case GTK_RESPONSE_OK:
104 entry_text = g_strdup( gtk_entry_get_text(GTK_ENTRY(attrib_entry)) );
106 /* Perhaps do some other checks . . . . */
107 if (entry_text != NULL) {
108 s_toplevel_add_new_attrib(entry_text);
109 g_free(entry_text);
111 break;
113 case GTK_RESPONSE_CANCEL:
114 default:
115 /* do nothing */
116 break;
119 gtk_widget_destroy(dialog);
123 /* ========================================================= *
124 * delete attrib column dialog widgets
125 * ========================================================= */
127 /* --------------------------------------------------------- *
128 * This fcn throws up the "detele foo, are you sure" dialog
129 * box. It offers two buttons: "yes" and "cancel"
130 * --------------------------------------------------------- */
131 void x_dialog_delattrib_confirm()
133 GtkWidget *dialog;
134 gint mincol, maxcol;
135 GtkSheet *sheet;
136 gint cur_page;
138 #ifdef DEBUG
139 printf("In x_dialog_delattrib_confirm, creating windows.\n");
140 #endif
142 /* First verify that exactly one column is selected. */
143 cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
144 sheet = GTK_SHEET(sheets[cur_page]);
145 if (sheet == NULL) {
146 return;
149 mincol = x_gtksheet_get_min_col(sheet);
150 maxcol = x_gtksheet_get_max_col(sheet);
151 #ifdef DEBUG
152 printf("In x_dialog_delattrib_confirm, column range selected = %d, %d\n",
153 mincol, maxcol);
154 #endif
156 if ( (mincol != maxcol) || (mincol == -1) || (maxcol == -1) ) {
157 /* Improper selection -- maybe throw up error box? */
158 return;
162 /* Create the dialog */
163 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
164 GTK_MESSAGE_QUESTION,
165 GTK_BUTTONS_YES_NO,
166 "Are you sure you want to delete this attribute?");
168 gtk_window_set_title(GTK_WINDOW(dialog), "Delete attribute");
169 switch(gtk_dialog_run(GTK_DIALOG(dialog))) {
170 case GTK_RESPONSE_YES:
171 /* call the fcn to actually delete the attrib column. */
172 s_toplevel_delete_attrib_col(); /* this fcn figures out
173 * which col to delete. */
174 break;
176 default:
177 break;
180 gtk_widget_destroy(dialog);
183 /* ========================================================= *
184 * Missing symbol file dialog boxes. *
185 * ========================================================= */
187 /* --------------------------------------------------------- *
188 * This is the "missing symbol file found on object" dialog.
189 * It offers the user the chance to close the project without
190 * saving because he read a schematic with a missing symbol file.
191 * --------------------------------------------------------- */
192 void x_dialog_missing_sym()
194 GtkWidget *label;
195 GtkWidget *dialog;
196 const char *string = "Warning! One or more components have been found with missing symbol files!\n\n"
197 "This probably happened because gattrib couldn't find your component libraries,\n"
198 "perhaps because your gafrc or gattribrc files are misconfigured.\n"
199 "Chose \"Quit\" to leave gattrib and fix the problem, or\n"
200 "\"Forward\" to continue working with gattrib.\n";
202 #ifdef DEBUG
203 printf("In x_dialog_missing_sym, creating windows.\n");
204 #endif
206 /* Create the dialog */
207 dialog = gtk_dialog_new_with_buttons("Missing symbol file found for component!", NULL,
208 GTK_DIALOG_MODAL,
209 GTK_STOCK_QUIT, GTK_RESPONSE_REJECT,
210 GTK_STOCK_GO_FORWARD, GTK_RESPONSE_ACCEPT,
211 NULL);
213 label = gtk_label_new(string);
214 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), label, FALSE, FALSE, 0);
215 gtk_widget_show(label);
217 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_REJECT);
219 switch(gtk_dialog_run(GTK_DIALOG(dialog))) {
220 case GTK_RESPONSE_ACCEPT:
221 /* Continue with the execution */
222 break;
224 default:
225 /* Terminate */
226 gattrib_quit(0);
227 break;
230 gtk_widget_destroy(dialog);
234 /* ========================================================= *
235 * Unsaved data windows
236 * ========================================================= */
238 /* --------------------------------------------------------- *
239 * This is the "Unsaved data -- are you sure you want to quit?"
240 * dialog box which is thrown up before the user quits.
241 * --------------------------------------------------------- */
242 void x_dialog_unsaved_data()
244 GtkWidget *dialog;
245 const char *string = "Warning! You have unsaved data in the spreadsheet!\n"
246 "Are you sure you want to quit?";
248 #ifdef DEBUG
249 printf("In x_dialog_unsaved_data, creating windows.\n");
250 #endif
252 /* Create the dialog */
253 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
254 GTK_MESSAGE_WARNING,
255 GTK_BUTTONS_YES_NO,
256 string);
258 gtk_window_set_title(GTK_WINDOW(dialog), "Unsaved data. Really quit?");
260 switch(gtk_dialog_run(GTK_DIALOG(dialog))) {
261 case GTK_RESPONSE_YES:
262 gattrib_quit(0);
263 break;
265 default:
266 break;
269 gtk_widget_destroy(dialog);
270 return;
274 /* ========================================================= *
275 * Unimplemented feature callback
276 * ========================================================= */
278 /* --------------------------------------------------------- *
279 * This fcn informs the user that he has chosen an
280 * unimplemented feature. It presents only an "OK" button
281 * to leave.
282 * --------------------------------------------------------- */
283 void x_dialog_unimplemented_feature()
285 GtkWidget *dialog;
286 const char *string = "Sorry -- you have chosen a feature which has net been\n"
287 "implemented yet.\n\nGattrib is an open-source program which\n"
288 "I work on as a hobby. It is still a work in progress.\n"
289 "If you wish to contribute (perhaps by implementing this\n"
290 "feature), please do so! Please send patches to gattrib\n"
291 "to Stuart Brorson: sdb@cloud9.net.\n\n"
292 "Otherwise, just hang tight -- I'll implement this feature soon!\n";
294 /* Create the dialog */
295 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
296 GTK_MESSAGE_INFO,
297 GTK_BUTTONS_OK,
298 string);
300 gtk_window_set_title(GTK_WINDOW(dialog), "Unimplemented feature!");
302 gtk_dialog_run(GTK_DIALOG(dialog));
303 gtk_widget_destroy(dialog);
308 /* ========================================================= *
309 * Exit announcment callback
310 * ========================================================= */
312 /* --------------------------------------------------------- *
313 * This fcn accepts a string and displays it. It presents
314 * only an "OK" button to close the box and exit gattrib.
315 * --------------------------------------------------------- */
316 void x_dialog_exit_announcement(gchar *string, gint return_code)
318 GtkWidget *dialog;
320 /* Create the dialog */
321 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
322 GTK_MESSAGE_WARNING,
323 GTK_BUTTONS_OK,
324 string);
326 gtk_window_set_title(GTK_WINDOW(dialog), "Attention!");
328 gtk_dialog_run(GTK_DIALOG(dialog));
329 gtk_widget_destroy(dialog);
331 gattrib_quit( GPOINTER_TO_INT(return_code) );
334 /* ========================================================= *
335 * help/about dialog widgets
336 * ========================================================= */
337 void x_dialog_about_dialog()
339 GtkWidget *dialog;
340 const char *string = "gEDA : GPL Electronic Design Automation\n\n"
341 "This is gattrib -- gEDA's attribute editor\n\n"
342 "Gattrib version: %s%s\n\n"
343 "Gattrib is written by: Stuart Brorson (sdb@cloud9.net)\n"
344 "with generous helpings of code from gschem, gnetlist, \n"
345 "and gtkextra, as well as support from the gEDA community.";
348 /* Create the dialog */
349 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL,
350 GTK_MESSAGE_INFO,
351 GTK_BUTTONS_OK,
352 string, VERSION, CUSTOM_VERSION);
354 gtk_window_set_title(GTK_WINDOW(dialog), "About...");
356 gtk_dialog_run(GTK_DIALOG(dialog));
357 gtk_widget_destroy(dialog);
360 /* ========================================================= *
361 * Get name of file for export of CSV
362 * ========================================================= */
363 /* --------------------------------------------------------- *
364 * This asks for the filename for the export file
365 * --------------------------------------------------------- */
366 void x_dialog_export_file()
368 gchar *filename;
369 GtkWidget *dialog;
371 dialog = gtk_file_chooser_dialog_new("Export CSV", NULL,
372 GTK_FILE_CHOOSER_ACTION_SAVE,
373 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
374 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
375 NULL);
377 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
379 switch(gtk_dialog_run(GTK_DIALOG(dialog))) {
380 case GTK_RESPONSE_ACCEPT:
381 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
382 if(filename != NULL) {
383 f_export_components(filename);
384 g_free(filename);
386 break;
388 default:
389 break;
392 gtk_widget_destroy(dialog);