[tepl] Utils: add show_warning_dialog()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] Utils: add show_warning_dialog()
- Date: Fri, 20 Mar 2020 17:29:33 +0000 (UTC)
commit c956155c1c6afceb60933f72b4590ec50ed923b9
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Mar 20 18:09:43 2020 +0100
Utils: add show_warning_dialog()
Like gedit_warning() from gedit-utils.c.
docs/reference/tepl-4.0-sections.txt | 1 +
tepl/tepl-utils.c | 57 ++++++++++++++++++++++++++++++++++++
tepl/tepl-utils.h | 4 +++
3 files changed, 62 insertions(+)
---
diff --git a/docs/reference/tepl-4.0-sections.txt b/docs/reference/tepl-4.0-sections.txt
index bcc24a4..68c8ba9 100644
--- a/docs/reference/tepl-4.0-sections.txt
+++ b/docs/reference/tepl-4.0-sections.txt
@@ -393,6 +393,7 @@ tepl_utils_str_replace
tepl_utils_get_file_extension
tepl_utils_get_file_shortname
tepl_utils_replace_home_dir_with_tilde
+tepl_utils_show_warning_dialog
</SECTION>
<SECTION>
diff --git a/tepl/tepl-utils.c b/tepl/tepl-utils.c
index 7e310a1..02c2db0 100644
--- a/tepl/tepl-utils.c
+++ b/tepl/tepl-utils.c
@@ -575,3 +575,60 @@ _tepl_utils_associate_secondary_window (GtkWindow *secondary_window,
gtk_window_group_add_window (window_group, secondary_window);
}
}
+
+/**
+ * tepl_utils_show_warning_dialog:
+ * @parent: (nullable): the #GtkWindow issuing the warning.
+ * @format: format string, as with printf().
+ * @...: parameters to insert into the format string.
+ *
+ * Shows a #GtkDialog with the provided warning message.
+ *
+ * Since: 4.6
+ */
+void
+tepl_utils_show_warning_dialog (GtkWindow *parent,
+ const gchar *format,
+ ...)
+{
+ va_list args;
+ gchar *str;
+ GtkWidget *dialog;
+ GtkWindowGroup *window_group = NULL;
+
+ g_return_if_fail (format != NULL);
+
+ if (parent != NULL)
+ {
+ window_group = gtk_window_get_group (parent);
+ }
+
+ va_start (args, format);
+ str = g_strdup_vprintf (format, args);
+ va_end (args);
+
+ dialog = gtk_message_dialog_new_with_markup (parent,
+ GTK_DIALOG_MODAL |
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", str);
+
+ g_free (str);
+
+ if (window_group != NULL)
+ {
+ gtk_window_group_add_window (window_group, GTK_WINDOW (dialog));
+ }
+
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+
+ g_signal_connect (dialog,
+ "response",
+ G_CALLBACK (gtk_widget_destroy),
+ NULL);
+
+ gtk_widget_show (dialog);
+}
diff --git a/tepl/tepl-utils.h b/tepl/tepl-utils.h
index fe569ba..8440e1e 100644
--- a/tepl/tepl-utils.h
+++ b/tepl/tepl-utils.h
@@ -68,6 +68,10 @@ G_GNUC_INTERNAL
void _tepl_utils_associate_secondary_window (GtkWindow *secondary_window,
GtkWidget *main_window_widget);
+void tepl_utils_show_warning_dialog (GtkWindow *parent,
+ const gchar *format,
+ ...) G_GNUC_PRINTF(2, 3);
+
G_END_DECLS
#endif /* TEPL_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]