Constants
---------------------------------------------------------------------------- */
-// NB: when changing order of the columns also update the gtk_list_store_new() call
-// in gtk_assert_dialog_create_backtrace_list_model() function
+/*
+ NB: when changing order of the columns also update the gtk_list_store_new() call
+ in gtk_assert_dialog_create_backtrace_list_model() function
+ */
#define STACKFRAME_LEVEL_COLIDX 0
#define FUNCTION_NAME_COLIDX 1
#define SOURCE_FILE_COLIDX 2
return button;
}
-void gtk_assert_dialog_add_button (GtkAssertDialog *dlg, const gchar *label,
- const gchar *stock, gint response_id)
+GtkWidget *gtk_assert_dialog_add_button (GtkAssertDialog *dlg, const gchar *label,
+ const gchar *stock, gint response_id)
{
/* create the button */
GtkWidget *button = gtk_assert_dialog_add_button_to (NULL, label, stock, response_id);
/* add the button to the dialog's action area */
gtk_dialog_add_action_widget (GTK_DIALOG (dlg), button, response_id);
+
+ return button;
}
void gtk_assert_dialog_append_text_column (GtkWidget *treeview, const gchar *name, int index)
/* create list store */
store = gtk_list_store_new (5,
- G_TYPE_UINT, // stack frame number
- G_TYPE_STRING, // function name
- G_TYPE_STRING, // source file name
- G_TYPE_UINT, // line number
- G_TYPE_STRING); // function arguments
+ G_TYPE_UINT, /* stack frame number */
+ G_TYPE_STRING, /* function name */
+ G_TYPE_STRING, /* source file name */
+ G_TYPE_STRING, /* line number */
+ G_TYPE_STRING); /* function arguments */
/* create the tree view */
treeview = gtk_tree_view_new_with_model (GTK_TREE_MODEL(store));
g_object_unref (store);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
- // append columns
+ /* append columns */
gtk_assert_dialog_append_text_column(treeview, "#", STACKFRAME_LEVEL_COLIDX);
gtk_assert_dialog_append_text_column(treeview, "Function name", FUNCTION_NAME_COLIDX);
gtk_assert_dialog_append_text_column(treeview, "Function args", FUNCTION_ARGS_COLIDX);
GtkAssertDialog signal handlers
---------------------------------------------------------------------------- */
-#if GTK_CHECK_VERSION(2,4,0) // GtkFileChooserDialog and GtkExpander
- // are only available in GTK+ >= 2.4
+/* GtkFileChooserDialog and GtkExpander are only available in GTK+ >= 2.4 */
+#if GTK_CHECK_VERSION(2,4,0)
void gtk_assert_dialog_expander_callback (GtkWidget *widget, GtkAssertDialog *dlg)
{
- // for some reason we need to invert the return value of gtk_expander_get_expanded
- // to get the real expanded status
+ /* status is not yet updated so we need to invert it to get the new one */
gboolean expanded = !gtk_expander_get_expanded (GTK_EXPANDER(dlg->expander));
gtk_window_set_resizable (GTK_WINDOW (dlg), expanded);
FILE *fp;
filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
- msg = gtk_assert_dialog_get_message (dlg);
- backtrace = gtk_assert_dialog_get_backtrace (dlg);
-
- /* open the file and write all info inside it */
- fp = fopen (filename, "w");
- if (fp && filename)
- fprintf (fp, "ASSERT INFO:\n%s\n\nBACKTRACE:\n%s", msg, backtrace);
-
- g_free (filename);
- g_free (msg);
- g_free (backtrace);
- fclose (fp);
+ if ( filename )
+ {
+ msg = gtk_assert_dialog_get_message (dlg);
+ backtrace = gtk_assert_dialog_get_backtrace (dlg);
+
+ /* open the file and write all info inside it */
+ fp = fopen (filename, "w");
+ if (fp)
+ {
+ fprintf (fp, "ASSERT INFO:\n%s\n\nBACKTRACE:\n%s", msg, backtrace);
+ fclose (fp);
+ }
+
+ g_free (filename);
+ g_free (msg);
+ g_free (backtrace);
+ }
}
gtk_widget_destroy (dialog);
}
-#endif
+#endif /* GTK+ 2.4+ */
void gtk_assert_dialog_copy_callback (GtkWidget *widget, GtkAssertDialog *dlg)
{
g_string_free (str, TRUE);
}
+void gtk_assert_dialog_continue_callback (GtkWidget *widget, GtkAssertDialog *dlg)
+{
+ gint response =
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(dlg->shownexttime)) ?
+ GTK_ASSERT_DIALOG_CONTINUE : GTK_ASSERT_DIALOG_CONTINUE_SUPPRESSING;
+
+ gtk_dialog_response (GTK_DIALOG(dlg), response);
+}
+
/* ----------------------------------------------------------------------------
GtkAssertDialogClass implementation
GtkType gtk_assert_dialog_get_type (void)
{
static GtkType assert_dialog_type = 0;
-
+
if (!assert_dialog_type)
{
- static const GTypeInfo assert_dialog_info =
+ const GTypeInfo assert_dialog_info =
{
sizeof (GtkAssertDialogClass),
NULL, /* base_init */
void gtk_assert_dialog_init(GtkAssertDialog *dlg)
{
- GtkWidget *vbox, *hbox, *image;
+ GtkWidget *continuebtn;
- /* start the main vbox */
- gtk_widget_push_composite_child ();
- vbox = gtk_vbox_new (FALSE, 8);
- gtk_container_set_border_width (GTK_CONTAINER(vbox), 8);
- gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), vbox, TRUE, TRUE, 5);
+ {
+ GtkWidget *vbox, *hbox, *image;
+ /* start the main vbox */
+ gtk_widget_push_composite_child ();
+ vbox = gtk_vbox_new (FALSE, 8);
+ gtk_container_set_border_width (GTK_CONTAINER(vbox), 8);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), vbox, TRUE, TRUE, 5);
- /* add the icon+message hbox */
- hbox = gtk_hbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
- /* icon */
- image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
- gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 12);
+ /* add the icon+message hbox */
+ hbox = gtk_hbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
- {
- GtkWidget *vbox2, *info;
-
- /* message */
- vbox2 = gtk_vbox_new (FALSE, 0);
- gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
- info = gtk_label_new ("An assertion failed!");
- gtk_box_pack_start (GTK_BOX(vbox2), info, TRUE, TRUE, 8);
-
- /* assert message */
- dlg->message = gtk_label_new (NULL);
- gtk_label_set_selectable (GTK_LABEL (dlg->message), TRUE);
- gtk_label_set_line_wrap (GTK_LABEL (dlg->message), TRUE);
- gtk_label_set_justify (GTK_LABEL (dlg->message), GTK_JUSTIFY_LEFT);
- gtk_widget_set_size_request (GTK_WIDGET(dlg->message), 450, -1);
-
- gtk_box_pack_end (GTK_BOX(vbox2), GTK_WIDGET(dlg->message), TRUE, TRUE, 8);
- }
+ /* icon */
+ image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_DIALOG);
+ gtk_box_pack_start (GTK_BOX(hbox), image, FALSE, FALSE, 12);
- /* add the expander */
+ {
+ GtkWidget *vbox2, *info;
+
+ /* message */
+ vbox2 = gtk_vbox_new (FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0);
+ info = gtk_label_new ("An assertion failed!");
+ gtk_box_pack_start (GTK_BOX(vbox2), info, TRUE, TRUE, 8);
+
+ /* assert message */
+ dlg->message = gtk_label_new (NULL);
+ gtk_label_set_selectable (GTK_LABEL (dlg->message), TRUE);
+ gtk_label_set_line_wrap (GTK_LABEL (dlg->message), TRUE);
+ gtk_label_set_justify (GTK_LABEL (dlg->message), GTK_JUSTIFY_LEFT);
+ gtk_widget_set_size_request (GTK_WIDGET(dlg->message), 450, -1);
+
+ gtk_box_pack_end (GTK_BOX(vbox2), GTK_WIDGET(dlg->message), TRUE, TRUE, 8);
+ }
+
+ /* add the expander */
#if GTK_CHECK_VERSION(2,4,0)
- if (!gtk_check_version (2, 4, 0))
- {
- dlg->expander = gtk_expander_new_with_mnemonic ("Back_trace:");
- gtk_box_pack_start (GTK_BOX(vbox), dlg->expander, TRUE, TRUE, 0);
- g_signal_connect (GTK_EXPANDER(dlg->expander), "activate",
- G_CALLBACK(gtk_assert_dialog_expander_callback), dlg);
- }
- else
+ if (!gtk_check_version (2, 4, 0))
+ {
+ dlg->expander = gtk_expander_new_with_mnemonic ("Back_trace:");
+ gtk_box_pack_start (GTK_BOX(vbox), dlg->expander, TRUE, TRUE, 0);
+ g_signal_connect (GTK_EXPANDER(dlg->expander), "activate",
+ G_CALLBACK(gtk_assert_dialog_expander_callback), dlg);
+ }
+ else
#endif
- {
- // if GtkExpander is unavailable, then use a static frame instead
- dlg->expander = gtk_frame_new ("Back_trace:");
- gtk_box_pack_start (GTK_BOX(vbox), dlg->expander, TRUE, TRUE, 0);
+ {
+ /* if GtkExpander is unavailable, then use a static frame instead */
+ dlg->expander = gtk_frame_new ("Back_trace:");
+ gtk_box_pack_start (GTK_BOX(vbox), dlg->expander, TRUE, TRUE, 0);
+ }
}
{
g_signal_connect (button, "clicked", G_CALLBACK(gtk_assert_dialog_copy_callback), dlg);
}
- /* add the buttons */
+ /* add the checkbutton */
+ dlg->shownexttime = gtk_check_button_new_with_mnemonic("Show this _dialog the next time");
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dlg->shownexttime), TRUE);
+ gtk_box_pack_end (GTK_BOX(GTK_DIALOG(dlg)->action_area), dlg->shownexttime, FALSE, TRUE, 8);
+
+ /* add the stop button */
gtk_assert_dialog_add_button (dlg, "_Stop", GTK_STOCK_QUIT, GTK_ASSERT_DIALOG_STOP);
- gtk_assert_dialog_add_button (dlg, "_Continue", GTK_STOCK_YES, GTK_ASSERT_DIALOG_CONTINUE);
- gtk_assert_dialog_add_button (dlg, "Continue su_ppressing", GTK_STOCK_OK,
- GTK_ASSERT_DIALOG_CONTINUE_SUPPRESSING);
- gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_ASSERT_DIALOG_STOP);
+
+ /* add the continue button */
+ continuebtn = gtk_assert_dialog_add_button (dlg, "_Continue", GTK_STOCK_YES, GTK_ASSERT_DIALOG_CONTINUE);
+ gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_ASSERT_DIALOG_CONTINUE);
+ g_signal_connect (continuebtn, "clicked", G_CALLBACK(gtk_assert_dialog_continue_callback), dlg);
/* complete creation */
dlg->callback = NULL;
gchar *gtk_assert_dialog_get_backtrace (GtkAssertDialog *dlg)
{
- gchar *function, *arguments, *sourcefile;
- guint count, linenum;
+ gchar *function, *arguments, *sourcefile, *linenum;
+ guint count;
GtkTreeModel *model;
GtkTreeIter iter;
LINE_NUMBER_COLIDX, &linenum,
-1);
+ g_string_append_printf (string, "[%u] %s(%s)",
+ count, function, arguments);
if (sourcefile[0] != '\0')
- g_string_append_printf (string, "[%d] %s(%s) %s:%d\n",
- count, function, arguments,
- sourcefile, linenum);
- else
- g_string_append_printf (string, "[%d] %s(%s)\n",
- count, function, arguments);
+ g_string_append_printf (string, " %s", sourcefile);
+ if (linenum[0] != '\0')
+ g_string_append_printf (string, ":%s", linenum);
+ g_string_append (string, "\n");
g_free (function);
g_free (arguments);
g_free (sourcefile);
+ g_free (linenum);
} while (gtk_tree_model_iter_next (model, &iter));
if (gtk_check_version (2, 4, 0))
{
- // we need to immediately process the stack trace as we're not using
- // an expander since GTK does not support it
+ /* we need to immediately process the stack trace as we're not using
+ an expander since GTK does not support it */
gtk_assert_dialog_process_backtrace (assertdlg);
}
}
{
GtkTreeModel *model;
GtkTreeIter iter;
+ GString *linenum;
gint count;
g_return_if_fail (GTK_IS_ASSERT_DIALOG (dlg));
/* how many items are in the list up to now ? */
count = gtk_tree_model_iter_n_children (model, NULL);
+ linenum = g_string_new("");
+ if ( line_number != 0 )
+ g_string_printf (linenum, "%u", line_number);
+
/* add data to the list store */
gtk_list_store_append (GTK_LIST_STORE(model), &iter);
gtk_list_store_set (GTK_LIST_STORE(model), &iter,
FUNCTION_NAME_COLIDX, function,
FUNCTION_ARGS_COLIDX, arguments,
SOURCE_FILE_COLIDX, sourcefile,
- LINE_NUMBER_COLIDX, line_number,
+ LINE_NUMBER_COLIDX, linenum->str,
-1);
+
+ g_string_free (linenum, TRUE);
}
GtkWidget *gtk_assert_dialog_new(void)