[tepl] io-error-info-bars: add externally_modified()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] io-error-info-bars: add externally_modified()
- Date: Tue, 24 Mar 2020 13:15:55 +0000 (UTC)
commit a9a8ab023b3da3f64a5bf17c5738bab93b809b5d
Author: Sébastien Wilmet <swilmet gnome org>
Date: Tue Mar 24 13:47:20 2020 +0100
io-error-info-bars: add externally_modified()
Code copied from gedit, will be used there.
docs/reference/tepl-4.0-sections.txt | 1 +
tepl/tepl-io-error-info-bars.c | 45 ++++++++++++++++++++++++++++++++++++
tepl/tepl-io-error-info-bars.h | 3 +++
3 files changed, 49 insertions(+)
---
diff --git a/docs/reference/tepl-4.0-sections.txt b/docs/reference/tepl-4.0-sections.txt
index 3755f6a..f9c8a7c 100644
--- a/docs/reference/tepl-4.0-sections.txt
+++ b/docs/reference/tepl-4.0-sections.txt
@@ -293,6 +293,7 @@ TeplInfoBarClass
<FILE>io-error-info-bars</FILE>
tepl_io_error_info_bar_file_already_open
tepl_io_error_info_bar_cant_create_backup
+tepl_io_error_info_bar_externally_modified
</SECTION>
<SECTION>
diff --git a/tepl/tepl-io-error-info-bars.c b/tepl/tepl-io-error-info-bars.c
index 80f5cb9..2275a3d 100644
--- a/tepl/tepl-io-error-info-bars.c
+++ b/tepl/tepl-io-error-info-bars.c
@@ -134,3 +134,48 @@ tepl_io_error_info_bar_cant_create_backup (GFile *location,
return info_bar;
}
+
+/**
+ * tepl_io_error_info_bar_externally_modified:
+ * @location: the #GFile for which there has been an external modification.
+ * @document_modified: whether the document (e.g. the #GtkTextBuffer) has
+ * unsaved modifications.
+ *
+ * Creates a warning about @location having changed on disk. The possible
+ * actions:
+ * - Depending on @document_modified, "Reload" or "Drop changes and reload":
+ * %GTK_RESPONSE_OK.
+ * - A close button as added with gtk_info_bar_set_show_close_button().
+ *
+ * Returns: (transfer floating): the newly created #TeplInfoBar.
+ * Since: 4.6
+ */
+TeplInfoBar *
+tepl_io_error_info_bar_externally_modified (GFile *location,
+ gboolean document_modified)
+{
+ TeplInfoBar *info_bar;
+ gchar *uri;
+ gchar *primary_msg;
+ const gchar *button_text;
+
+ g_return_val_if_fail (G_IS_FILE (location), NULL);
+
+ info_bar = tepl_info_bar_new ();
+
+ uri = g_file_get_parse_name (location);
+ primary_msg = g_strdup_printf (_("The file “%s” changed on disk."), uri);
+ tepl_info_bar_add_primary_message (info_bar, primary_msg);
+ g_free (uri);
+ g_free (primary_msg);
+
+ button_text = document_modified ? _("Drop Changes and _Reload") : _("_Reload");
+ gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
+ button_text,
+ GTK_RESPONSE_OK);
+
+ gtk_info_bar_set_show_close_button (GTK_INFO_BAR (info_bar), TRUE);
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
+
+ return info_bar;
+}
diff --git a/tepl/tepl-io-error-info-bars.h b/tepl/tepl-io-error-info-bars.h
index 87ca7f5..e776ded 100644
--- a/tepl/tepl-io-error-info-bars.h
+++ b/tepl/tepl-io-error-info-bars.h
@@ -30,6 +30,9 @@ TeplInfoBar * tepl_io_error_info_bar_file_already_open (GFile *location);
TeplInfoBar * tepl_io_error_info_bar_cant_create_backup (GFile *location,
const GError *error);
+TeplInfoBar * tepl_io_error_info_bar_externally_modified (GFile *location,
+ gboolean document_modified);
+
G_END_DECLS
#endif /* TEPL_IO_ERROR_INFO_BARS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]