Re: [gedit-list] GtkSourceView, highlight lines with errors



On Fri, May 20, 2016 at 01:22:57PM +0200, Stefan Salewski wrote:
Some days ago I started writing a simple editor for Nim language, using
Nims advanced idetools/nimsuggest service for error locating and source
completion.

I found no way to highlight lines with errors in a clean way. test-
widget.c example uses this code

gdk_rgba_parse (&color, "lightgreen");
gtk_source_mark_attributes_set_background (attrs, &color);

That works fine, but using a fixed color makes not too much sense for
applications using arbitrary color schemes with syntax highlight. What
would one do to highlight background, when color schemes are used? No
idea still after some hour of googling and testing. What we would need
is a way to ask current background color, so that we can change that
color.

For ordinary widgets this is available

https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-
context-get-background-color

but it is already deprecated.

So we need access to the general background color, so that we can
modify it, or access to a highlighted background color variant, which
we can set.

I think there is a "highlight current line" function somewhere hidden
in the code -- it is possible to apply that method to lines with
compiler errors?

Good question.

Some applications have a function to choose a color in a smart way:
choose the best color depending on some other colors. But GtkSourceView
doesn't have such function, unfortunately.

The style schemes have a list of colors. Maybe you can use one of them.

There are some code in GtkSourceView that do:

gtk_style_context_get (style_context,
                       gtk_style_context_get_state (style_context),
                       "background-color", &background_color,
                       NULL);

So it is still possible to retrieve the background color.

The highlight current line implementation is in gtksourceview.c. See
gtk_source_view_draw_layer() (it overrides the GtkTextView draw_layer
virtual function).

Hope that helps.

--
Sébastien


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