gui: Pasting also considers labels as valid data
authorFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 12 Jul 2020 16:36:16 +0000 (18:36 +0200)
committerFriedrich Beckmann <friedrich.beckmann@gmx.de>
Sun, 12 Jul 2020 16:47:08 +0000 (18:47 +0200)
With this patch pasting from clipboard also interprets labels as
valid data. First it is checked if the pasted data is a label for
the destination variable. Then the corresponding data is stored.

src/ui/gui/psppire-data-store.c

index c780e06eb0e2dd75024e5c4059ab31a1556856f7..c0fc42a2f285a87ff32a5da5a9e3d1595990a621 100644 (file)
@@ -155,9 +155,20 @@ psppire_data_store_string_to_value (GtkTreeModel *model, gint col, gint row,
 
   union value val;
   value_init (&val, width);
-  char *xx =
-    data_in (ss_cstr (in), psppire_dict_encoding (store->dict),
-            fmt->type, &val, width, "UTF-8");
+  const struct val_labs *value_labels = var_get_value_labels (variable);
+  const union value *vp = NULL;
+  if (value_labels)
+    {
+      vp = val_labs_find_value (value_labels, in);
+      if (vp)
+       value_copy (&val, vp, width);
+    }
+  char *xx = NULL;
+  if (vp == NULL)
+    {
+      xx = data_in (ss_cstr (in), psppire_dict_encoding (store->dict),
+                   fmt->type, &val, width, "UTF-8");
+    }
 
   GVariant *vrnt = value_variant_new (&val, width);
   value_destroy (&val, width);