[gedit] Add invalid char support.



commit 33ff3bf2196729ba5e2601d08596595f281a1514
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Nov 22 19:49:54 2010 +0100

    Add invalid char support.

 gedit/gedit-document.c         |   46 ++++++++++++++++++++++++++++++++++++++++
 gedit/gedit-document.h         |    5 ++++
 tests/document-output-stream.c |   12 ++++++++++
 3 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/gedit/gedit-document.c b/gedit/gedit-document.c
index 2f5cdea..29f4590 100644
--- a/gedit/gedit-document.c
+++ b/gedit/gedit-document.c
@@ -138,6 +138,8 @@ struct _GeditDocumentPrivate
 	GeditTextRegion *to_search_region;
 	GtkTextTag      *found_tag;
 
+	GtkTextTag      *error_tag;
+
 	/* Mount operation factory */
 	GeditMountOperationFactory  mount_operation_factory;
 	gpointer		    mount_operation_userdata;
@@ -3100,4 +3102,48 @@ gedit_document_set_metadata (GeditDocument *doc,
 }
 #endif
 
+static void
+sync_error_tag (GeditDocument *doc,
+                GParamSpec    *pspec,
+                gpointer       data)
+{
+	sync_tag_style (doc, doc->priv->error_tag, "def:error");
+}
+
+void
+_gedit_document_apply_error_style (GeditDocument *doc,
+                                   GtkTextIter   *start,
+                                   GtkTextIter   *end)
+{
+	GtkTextBuffer *buffer;
+
+	gedit_debug (DEBUG_DOCUMENT);
+
+	buffer = GTK_TEXT_BUFFER (doc);
+
+	if (doc->priv->error_tag == NULL)
+	{
+		doc->priv->error_tag = gtk_text_buffer_create_tag (GTK_TEXT_BUFFER (doc),
+		                                                   "error-style",
+		                                                   NULL);
+
+		sync_error_tag (doc, NULL, NULL);
+
+		g_signal_connect (doc,
+		                  "notify::style-scheme",
+		                  G_CALLBACK (sync_error_tag),
+		                  NULL);
+	}
+
+	/* make sure the 'error' tag has the priority over
+	 * syntax highlighting tags */
+	text_tag_set_highest_priority (doc->priv->error_tag,
+	                               GTK_TEXT_BUFFER (doc));
+
+	gtk_text_buffer_apply_tag (buffer,
+	                           doc->priv->error_tag,
+	                           start,
+	                           end);
+}
+
 /* ex:set ts=8 noet: */
diff --git a/gedit/gedit-document.h b/gedit/gedit-document.h
index dcbb5bc..498c4f2 100644
--- a/gedit/gedit-document.h
+++ b/gedit/gedit-document.h
@@ -323,6 +323,11 @@ void		 _gedit_document_set_readonly 	(GeditDocument       *doc,
 glong		 _gedit_document_get_seconds_since_last_save_or_load 
 						(GeditDocument       *doc);
 
+void		 _gedit_document_apply_error_style
+                                                (GeditDocument *doc,
+                                                 GtkTextIter   *start,
+                                                 GtkTextIter   *end);
+
 /* Note: this is a sync stat: use only on local files */
 gboolean	_gedit_document_check_externally_modified
 						(GeditDocument       *doc);
diff --git a/tests/document-output-stream.c b/tests/document-output-stream.c
index 591a434..b58ec0c 100644
--- a/tests/document-output-stream.c
+++ b/tests/document-output-stream.c
@@ -152,6 +152,17 @@ test_boundary ()
 	g_object_unref (out);
 }
 
+static void
+test_invalid_utf8 ()
+{
+	test_consecutive_write ("foobar\n\xef\xbf\xbe", "foobar\n\\EF\\BF\\BE", 10,
+	                        GEDIT_DOCUMENT_NEWLINE_TYPE_LF);
+	test_consecutive_write ("foobar\n\xef\xbf\xbezzzzzz\n", "foobar\n\\EF\\BF\\BEzzzzzz", 10,
+	                        GEDIT_DOCUMENT_NEWLINE_TYPE_LF);
+	test_consecutive_write ("\xef\xbf\xbezzzzzz\n", "\\EF\\BF\\BEzzzzzz", 10,
+	                        GEDIT_DOCUMENT_NEWLINE_TYPE_LF);
+}
+
 /* SMART CONVERSION */
 
 #define TEXT_TO_CONVERT "this is some text to make the tests"
@@ -395,6 +406,7 @@ int main (int   argc,
 	g_test_add_func ("/document-output-stream/consecutive_tnewline", test_consecutive_tnewline);
 	g_test_add_func ("/document-output-stream/big-char", test_big_char);
 	g_test_add_func ("/document-output-stream/test-boundary", test_boundary);
+	g_test_add_func ("/document-output-stream/test-invalid-utf8", test_invalid_utf8);
 
 	g_test_add_func ("/document-output-stream/smart conversion: utf8-utf8", test_utf8_utf8);
 	g_test_add_func ("/document-output-stream/smart conversion: guessed", test_guessed);



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