Improve behaviour when importing trivial csv files.
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 27 Jun 2020 07:19:27 +0000 (09:19 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 27 Jun 2020 07:19:27 +0000 (09:19 +0200)
This is a follow up to commit 5312cd16f3d7226d4e62a847d64849c57d4b4843
Don't activate any check button, if there is no obvious candidate.

src/ui/gui/psppire-import-assistant.c

index 4de70352438dbb2bfc1b70add83ced17ad21fb2c..e8b64d8c5811c96e197d45f2c3c7ee0bc619664f 100644 (file)
@@ -285,24 +285,30 @@ choose_likely_separators (PsppireImportAssistant *ia)
     }
   gtk_tree_path_free (p);
 
-  int most_frequent = -1;
-  int largest = 0;
-  for (j = 0; j < SEPARATOR_CNT; ++j)
+  if (hmap_count (count_map) > 0)
     {
-      struct separator_count_node *cn;
-      HMAP_FOR_EACH (cn, struct separator_count_node, node, &count_map[j])
-       {
-         if (largest < cn->quantity)
-           {
-             largest = cn->quantity;
-             most_frequent = j;
-           }
-       }
-      hmap_destroy (&count_map[j]);
-    }
+      int most_frequent = -1;
+      int largest = 0;
+      for (j = 0; j < SEPARATOR_CNT; ++j)
+        {
+          struct separator_count_node *cn;
+          HMAP_FOR_EACH (cn, struct separator_count_node, node, &count_map[j])
+            {
+              if (largest < cn->quantity)
+                {
+                  largest = cn->quantity;
+                  most_frequent = j;
+                }
+            }
+          hmap_destroy (&count_map[j]);
+        }
+
+      g_return_if_fail (most_frequent >= 0);
 
-  const char* sepname = separators[MAX (0,most_frequent)].name;
-  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (get_widget_assert (ia->builder, sepname)), TRUE);
+      GtkWidget *toggle =
+        get_widget_assert (ia->builder, separators[most_frequent].name);
+      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), TRUE);
+    }
 }
 
 static void