X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fdialog-common.c;h=0aab294e12ef0b2a8ca937851f60533525847619;hb=81622911cfbb5f21b20c04dc88c711ecb45a9504;hp=723a65e4a3bf5751b0923961db90bdf36000e989;hpb=c65449a628d13f4683e7dc7125874608c7152017;p=pspp-builds.git diff --git a/src/ui/gui/dialog-common.c b/src/ui/gui/dialog-common.c index 723a65e4..0aab294e 100644 --- a/src/ui/gui/dialog-common.c +++ b/src/ui/gui/dialog-common.c @@ -15,18 +15,22 @@ along with this program. If not, see . */ #include + #include "dialog-common.h" +#include "psppire-var-ptr.h" + #include "helper.h" /* Append the names of selected variables to STRING. TREEVIEW is the treeview containing the variables. + COLUMN is the column in the treeview containing the variables. DICT is the dictionary for those variables. */ gint append_variable_names (GString *string, - PsppireDict *dict, GtkTreeView *treeview) + PsppireDict *dict, GtkTreeView *treeview, gint column) { gint n_vars = 0; GtkTreeIter iter; @@ -39,12 +43,23 @@ append_variable_names (GString *string, do { GValue value = {0}; - struct variable *var; + struct variable *var = NULL; GtkTreePath *path = gtk_tree_model_get_path (list_store, &iter); - gtk_tree_model_get_value (list_store, &iter, 0, &value); + gtk_tree_model_get_value (list_store, &iter, column, &value); + /* FIXME: G_TYPE_INT should be deprecated. + As well as being simpler, it'd be unecessary to pass dict */ + if ( G_VALUE_TYPE (&value) == G_TYPE_INT ) var = psppire_dict_get_variable (dict, g_value_get_int (&value)); + + else if ( G_VALUE_TYPE (&value) == PSPPIRE_VAR_PTR_TYPE) + var = g_value_get_boxed (&value); + + else + g_critical ("Unsupported type \"%s\", in variable name treeview.", + G_VALUE_TYPE_NAME (&value)); + g_value_unset (&value); g_string_append (string, " "); @@ -178,16 +193,15 @@ homogeneous_types (GtkWidget *source, GtkWidget *dest) for (l = list; l ; l = l->next) { GtkTreePath *path = l->data; - GtkTreePath *fpath; - gint *idx; - const struct variable *v; + GtkTreePath *fpath = + gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path); - fpath = gtk_tree_model_filter_convert_path_to_child_path (GTK_TREE_MODEL_FILTER (model), path); + gint *idx = gtk_tree_path_get_indices (fpath); - idx = gtk_tree_path_get_indices (fpath); + const struct variable *v = psppire_dict_get_variable (dict, idx[0]); - v = psppire_dict_get_variable (dict, idx[0]); + gtk_tree_path_free (fpath); if ( type != -1 ) { @@ -236,3 +250,54 @@ homogeneous_types (GtkWidget *source, GtkWidget *dest) return retval; } + + +/* Returns true iff the variable selected by SOURCE is numeric */ +gboolean +numeric_only (GtkWidget *source, GtkWidget *dest) +{ + gboolean retval = TRUE; + + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (source)); + + PsppireDict *dict; + GtkTreeSelection *selection; + GList *list, *l; + + while (GTK_IS_TREE_MODEL_FILTER (model)) + { + model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model)); + } + + dict = PSPPIRE_DICT (model); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (source)); + + list = gtk_tree_selection_get_selected_rows (selection, &model); + + /* Iterate through the selection of the source treeview */ + for (l = list; l ; l = l->next) + { + GtkTreePath *path = l->data; + GtkTreePath *fpath = gtk_tree_model_filter_convert_path_to_child_path + (GTK_TREE_MODEL_FILTER (model), path); + + gint *idx = gtk_tree_path_get_indices (fpath); + + const struct variable *v = psppire_dict_get_variable (dict, idx[0]); + + gtk_tree_path_free (fpath); + + if ( var_is_alpha (v)) + { + retval = FALSE; + break; + } + } + + g_list_foreach (list, (GFunc) gtk_tree_path_free, NULL); + g_list_free (list); + + return retval; +} +