#include "builder-wrapper.h"
#include "helper.h"
-#include "pspp-sheet-view.h"
-#include "pspp-sheet-selection.h"
#include "psppire-import-assistant.h"
#include "psppire-scanf.h"
#include "psppire-dialog.h"
#include "psppire-empty-list-store.h"
#include "psppire-encoding-selector.h"
#include "psppire-spreadsheet-model.h"
-#include "psppire-var-sheet.h"
#include "ui/syntax-gen.h"
#include <gettext.h>
close_assistant (ia, PSPPIRE_RESPONSE_PASTE);
}
+
/* Revises the contents of the fields tree view based on the
currently chosen set of separators. */
static void
return TRUE;
}
+#if SHEET_MERGE
+
static void
render_line_number (PsppSheetViewColumn *tree_column,
}
-
static gint
get_string_width (GtkWidget *treeview, GtkCellRenderer *renderer,
const char *string)
return tree_view;
}
+#endif
+
static GtkWidget *
add_page_to_assistant (PsppireImportAssistant *ia,
GtkWidget *page, GtkAssistantPageType type, const gchar *);
}
-
/* Initializes IA's sheet_spec substructure. */
static void
sheet_spec_page_create (PsppireImportAssistant *ia)
g_object_set_data (G_OBJECT (page), "on-entering", prepare_sheet_spec_page);
}
-
static void
on_chosen (PsppireImportAssistant *ia, GtkWidget *page)
{
on_chosen (ia, page);
}
+
+
static void
chooser_page_enter (PsppireImportAssistant *ia, GtkWidget *page)
{
on_chosen (ia, page);
}
+
+
static void
chooser_page_create (PsppireImportAssistant *ia)
{
}
+
static void
psppire_import_assistant_init (PsppireImportAssistant *ia)
{
}
+#if SHEET_MERGE
+
static void
render_line (PsppSheetViewColumn *tree_column,
GtkCellRenderer *cell,
g_object_set (cell, "text", ds_cstr (&lines[row]), NULL);
}
+#endif
+
/* 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);
-
+#if SHEET_MERGE
set_model_on_treeview (ia, ia->tree_view, 0);
-
pspp_sheet_view_set_cursor (PSPP_SHEET_VIEW (ia->tree_view),
path, NULL, false);
+#endif
gtk_tree_path_free (path);
gtk_toggle_button_set_active (
ia->skip_lines > 0);
}
+#if SHEET_MERGE
/* Creates and returns a tree view that contains each of the
lines in IA's file as a row. */
}
+
/* Sets IA's first_line substructure to match the widgets. */
static void
set_first_line_options (PsppireImportAssistant *ia)
gtk_widget_set_sensitive (ia->variable_names_cb, ia->skip_lines > 0);
}
+
+
static void
reset_first_line_page (PsppireImportAssistant *ia)
{
gtk_widget_set_sensitive (ia->variable_names_cb, FALSE);
}
-
+#endif
/* Initializes IA's first_line substructure. */
static void
first_line_page_create (PsppireImportAssistant *ia)
add_page_to_assistant (ia, w,
GTK_ASSISTANT_PAGE_CONTENT, _("Select the First Line"));
+#if SHEET_MERGE
+
ia->tree_view = GTK_WIDGET (create_lines_tree_view (
GTK_CONTAINER (get_widget_assert (ia->builder, "first-line-scroller")), ia));
ia->variable_names_cb = get_widget_assert (ia->builder, "variable-names");
g_object_set_data (G_OBJECT (w), "on-reset", reset_first_line_page);
+#endif
}
+
+
static void
intro_on_enter (PsppireImportAssistant *ia)
{
NULL));
}
+
+
\f
struct column
free (ia->columns);
}
+#if SHEET_MERGE
+
/* Called to render one of the cells in the fields preview tree
view. */
static void
(void *) NULL);
}
+#endif
/* Parses the contents of the field at (ROW,COLUMN) according to
its variable format. If OUTPUTP is non-null, then *OUTPUTP
return ok;
}
+#if SHEET_MERGE
/* Called to render one of the cells in the data preview tree
view. */
}
+
\f
free (text);
return TRUE;
}
-
+#endif
\f
}
}
+
+#if SHEET_MERGE
static PsppSheetViewColumn *
make_data_column (PsppireImportAssistant *ia, GtkWidget *tree_view,
bool input, gint dict_idx)
return tree_column;
}
+#endif
static GtkWidget *
create_data_tree_view (gboolean input, GtkContainer *parent,
PsppireImportAssistant *ia)
{
gint i;
+#if SHEET_MERGE
GtkWidget *tree_view = make_tree_view (ia);
set_model_on_treeview (ia, tree_view, ia->skip_lines);
+
+
pspp_sheet_selection_set_mode (pspp_sheet_view_get_selection (PSPP_SHEET_VIEW (tree_view)),
PSPP_SHEET_SELECTION_NONE);
gtk_widget_show (tree_view);
return tree_view;
+#endif
}
+
/* Chooses a name for each column on the separators page */
static void
choose_column_names (PsppireImportAssistant *ia)
\f
+
+#if SHEET_MERGE
+
/* Called when the user changes one of the variables in the
dictionary. */
static void
pop_watch_cursor (ia);
}
-
+#endif
/* Called just before the formats page of the assistant is
static void
prepare_formats_page (PsppireImportAssistant *ia)
{
- PsppireDict *psppire_dict = NULL;
- PsppireVarSheet *var_sheet;
- GtkBin *vars_scroller;
- GtkWidget *old_var_sheet;
-
-
- push_watch_cursor (ia);
-
- if (ia->spreadsheet == NULL)
- {
- struct fmt_guesser *fg;
- unsigned long int number = 0;
- size_t column_idx;
-
-
- ia->dict = dict_create (get_default_encoding ());
- fg = fmt_guesser_create ();
- for (column_idx = 0; column_idx < ia->column_cnt; column_idx++)
- {
- struct variable *modified_var =
- (column_idx < ia->modified_var_cnt ? ia->modified_vars[column_idx] : NULL);
-
- if (modified_var == NULL)
- {
- struct column *column = &ia->columns[column_idx];
- struct variable *var;
- struct fmt_spec format;
- char *name;
- size_t row;
-
- /* Choose variable name. */
- name = dict_make_unique_var_name (ia->dict, column->name, &number);
-
- /* Choose variable format. */
- fmt_guesser_clear (fg);
- for (row = ia->skip_lines; row < ia->line_cnt; row++)
- fmt_guesser_add (fg, column->contents[row]);
- fmt_guesser_guess (fg, &format);
- fmt_fix_input (&format);
-
- /* Create variable. */
- var = dict_create_var_assert (ia->dict, name, fmt_var_width (&format));
- var_set_both_formats (var, &format);
-
- free (name);
- }
- else
- {
- char *name;
-
- name = dict_make_unique_var_name (ia->dict, var_get_name (modified_var),
- &number);
- dict_clone_var_as_assert (ia->dict, modified_var, name);
- free (name);
- }
- }
- fmt_guesser_destroy (fg);
- }
- else
- {
- int row_start = -1;
- int row_stop = -1;
- int col_start = -1;
- int col_stop = -1;
-
- GtkBuilder *builder = ia->builder;
-
- struct casereader *reader = NULL;
-
- GtkWidget *readnames_checkbox = get_widget_assert (builder, "readnames-checkbox");
- GtkWidget *range_entry = get_widget_assert (builder, "cell-range-entry");
- const gchar *range = gtk_entry_get_text (GTK_ENTRY (range_entry));
- GtkWidget *combo_box = get_widget_assert (builder, "sheet-entry");
-
- gint num = gtk_combo_box_get_active (GTK_COMBO_BOX (combo_box));
-
- struct spreadsheet_read_options sro;
-
- sro.sheet_name = NULL;
- sro.cell_range = NULL;
- sro.sheet_index = num + 1;
-
- if ( convert_cell_ref (range, &col_start, &row_start, &col_stop, &row_stop))
- {
- sro.cell_range = g_strdup (range);
- }
-
- sro.read_names = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (readnames_checkbox));
- sro.asw = -1;
-
- switch (ia->spreadsheet->type)
- {
- case SPREADSHEET_ODS:
- case SPREADSHEET_GNUMERIC:
- {
- reader = spreadsheet_make_reader (ia->spreadsheet, &sro);
- ia->dict = dict_clone (ia->spreadsheet->dict);
- }
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- g_free (sro.cell_range);
-
- if (reader && ia->dict)
- {
- struct ccase *c;
- int col;
-
- ia->column_cnt = dict_get_var_cnt (ia->dict);
- ia->columns = xcalloc (ia->column_cnt, sizeof (*ia->columns));
- for (col = 0; col < ia->column_cnt ; ++col)
- {
- const struct variable *var = dict_get_var (ia->dict, col);
- ia->columns[col].name = xstrdup (var_get_name (var));
- ia->columns[col].contents = NULL;
- }
-
- casenumber rows = 0;
- for (; (c = casereader_read (reader)) != NULL; case_unref (c))
- {
- rows++;
- for (col = 0; col < ia->column_cnt ; ++col)
- {
- char *ss;
- const struct variable *var = dict_get_var (ia->dict, col);
-
- ia->columns[col].contents = xrealloc (ia->columns[col].contents,
- sizeof (struct substring) * rows);
-
- ss = data_out (case_data (c, var), dict_get_encoding (ia->dict),
- var_get_print_format (var));
-
- ia->columns[col].contents[rows - 1] = ss_cstr (ss);
- }
-
- if (rows > MAX_PREVIEW_LINES)
- {
- case_unref (c);
- break;
- }
- }
- casereader_destroy (reader);
- ia->line_cnt = rows;
- }
- else
- {
- GtkWidget * dialog = gtk_message_dialog_new (NULL,
- GTK_DIALOG_MODAL,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_CLOSE,
- _("An error occurred reading the spreadsheet file."));
-
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- }
- }
-
- psppire_dict = psppire_dict_new_from_dict (ia->dict);
- g_signal_connect (psppire_dict, "variable-changed",
- G_CALLBACK (on_variable_change), ia);
- ia->psppire_dict = psppire_dict;
-
-
- /* XXX: PsppireVarStore doesn't hold a reference to
- psppire_dict for now, but it should. After it does, we
- should g_object_ref the psppire_dict here, since we also
- hold a reference via ia->formats->dict. */
- var_sheet = PSPPIRE_VAR_SHEET (psppire_var_sheet_new ());
- g_object_set (var_sheet,
- "dictionary", psppire_dict,
- "may-create-vars", FALSE,
- "may-delete-vars", FALSE,
- "format-use", FMT_FOR_INPUT,
- "enable-grid-lines", PSPP_SHEET_VIEW_GRID_LINES_BOTH,
- (void *) NULL);
-
- vars_scroller = GTK_BIN (get_widget_assert (ia->builder, "vars-scroller"));
- old_var_sheet = gtk_bin_get_child (GTK_BIN (vars_scroller));
- if (old_var_sheet != NULL)
- gtk_container_remove (GTK_CONTAINER (vars_scroller), old_var_sheet);
- gtk_container_add (GTK_CONTAINER (vars_scroller), GTK_WIDGET (var_sheet));
- gtk_widget_show (GTK_WIDGET (var_sheet));
-
- ia->data_tree_view =
- GTK_WIDGET (create_data_tree_view (
- FALSE,
- GTK_CONTAINER (get_widget_assert (ia->builder, "data-scroller")),
- ia));
-
- gtk_widget_show (ia->paste_button);
-
- pop_watch_cursor (ia);
}
static void
return ds_cstr (&s);
}
+
gchar *
psppire_import_assistant_generate_syntax (PsppireImportAssistant *ia)
{
struct string s = DS_EMPTY_INITIALIZER;
+#if SHEET_MERGE
if (!ia->spreadsheet)
{
if (ia->file_name == NULL)
{
return sheet_spec_gen_syntax (ia);
}
+
+#endif
return ds_cstr (&s);
}