[tepl] io-error-info-bars: add invalid_characters()



commit ddb175d7432da7aa4bbe270ed7eed0e2a739a051
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Mar 24 14:05:52 2020 +0100

    io-error-info-bars: add invalid_characters()
    
    Copied from gedit, will be used there.

 docs/reference/tepl-4.0-sections.txt |  1 +
 tepl/tepl-io-error-info-bars.c       | 47 ++++++++++++++++++++++++++++++++++++
 tepl/tepl-io-error-info-bars.h       |  2 ++
 3 files changed, 50 insertions(+)
---
diff --git a/docs/reference/tepl-4.0-sections.txt b/docs/reference/tepl-4.0-sections.txt
index f9c8a7c..b03ca9a 100644
--- a/docs/reference/tepl-4.0-sections.txt
+++ b/docs/reference/tepl-4.0-sections.txt
@@ -294,6 +294,7 @@ TeplInfoBarClass
 tepl_io_error_info_bar_file_already_open
 tepl_io_error_info_bar_cant_create_backup
 tepl_io_error_info_bar_externally_modified
+tepl_io_error_info_bar_invalid_characters
 </SECTION>
 
 <SECTION>
diff --git a/tepl/tepl-io-error-info-bars.c b/tepl/tepl-io-error-info-bars.c
index 2275a3d..4aa9f95 100644
--- a/tepl/tepl-io-error-info-bars.c
+++ b/tepl/tepl-io-error-info-bars.c
@@ -179,3 +179,50 @@ tepl_io_error_info_bar_externally_modified (GFile    *location,
 
        return info_bar;
 }
+
+/**
+ * tepl_io_error_info_bar_invalid_characters:
+ * @location: where to save the document.
+ *
+ * For file saving, creates a warning about invalid characters that can corrupt
+ * the file. Possible actions:
+ * - Save anyway: %GTK_RESPONSE_YES.
+ * - Don't save: %GTK_RESPONSE_CANCEL.
+ *
+ * Returns: (transfer floating): the newly created #TeplInfoBar.
+ * Since: 4.6
+ */
+TeplInfoBar *
+tepl_io_error_info_bar_invalid_characters (GFile *location)
+{
+       TeplInfoBar *info_bar;
+       gchar *uri;
+       gchar *primary_msg;
+       const gchar *secondary_msg;
+
+       g_return_val_if_fail (G_IS_FILE (location), NULL);
+
+       info_bar = tepl_info_bar_new ();
+
+       gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
+                                _("S_ave Anyway"),
+                                GTK_RESPONSE_YES);
+
+       gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
+                                _("_Don’t Save"),
+                                GTK_RESPONSE_CANCEL);
+
+       gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
+
+       uri = g_file_get_parse_name (location);
+       primary_msg = g_strdup_printf (_("Some invalid characters have been detected while saving “%s”."), 
uri);
+       tepl_info_bar_add_primary_message (info_bar, primary_msg);
+       g_free (uri);
+       g_free (primary_msg);
+
+       secondary_msg = _("If you continue saving this file you can corrupt the document. "
+                         "Save anyway?");
+       tepl_info_bar_add_secondary_message (info_bar, secondary_msg);
+
+       return info_bar;
+}
diff --git a/tepl/tepl-io-error-info-bars.h b/tepl/tepl-io-error-info-bars.h
index e776ded..0bbc543 100644
--- a/tepl/tepl-io-error-info-bars.h
+++ b/tepl/tepl-io-error-info-bars.h
@@ -33,6 +33,8 @@ TeplInfoBar * tepl_io_error_info_bar_cant_create_backup               (GFile        
*location
 TeplInfoBar *  tepl_io_error_info_bar_externally_modified              (GFile    *location,
                                                                         gboolean  document_modified);
 
+TeplInfoBar *  tepl_io_error_info_bar_invalid_characters               (GFile *location);
+
 G_END_DECLS
 
 #endif /* TEPL_IO_ERROR_INFO_BARS_H */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]