Ensure SourceView really works with a valid file.

This commit is contained in:
Christian Dywan 2008-07-15 00:36:26 +02:00
parent 762babfeee
commit 87f5ce1c55

View file

@ -1827,18 +1827,24 @@ _action_source_view_activate (GtkAction* action,
return; return;
uri = midori_web_view_get_display_uri (MIDORI_WEB_VIEW (web_view)); uri = midori_web_view_get_display_uri (MIDORI_WEB_VIEW (web_view));
contents = NULL; contents = NULL;
tag = NULL;
#if GLIB_CHECK_VERSION (2, 16, 0) #if GLIB_CHECK_VERSION (2, 16, 0)
file = g_file_new_for_uri (uri); file = g_file_new_for_uri (uri);
contents = NULL; #ifdef HAVE_GTKSOURCEVIEW
g_file_load_contents (file, NULL, &contents, NULL, &tag, NULL); content_type = NULL;
#endif
if (g_file_load_contents (file, NULL, &contents, NULL, &tag, NULL))
{
#ifdef HAVE_GTKSOURCEVIEW #ifdef HAVE_GTKSOURCEVIEW
info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
G_FILE_QUERY_INFO_NONE, NULL, NULL); G_FILE_QUERY_INFO_NONE, NULL, NULL);
content_type = info ? g_file_info_get_content_type (info) : NULL; content_type = g_file_info_get_content_type (info);
#endif #endif
g_object_unref (file); g_object_unref (file);
}
if (contents && !g_utf8_validate (contents, -1, NULL)) if (contents && !g_utf8_validate (contents, -1, NULL))
{ {
contents_utf8 = g_convert (contents, -1, "UTF-8", "ISO-8859-1", contents_utf8 = g_convert (contents, -1, "UTF-8", "ISO-8859-1",