From: Christian Dywan Date: Sun, 13 Jul 2008 21:21:46 +0000 (+0200) Subject: Use GtkSourceView2 if available X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=103df3d8cc1a57e604752aa232a52b0510c51fc7;p=midori Use GtkSourceView2 if available --- diff --git a/configure.in b/configure.in index 17ad974c..b00a35ad 100644 --- a/configure.in +++ b/configure.in @@ -40,9 +40,6 @@ fi # Checks for GIO2 PKG_CHECK_MODULES(GIO, gio-2.0 >= 2.16, have_gio=true, have_gio=false) -if test "x${have_gio}" = "xfalse" ; then - AC_MSG_ERROR([No GIO2 package information found]) -fi AC_SUBST(GIO_CFLAGS) AC_SUBST(GIO_LIBS) @@ -54,14 +51,6 @@ fi AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) -# Checks for WebKit -PKG_CHECK_MODULES(WEBKIT, webkit-1.0, have_webkit=true, have_webkit=false) -if test "x${have_webkit}" = "xfalse" ; then - AC_MSG_ERROR([No WebKit package information found]) -fi -AC_SUBST(WEBKIT_CFLAGS) -AC_SUBST(WEBKIT_LIBS) - # Checks for libsexy PKG_CHECK_MODULES(LIBSEXY, libsexy, have_libsexy=true, have_libsexy=false) if test "x${have_libsexy}" = "xfalse" ; then @@ -70,6 +59,19 @@ fi AC_SUBST(LIBSEXY_CFLAGS) AC_SUBST(LIBSEXY_LIBS) +# Checks for gtksourceview +PKG_CHECK_MODULES(GTKSOURCEVIEW, gtksourceview, have_gtksourceview=true, have_gtksourceview=false) +AC_SUBST(GTKSOURCEVIEW_CFLAGS) +AC_SUBST(GTKSOURCEVIEW_LIBS) + +# Checks for WebKit +PKG_CHECK_MODULES(WEBKIT, webkit-1.0, have_webkit=true, have_webkit=false) +if test "x${have_webkit}" = "xfalse" ; then + AC_MSG_ERROR([No WebKit package information found]) +fi +AC_SUBST(WEBKIT_CFLAGS) +AC_SUBST(WEBKIT_LIBS) + # Checks for LibXML2 PKG_CHECK_MODULES(LIBXML, libxml-2.0 >= 2.6, have_libxml=true, have_libxml=false) if test "x${have_libxml}" = "xfalse" ; then diff --git a/midori/Makefile.am b/midori/Makefile.am index 69c8d133..13b237bd 100644 --- a/midori/Makefile.am +++ b/midori/Makefile.am @@ -1,8 +1,9 @@ INCLUDES = \ - $(GIO_CFLAGS) \ - $(GTK_CFLAGS) \ - $(WEBKIT_CFLAGS) \ - $(LIBSEXY_CFLAGS) \ + $(GIO_CFLAGS) \ + $(GTK_CFLAGS) \ + $(LIBSEXY_CFLAGS) \ + $(GTKSOURCEVIEW_CFLAGS) \ + $(WEBKIT_CFLAGS) \ -I../katze AM_CFLAGS = -DMIDORI_LOCALEDIR=\""$(localedir)"\" @@ -10,8 +11,9 @@ AM_CFLAGS = -DMIDORI_LOCALEDIR=\""$(localedir)"\" LDADD = \ $(GIO_LIBS) \ $(GTK_LIBS) \ - $(WEBKIT_LIBS) \ $(LIBSEXY_LIBS) \ + $(GTKSOURCEVIEW_LIBS)\ + $(WEBKIT_LIBS) \ $(INTLLIBS) \ ../katze/libkatze.la diff --git a/midori/midori-browser.c b/midori/midori-browser.c index 9d587389..5965cbe2 100644 --- a/midori/midori-browser.c +++ b/midori/midori-browser.c @@ -29,6 +29,10 @@ #include #include #include +#if HAVE_GTKSOURCEVIEW +#include +#include +#endif #include struct _MidoriBrowser @@ -1804,10 +1808,22 @@ _action_source_view_activate (GtkAction* action, #if GLIB_CHECK_VERSION (2, 16, 0) GFile* file; gchar* tag; + #ifdef HAVE_GTKSOURCEVIEW + GFileInfo* info; + const gchar* content_type; + #endif #endif gchar* contents; gchar* contents_utf8; + #ifdef HAVE_GTKSOURCEVIEW + GtkSourceBuffer* buffer; + #if GLIB_CHECK_VERSION (2, 16, 0) + GtkSourceLanguageManager* language_manager; + GtkSourceLanguage* language; + #endif + #else GtkTextBuffer* buffer; + #endif GtkWidget* text_view; gint n; @@ -1822,6 +1838,11 @@ _action_source_view_activate (GtkAction* action, file = g_file_new_for_uri (uri); contents = NULL; g_file_load_contents (file, NULL, &contents, NULL, &tag, NULL); + #ifdef HAVE_GTKSOURCEVIEW + info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + G_FILE_QUERY_INFO_NONE, NULL, NULL); + content_type = info ? g_file_info_get_content_type (info) : NULL; + #endif g_object_unref (file); if (contents && !g_utf8_validate (contents, -1, NULL)) { @@ -1833,10 +1854,42 @@ _action_source_view_activate (GtkAction* action, #endif contents_utf8 = contents; + #ifdef HAVE_GTKSOURCEVIEW + buffer = gtk_source_buffer_new (NULL); + gtk_source_buffer_set_highlight_syntax (buffer, TRUE); + if (content_type) + { + language_manager = gtk_source_language_manager_get_default (); + if (!strcmp (content_type, "text/html")) + { + language = gtk_source_language_manager_get_language ( + language_manager, "html"); + gtk_source_buffer_set_language (buffer, language); + } + else if (!strcmp (content_type, "text/css")) + { + language = gtk_source_language_manager_get_language ( + language_manager, "css"); + gtk_source_buffer_set_language (buffer, language); + } + else if (!strcmp (content_type, "text/javascript")) + { + language = gtk_source_language_manager_get_language ( + language_manager, "js"); + gtk_source_buffer_set_language (buffer, language); + } + } + #else buffer = gtk_text_buffer_new (NULL); + #endif if (contents_utf8) - gtk_text_buffer_set_text (buffer, contents_utf8, -1); + gtk_text_buffer_set_text (GTK_TEXT_BUFFER (buffer), contents_utf8, -1); + #ifdef HAVE_GTKSOURCEVIEW + text_view = gtk_source_view_new_with_buffer (buffer); + gtk_source_view_set_show_line_numbers (GTK_SOURCE_VIEW (text_view), TRUE); + #else text_view = gtk_text_view_new_with_buffer (buffer); + #endif gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE); g_object_set_data (G_OBJECT (text_view), "browser-tab-uri", g_strconcat ("view-source:", uri, NULL)); diff --git a/midori/wscript_build b/midori/wscript_build index 228342de..9a70f59a 100644 --- a/midori/wscript_build +++ b/midori/wscript_build @@ -5,5 +5,5 @@ obj = bld.create_obj ('cc', 'program') obj.target = 'midori' obj.includes = '.. ../katze' obj.find_sources_in_dirs ('.') -obj.uselib = 'GIO GTK WEBKIT LIBXML LIBSEXY' +obj.uselib = 'GIO GTK LIBSEXY GTKSOURCEVIEW WEBKIT LIBXML' obj.uselib_local = 'katze' diff --git a/wscript b/wscript index 45380fe7..7fe577af 100644 --- a/wscript +++ b/wscript @@ -37,9 +37,10 @@ def configure (conf): conf.check_pkg ('gio-2.0', destvar='GIO', vnum='2.16.0', mandatory=False) conf.check_pkg ('gtk+-2.0', destvar='GTK', vnum='2.6.0', mandatory=True) + conf.check_pkg ('libsexy', destvar='LIBSEXY', vnum='0.1', mandatory=True) + conf.check_pkg ('gtksourceview-2.0', destvar='GTKSOURCEVIEW', vnum='2.0', mandatory=False) conf.check_pkg ('webkit-1.0', destvar='WEBKIT', vnum='0.1', mandatory=True) conf.check_pkg ('libxml-2.0', destvar='LIBXML', vnum='2.6', mandatory=True) - conf.check_pkg ('libsexy', destvar='LIBSEXY', vnum='0.1', mandatory=True) conf.check_header ('unistd.h', 'HAVE_UNISTD_H')