diff options
| author | Přemysl Janouch <p.janouch@gmail.com> | 2016-09-26 21:04:27 +0200 | 
|---|---|---|
| committer | Přemysl Janouch <p.janouch@gmail.com> | 2016-09-26 21:06:51 +0200 | 
| commit | 5ee562faf4c10c88a8223d2a26d237a99755f73c (patch) | |
| tree | 80ecedc13710f938fb0513b84e3d1834d5ba0db3 /src | |
| parent | 81d702ed66b8f3ce86d05e22ecd2425eccd1bcf7 (diff) | |
| download | tdv-5ee562faf4c10c88a8223d2a26d237a99755f73c.tar.gz tdv-5ee562faf4c10c88a8223d2a26d237a99755f73c.tar.xz tdv-5ee562faf4c10c88a8223d2a26d237a99755f73c.zip | |
Make it possible to disable prefix highlighting
Diffstat (limited to 'src')
| -rw-r--r-- | src/sdtui.c | 53 | 
1 files changed, 30 insertions, 23 deletions
| diff --git a/src/sdtui.c b/src/sdtui.c index ee03870..b9ed153 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -112,6 +112,7 @@ struct application  	guint           show_help : 1;      ///< Whether help can be shown  	guint           center_search : 1;  ///< Whether to center the search  	guint           underline_last : 1; ///< Underline the last definition +	guint           hl_prefix : 1;      ///< Highlight the common prefix  	guint32         top_position;       ///< Index of the topmost dict. entry  	guint           top_offset;         ///< Offset into the top entry @@ -284,27 +285,28 @@ app_load_color (Application *self, GKeyFile *kf, const gchar *name, int id)  	self->attrs[id] = attrs;  } -static void -app_load_config_values (Application *self, GKeyFile *kf) +static gboolean +app_load_bool (GKeyFile *kf, const gchar *name, gboolean def)  { -	GError *e; -	const gchar *settings = "Settings"; - -	e = NULL; -	bool center_search = -		g_key_file_get_boolean (kf, settings, "center-search", &e); +	GError *e = NULL; +	bool value = g_key_file_get_boolean (kf, "Settings", name, &e);  	if (e) +	{  		g_error_free (e); -	else -		self->center_search = center_search; +		return def; +	} +	return value; +} -	e = NULL; -	bool underline_last = -		g_key_file_get_boolean (kf, settings, "underline-last", &e); -	if (e) -		g_error_free (e); -	else -		self->underline_last = underline_last; +static void +app_load_config_values (Application *self, GKeyFile *kf) +{ +	self->center_search = +		app_load_bool (kf, "center-search", self->center_search); +	self->underline_last = +		app_load_bool (kf, "underline-last", self->underline_last); +	self->hl_prefix = +		app_load_bool (kf, "hl-common-prefix", self->hl_prefix);  #define XX(name, config, fg_, bg_, attrs_) \  	app_load_color (self, kf, config, ATTRIBUTE_ ## name); @@ -391,6 +393,7 @@ app_init (Application *self, AppOptions *options, const gchar *filename)  	self->show_help = TRUE;  	self->center_search = TRUE;  	self->underline_last = TRUE; +	self->hl_prefix = TRUE;  	self->top_position = 0;  	self->top_offset = 0; @@ -779,6 +782,7 @@ app_redraw_view (Application *self)  	move (TOP_BAR_CUTOFF, 0);  	clrtobot (); +	// TODO: clean this stuff up a bit, it's all rather ugly  	gchar *input_utf8 = g_ucs4_to_utf8  		((gunichar *) self->input->data, -1, NULL, NULL, NULL); @@ -799,13 +803,16 @@ app_redraw_view (Application *self)  			RowBuffer buf;  			row_buffer_init (&buf, self); -			size_t common = stardict_longest_common_collation_prefix -				(self->dict, ve->word, input_utf8); - -			gchar *prefix = g_strndup (ve->word, common); -			row_buffer_append (&buf, prefix, A_BOLD); -			g_free (prefix); +			size_t common = 0; +			if (self->hl_prefix) +			{ +				common = stardict_longest_common_collation_prefix +					(self->dict, ve->word, input_utf8); +				gchar *prefix = g_strndup (ve->word, common); +				row_buffer_append (&buf, prefix, A_BOLD); +				g_free (prefix); +			}  			row_buffer_append (&buf, ve->word + common, 0);  			gint left_width = app_get_left_column_width (self); | 
