static void
chooser_page_leave (PsppireImportAssistant *ia, GtkWidget *page)
{
- g_print ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
g_free (ia->file_name);
ia->file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (page));
gchar *encoding = psppire_encoding_selector_get_encoding (ia->encoding_selector);
on_intro_amount_changed (PsppireImportAssistant *p)
{
gtk_widget_set_sensitive (p->n_cases_spin,
- gtk_toggle_button_get_active (
- GTK_TOGGLE_BUTTON (p->n_cases_button)));
+ gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (p->n_cases_button)));
gtk_widget_set_sensitive (p->percent_spin,
- gtk_toggle_button_get_active (
- GTK_TOGGLE_BUTTON (p->percent_button)));
+ gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (p->percent_button)));
}
-
-
static void
on_treeview_selection_change (PsppireImportAssistant *ia)
{
GtkTreeIter iter;
if (gtk_tree_selection_get_selected (selection, &model, &iter))
{
+ gint max_lines;
int n;
GtkTreePath *path = gtk_tree_model_get_path (model, &iter);
gint *index = gtk_tree_path_get_indices (path);
-
n = *index;
-
gtk_tree_path_free (path);
-
- gtk_widget_set_sensitive (ia->variable_names_cb, n > 0);
-
- ia->delimiters_model
- = psppire_delimited_text_new (GTK_TREE_MODEL (ia->text_file));
+ g_object_get (model, "maximum-lines", &max_lines, NULL);
+ gtk_widget_set_sensitive (ia->variable_names_cb,
+ (n > 0 && n < max_lines));
+ 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 DT %p first line %d\n", __FILE__, __LINE__, ia->delimiters_model, n);
}
}
+static void
+render_text_preview_line (GtkTreeViewColumn *tree_column,
+ GtkCellRenderer *cell,
+ GtkTreeModel *tree_model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ /*
+ Set the text to a "insensitive" state if the row
+ is greater than what the user declared to be the maximum.
+ */
+ PsppireImportAssistant *ia = PSPPIRE_IMPORT_ASSISTANT (data);
+ GtkTreePath *path = gtk_tree_model_get_path (tree_model, iter);
+ gint *ii = gtk_tree_path_get_indices (path);
+ gint max_lines;
+ g_object_get (tree_model, "maximum-lines", &max_lines, NULL);
+ g_object_set (cell, "sensitive", (*ii < max_lines), NULL);
+ gtk_tree_path_free (path);
+}
/* Initializes IA's first_line substructure. */
static void
first_line_page_create (PsppireImportAssistant *ia)
{
- 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", on_treeview_selection_change);
GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes (_("Line"), renderer,
"text", 0,
NULL);
+
+ gtk_tree_view_column_set_cell_data_func (column, renderer, render_text_preview_line, ia, 0);
gtk_tree_view_append_column (GTK_TREE_VIEW (ia->first_line_tree_view), column);
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes (_("Text"), renderer, "text", 1, NULL);
- gtk_tree_view_append_column (GTK_TREE_VIEW (ia->first_line_tree_view), column);
+ gtk_tree_view_column_set_cell_data_func (column, renderer, render_text_preview_line, ia, 0);
- gtk_container_add (GTK_CONTAINER (scrolled_window), ia->first_line_tree_view);
+ gtk_tree_view_append_column (GTK_TREE_VIEW (ia->first_line_tree_view), column);
g_signal_connect_swapped (ia->first_line_tree_view, "cursor-changed",
- G_CALLBACK (on_treeview_selection_change), ia);
+ G_CALLBACK (on_treeview_selection_change), ia);
+ gtk_container_add (GTK_CONTAINER (scrolled_window), ia->first_line_tree_view);
}
+
gtk_widget_show_all (scrolled_window);
ia->variable_names_cb = get_widget_assert (ia->builder, "variable-names");
-
}
-
+static void
+intro_on_leave (PsppireImportAssistant *ia)
+{
+ gint lc = 0;
+ g_object_get (ia->text_file, "line-count", &lc, NULL);
+ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ia->n_cases_button)))
+ {
+ gint max_lines = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ia->n_cases_spin));
+ g_object_set (ia->text_file, "maximum-lines", max_lines, NULL);
+ }
+ else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ia->percent_button)))
+ {
+ gdouble percent = gtk_spin_button_get_value (GTK_SPIN_BUTTON (ia->percent_spin));
+ g_object_set (ia->text_file, "maximum-lines", (gint) (lc * percent / 100.0), NULL);
+ }
+ else
+ {
+ g_object_set (ia->text_file, "maximum-lines", lc, NULL);
+ }
+}
static void
G_CALLBACK (on_intro_amount_changed), ia);
+ g_object_set_data (G_OBJECT (w), "on-forward", intro_on_leave);
g_object_set_data (G_OBJECT (w), "on-entering", intro_on_enter);
g_object_set_data (G_OBJECT (w), "on-reset", reset_intro_page);
}
{
PROP_0,
PROP_FILE_NAME,
- PROP_ENCODING
+ PROP_ENCODING,
+ PROP_MAXIMUM_LINES,
+ PROP_LINE_COUNT
};
enum {MAX_LINE_LEN = 16384}; /* Max length of an acceptable line. */
done:
line_reader_close (reader);
}
-
}
static void
switch (prop_id)
{
+ case PROP_MAXIMUM_LINES:
+ tf->maximum_lines = g_value_get_int (value);
+ break;
case PROP_FILE_NAME:
tf->file_name = g_value_dup_string (value);
read_lines (tf);
switch (prop_id)
{
+ case PROP_MAXIMUM_LINES:
+ g_value_set_int (value, text_file->maximum_lines);
+ break;
+ case PROP_LINE_COUNT:
+ g_value_set_int (value, text_file->line_cnt);
+ break;
case PROP_FILE_NAME:
g_value_set_string (value, text_file->file_name);
break;
static GObjectClass *parent_class = NULL;
-
static gboolean
__tree_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
parent_class = g_type_class_peek_parent (class);
object_class = (GObjectClass*) class;
+ GParamSpec *maximum_lines_spec =
+ g_param_spec_int ("maximum-lines",
+ "Maximum Lines",
+ P_("An upper limit on the number of lines to consider"),
+ 0, G_MAXINT, G_MAXINT,
+ G_PARAM_READWRITE);
+
+ GParamSpec *line_count_spec =
+ g_param_spec_int ("line-count",
+ "Line Count",
+ P_("The number of lines in the file"),
+ 0, G_MAXINT, G_MAXINT,
+ G_PARAM_READABLE);
+
GParamSpec *file_name_spec =
g_param_spec_string ("file-name",
"File Name",
object_class->set_property = psppire_text_file_set_property;
object_class->get_property = psppire_text_file_get_property;
+ g_object_class_install_property (object_class,
+ PROP_MAXIMUM_LINES,
+ maximum_lines_spec);
+
+ g_object_class_install_property (object_class,
+ PROP_LINE_COUNT,
+ line_count_spec);
+
g_object_class_install_property (object_class,
PROP_FILE_NAME,
file_name_spec);
object_class->dispose = psppire_text_file_dispose;
}
-
static void
psppire_text_file_init (PsppireTextFile *text_file)
{