[Goodies-commits] r7330 - in xfce4-dict/trunk: . lib

Enrico Troeger enrico at xfce.org
Tue May 12 23:14:13 CEST 2009


Author: enrico
Date: 2009-05-12 21:14:13 +0000 (Tue, 12 May 2009)
New Revision: 7330

Modified:
   xfce4-dict/trunk/ChangeLog
   xfce4-dict/trunk/lib/common.c
   xfce4-dict/trunk/lib/common.h
   xfce4-dict/trunk/lib/dictd.c
   xfce4-dict/trunk/lib/gui.c
   xfce4-dict/trunk/lib/gui.h
   xfce4-dict/trunk/lib/spell.c
Log:
Add 'success' colour to mark found search terms.
Colourise search terms according to the search result for better visual feedback.

Modified: xfce4-dict/trunk/ChangeLog
===================================================================
--- xfce4-dict/trunk/ChangeLog	2009-05-11 20:03:05 UTC (rev 7329)
+++ xfce4-dict/trunk/ChangeLog	2009-05-12 21:14:13 UTC (rev 7330)
@@ -1,3 +1,12 @@
+2009-05-12  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
+
+ * lib/common.c, lib/common.h, lib/dictd.c, lib/gui.c, lib/gui.h,
+   lib/spell.c:
+   Add 'success' colour to mark found search terms.
+   Colourise search terms according to the search result for better
+   visual feedback.
+
+
 2009-05-10  Enrico Tröger  <enrico(dot)troeger(at)uvena(dot)de>
 
  * lib/Makefile.am, lib/common.c, lib/common.h, lib/gui.c,

Modified: xfce4-dict/trunk/lib/common.c
===================================================================
--- xfce4-dict/trunk/lib/common.c	2009-05-11 20:03:05 UTC (rev 7329)
+++ xfce4-dict/trunk/lib/common.c	2009-05-12 21:14:13 UTC (rev 7330)
@@ -35,8 +35,6 @@
 
 #include <libxfcegui4/libxfcegui4.h>
 
-
-
 #include "common.h"
 #include "spell.h"
 #include "dictd.h"
@@ -548,4 +546,3 @@
 	return dd;
 }
 
-

Modified: xfce4-dict/trunk/lib/common.h
===================================================================
--- xfce4-dict/trunk/lib/common.h	2009-05-11 20:03:05 UTC (rev 7329)
+++ xfce4-dict/trunk/lib/common.h	2009-05-12 21:14:13 UTC (rev 7330)
@@ -55,6 +55,11 @@
 	SERVER_NOT_READY
 };
 
+#define TAG_ERROR "error"
+#define TAG_SUCCESS "success"
+#define TAG_LINK "link"
+#define TAG_BOLD "bold"
+#define TAG_PHONETIC "phonetic"
 
 typedef struct
 {

Modified: xfce4-dict/trunk/lib/dictd.c
===================================================================
--- xfce4-dict/trunk/lib/dictd.c	2009-05-11 20:03:05 UTC (rev 7329)
+++ xfce4-dict/trunk/lib/dictd.c	2009-05-12 21:14:13 UTC (rev 7330)
@@ -190,7 +190,7 @@
 		len = end - buffer->str; /* length of the phonetic string */
 
 		gtk_text_buffer_insert_with_tags_by_name(dd->main_textbuffer, &dd->textiter,
-				buffer->str, len, "phonetic", NULL);
+				buffer->str, len, TAG_PHONETIC, NULL);
 
 		g_string_erase(buffer, 0, len + 1); /* remove already handled text */
 	}
@@ -205,7 +205,7 @@
 		"underline", PANGO_UNDERLINE_SINGLE,
 		"foreground-gdk", dd->link_color, NULL);
 
-	g_object_set_data_full(G_OBJECT(tag), "link", g_strdup(link_str), g_free);
+	g_object_set_data_full(G_OBJECT(tag), TAG_LINK, g_strdup(link_str), g_free);
 
 	return tag;
 }
@@ -413,8 +413,9 @@
 
 		gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\n", 1);
 		tmp = g_strdup_printf(_("No matches could be found for \"%s\"."), dd->searched_word);
-		gtk_text_buffer_insert_with_tags_by_name(dd->main_textbuffer, &dd->textiter,
-			tmp, -1, "error", NULL);
+		gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, tmp, -1);
+		dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, dd->searched_word, &dd->textiter,
+			TAG_ERROR, TAG_BOLD, NULL);
 		dict_gui_status_add(dd, "%s", tmp);
 		g_free(tmp);
 		g_free(dd->query_buffer);
@@ -423,14 +424,18 @@
 		 * spell check and offer a Web search*/
 		if (NZV(dd->web_url))
 		{
+			gchar *label = _(dict_prefs_get_web_url_label(dd));
 			gchar *text = g_strdup_printf(
 				/* for translators: the first wildcard is the search term, the second wildcard
 				 * is the name of the preferred web search engine */
 				_("Search \"%s\" using \"%s\""),
-				dd->searched_word, _(dict_prefs_get_web_url_label(dd)));
+				dd->searched_word, label);
 			gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\n\n", 2);
-			gtk_text_buffer_insert_with_tags_by_name(dd->main_textbuffer, &dd->textiter,
-				text, -1, "link", NULL);
+			gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, text, -1);
+			dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, label,
+				&dd->textiter, TAG_LINK, NULL);
+			dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, dd->searched_word,
+				&dd->textiter, TAG_ERROR, TAG_BOLD, NULL);
 			g_free(text);
 		}
 		if (NZV(dd->spell_bin))

Modified: xfce4-dict/trunk/lib/gui.c
===================================================================
--- xfce4-dict/trunk/lib/gui.c	2009-05-11 20:03:05 UTC (rev 7329)
+++ xfce4-dict/trunk/lib/gui.c	2009-05-12 21:14:13 UTC (rev 7330)
@@ -26,6 +26,8 @@
 #endif
 
 #include <string.h>
+#include <stdarg.h>
+
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 #include <libxfcegui4/libxfcegui4.h>
@@ -44,6 +46,7 @@
 static GdkCursor *regular_cursor = NULL;
 static gboolean entry_is_dirty = FALSE;
 static const GdkColor error_color = { 0, 0x8000, 0, 0 }; /* dark red */
+static const GdkColor success_color = { 0, 0x1000, 0x7000, 0 };
 
 
 /* all textview_* functions are from the gtk-demo app to get links in the textview working */
@@ -271,6 +274,33 @@
 }
 
 
+void dict_gui_textview_apply_tag_to_word(GtkTextBuffer *buffer, const gchar *word,
+										 GtkTextIter *pos, const gchar *first_tag, ...)
+{
+	GtkTextIter start, end;
+	gchar *s;
+
+	g_return_if_fail(word != NULL);
+	g_return_if_fail(first_tag != NULL);
+
+	/* This is a bit ugly but works:
+	 * we search the passed word backwards from 'pos' and apply the tag to it. */
+	if (gtk_text_iter_backward_search(pos, word, GTK_TEXT_SEARCH_TEXT_ONLY, &start, &end, NULL))
+	{
+		va_list args;
+
+		gtk_text_buffer_apply_tag_by_name(buffer, first_tag, &start, &end);
+
+		va_start(args, first_tag);
+		for (; s = va_arg(args, gchar*), s != NULL;)
+		{
+			gtk_text_buffer_apply_tag_by_name(buffer, s, &start, &end);
+		}
+		va_end(args);
+	}
+}
+
+
 void dict_gui_set_panel_entry_text(DictData *dd, const gchar *text)
 {
 	if (dd->panel_entry != NULL)
@@ -656,21 +686,24 @@
 	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(dd->main_textview), GTK_WRAP_WORD);
 	dd->main_textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(dd->main_textview));
 	gtk_text_buffer_create_tag(dd->main_textbuffer,
-			"bold",
+			TAG_BOLD,
 			"weight", PANGO_WEIGHT_BOLD,
 			"style", PANGO_STYLE_ITALIC,
 			"indent", 10,
 			"pixels-below-lines", 5, NULL);
 	gtk_text_buffer_create_tag(dd->main_textbuffer,
-			"error",
+			TAG_ERROR,
 			"style", PANGO_STYLE_ITALIC,
 			"foreground-gdk", &error_color, NULL);
+	gtk_text_buffer_create_tag(dd->main_textbuffer,
+			TAG_SUCCESS,
+			"foreground-gdk", &success_color, NULL);
 	dd->phon_tag = gtk_text_buffer_create_tag(dd->main_textbuffer,
-			"phonetic",
+			TAG_PHONETIC,
 			"style", PANGO_STYLE_ITALIC,
 			"foreground-gdk", dd->phon_color, NULL);
 	dd->link_tag = gtk_text_buffer_create_tag(dd->main_textbuffer,
-			"link",
+			TAG_LINK,
 			"underline", PANGO_UNDERLINE_SINGLE,
 			"foreground-gdk", dd->link_color, NULL);
 

Modified: xfce4-dict/trunk/lib/gui.h
===================================================================
--- xfce4-dict/trunk/lib/gui.h	2009-05-11 20:03:05 UTC (rev 7329)
+++ xfce4-dict/trunk/lib/gui.h	2009-05-12 21:14:13 UTC (rev 7330)
@@ -32,5 +32,8 @@
 void dict_gui_finalize(DictData *dd);
 const guint8 *dict_gui_get_icon_data(void);
 
+void dict_gui_textview_apply_tag_to_word(GtkTextBuffer *buffer, const gchar *word,
+										 GtkTextIter *pos, const gchar *first_tag, ...);
 
+
 #endif

Modified: xfce4-dict/trunk/lib/spell.c
===================================================================
--- xfce4-dict/trunk/lib/spell.c	2009-05-11 20:03:05 UTC (rev 7329)
+++ xfce4-dict/trunk/lib/spell.c	2009-05-12 21:14:13 UTC (rev 7330)
@@ -90,6 +90,8 @@
 				tmp = g_strdup_printf(_("Suggestions for \"%s\":"), iod->word);
 				gtk_text_buffer_insert_with_tags_by_name(
 					dd->main_textbuffer, &dd->textiter, tmp, -1, "bold", NULL);
+				dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, iod->word, &dd->textiter,
+					TAG_ERROR, TAG_BOLD, NULL);
 				g_free(tmp);
 				/* TODO include the dictionary string into the above message */
 				tmp = g_strdup_printf(" (%s)", dd->spell_dictionary);
@@ -106,6 +108,8 @@
 				gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\n", 1);
 				tmp = g_strdup_printf(_("\"%s\" is spelled correctly."), iod->word);
 				gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, tmp, -1);
+				dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, iod->word, &dd->textiter,
+					TAG_SUCCESS, TAG_BOLD, NULL);
 				g_free(tmp);
 				tmp = g_strdup_printf(" (%s)", dd->spell_dictionary);
 				gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, tmp, -1);
@@ -118,6 +122,8 @@
 				tmp = g_strdup_printf(_("No suggestions could be found for \"%s\"."),
 					iod->word);
 				gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, tmp, -1);
+				dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, iod->word, &dd->textiter,
+					TAG_ERROR, TAG_BOLD, NULL);
 				g_free(tmp);
 				tmp = g_strdup_printf(" (%s)", dd->spell_dictionary);
 				gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, tmp, -1);




More information about the Goodies-commits mailing list