|
|
|
@ -460,20 +460,38 @@ void Source::View::configure() { |
|
|
|
{ |
|
|
|
{ |
|
|
|
#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 24)) |
|
|
|
#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 24)) |
|
|
|
namespace qi = boost::spirit::qi; |
|
|
|
namespace qi = boost::spirit::qi; |
|
|
|
qi::symbols<char, GtkSourceSpaceLocationFlags> location_options; |
|
|
|
std::set<std::string> out; |
|
|
|
qi::symbols<char, GtkSourceSpaceTypeFlags> type_options; |
|
|
|
qi::phrase_parse(Config::get().source.show_whitespace_characters.begin(), Config::get().source.show_whitespace_characters.end(), (+(~qi::char_(','))) % ',', qi::space, out); |
|
|
|
location_options.add("leading", GTK_SOURCE_SPACE_LOCATION_LEADING)("text", GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT)("trailing", GTK_SOURCE_SPACE_LOCATION_TRAILING)("all", GTK_SOURCE_SPACE_LOCATION_ALL); |
|
|
|
|
|
|
|
type_options.add("space", GTK_SOURCE_SPACE_TYPE_SPACE)("tab", GTK_SOURCE_SPACE_TYPE_TAB)("newline", GTK_SOURCE_SPACE_TYPE_NEWLINE)("nbsp", GTK_SOURCE_SPACE_TYPE_NBSP)("all", GTK_SOURCE_SPACE_TYPE_ALL); |
|
|
|
|
|
|
|
std::set<GtkSourceSpaceLocationFlags> location_out; |
|
|
|
|
|
|
|
std::set<GtkSourceSpaceTypeFlags> type_out; |
|
|
|
|
|
|
|
qi::phrase_parse(Config::get().source.show_whitespace_characters.begin(), Config::get().source.show_whitespace_characters.end(), location_options % ',', qi::space, location_out); |
|
|
|
|
|
|
|
qi::phrase_parse(Config::get().source.show_whitespace_characters.begin(), Config::get().source.show_whitespace_characters.end(), type_options % ',', qi::space, type_out); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto space_drawer = gtk_source_view_get_space_drawer(gobj()); |
|
|
|
auto space_drawer = gtk_source_view_get_space_drawer(gobj()); |
|
|
|
auto locations = location_out.count(GTK_SOURCE_SPACE_LOCATION_ALL) > 0 ? GTK_SOURCE_SPACE_LOCATION_ALL : static_cast<GtkSourceSpaceLocationFlags>(std::accumulate(location_out.begin(), location_out.end(), 0)); |
|
|
|
int locations = GTK_SOURCE_SPACE_LOCATION_NONE; |
|
|
|
auto types = type_out.count(GTK_SOURCE_SPACE_TYPE_ALL) > 0 ? GTK_SOURCE_SPACE_TYPE_ALL : static_cast<GtkSourceSpaceTypeFlags>(std::accumulate(type_out.begin(), type_out.end(), 0)); |
|
|
|
if(out.count("leading") > 0) |
|
|
|
|
|
|
|
locations |= GTK_SOURCE_SPACE_LOCATION_LEADING; |
|
|
|
|
|
|
|
if(out.count("text") > 0) |
|
|
|
|
|
|
|
locations |= GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT; |
|
|
|
|
|
|
|
if(out.count("trailing") > 0) |
|
|
|
|
|
|
|
locations |= GTK_SOURCE_SPACE_LOCATION_TRAILING; |
|
|
|
|
|
|
|
if(out.count("all") > 0) |
|
|
|
|
|
|
|
locations |= GTK_SOURCE_SPACE_LOCATION_ALL; |
|
|
|
|
|
|
|
int types = GTK_SOURCE_SPACE_TYPE_NONE; |
|
|
|
|
|
|
|
if(out.count("space") > 0) |
|
|
|
|
|
|
|
types |= GTK_SOURCE_SPACE_TYPE_SPACE; |
|
|
|
|
|
|
|
if(out.count("tab") > 0) |
|
|
|
|
|
|
|
types |= GTK_SOURCE_SPACE_TYPE_TAB; |
|
|
|
|
|
|
|
if(out.count("newline") > 0) |
|
|
|
|
|
|
|
types |= GTK_SOURCE_SPACE_TYPE_NEWLINE; |
|
|
|
|
|
|
|
if(out.count("nbsp") > 0) |
|
|
|
|
|
|
|
types |= GTK_SOURCE_SPACE_TYPE_NBSP; |
|
|
|
|
|
|
|
if(out.count("all") > 0) |
|
|
|
|
|
|
|
types |= GTK_SOURCE_SPACE_TYPE_ALL; |
|
|
|
|
|
|
|
|
|
|
|
if(locations != GTK_SOURCE_SPACE_LOCATION_NONE || types != GTK_SOURCE_SPACE_TYPE_NONE) { |
|
|
|
if(locations != GTK_SOURCE_SPACE_LOCATION_NONE || types != GTK_SOURCE_SPACE_TYPE_NONE) { |
|
|
|
gtk_source_space_drawer_set_types_for_locations(space_drawer, locations, types); |
|
|
|
if(locations == GTK_SOURCE_SPACE_LOCATION_NONE) |
|
|
|
|
|
|
|
locations = GTK_SOURCE_SPACE_LOCATION_ALL; |
|
|
|
|
|
|
|
if(types == GTK_SOURCE_SPACE_TYPE_NONE) |
|
|
|
|
|
|
|
types = GTK_SOURCE_SPACE_TYPE_ALL; |
|
|
|
|
|
|
|
gtk_source_space_drawer_set_matrix(space_drawer, nullptr); |
|
|
|
|
|
|
|
gtk_source_space_drawer_set_types_for_locations(space_drawer, static_cast<GtkSourceSpaceLocationFlags>(locations), static_cast<GtkSourceSpaceTypeFlags>(types)); |
|
|
|
gtk_source_space_drawer_set_enable_matrix(space_drawer, true); |
|
|
|
gtk_source_space_drawer_set_enable_matrix(space_drawer, true); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
|