Kaydet (Commit) 1c1d7672 authored tarafından Colomban Wendling's avatar Colomban Wendling

Fix several tooltips to properly use plain text instead of markup

Most of our tree view tooltips were set from plain text values but
parsed as markup by GTK, which sometimes lead to markup errors, when
the tooltip value contained markup control characters.

This also adds ui_tree_view_set_tooltip_text_column() to the plugin
API so plugins can easily set plain text tooltips from tree views
columns.

Fixes https://sourceforge.net/p/geany/bugs/1091/
üst a8a2d147
......@@ -850,7 +850,7 @@ static void prepare_file_view(void)
ui_widget_modify_font_from_string(file_view, geany->interface_prefs->tagbar_font);
/* tooltips */
gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(file_view), FILEVIEW_COLUMN_FILENAME);
ui_tree_view_set_tooltip_text_column(GTK_TREE_VIEW(file_view), FILEVIEW_COLUMN_FILENAME);
/* selection handling */
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(file_view));
......
......@@ -308,6 +308,8 @@
geany_functions->p_ui->ui_menu_add_document_items_sorted
#define ui_lookup_stock_label \
geany_functions->p_ui->ui_lookup_stock_label
#define ui_tree_view_set_tooltip_text_column \
geany_functions->p_ui->ui_tree_view_set_tooltip_text_column
#define dialogs_show_question \
geany_functions->p_dialogs->dialogs_show_question
#define dialogs_show_msgbox \
......
......@@ -58,7 +58,7 @@ G_BEGIN_DECLS
* @warning You should not test for values below 200 as previously
* @c GEANY_API_VERSION was defined as an enum value, not a macro.
*/
#define GEANY_API_VERSION 222
#define GEANY_API_VERSION 223
/* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins
* with GTK3-linked Geany leads to crash */
......@@ -501,6 +501,7 @@ typedef struct UIUtilsFuncs
void (*ui_menu_add_document_items_sorted) (GtkMenu *menu, struct GeanyDocument *active,
GCallback callback, GCompareFunc compare_func);
const gchar* (*ui_lookup_stock_label)(const gchar *stock_id);
void (*ui_tree_view_set_tooltip_text_column) (GtkTreeView *tree_view, gint column);
}
UIUtilsFuncs;
......
......@@ -247,7 +247,8 @@ static UIUtilsFuncs uiutils_funcs = {
&ui_get_gtk_settings_integer,
&ui_combo_box_add_to_history,
&ui_menu_add_document_items_sorted,
&ui_lookup_stock_label
&ui_lookup_stock_label,
&ui_tree_view_set_tooltip_text_column
};
static DialogFuncs dialog_funcs = {
......
......@@ -142,7 +142,7 @@ static void prepare_taglist(GtkWidget *tree, GtkTreeStore *store)
if (! interface_prefs.show_symbol_list_expanders)
gtk_tree_view_set_level_indentation(GTK_TREE_VIEW(tree), 10);
/* Tooltips */
gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(tree), SYMBOLS_COLUMN_TOOLTIP);
ui_tree_view_set_tooltip_text_column(GTK_TREE_VIEW(tree), SYMBOLS_COLUMN_TOOLTIP);
/* selection handling */
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree));
......@@ -312,7 +312,7 @@ static void prepare_openfiles(void)
ui_widget_modify_font_from_string(tv.tree_openfiles, interface_prefs.tagbar_font);
/* tooltips */
gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(tv.tree_openfiles), DOCUMENTS_FILENAME);
ui_tree_view_set_tooltip_text_column(GTK_TREE_VIEW(tv.tree_openfiles), DOCUMENTS_FILENAME);
/* selection handling */
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv.tree_openfiles));
......
......@@ -1048,9 +1048,6 @@ static gchar *get_symbol_tooltip(GeanyDocument *doc, const TMTag *tag)
encodings_convert_to_utf8_from_charset(utf8_name, -1, doc->encoding, TRUE));
}
if (utf8_name != NULL)
SETPTR(utf8_name, g_markup_escape_text(utf8_name, -1));
return utf8_name;
}
......
......@@ -563,7 +563,7 @@ static void cc_show_dialog_custom_commands(void)
cc.store = gtk_list_store_new(CC_COLUMN_COUNT, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING);
cc.view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(cc.store));
gtk_tree_view_set_tooltip_column(GTK_TREE_VIEW(cc.view), CC_COLUMN_TOOLTIP);
ui_tree_view_set_tooltip_text_column(GTK_TREE_VIEW(cc.view), CC_COLUMN_TOOLTIP);
gtk_tree_view_set_reorderable(GTK_TREE_VIEW(cc.view), TRUE);
cc.selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cc.view));
/* ID column */
......
......@@ -1806,6 +1806,67 @@ gboolean ui_tree_view_find_previous(GtkTreeView *treeview, TVMatchCallback cb)
}
/* Shamelessly stolen from GTK */
static gboolean ui_tree_view_query_tooltip_cb(GtkWidget *widget, gint x, gint y,
gboolean keyboard_tip, GtkTooltip *tooltip, gpointer data)
{
GValue value = G_VALUE_INIT;
GValue transformed = G_VALUE_INIT;
GtkTreeIter iter;
GtkTreePath *path;
GtkTreeModel *model;
GtkTreeView *tree_view = GTK_TREE_VIEW(widget);
gint column = GPOINTER_TO_INT(data);
gboolean tootlip_set = FALSE;
if (! gtk_tree_view_get_tooltip_context(tree_view, &x, &y, keyboard_tip, &model, &path, &iter))
return FALSE;
gtk_tree_model_get_value(model, &iter, column, &value);
g_value_init(&transformed, G_TYPE_STRING);
if (g_value_transform(&value, &transformed) && g_value_get_string(&transformed))
{
gtk_tooltip_set_text(tooltip, g_value_get_string(&transformed));
gtk_tree_view_set_tooltip_row(tree_view, tooltip, path);
tootlip_set = TRUE;
}
g_value_unset(&transformed);
g_value_unset(&value);
gtk_tree_path_free(path);
return tootlip_set;
}
/** Adds text tooltips to a tree view.
*
* This is similar to gtk_tree_view_set_tooltip_column() but considers the column contents to be
* text, not markup -- it uses gtk_tooltip_set_text() rather than gtk_tooltip_set_markup() to set
* the tooltip's value.
*
* @warning Unlike gtk_tree_view_set_tooltip_column() you currently cannot change or remove the
* tooltip column after it has been added. Trying to do so will probably give funky results.
*
* @param tree_view The tree view
* @param column The column to get the tooltip from
*
* @since 1.25 (API 223)
*/
/* Note: @p column is int and not uint both to match gtk_tree_view_set_tooltip_column() signature
* and to allow future support of -1 to unset if ever wanted */
void ui_tree_view_set_tooltip_text_column(GtkTreeView *tree_view, gint column)
{
g_return_if_fail(column >= 0);
g_return_if_fail(GTK_IS_TREE_VIEW(tree_view));
g_signal_connect(tree_view, "query-tooltip",
G_CALLBACK(ui_tree_view_query_tooltip_cb), GINT_TO_POINTER(column));
gtk_widget_set_has_tooltip(GTK_WIDGET(tree_view), TRUE);
}
/**
* Modifies the font of a widget using gtk_widget_modify_font().
*
......
......@@ -139,6 +139,8 @@ void ui_combo_box_add_to_history(GtkComboBoxText *combo_entry,
const gchar *ui_lookup_stock_label(const gchar *stock_id);
void ui_tree_view_set_tooltip_text_column(GtkTreeView *tree_view, gint column);
#ifdef GEANY_PRIVATE
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment