From c3e2ab6b50eb3b3c7e0852f2a4e2122f695714ff Mon Sep 17 00:00:00 2001 From: John Darrington Date: Tue, 17 Mar 2009 19:11:20 +0900 Subject: [PATCH] New object PsppireDictView Created a new object PsppireDictView, which derives from GtkTreeView for the purpose of displaying a dictionary. Replaces much of the functionality in dict-display.c --- src/ui/gui/automake.mk | 4 +- src/ui/gui/compute-dialog.c | 9 +- src/ui/gui/crosstabs-dialog.c | 4 +- src/ui/gui/crosstabs.glade | 2 +- src/ui/gui/descriptives-dialog.c | 5 +- src/ui/gui/descriptives-dialog.glade | 2 +- src/ui/gui/dict-display.c | 245 +-------- src/ui/gui/dict-display.h | 15 - src/ui/gui/examine-dialog.c | 5 +- src/ui/gui/examine.glade | 2 +- src/ui/gui/find-dialog.c | 7 +- src/ui/gui/frequencies-dialog.c | 4 +- src/ui/gui/frequencies.glade | 2 +- src/ui/gui/oneway-anova-dialog.c | 4 +- src/ui/gui/oneway.glade | 2 +- src/ui/gui/psppire-dictview.c | 509 ++++++++++++++++++ src/ui/gui/psppire-dictview.h | 66 +++ src/ui/gui/psppire.glade | 12 +- src/ui/gui/rank-dialog.c | 5 +- src/ui/gui/rank.glade | 2 +- src/ui/gui/recode-dialog.c | 5 +- src/ui/gui/recode.glade | 2 +- src/ui/gui/regression-dialog.c | 4 +- src/ui/gui/regression.glade | 2 +- src/ui/gui/select-cases-dialog.c | 7 +- src/ui/gui/sort-cases-dialog.c | 4 +- src/ui/gui/split-file-dialog.c | 5 +- .../gui/t-test-independent-samples-dialog.c | 4 +- src/ui/gui/t-test-one-sample.c | 6 +- src/ui/gui/t-test-paired-samples.c | 6 +- src/ui/gui/t-test.glade | 6 +- src/ui/gui/transpose-dialog.c | 4 +- src/ui/gui/variable-info-dialog.c | 62 +-- src/ui/gui/variable-info-dialog.glade | 2 +- src/ui/gui/weight-cases-dialog.c | 9 +- src/ui/gui/widgets.c | 5 + 36 files changed, 657 insertions(+), 382 deletions(-) create mode 100644 src/ui/gui/psppire-dictview.c create mode 100644 src/ui/gui/psppire-dictview.h diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index e104b275..1a2b4af1 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -119,8 +119,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/descriptives-dialog.h \ src/ui/gui/dialog-common.c \ src/ui/gui/dialog-common.h \ - src/ui/gui/dict-display.c \ src/ui/gui/dict-display.h \ + src/ui/gui/dict-display.c \ src/ui/gui/examine-dialog.c \ src/ui/gui/examine-dialog.h \ src/ui/gui/find-dialog.c \ @@ -153,6 +153,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog.h \ src/ui/gui/psppire-dict.c \ src/ui/gui/psppire-dict.h \ + src/ui/gui/psppire-dictview.c \ + src/ui/gui/psppire-dictview.h \ src/ui/gui/psppire-hbuttonbox.h \ src/ui/gui/psppire-keypad.h \ src/ui/gui/psppire-output-window.c \ diff --git a/src/ui/gui/compute-dialog.c b/src/ui/gui/compute-dialog.c index 7269ab79..ba5871a8 100644 --- a/src/ui/gui/compute-dialog.c +++ b/src/ui/gui/compute-dialog.c @@ -396,11 +396,10 @@ compute_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - - attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view), - vs->dict, - GTK_SELECTION_SINGLE, NULL); - + g_object_set (dict_view, + "model", vs->dict, + "selection-mode", GTK_SELECTION_SINGLE, + NULL); psppire_selector_set_subjects (PSPPIRE_SELECTOR (var_selector), dict_view, syntax_area, diff --git a/src/ui/gui/crosstabs-dialog.c b/src/ui/gui/crosstabs-dialog.c index 188c4aaa..3d5c5718 100644 --- a/src/ui/gui/crosstabs-dialog.c +++ b/src/ui/gui/crosstabs-dialog.c @@ -422,9 +422,7 @@ crosstabs_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + g_object_set (source, "model", vs->dict, NULL); set_dest_model (GTK_TREE_VIEW (dest_rows), vs->dict); set_dest_model (GTK_TREE_VIEW (dest_cols), vs->dict); diff --git a/src/ui/gui/crosstabs.glade b/src/ui/gui/crosstabs.glade index d5907a55..0409d9e5 100644 --- a/src/ui/gui/crosstabs.glade +++ b/src/ui/gui/crosstabs.glade @@ -111,7 +111,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True False diff --git a/src/ui/gui/descriptives-dialog.c b/src/ui/gui/descriptives-dialog.c index e3a6d505..77bf9541 100644 --- a/src/ui/gui/descriptives-dialog.c +++ b/src/ui/gui/descriptives-dialog.c @@ -223,9 +223,8 @@ descriptives_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, var_is_numeric); + g_object_set (source, "model", vs->dict, + "predicate", var_is_numeric, NULL); set_dest_model (GTK_TREE_VIEW (dest), vs->dict); diff --git a/src/ui/gui/descriptives-dialog.glade b/src/ui/gui/descriptives-dialog.glade index 6ce00df8..3fa67a55 100644 --- a/src/ui/gui/descriptives-dialog.glade +++ b/src/ui/gui/descriptives-dialog.glade @@ -29,7 +29,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/dict-display.c b/src/ui/gui/dict-display.c index 023b063f..2123c3c5 100644 --- a/src/ui/gui/dict-display.c +++ b/src/ui/gui/dict-display.c @@ -30,68 +30,7 @@ #define _(msgid) gettext (msgid) #define N_(msgid) msgid - -/* A GtkTreeModelFilterVisibleFunc to filter lines in the treeview */ -static gboolean -filter_variables (GtkTreeModel *model, GtkTreeIter *iter, gpointer data) -{ - var_predicate_func *predicate = data; - struct variable *var; - PsppireDict *dict = PSPPIRE_DICT (model); - - GtkTreePath *path = gtk_tree_model_get_path (model, iter); - - gint *idx = gtk_tree_path_get_indices (path); - - var = psppire_dict_get_variable (dict, *idx); - - gtk_tree_path_free (path); - - return predicate (var); -} - -/* A GtkTreeCellDataFunc which sets the icon appropriate to the type - of variable */ static void -var_icon_cell_data_func (GtkTreeViewColumn *col, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - struct variable *var; - gtk_tree_model_get (model, iter, DICT_TVM_COL_VAR, &var, -1); - - if ( var_is_alpha (var)) - { - g_object_set (cell, "stock-id", "var-string", NULL); - } - else - { - const struct fmt_spec *fs = var_get_write_format (var); - int cat = fmt_get_category (fs->type); - switch ( var_get_measure (var)) - { - case MEASURE_NOMINAL: - g_object_set (cell, "stock-id", "var-nominal", NULL); - break; - case MEASURE_ORDINAL: - g_object_set (cell, "stock-id", "var-ordinal", NULL); - break; - case MEASURE_SCALE: - if ( ( FMT_CAT_DATE | FMT_CAT_TIME ) & cat ) - g_object_set (cell, "stock-id", "var-date-scale", NULL); - else - g_object_set (cell, "stock-id", "var-scale", NULL); - break; - default: - g_assert_not_reached (); - }; - } -} - - -void get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter, GtkTreeModel **model, GtkTreeIter *iter ) @@ -113,189 +52,6 @@ get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter, g_assert (PSPPIRE_IS_DICT (*model)); } -/* A GtkTreeCellDataFunc which renders the name and/or label of the - variable */ -static void -var_description_cell_data_func (GtkTreeViewColumn *col, - GtkCellRenderer *cell, - GtkTreeModel *top_model, - GtkTreeIter *top_iter, - gpointer data) -{ - 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); - - g_assert (PSPPIRE_IS_DICT (model)); - - - gtk_tree_model_get (model, - &iter, DICT_TVM_COL_VAR, &var, -1); - - if ( var_has_label (var) && prefer_labels) - { - gchar *text = g_strdup_printf ( - "%s", - var_get_label (var)); - - char *utf8 = pspp_locale_to_utf8 (text, -1, NULL); - - g_free (text); - g_object_set (cell, "markup", utf8, NULL); - g_free (utf8); - } - else - { - 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 - all are to be visible. - */ -void -attach_dictionary_to_treeview (GtkTreeView *treeview, PsppireDict *dict, - GtkSelectionMode mode, - var_predicate_func *predicate - ) -{ - GtkTreeViewColumn *col; - - GtkTreeSelection *selection = - gtk_tree_view_get_selection (treeview); - - GtkCellRenderer *renderer; - - GtkTreeModel *model ; - - if ( predicate ) - { - model = gtk_tree_model_filter_new (GTK_TREE_MODEL (dict), - NULL); - - gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model), - filter_variables, - predicate, - NULL); - } - else - { - model = GTK_TREE_MODEL (dict); - } - - gtk_tree_view_set_model (GTK_TREE_VIEW (treeview), model); - - - col = gtk_tree_view_column_new (); - gtk_tree_view_column_set_title (col, _("Variable")); - - renderer = gtk_cell_renderer_pixbuf_new (); - gtk_tree_view_column_pack_start (col, renderer, FALSE); - - gtk_tree_view_column_set_cell_data_func (col, renderer, - var_icon_cell_data_func, - NULL, NULL); - - - renderer = gtk_cell_renderer_text_new (); - gtk_tree_view_column_pack_start (col, renderer, TRUE); - gtk_tree_view_column_set_cell_data_func (col, renderer, - var_description_cell_data_func, - NULL, NULL); - - g_object_set (renderer, "ellipsize-set", TRUE, NULL); - g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_MIDDLE, NULL); - - gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED); - - /* FIXME: make this a value in terms of character widths */ - gtk_tree_view_column_set_min_width (col, 150); - - gtk_tree_view_append_column (treeview, col); - - gtk_tree_selection_set_mode (selection, mode); - - g_object_set (treeview, "has-tooltip", TRUE, NULL); - - g_signal_connect (treeview, "query-tooltip", G_CALLBACK (set_tooltip_for_variable), NULL); -} void @@ -394,3 +150,4 @@ is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter, } + diff --git a/src/ui/gui/dict-display.h b/src/ui/gui/dict-display.h index a9481c6d..2c8df440 100644 --- a/src/ui/gui/dict-display.h +++ b/src/ui/gui/dict-display.h @@ -22,18 +22,6 @@ #include #include "psppire-selector.h" -#include "psppire-dict.h" -#include - -/* 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 - all are to be visible. - */ -void attach_dictionary_to_treeview (GtkTreeView *treeview, PsppireDict *dict, - GtkSelectionMode mode, - var_predicate_func *predicate - ); /* A SelectItemsFunc function for GtkTreeView widgets */ @@ -58,6 +46,3 @@ gboolean is_currently_in_entry (GtkTreeModel *model, GtkTreeIter *iter, PsppireSelector *selector); -void get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter, - GtkTreeModel **model, GtkTreeIter *iter - ); diff --git a/src/ui/gui/examine-dialog.c b/src/ui/gui/examine-dialog.c index 171d88cf..2902685d 100644 --- a/src/ui/gui/examine-dialog.c +++ b/src/ui/gui/examine-dialog.c @@ -279,10 +279,7 @@ examine_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (ex_d.stats_dialog), GTK_WINDOW (de)); gtk_window_set_transient_for (GTK_WINDOW (ex_d.opts_dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); - + g_object_set (source, "model", vs->dict, NULL); set_dest_model (GTK_TREE_VIEW (ex_d.dep_list), vs->dict); ex_d.dict = vs->dict; diff --git a/src/ui/gui/examine.glade b/src/ui/gui/examine.glade index 884e0001..a6f7ca8a 100644 --- a/src/ui/gui/examine.glade +++ b/src/ui/gui/examine.glade @@ -218,7 +218,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/find-dialog.c b/src/ui/gui/find-dialog.c index 130b25cf..60d54e26 100644 --- a/src/ui/gui/find-dialog.c +++ b/src/ui/gui/find-dialog.c @@ -241,10 +241,9 @@ find_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - fd.dict, - GTK_SELECTION_SINGLE, - NULL); + g_object_set (source, "model", fd.dict, + "selection-mode", GTK_SELECTION_SINGLE, + NULL); psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector), source, diff --git a/src/ui/gui/frequencies-dialog.c b/src/ui/gui/frequencies-dialog.c index 37e301b8..a368cabb 100644 --- a/src/ui/gui/frequencies-dialog.c +++ b/src/ui/gui/frequencies-dialog.c @@ -333,9 +333,7 @@ frequencies_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + g_object_set (source, "model", vs->dict, NULL); set_dest_model (GTK_TREE_VIEW (dest), vs->dict); diff --git a/src/ui/gui/frequencies.glade b/src/ui/gui/frequencies.glade index 5617d40d..3e5e9213 100644 --- a/src/ui/gui/frequencies.glade +++ b/src/ui/gui/frequencies.glade @@ -29,7 +29,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/oneway-anova-dialog.c b/src/ui/gui/oneway-anova-dialog.c index d41b2760..a2b47fa5 100644 --- a/src/ui/gui/oneway-anova-dialog.c +++ b/src/ui/gui/oneway-anova-dialog.c @@ -170,9 +170,7 @@ oneway_anova_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (ow.dialog, GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + g_object_set (dict_view, "model", vs->dict, NULL); set_dest_model (GTK_TREE_VIEW (ow.vars_treeview), vs->dict); diff --git a/src/ui/gui/oneway.glade b/src/ui/gui/oneway.glade index bdca13dd..4b12f68b 100644 --- a/src/ui/gui/oneway.glade +++ b/src/ui/gui/oneway.glade @@ -139,7 +139,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/psppire-dictview.c b/src/ui/gui/psppire-dictview.c new file mode 100644 index 00000000..d955fae1 --- /dev/null +++ b/src/ui/gui/psppire-dictview.c @@ -0,0 +1,509 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2009 Free Software Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +#include +#include "psppire-dictview.h" +#include "psppire-dict.h" +#include "psppire-conf.h" +#include +#include "helper.h" + +#include +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + +static void psppire_dict_view_base_finalize (PsppireDictViewClass *, gpointer); +static void psppire_dict_view_base_init (PsppireDictViewClass *class); +static void psppire_dict_view_class_init (PsppireDictViewClass *class); +static void psppire_dict_view_init (PsppireDictView *dict_view); + + +GType +psppire_dict_view_get_type (void) +{ + static GType psppire_dict_view_type = 0; + + if (!psppire_dict_view_type) + { + static const GTypeInfo psppire_dict_view_info = + { + sizeof (PsppireDictViewClass), + (GBaseInitFunc) psppire_dict_view_base_init, + (GBaseFinalizeFunc) psppire_dict_view_base_finalize, + (GClassInitFunc)psppire_dict_view_class_init, + (GClassFinalizeFunc) NULL, + NULL, + sizeof (PsppireDictView), + 0, + (GInstanceInitFunc) psppire_dict_view_init, + }; + + psppire_dict_view_type = + g_type_register_static (GTK_TYPE_TREE_VIEW, "PsppireDictView", + &psppire_dict_view_info, 0); + } + + return psppire_dict_view_type; +} + + +static void +psppire_dict_view_finalize (GObject *object) +{ +} + +/* Properties */ +enum +{ + PROP_0, + PROP_MODEL, + PROP_PREDICATE, + PROP_SELECTION_MODE +}; + + +/* A GtkTreeModelFilterVisibleFunc to filter lines in the treeview */ +static gboolean +filter_variables (GtkTreeModel *model, GtkTreeIter *iter, gpointer data) +{ + var_predicate_func *predicate = data; + struct variable *var; + PsppireDict *dict = PSPPIRE_DICT (model); + + GtkTreePath *path = gtk_tree_model_get_path (model, iter); + + gint *idx = gtk_tree_path_get_indices (path); + + var = psppire_dict_get_variable (dict, *idx); + + gtk_tree_path_free (path); + + return predicate (var); +} + +static void +set_model (PsppireDictView *dict_view) +{ + GtkTreeModel *model ; + + if ( dict_view->predicate ) + { + model = gtk_tree_model_filter_new (GTK_TREE_MODEL (dict_view->dict), + NULL); + + gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (model), + filter_variables, + dict_view->predicate, + NULL); + } + else + { + model = GTK_TREE_MODEL (dict_view->dict); + } + + gtk_tree_view_set_model (GTK_TREE_VIEW (dict_view), model); +} + +static void +psppire_dict_view_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + PsppireDictView *dict_view = PSPPIRE_DICT_VIEW (object); + + switch (prop_id) + { + case PROP_MODEL: + dict_view->dict = g_value_get_object (value); + break; + case PROP_PREDICATE: + dict_view->predicate = g_value_get_pointer (value); + break; + case PROP_SELECTION_MODE: + { + GtkTreeSelection *selection = + gtk_tree_view_get_selection (GTK_TREE_VIEW (dict_view)); + + GtkSelectionMode mode = g_value_get_enum (value); + + gtk_tree_selection_set_mode (selection, mode); + } + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + }; + + + set_model (dict_view); +} + + +static void +psppire_dict_view_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + PsppireDictView *dict_view = PSPPIRE_DICT_VIEW (object); + + switch (prop_id) + { + case PROP_MODEL: + g_value_set_object (value, dict_view->dict); + break; + case PROP_PREDICATE: + g_value_set_pointer (value, dict_view->predicate); + break; + case PROP_SELECTION_MODE: + { + GtkTreeSelection *selection = + gtk_tree_view_get_selection (GTK_TREE_VIEW (dict_view)); + + g_value_set_enum (value, gtk_tree_selection_get_mode (selection)); + } + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + }; +} + + + +static void +psppire_dict_view_class_init (PsppireDictViewClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + GParamSpec *model_spec = + g_param_spec_object ("model", + "Model", + _("The dictionary to be displayed by this widget"), + G_TYPE_PSPPIRE_DICT, + G_PARAM_READABLE | G_PARAM_WRITABLE); + + GParamSpec *predicate_spec = + g_param_spec_pointer ("predicate", + "Predicate", + _("A predicate function"), + G_PARAM_READABLE | G_PARAM_WRITABLE); + + + GParamSpec *selection_mode_spec = + g_param_spec_enum ("selection-mode", + "Selection Mode", + _("How many things can be selected"), + GTK_TYPE_SELECTION_MODE, + GTK_SELECTION_MULTIPLE, + G_PARAM_CONSTRUCT | G_PARAM_READABLE | G_PARAM_WRITABLE); + + + object_class->set_property = psppire_dict_view_set_property; + object_class->get_property = psppire_dict_view_get_property; + + g_object_class_install_property (object_class, + PROP_MODEL, + model_spec); + + g_object_class_install_property (object_class, + PROP_PREDICATE, + predicate_spec); + + g_object_class_install_property (object_class, + PROP_SELECTION_MODE, + selection_mode_spec); +} + + +static void +psppire_dict_view_base_init (PsppireDictViewClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->finalize = psppire_dict_view_finalize; +} + + + +static void +psppire_dict_view_base_finalize(PsppireDictViewClass *class, + gpointer class_data) +{ + +} + + +static void +dv_get_base_model (GtkTreeModel *top_model, GtkTreeIter *top_iter, + GtkTreeModel **model, GtkTreeIter *iter + ) +{ + *model = top_model; + *iter = *top_iter; + while (GTK_IS_TREE_MODEL_FILTER (*model)) + { + GtkTreeIter parent_iter = *iter; + GtkTreeModelFilter *parent_model = GTK_TREE_MODEL_FILTER (*model); + + *model = gtk_tree_model_filter_get_model (parent_model); + + gtk_tree_model_filter_convert_iter_to_child_iter (parent_model, + iter, + &parent_iter); + } + + g_assert (PSPPIRE_IS_DICT (*model)); +} + + + +/* A GtkTreeCellDataFunc which renders the name and/or label of the + variable */ +static void +var_description_cell_data_func (GtkTreeViewColumn *col, + GtkCellRenderer *cell, + GtkTreeModel *top_model, + GtkTreeIter *top_iter, + gpointer data) +{ + 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); + + dv_get_base_model (top_model, top_iter, &model, &iter); + + g_assert (PSPPIRE_IS_DICT (model)); + + + gtk_tree_model_get (model, + &iter, DICT_TVM_COL_VAR, &var, -1); + + if ( var_has_label (var) && prefer_labels) + { + gchar *text = g_strdup_printf ( + "%s", + var_get_label (var)); + + char *utf8 = pspp_locale_to_utf8 (text, -1, NULL); + + g_free (text); + g_object_set (cell, "markup", utf8, NULL); + g_free (utf8); + } + else + { + char *name = pspp_locale_to_utf8 (var_get_name (var), -1, NULL); + g_object_set (cell, "text", name, NULL); + g_free (name); + } +} + + + +/* A GtkTreeCellDataFunc which sets the icon appropriate to the type + of variable */ +static void +var_icon_cell_data_func (GtkTreeViewColumn *col, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data) +{ + struct variable *var; + gtk_tree_model_get (model, iter, DICT_TVM_COL_VAR, &var, -1); + + if ( var_is_alpha (var)) + { + g_object_set (cell, "stock-id", "var-string", NULL); + } + else + { + const struct fmt_spec *fs = var_get_write_format (var); + int cat = fmt_get_category (fs->type); + switch ( var_get_measure (var)) + { + case MEASURE_NOMINAL: + g_object_set (cell, "stock-id", "var-nominal", NULL); + break; + case MEASURE_ORDINAL: + g_object_set (cell, "stock-id", "var-ordinal", NULL); + break; + case MEASURE_SCALE: + if ( ( FMT_CAT_DATE | FMT_CAT_TIME ) & cat ) + g_object_set (cell, "stock-id", "var-date-scale", NULL); + else + g_object_set (cell, "stock-id", "var-scale", NULL); + break; + default: + g_assert_not_reached (); + }; + } +} + + +/* 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; +} + + +static void +psppire_dict_view_init (PsppireDictView *dict_view) +{ + GtkTreeViewColumn *col; + + GtkCellRenderer *renderer; + + col = gtk_tree_view_column_new (); + gtk_tree_view_column_set_title (col, _("Variable")); + + renderer = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (col, renderer, FALSE); + + gtk_tree_view_column_set_cell_data_func (col, renderer, + var_icon_cell_data_func, + NULL, NULL); + + + renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (col, renderer, TRUE); + gtk_tree_view_column_set_cell_data_func (col, renderer, + var_description_cell_data_func, + NULL, NULL); + + g_object_set (renderer, "ellipsize-set", TRUE, NULL); + g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_MIDDLE, NULL); + + gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_FIXED); + + /* FIXME: make this a value in terms of character widths */ + gtk_tree_view_column_set_min_width (col, 150); + + gtk_tree_view_append_column (GTK_TREE_VIEW (dict_view), col); + + g_object_set (dict_view, "has-tooltip", TRUE, NULL); + + g_signal_connect (dict_view, "query-tooltip", + G_CALLBACK (set_tooltip_for_variable), NULL); +} + + +GtkWidget* +psppire_dict_view_new (void) +{ + return GTK_WIDGET (g_object_new (psppire_dict_view_get_type (), NULL)); +} + + + +struct variable * +psppire_dict_view_get_selected_variable (PsppireDictView *treeview) +{ + struct variable *var; + GtkTreeModel *top_model; + GtkTreeIter top_iter; + + GtkTreeModel *model; + GtkTreeIter iter; + + GtkTreeSelection *selection = + gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); + + if (! gtk_tree_selection_get_selected (selection, + &top_model, &top_iter)) + { + return NULL; + } + + dv_get_base_model (top_model, &top_iter, &model, &iter); + + g_assert (PSPPIRE_IS_DICT (model)); + + gtk_tree_model_get (model, + &iter, DICT_TVM_COL_VAR, &var, -1); + + return var; +} + + diff --git a/src/ui/gui/psppire-dictview.h b/src/ui/gui/psppire-dictview.h new file mode 100644 index 00000000..98000ff5 --- /dev/null +++ b/src/ui/gui/psppire-dictview.h @@ -0,0 +1,66 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2009 Free Software Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#ifndef __PSPPIRE_DICT_VIEW_H__ +#define __PSPPIRE_DICT_VIEW_H__ + + +#include +#include +#include + +#include "psppire-dict.h" +#include "dict-display.h" + +G_BEGIN_DECLS + +#define PSPPIRE_DICT_VIEW_TYPE (psppire_dict_view_get_type ()) +#define PSPPIRE_DICT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PSPPIRE_DICT_VIEW_TYPE, PsppireDictView)) +#define PSPPIRE_DICT_VIEW_CLASS(class) (G_TYPE_CHECK_CLASS_CAST ((class), \ + PSPPIRE_DICT_VIEW_TYPE, PsppireDictViewClass)) +#define PSPPIRE_IS_DICT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + PSPPIRE_DICT_VIEW_TYPE)) +#define PSPPIRE_IS_DICT_VIEW_CLASS(class) (G_TYPE_CHECK_CLASS_TYPE ((class), \ + PSPPIRE_DICT_VIEW_TYPE)) + + +typedef struct _PsppireDictView PsppireDictView; +typedef struct _PsppireDictViewClass PsppireDictViewClass; + + + +struct _PsppireDictView +{ + GtkTreeView parent; + + PsppireDict *dict; + var_predicate_func *predicate; +}; + +struct _PsppireDictViewClass +{ + GtkTreeViewClass parent_class; + +}; + +GType psppire_dict_view_get_type (void); +struct variable * psppire_dict_view_get_selected_variable (PsppireDictView *); + + +G_END_DECLS + +#endif /* __PSPPIRE_DICT_VIEW_H__ */ diff --git a/src/ui/gui/psppire.glade b/src/ui/gui/psppire.glade index 8be27e38..ad08cb2b 100644 --- a/src/ui/gui/psppire.glade +++ b/src/ui/gui/psppire.glade @@ -47,7 +47,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True False True @@ -212,7 +212,7 @@ GTK_POLICY_NEVER GTK_POLICY_AUTOMATIC - + True False @@ -394,7 +394,7 @@ GTK_POLICY_NEVER GTK_POLICY_AUTOMATIC - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -680,7 +680,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -924,7 +924,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -1187,7 +1187,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/rank-dialog.c b/src/ui/gui/rank-dialog.c index 8ea25a1d..606475ba 100644 --- a/src/ui/gui/rank-dialog.c +++ b/src/ui/gui/rank-dialog.c @@ -306,10 +306,7 @@ rank_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (vars), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); - + g_object_set (vars, "model", vs->dict, NULL); set_dest_model (GTK_TREE_VIEW (rd.rank_vars), vs->dict); diff --git a/src/ui/gui/rank.glade b/src/ui/gui/rank.glade index 6f65542f..fd412dfe 100644 --- a/src/ui/gui/rank.glade +++ b/src/ui/gui/rank.glade @@ -32,7 +32,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/recode-dialog.c b/src/ui/gui/recode-dialog.c index 859737f6..e5de4597 100644 --- a/src/ui/gui/recode-dialog.c +++ b/src/ui/gui/recode-dialog.c @@ -885,10 +885,7 @@ recode_dialog (PsppireDataWindow *de, gboolean diff) gtk_window_set_transient_for (GTK_WINDOW (rd.dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (rd.dict_treeview), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); - + g_object_set (rd.dict_treeview, "model", vs->dict, NULL); if ( ! rd.different ) { diff --git a/src/ui/gui/recode.glade b/src/ui/gui/recode.glade index a3b795e6..6edcc0ab 100644 --- a/src/ui/gui/recode.glade +++ b/src/ui/gui/recode.glade @@ -775,7 +775,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/regression-dialog.c b/src/ui/gui/regression-dialog.c index 2d8aca3e..a8605018 100644 --- a/src/ui/gui/regression-dialog.c +++ b/src/ui/gui/regression-dialog.c @@ -252,9 +252,7 @@ regression_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + g_object_set (source, "model", vs->dict, NULL); set_dest_model (GTK_TREE_VIEW (dest_dep), vs->dict); set_dest_model (GTK_TREE_VIEW (dest_indep), vs->dict); diff --git a/src/ui/gui/regression.glade b/src/ui/gui/regression.glade index 3ee4973b..e6bac4d8 100644 --- a/src/ui/gui/regression.glade +++ b/src/ui/gui/regression.glade @@ -95,7 +95,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/select-cases-dialog.c b/src/ui/gui/select-cases-dialog.c index e4d599ed..9d72344f 100644 --- a/src/ui/gui/select-cases-dialog.c +++ b/src/ui/gui/select-cases-dialog.c @@ -324,9 +324,10 @@ select_cases_dialog (GObject *o, gpointer data) { GtkWidget *source = get_widget_assert (scd.xml, "select-cases-treeview"); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - scd.data_store->dict, - GTK_SELECTION_SINGLE, NULL); + g_object_set (source, "model", + scd.data_store->dict, + "selection-mode", + GTK_SELECTION_SINGLE, NULL); psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector), source, diff --git a/src/ui/gui/sort-cases-dialog.c b/src/ui/gui/sort-cases-dialog.c index d9c665e6..44792432 100644 --- a/src/ui/gui/sort-cases-dialog.c +++ b/src/ui/gui/sort-cases-dialog.c @@ -110,9 +110,7 @@ sort_cases_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + g_object_set (source, "model", vs->dict, NULL); set_dest_model (GTK_TREE_VIEW (dest), vs->dict); diff --git a/src/ui/gui/split-file-dialog.c b/src/ui/gui/split-file-dialog.c index 8708b33f..1641b50c 100644 --- a/src/ui/gui/split-file-dialog.c +++ b/src/ui/gui/split-file-dialog.c @@ -191,9 +191,8 @@ split_file_dialog (GObject *o, gpointer data) sfd.selector = PSPPIRE_SELECTOR ( get_widget_assert (sfd.xml, "split-file-selector")); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + g_object_set (source, "model", + vs->dict, NULL); g_signal_connect (on_off, "toggled", G_CALLBACK(on_off_toggled), sfd.xml); diff --git a/src/ui/gui/t-test-independent-samples-dialog.c b/src/ui/gui/t-test-independent-samples-dialog.c index 392867ad..53b2c20c 100644 --- a/src/ui/gui/t-test-independent-samples-dialog.c +++ b/src/ui/gui/t-test-independent-samples-dialog.c @@ -426,9 +426,9 @@ t_test_independent_samples_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (tt_d.dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view), + g_object_set (dict_view, "model", vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + NULL); set_dest_model (GTK_TREE_VIEW (test_variables_treeview), vs->dict); diff --git a/src/ui/gui/t-test-one-sample.c b/src/ui/gui/t-test-one-sample.c index 3cdc91c3..64232d85 100644 --- a/src/ui/gui/t-test-one-sample.c +++ b/src/ui/gui/t-test-one-sample.c @@ -147,10 +147,10 @@ t_test_one_sample_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view), + g_object_set (dict_view, "model", vs->dict, - GTK_SELECTION_MULTIPLE, - var_is_numeric); + "predicate", + var_is_numeric, NULL); set_dest_model (GTK_TREE_VIEW (tt_d.vars_treeview), vs->dict); diff --git a/src/ui/gui/t-test-paired-samples.c b/src/ui/gui/t-test-paired-samples.c index ca1d776a..50964b6e 100644 --- a/src/ui/gui/t-test-paired-samples.c +++ b/src/ui/gui/t-test-paired-samples.c @@ -205,10 +205,10 @@ t_test_paired_samples_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (dict_view), + g_object_set (dict_view, "model", vs->dict, - GTK_SELECTION_MULTIPLE, - var_is_numeric); + "predicate", + var_is_numeric, NULL); { tt_d.list_store = diff --git a/src/ui/gui/t-test.glade b/src/ui/gui/t-test.glade index e355daf4..040a99ea 100644 --- a/src/ui/gui/t-test.glade +++ b/src/ui/gui/t-test.glade @@ -26,7 +26,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -568,7 +568,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK @@ -686,7 +686,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_ETCHED_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/transpose-dialog.c b/src/ui/gui/transpose-dialog.c index 09756d37..0e8a6259 100644 --- a/src/ui/gui/transpose-dialog.c +++ b/src/ui/gui/transpose-dialog.c @@ -94,9 +94,7 @@ transpose_dialog (GObject *o, gpointer data) g_object_get (de->data_editor, "var-store", &vs, NULL); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_MULTIPLE, NULL); + g_object_set (source, "model", vs->dict, NULL); set_dest_model (GTK_TREE_VIEW (dest), vs->dict); diff --git a/src/ui/gui/variable-info-dialog.c b/src/ui/gui/variable-info-dialog.c index 6fc8dd89..0b40a8f1 100644 --- a/src/ui/gui/variable-info-dialog.c +++ b/src/ui/gui/variable-info-dialog.c @@ -17,7 +17,7 @@ #include #include -#include "dict-display.h" +//#include "dict-display.h" #include "var-display.h" #include #include @@ -25,6 +25,7 @@ #include "psppire-data-window.h" #include "psppire-dialog.h" #include "psppire-var-store.h" +#include "psppire-dictview.h" #include "helper.h" #include @@ -36,44 +37,17 @@ #define N_(msgid) msgid -static struct variable * -get_selected_variable (GtkTreeView *treeview) -{ - struct variable *var; - GtkTreeModel *top_model; - GtkTreeIter top_iter; - - GtkTreeModel *model; - GtkTreeIter iter; - - GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); - - if (! gtk_tree_selection_get_selected (selection, - &top_model, &top_iter)) - { - return NULL; - } - - get_base_model (top_model, &top_iter, &model, &iter); - - g_assert (PSPPIRE_IS_DICT (model)); - - gtk_tree_model_get (model, - &iter, DICT_TVM_COL_VAR, &var, -1); - - return var; -} - - static void -populate_text (GtkTreeView *treeview, gpointer data) +populate_text (PsppireDictView *treeview, gpointer data) { gchar *text = 0; GString *gstring; GtkTextBuffer *textbuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(data)); - const struct variable *var = get_selected_variable (treeview); + const struct variable *var = + psppire_dict_view_get_selected_variable (treeview); + if ( var == NULL) return; @@ -157,7 +131,7 @@ treeview_item_selected (gpointer data) } -static gchar * generate_syntax (GtkTreeView *treeview); +static gchar * generate_syntax (PsppireDictView *treeview); void @@ -179,11 +153,10 @@ variable_info_dialog (GObject *o, gpointer data) gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de)); - attach_dictionary_to_treeview (GTK_TREE_VIEW (treeview), - vs->dict, - GTK_SELECTION_SINGLE, - NULL ); - + g_object_set (treeview, + "model", vs->dict, + "selection-mode", GTK_SELECTION_SINGLE, + NULL); g_signal_connect (treeview, "cursor-changed", G_CALLBACK (populate_text), textview); @@ -201,18 +174,20 @@ variable_info_dialog (GObject *o, gpointer data) case PSPPIRE_RESPONSE_GOTO: { const struct variable *var = - get_selected_variable (GTK_TREE_VIEW (treeview)); + psppire_dict_view_get_selected_variable (PSPPIRE_DICT_VIEW (treeview)); if ( NULL == var) goto done; - g_object_set (de->data_editor, "current-variable", var_get_dict_index (var), NULL); + g_object_set (de->data_editor, + "current-variable", var_get_dict_index (var), + NULL); } break; case PSPPIRE_RESPONSE_PASTE: { - gchar *syntax = generate_syntax (GTK_TREE_VIEW (treeview)); + gchar *syntax = generate_syntax (PSPPIRE_DICT_VIEW (treeview)); paste_syntax_in_new_window (syntax); g_free (syntax); @@ -227,9 +202,10 @@ variable_info_dialog (GObject *o, gpointer data) } static gchar * -generate_syntax (GtkTreeView *treeview) +generate_syntax (PsppireDictView *treeview) { - const struct variable *var = get_selected_variable (treeview); + const struct variable *var = + psppire_dict_view_get_selected_variable (treeview); if ( NULL == var) return g_strdup (""); diff --git a/src/ui/gui/variable-info-dialog.glade b/src/ui/gui/variable-info-dialog.glade index 147d66a2..1acb84ea 100644 --- a/src/ui/gui/variable-info-dialog.glade +++ b/src/ui/gui/variable-info-dialog.glade @@ -21,7 +21,7 @@ GTK_POLICY_AUTOMATIC GTK_SHADOW_IN - + True True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK diff --git a/src/ui/gui/weight-cases-dialog.c b/src/ui/gui/weight-cases-dialog.c index a464646f..8cfae24b 100644 --- a/src/ui/gui/weight-cases-dialog.c +++ b/src/ui/gui/weight-cases-dialog.c @@ -130,11 +130,10 @@ weight_cases_dialog (GObject *o, gpointer data) g_signal_connect (selector, "de-selected", G_CALLBACK (on_deselect), radiobutton1); - attach_dictionary_to_treeview (GTK_TREE_VIEW (source), - vs->dict, - GTK_SELECTION_SINGLE, - var_is_numeric - ); + g_object_set (source, "model", vs->dict, + "selection-mode", GTK_SELECTION_SINGLE, + "predicate", var_is_numeric, + NULL); psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector), source, diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 843f1f3c..979224fe 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -1,11 +1,15 @@ +#include + #include "widgets.h" + #include "psppire-dialog.h" #include "psppire-selector.h" #include "psppire-vbuttonbox.h" #include "psppire-hbuttonbox.h" #include "psppire-keypad.h" #include "psppire-acr.h" +#include "psppire-dictview.h" /* Any custom widgets which are to be used in GtkBuilder ui files @@ -20,4 +24,5 @@ preregister_widgets (void) psppire_hbutton_box_get_type (); psppire_keypad_get_type (); psppire_acr_get_type (); + psppire_dict_view_get_type (); } -- 2.30.2