X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fdict-display.c;h=6d1671454740454eb32c0d459815d718469f8eb3;hb=4612957073c41b6f15e8b36de14f43fb40cd9bfb;hp=d54583b802349e093bec38554aacad4c84dc6dda;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp-builds.git diff --git a/src/ui/gui/dict-display.c b/src/ui/gui/dict-display.c index d54583b8..6d167145 100644 --- a/src/ui/gui/dict-display.c +++ b/src/ui/gui/dict-display.c @@ -19,11 +19,13 @@ #include #include +#include "psppire-conf.h" #include "dict-display.h" #include "psppire-dict.h" #include "helper.h" #include +#include #define _(msgid) gettext (msgid) #define N_(msgid) msgid @@ -123,7 +125,12 @@ var_description_cell_data_func (GtkTreeViewColumn *col, struct variable *var; GtkTreeIter iter; GtkTreeModel *model; + gboolean prefer_labels = FALSE; + PsppireConf *conf = psppire_conf_new (); + + psppire_conf_get_boolean (conf, "dialog-boxes", "prefer-labels", + &prefer_labels); get_base_model (top_model, top_iter, &model, &iter); @@ -133,13 +140,11 @@ var_description_cell_data_func (GtkTreeViewColumn *col, gtk_tree_model_get (model, &iter, DICT_TVM_COL_VAR, &var, -1); - if ( var_has_label (var)) + if ( var_has_label (var) && prefer_labels) { gchar *text = g_strdup_printf ( - "%s" - " (%s)", - var_get_label (var), - var_get_name (var)); + "%s", + var_get_label (var)); char *utf8 = pspp_locale_to_utf8 (text, -1, NULL); @@ -149,10 +154,77 @@ var_description_cell_data_func (GtkTreeViewColumn *col, } else { - g_object_set (cell, "text", var_get_name (var), NULL); + char *name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL); + g_object_set (cell, "text", name, NULL); + g_free (name); } } + +/* Sets the tooltip to be the name of the variable under the cursor */ +static gboolean +set_tooltip_for_variable (GtkTreeView *treeview, + gint x, + gint y, + gboolean keyboard_mode, + GtkTooltip *tooltip, + gpointer user_data) + +{ + gint bx, by; + GtkTreeIter iter; + GtkTreePath *path; + GtkTreeModel *tree_model; + struct variable *var = NULL; + gboolean ok; + + + gtk_tree_view_convert_widget_to_bin_window_coords (treeview, + x, y, &bx, &by); + + if (!gtk_tree_view_get_path_at_pos (treeview, bx, by, + &path, NULL, NULL, NULL)) + return FALSE; + + tree_model = gtk_tree_view_get_model (treeview); + + + gtk_tree_view_set_tooltip_row (treeview, tooltip, path); + + ok = gtk_tree_model_get_iter (tree_model, &iter, path); + + gtk_tree_path_free (path); + if (!ok) + return FALSE; + + + gtk_tree_model_get (tree_model, &iter, DICT_TVM_COL_VAR, &var, -1); + + if ( ! var_has_label (var)) + return FALSE; + + { + gchar *tip ; + gboolean prefer_labels = FALSE; + + PsppireConf *conf = psppire_conf_new (); + + psppire_conf_get_boolean (conf, "dialog-boxes", "prefer-labels", + &prefer_labels); + + if ( prefer_labels ) + tip = pspp_locale_to_utf8 (var_get_name (var), -1, NULL); + else + tip = pspp_locale_to_utf8 (var_get_label (var), -1, NULL); + + gtk_tooltip_set_text (tooltip, tip); + + g_free (tip); + } + + return TRUE; +} + /* Sets up TREEVIEW to display the variables of DICT. MODE is the selection mode for TREEVIEW. PREDICATE determines which variables should be visible, or NULL if @@ -219,13 +291,20 @@ attach_dictionary_to_treeview (GtkTreeView *treeview, PsppireDict *dict, gtk_tree_view_append_column (treeview, col); gtk_tree_selection_set_mode (selection, mode); + + g_object_set (treeview, "has-tooltip", TRUE, NULL); + +#if GTK_CHECK_VERSION (2, 12, 0) + g_signal_connect (treeview, "query-tooltip", G_CALLBACK (set_tooltip_for_variable), NULL); +#endif } void insert_source_row_into_entry (GtkTreeIter iter, GtkWidget *dest, - GtkTreeModel *model + GtkTreeModel *model, + gpointer data ) { GtkTreePath *path; @@ -257,7 +336,8 @@ insert_source_row_into_entry (GtkTreeIter iter, void insert_source_row_into_tree_view (GtkTreeIter iter, GtkWidget *dest, - GtkTreeModel *model + GtkTreeModel *model, + gpointer data ) { GtkTreePath *path;