Use GtkSourceView2 if available
This commit is contained in:
parent
a249a6d6f7
commit
103df3d8cc
5 changed files with 77 additions and 19 deletions
24
configure.in
24
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
#include <gdk/gdkkeysyms.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <libsexy/sexy.h>
|
||||
#if HAVE_GTKSOURCEVIEW
|
||||
#include <gtksourceview/gtksourceview.h>
|
||||
#include <gtksourceview/gtksourcelanguagemanager.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
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));
|
||||
|
|
|
@ -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'
|
||||
|
|
3
wscript
3
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')
|
||||
|
||||
|
|
Loading…
Reference in a new issue