[Goodies-commits] r7364 - xfce4-dict/trunk/lib
Enrico Troeger
enrico at xfce.org
Mon May 18 20:12:26 CEST 2009
Author: enrico
Date: 2009-05-18 18:12:26 +0000 (Mon, 18 May 2009)
New Revision: 7364
Modified:
xfce4-dict/trunk/lib/common.c
xfce4-dict/trunk/lib/common.h
xfce4-dict/trunk/lib/dictd.c
xfce4-dict/trunk/lib/gui.c
Log:
When offering a Web search link for a failed search, display the full target URI as tooltip.
Minor other improvements.
Modified: xfce4-dict/trunk/lib/common.c
===================================================================
--- xfce4-dict/trunk/lib/common.c 2009-05-18 16:28:12 UTC (rev 7363)
+++ xfce4-dict/trunk/lib/common.c 2009-05-18 18:12:26 UTC (rev 7364)
@@ -155,9 +155,8 @@
}
-gboolean dict_start_web_query(DictData *dd, const gchar *word)
+gchar *dict_get_web_query_uri(DictData *dd, const gchar *word)
{
- gboolean success = TRUE;
gchar *uri;
#if GLIB_CHECK_VERSION(2, 16, 0)
@@ -172,6 +171,17 @@
#else
uri = str_replace(g_strdup(dd->web_url), "{word}", dd->searched_word);
#endif
+
+ return uri;
+}
+
+
+gboolean dict_start_web_query(DictData *dd, const gchar *word)
+{
+ gboolean success = TRUE;
+ gchar *uri = dict_get_web_query_uri(dd, word);
+
+
if (! NZV(uri))
{
xfce_err(_("The search URL is empty. Please check your preferences."));
Modified: xfce4-dict/trunk/lib/common.h
===================================================================
--- xfce4-dict/trunk/lib/common.h 2009-05-18 16:28:12 UTC (rev 7363)
+++ xfce4-dict/trunk/lib/common.h 2009-05-18 18:12:26 UTC (rev 7364)
@@ -131,5 +131,6 @@
DictData *dict_create_dictdata();
gboolean dict_start_web_query(DictData *dd, const gchar *word);
+gchar *dict_get_web_query_uri(DictData *dd, const gchar *word);
#endif
Modified: xfce4-dict/trunk/lib/dictd.c
===================================================================
--- xfce4-dict/trunk/lib/dictd.c 2009-05-18 16:28:12 UTC (rev 7363)
+++ xfce4-dict/trunk/lib/dictd.c 2009-05-18 18:12:26 UTC (rev 7364)
@@ -431,11 +431,10 @@
_("Search \"%s\" using \"%s\""),
dd->searched_word, label);
gtk_text_buffer_insert(dd->main_textbuffer, &dd->textiter, "\n\n", 2);
- 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);
+ gtk_text_buffer_insert_with_tags_by_name(dd->main_textbuffer, &dd->textiter,
+ text, -1, TAG_LINK, NULL);
+ /*dict_gui_textview_apply_tag_to_word(dd->main_textbuffer, dd->searched_word,
+ &dd->textiter, 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-18 16:28:12 UTC (rev 7363)
+++ xfce4-dict/trunk/lib/gui.c 2009-05-18 18:12:26 UTC (rev 7364)
@@ -161,6 +161,7 @@
g_free(name);
break;
}
+ g_free(name);
}
if (hovering != hovering_over_link)
@@ -187,8 +188,6 @@
textview_set_cursor_if_appropriate(GTK_TEXT_VIEW(text_view), x, y, event->window);
- gdk_window_get_pointer(text_view->window, NULL, NULL, NULL);
-
return FALSE;
}
@@ -275,6 +274,41 @@
}
+#if GTK_CHECK_VERSION(2, 12, 0)
+static gboolean textview_query_tooltip_cb(GtkWidget *widget, gint x, gint y, gboolean keyboard_mode,
+ GtkTooltip *tooltip, DictData *dd)
+{
+ gint tx, ty;
+ GSList *tags = NULL, *tagp = NULL;
+ GtkTextIter iter;
+
+ gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget),
+ GTK_TEXT_WINDOW_WIDGET, x, y, &tx, &ty);
+
+ gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &iter, tx, ty);
+
+ tags = gtk_text_iter_get_tags(&iter);
+ for (tagp = tags; tagp != NULL; tagp = tagp->next)
+ {
+ GtkTextTag *tag = tagp->data;
+ gchar *name;
+
+ g_object_get(G_OBJECT(tag), "name", &name, NULL);
+ if (name != NULL && strcmp("link", name) == 0)
+ {
+ gchar *target_uri = dict_get_web_query_uri(dd, dd->searched_word);
+ gtk_tooltip_set_markup(tooltip, target_uri);
+ g_free(name);
+ g_free(target_uri);
+ return TRUE;
+ }
+ g_free(name);
+ }
+ return FALSE;
+}
+#endif
+
+
void dict_gui_textview_apply_tag_to_word(GtkTextBuffer *buffer, const gchar *word,
GtkTextIter *pos, const gchar *first_tag, ...)
{
@@ -733,6 +767,11 @@
g_signal_connect(dd->main_textview, "populate-popup",
G_CALLBACK(textview_populate_popup_cb), dd);
}
+ /* tooltips */
+#if GTK_CHECK_VERSION(2, 12, 0)
+ gtk_widget_set_has_tooltip(dd->main_textview, TRUE);
+ g_signal_connect(dd->main_textview, "query-tooltip", G_CALLBACK(textview_query_tooltip_cb), dd);
+#endif
gtk_widget_show(dd->main_textview);
gtk_container_add(GTK_CONTAINER(scrolledwindow_results), dd->main_textview);
More information about the Goodies-commits
mailing list