From 79782fe066e3e5fa2a82c7ca80a4f7d3306fe1ee Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 27 Jun 2020 09:19:27 +0200 Subject: [PATCH] Improve behaviour when importing trivial csv files. 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 | 38 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/ui/gui/psppire-import-assistant.c b/src/ui/gui/psppire-import-assistant.c index 4de7035243..e8b64d8c58 100644 --- a/src/ui/gui/psppire-import-assistant.c +++ b/src/ui/gui/psppire-import-assistant.c @@ -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 -- 2.30.2