1 /* gEDA - GPL Electronic Design Automation
2 * gattrib -- gEDA component and net attribute manipulation using spreadsheet.
3 * Copyright (C) 2003-2010 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 /*------------------------------------------------------------------*/
22 * \brief Functions used to display dialog boxes.
24 * Functions used to display dialog boxes.
33 /*------------------------------------------------------------------
34 * Includes required to run graphical widgets.
35 *------------------------------------------------------------------*/
40 #include <gdk/gdkkeysyms.h>
43 #include <glib-object.h>
51 /*------------------------------------------------------------------
52 * Gattrib specific includes
53 *------------------------------------------------------------------*/
54 #include <libgeda/libgeda.h> /* geda library fcns */
55 #include "../include/struct.h" /* typdef and struct declarations */
56 #include "../include/prototype.h" /* function prototypes */
57 #include "../include/globals.h"
59 #ifdef HAVE_LIBDMALLOC
64 /*! \brief Add new attribute dialog.
66 * This asks for the name of the attrib column to insert
67 * and then inserts the column.
69 void x_dialog_newattrib()
73 GtkWidget
*attrib_entry
;
76 /* Create the dialog */
77 dialog
= gtk_dialog_new_with_buttons("Add new attribute", NULL
,
79 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
80 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
83 gtk_dialog_set_default_response(GTK_DIALOG(dialog
), GTK_RESPONSE_OK
);
85 /* Create a text label for the dialog window */
86 label
= gtk_label_new ("Enter new attribute name");
87 gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog
)->vbox
), label
,
90 /* Create the "attrib" text entry area */
91 attrib_entry
= gtk_entry_new_with_max_length(1024);
92 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog
)->vbox
), attrib_entry
, TRUE
, TRUE
, 5);
93 gtk_widget_set_size_request (dialog
, 260, 140);
95 gtk_widget_show_all(dialog
);
97 switch(gtk_dialog_run(GTK_DIALOG(dialog
))) {
99 entry_text
= g_strdup( gtk_entry_get_text(GTK_ENTRY(attrib_entry
)) );
101 /* Perhaps do some other checks . . . . */
102 if (entry_text
!= NULL
) {
103 s_toplevel_add_new_attrib(entry_text
);
108 case GTK_RESPONSE_CANCEL
:
114 gtk_widget_destroy(dialog
);
118 /*! \brief Delete Attribute dialog
120 * This function throws up the "Delete foo, are you sure?" dialog
121 * box. It offers two buttons: "yes" and "cancel".
123 void x_dialog_delattrib()
130 /* First verify that exactly one column is selected. */
131 cur_page
= gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook
));
132 sheet
= GTK_SHEET(sheets
[cur_page
]);
137 mincol
= x_gtksheet_get_min_col(sheet
);
138 maxcol
= x_gtksheet_get_max_col(sheet
);
140 if ( (mincol
!= maxcol
) || (mincol
== -1) || (maxcol
== -1) ) {
141 /* Improper selection -- maybe throw up error box? */
145 /* Create the dialog */
146 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
147 GTK_MESSAGE_QUESTION
,
149 "Are you sure you want to delete this attribute?");
151 gtk_window_set_title(GTK_WINDOW(dialog
), "Delete attribute");
152 switch(gtk_dialog_run(GTK_DIALOG(dialog
))) {
153 case GTK_RESPONSE_YES
:
154 /* call the fcn to actually delete the attrib column. */
155 s_toplevel_delete_attrib_col(); /* this fcn figures out
156 * which col to delete. */
163 gtk_widget_destroy(dialog
);
166 /*! \brief Missing Symbol dialog
168 * This is the "missing symbol file found on object" dialog.
170 * It offers the user the chance to close the project without
171 * saving because he read a schematic with a missing symbol file.
173 void x_dialog_missing_sym()
176 const char *string
= "One or more components have been found with missing symbol files!\n\n"
177 "This probably happened because gattrib couldn't find your component libraries, "
178 "perhaps because your gafrc or gattribrc files are misconfigured.\n\n"
179 "Chose \"Quit\" to leave gattrib and fix the problem, or\n"
180 "\"Forward\" to continue working with gattrib.\n";
182 /* Create the dialog */
183 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
188 gtk_dialog_add_buttons(GTK_DIALOG(dialog
),
189 GTK_STOCK_QUIT
, GTK_RESPONSE_REJECT
,
190 GTK_STOCK_GO_FORWARD
, GTK_RESPONSE_ACCEPT
,
193 gtk_window_set_title(GTK_WINDOW(dialog
), "Missing symbol file found for component!");
194 gtk_dialog_set_default_response(GTK_DIALOG(dialog
), GTK_RESPONSE_REJECT
);
196 switch(gtk_dialog_run(GTK_DIALOG(dialog
))) {
197 case GTK_RESPONSE_ACCEPT
:
198 /* Continue with the execution */
207 gtk_widget_destroy(dialog
);
210 /*! \brief Unsaved data dialog
212 * This is the "Unsaved data -- are you sure you want to quit?" dialog
213 * box which is thrown up before the user quits.
215 void x_dialog_unsaved_data()
221 tmp
= "Save the changes before closing?";
222 str
= g_strconcat ("<big><b>", tmp
, "</b></big>", NULL
);
224 tmp
= "If you don't save, all your changes will be permanently lost.";
225 str
= g_strconcat (str
, "\n\n", tmp
, NULL
);
227 dialog
= gtk_message_dialog_new (GTK_WINDOW (window
),
229 GTK_DIALOG_DESTROY_WITH_PARENT
,
231 GTK_BUTTONS_NONE
, NULL
);
232 gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog
), str
);
233 gtk_dialog_add_buttons (GTK_DIALOG (dialog
),
234 "Close without saving", GTK_RESPONSE_NO
,
235 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
236 GTK_STOCK_SAVE
, GTK_RESPONSE_YES
,
239 /* Set the alternative button order (ok, cancel, help) for other systems */
240 gtk_dialog_set_alternative_button_order(GTK_DIALOG(dialog
),
246 gtk_dialog_set_default_response (GTK_DIALOG (dialog
), GTK_RESPONSE_YES
);
248 switch (gtk_dialog_run (GTK_DIALOG (dialog
)))
250 case GTK_RESPONSE_NO
:
255 case GTK_RESPONSE_YES
:
257 s_toplevel_gtksheet_to_toplevel(); /* Dumps sheet data into TOPLEVEL */
258 s_page_save_all(pr_current
); /* saves all pages in design */
259 sheet_head
->CHANGED
= FALSE
;
263 case GTK_RESPONSE_CANCEL
:
269 gtk_widget_destroy (dialog
);
273 /*! \brief Unimplemented feature dialog
275 * This function informs the user that he has chosen an unimplemented
276 * feature. It presents only an "OK" button to leave.
278 void x_dialog_unimplemented_feature()
281 const char *string
= "Sorry -- you have chosen a feature which has net been\n"
282 "implemented yet.\n\nGattrib is an open-source program which\n"
283 "I work on as a hobby. It is still a work in progress.\n"
284 "If you wish to contribute (perhaps by implementing this\n"
285 "feature), please do so! Please send patches to gattrib\n"
286 "to Stuart Brorson: sdb@cloud9.net.\n\n"
287 "Otherwise, just hang tight -- I'll implement this feature soon!\n";
289 /* Create the dialog */
290 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
295 gtk_window_set_title(GTK_WINDOW(dialog
), "Unimplemented feature!");
297 gtk_dialog_run(GTK_DIALOG(dialog
));
298 gtk_widget_destroy(dialog
);
301 /*! \brief Fatal error dialog
303 * This function displays a dialog with the error string and
304 * terminates the program.
306 * \param [in] string the error string
307 * \param [in] return_code the exit code
308 * \todo Is the GPOINTER_TO_INT() call needed in exit()?
310 void x_dialog_fatal_error(gchar
*string
, gint return_code
)
314 fprintf(stderr
, "%s\n", string
);
316 /* Create the dialog */
317 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
322 gtk_window_set_title(GTK_WINDOW(dialog
), "Fatal error");
324 gtk_dialog_run(GTK_DIALOG(dialog
));
325 gtk_widget_destroy(dialog
);
327 exit(GPOINTER_TO_INT(return_code
));
330 /*! \brief About gattrib dialog
332 * This dosplays the about dialog.
334 void x_dialog_about_dialog()
337 const char *string
= "gEDA : GPL Electronic Design Automation\n\n"
338 "This is gattrib -- gEDA's attribute editor\n\n"
339 "Gattrib version: %s%s.%s\n\n"
340 "Gattrib is written by: Stuart Brorson (sdb@cloud9.net)\n"
341 "with generous helpings of code from gschem, gnetlist, \n"
342 "and gtkextra, as well as support from the gEDA community.";
345 /* Create the dialog */
346 dialog
= gtk_message_dialog_new (NULL
, GTK_DIALOG_MODAL
,
349 string
, PREPEND_VERSION_STRING
,
350 PACKAGE_DOTTED_VERSION
,
351 PACKAGE_DATE_VERSION
);
353 gtk_window_set_title(GTK_WINDOW(dialog
), "About...");
355 gtk_dialog_run(GTK_DIALOG(dialog
));
356 gtk_widget_destroy(dialog
);
359 /*! \brief Export file dialog
361 * This asks for the filename for the CSV export file and then
362 * does the exporting.
364 void x_dialog_export_file()
369 dialog
= gtk_file_chooser_dialog_new("Export CSV", NULL
,
370 GTK_FILE_CHOOSER_ACTION_SAVE
,
371 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
372 GTK_STOCK_SAVE
, GTK_RESPONSE_ACCEPT
,
375 gtk_dialog_set_default_response(GTK_DIALOG(dialog
), GTK_RESPONSE_ACCEPT
);
377 switch(gtk_dialog_run(GTK_DIALOG(dialog
))) {
378 case GTK_RESPONSE_ACCEPT
:
379 filename
= gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog
));
380 if(filename
!= NULL
) {
381 f_export_components(filename
);
390 gtk_widget_destroy(dialog
);