return FALSE;
// g_print ("%s:%d %s %s\n", __FILE__, __LINE__, __FUNCTION__, gtk_tree_path_to_string (path));
-
+
gint *indices = gtk_tree_path_get_indices (path);
if (!indices)
if (n >= children - file->first_line)
return FALSE;
-
+
// g_print ("%s:%d %s %d Children: %d\n", __FILE__, __LINE__, __FUNCTION__, n, children);
-
+
iter->user_data = GINT_TO_POINTER (n);
iter->stamp = file->stamp;
g_return_val_if_fail (file->stamp == iter->stamp, FALSE);
gint n = GPOINTER_TO_INT (iter->user_data);
-
+
// g_print ("%s:%d %s %d\n", __FILE__, __LINE__, __FUNCTION__, n);
gint children = gtk_tree_model_iter_n_children (file->child, NULL);
if (n >= children - file->first_line)
return NULL;
-
+
return gtk_tree_path_new_from_indices (n, -1);
}
GtkTreeIter *iter)
{
g_print ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
- PsppireDelimitedText *file = PSPPIRE_DELIMITED_TEXT (tree_model);
g_assert (iter == NULL);
return 0;
}
}
+/* Split row N into it's delimited fields (if it is not already cached)
+ and set this row as the current cache. */
static void
-__get_value (GtkTreeModel *tree_model,
- GtkTreeIter *iter,
- gint column,
- GValue *value)
+split_row_into_fields (PsppireDelimitedText *file, gint n)
{
- // g_print ("%s:%d %s Col: %d\n", __FILE__, __LINE__, __FUNCTION__, column);
- PsppireDelimitedText *file = PSPPIRE_DELIMITED_TEXT (tree_model);
-
- g_return_if_fail (iter->stamp == file->stamp);
-
- gint n = GPOINTER_TO_INT (iter->user_data) + file->first_line;
-
- // g_print ("%s:%d Row: %d\n", __FILE__, __LINE__, n);
-
- if (column == 0)
- {
- g_value_init (value, G_TYPE_INT);
- g_value_set_int (value, n + 1);
- return;
- }
-
- g_value_init (value, G_TYPE_STRING);
-
if (n != file->cache_row)
{
if (file->const_cache.string)
file->cache_row = n;
}
-
+}
+
+const gchar *
+psppire_delimited_text_get_header_title (PsppireDelimitedText *file, gint column)
+{
+ if (file->first_line <= 0)
+ return NULL;
+
+ split_row_into_fields (file, file->first_line - 1);
+
+ return file->cache_starts [column];
+}
+
+static void
+__get_value (GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gint column,
+ GValue *value)
+{
+ // g_print ("%s:%d %s Col: %d\n", __FILE__, __LINE__, __FUNCTION__, column);
+ PsppireDelimitedText *file = PSPPIRE_DELIMITED_TEXT (tree_model);
+
+ g_return_if_fail (iter->stamp == file->stamp);
+
+ gint n = GPOINTER_TO_INT (iter->user_data) + file->first_line;
+
+ // g_print ("%s:%d Row: %d\n", __FILE__, __LINE__, n);
+
+ if (column == 0)
+ {
+ g_value_init (value, G_TYPE_INT);
+ g_value_set_int (value, n + 1);
+ return;
+ }
+
+ g_value_init (value, G_TYPE_STRING);
+
+ split_row_into_fields (file, n);
+
g_value_set_string (value, file->cache_starts [column - 1]);
}
P_("The first line to be considered."),
0, 1000, 0,
G_PARAM_READWRITE);
-
+
GParamSpec *delimiters_spec =
g_param_spec_pointer ("delimiters",
"Field Delimiters",
P_("A GSList of gunichars which delimit the fields."),
G_PARAM_READWRITE);
- GParamSpec *child_spec =
+ GParamSpec *child_spec =
g_param_spec_object ("child",
"Child Model",
P_("The GtkTextModel which this object wraps."),
GTK_TYPE_TREE_MODEL,
G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
-
+
object_class->set_property = psppire_delimited_text_set_property;
object_class->get_property = psppire_delimited_text_get_property;
g_object_class_install_property (object_class,
PROP_FIRST_LINE,
first_line_spec);
-
+
object_class->finalize = psppire_delimited_text_finalize;
object_class->dispose = psppire_delimited_text_dispose;
}
f < n_fields; f++)
{
GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+
+ const gchar *title = NULL;
+
+ if (f == 0)
+ title = _("line");
+ else
+ {
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ia->variable_names_cb)))
+ {
+ title =
+ psppire_delimited_text_get_header_title
+ (PSPPIRE_DELIMITED_TEXT (ia->delimiters_model), f - 1);
+ }
+ if (title == NULL)
+ title = _("var");
+ }
+
GtkTreeViewColumn *column =
- gtk_tree_view_column_new_with_attributes ("var", renderer,
+ gtk_tree_view_column_new_with_attributes (title,
+ renderer,
"text", f,
NULL);
g_object_set (column,
GTK_TOGGLE_BUTTON (p->percent_button)));
}
-/* Sets the widgets to match IA's first_line substructure. */
-static void
-set_first_line (PsppireImportAssistant *ia)
-{
- GtkTreePath *path = gtk_tree_path_new_from_indices (ia->skip_lines, -1);
-
- gtk_tree_path_free (path);
-
- gtk_toggle_button_set_active (
- GTK_TOGGLE_BUTTON (ia->variable_names_cb),
- ia->variable_names);
- gtk_widget_set_sensitive (ia->variable_names_cb,
- ia->skip_lines > 0);
-}
#if SHEET_MERGE
#endif
static void
-on_cursor_change (GtkTreeView *treeview, gpointer user_data)
+on_treeview_selection_change (PsppireImportAssistant *ia)
{
- PsppireImportAssistant *ia = PSPPIRE_IMPORT_ASSISTANT (user_data);
- GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
+ GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ia->first_line_tree_view));
GtkTreeModel *model = NULL;
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (selection, &model, &iter))
gtk_tree_path_free (path);
- g_print ("%s:%d Setting first line to %d\n", __FILE__, __LINE__, n);
+ gtk_widget_set_sensitive (ia->variable_names_cb, n > 0);
- ia->delimiters_model = psppire_delimited_text_new (ia->text_file);
+ ia->delimiters_model
+ = psppire_delimited_text_new (GTK_TREE_MODEL (ia->text_file));
g_object_set (ia->delimiters_model, "first-line", n, NULL);
}
}
g_print ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
GtkWidget *w = get_widget_assert (ia->builder, "FirstLine");
- g_object_set_data (G_OBJECT (w), "on-entering", set_first_line);
+ g_object_set_data (G_OBJECT (w), "on-entering", on_treeview_selection_change);
add_page_to_assistant (ia, w,
GTK_ASSISTANT_PAGE_CONTENT, _("Select the First Line"));
gtk_container_add (GTK_CONTAINER (scrolled_window), ia->first_line_tree_view);
- g_signal_connect (ia->first_line_tree_view, "cursor-changed",
- G_CALLBACK (on_cursor_change), ia);
+ g_signal_connect_swapped (ia->first_line_tree_view, "cursor-changed",
+ G_CALLBACK (on_treeview_selection_change), ia);
}
gtk_widget_show_all (scrolled_window);
-
+ ia->variable_names_cb = get_widget_assert (ia->builder, "variable-names");
#if SHEET_MERGE
- ia->variable_names_cb = get_widget_assert (ia->builder, "variable-names");
pspp_sheet_selection_set_mode (
pspp_sheet_view_get_selection (PSPP_SHEET_VIEW (ia->tree_view)),
PSPP_SHEET_SELECTION_BROWSE);