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 *------------------------------------------------------------------*/
28 /*------------------------------------------------------------------
29 * Includes required to run graphical widgets.
30 *------------------------------------------------------------------*/
35 #include <gdk/gdkkeysyms.h>
38 #include <glib-object.h>
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
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()
73 GtkWidget
*attrib_entry
;
77 printf("In x_dialog_newattrib_get_name, creating windows.\n");
81 /* Create the dialog */
82 dialog
= gtk_dialog_new_with_buttons("Add new attribute", NULL
,
84 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
85 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
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
,
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
);
113 case GTK_RESPONSE_CANCEL
:
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()
139 printf("In x_dialog_delattrib_confirm, creating windows.\n");
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
]);
149 mincol
= x_gtksheet_get_min_col(sheet
);
150 maxcol
= x_gtksheet_get_max_col(sheet
);
152 printf("In x_dialog_delattrib_confirm, column range selected = %d, %d\n",
156 if ( (mincol
!= maxcol
) || (mincol
== -1) || (maxcol
== -1) ) {
157 /* Improper selection -- maybe throw up error box? */
162 /* Create the dialog */
163 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
164 GTK_MESSAGE_QUESTION
,
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. */
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()
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";
203 printf("In x_dialog_missing_sym, creating windows.\n");
206 /* Create the dialog */
207 dialog
= gtk_dialog_new_with_buttons("Missing symbol file found for component!", NULL
,
209 GTK_STOCK_QUIT
, GTK_RESPONSE_REJECT
,
210 GTK_STOCK_GO_FORWARD
, GTK_RESPONSE_ACCEPT
,
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 */
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()
245 const char *string
= "Warning! You have unsaved data in the spreadsheet!\n"
246 "Are you sure you want to quit?";
249 printf("In x_dialog_unsaved_data, creating windows.\n");
252 /* Create the dialog */
253 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
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
:
269 gtk_widget_destroy(dialog
);
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
282 * --------------------------------------------------------- */
283 void x_dialog_unimplemented_feature()
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
,
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
)
320 /* Create the dialog */
321 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
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()
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
,
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()
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
,
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
);
392 gtk_widget_destroy(dialog
);