/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2016 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014,
+ 2016, 2017 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
#include "ui/gui/helper.h"
#include "ui/gui/psppire-import-assistant.h"
#include "ui/gui/psppire-data-window.h"
+#include "ui/gui/psppire-data-editor.h"
#include "ui/gui/psppire-dialog-action.h"
#include "ui/gui/psppire-encoding-selector.h"
#include "ui/gui/psppire-syntax-window.h"
#include "ui/gui/psppire-window.h"
-#include "ui/gui/psppire-data-sheet.h"
-#include "ui/gui/psppire-var-sheet.h"
#include "ui/gui/windows-menu.h"
#include "ui/gui/goto-case-dialog.h"
#include "ui/gui/psppire.h"
#include "gl/c-strcasestr.h"
#include "gl/xvasprintf.h"
+#include <ssw-sheet.h>
+
#include "find-dialog.h"
#include "options-dialog.h"
#include "psppire-dialog-action-1sks.h"
PsppireImportAssistant *asst = PSPPIRE_IMPORT_ASSISTANT (w);
gtk_widget_show_all (w);
- asst->main_loop = g_main_loop_new (NULL, TRUE);
- g_main_loop_run (asst->main_loop);
- g_main_loop_unref (asst->main_loop);
-
- if (!asst->file_name)
- goto end;
+ int response = psppire_import_assistant_run (asst);
- switch (asst->response)
+ switch (response)
{
case GTK_RESPONSE_APPLY:
{
break;
}
- end:
gtk_widget_destroy (GTK_WIDGET (asst));
}
static void
-set_data_page (PsppireDataWindow *dw)
+on_realize (PsppireDataWindow *dw)
{
gtk_notebook_set_current_page (GTK_NOTEBOOK (dw->data_editor), 1);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (dw->data_editor), 0);
}
on_cut (PsppireDataWindow *dw)
{
int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
- if (p == 0)
- {
- PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
- psppire_data_sheet_edit_cut (ds);
+ if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
+ {
+ PsppireDict *dict = NULL;
+ g_object_get (dw->data_editor, "dictionary", &dict, NULL);
+
+ gint x, y;
+ SswSheet *sheet = SSW_SHEET (dw->data_editor->data_sheet);
+ SswRange sel = *sheet->selection;
+
+ GtkClipboard *clip =
+ gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (dw)),
+ GDK_SELECTION_CLIPBOARD);
+
+ /* Save the selected area to a string */
+ GString *str = g_string_new ("");
+ for (y = sel.start_y ; y <= sel.end_y; ++y)
+ {
+ for (x = sel.start_x ; x <= sel.end_x; ++x)
+ {
+ const struct variable * var = psppire_dict_get_variable (dict, x);
+ gchar *s = psppire_data_store_get_string (dw->data_editor->data_store,
+ y, var, FALSE);
+ g_string_append (str, s);
+ g_string_append (str, "\t");
+ g_free (s);
+ }
+ g_string_append (str, "\n");
+ }
+
+ gtk_clipboard_set_text (clip, str->str, str->len);
+ g_string_free (str, TRUE);
+
+ /* Now fill the selected area with SYSMIS */
+ union value sm ;
+ sm.f = SYSMIS;
+ for (x = sel.start_x ; x <= sel.end_x; ++x)
+ {
+ const struct variable * var = psppire_dict_get_variable (dict, x);
+ for (y = sel.start_y ; y <= sel.end_y; ++y)
+ {
+ psppire_data_store_set_value (dw->data_editor->data_store,
+ y,
+ var, &sm);
+ }
+ }
+
}
}
on_copy (PsppireDataWindow *dw)
{
int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
- if (p == 0)
+ if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
{
- PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
- psppire_data_sheet_edit_copy (ds);
+ GtkClipboard *clip =
+ gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (dw)),
+ GDK_SELECTION_CLIPBOARD);
+
+ ssw_sheet_set_clip (SSW_SHEET (dw->data_editor->data_sheet), clip);
}
}
on_paste (PsppireDataWindow *dw)
{
int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
- if (p == 0)
+ if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
{
- PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
- psppire_data_sheet_edit_paste (ds);
+ psppire_data_editor_paste (dw->data_editor);
}
}
-
static void
on_clear_cases (PsppireDataWindow *dw)
{
- int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
- if (p == 0)
+ PsppireDataEditor *de = dw->data_editor;
+ int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (de));
+ if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
{
- PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
- psppire_data_sheet_edit_clear_cases (ds);
+ SswRange *range = SSW_SHEET(de->data_sheet)->selection;
+ g_return_if_fail (range->start_y >= 0);
+ psppire_data_store_delete_cases (de->data_store, range->start_y,
+ range->end_y - range->start_y + 1);
+ gtk_widget_queue_draw (GTK_WIDGET (de->data_sheet));
}
}
static void
on_clear_variables (PsppireDataWindow *dw)
{
- int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
- if (p == 0)
+ PsppireDataEditor *de = dw->data_editor;
+ int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (de));
+ if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
{
- PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
- psppire_data_sheet_edit_clear_variables (ds);
+ psppire_data_editor_data_delete_variables (de);
}
else
{
- psppire_var_sheet_clear_variables (PSPPIRE_VAR_SHEET (dw->data_editor->var_sheet));
+ psppire_data_editor_var_delete_variables (de);
}
}
-
static void
insert_variable (PsppireDataWindow *dw)
{
- int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
- if (p == 0)
+ PsppireDataEditor *de = dw->data_editor;
+ int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (de));
+
+ if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
{
- PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
- psppire_data_sheet_insert_variable (ds);
+ SswRange *range = SSW_SHEET(de->data_sheet)->selection;
+ psppire_data_editor_insert_new_variable_at_posn (de, range->start_x);
}
else
{
- psppire_var_sheet_insert_variable (PSPPIRE_VAR_SHEET (dw->data_editor->var_sheet));
+ SswRange *range = SSW_SHEET(de->var_sheet)->selection;
+ psppire_data_editor_insert_new_variable_at_posn (de, range->start_y);
}
}
-
static void
insert_case_at_row (PsppireDataWindow *dw)
{
- PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
-
- psppire_data_sheet_insert_case (ds);
+ PsppireDataEditor *de = dw->data_editor;
+ SswRange *range = SSW_SHEET(de->data_sheet)->selection;
+ psppire_data_editor_insert_new_case_at_posn (de, range->start_y);
}
static void
goto_case (PsppireDataWindow *dw)
{
- PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
-
- goto_case_dialog (ds);
+ PsppireDataEditor *de = dw->data_editor;
+ int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (de));
+ if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
+ {
+ goto_case_dialog (PSPPIRE_DATA_SHEET (de->data_sheet));
+ }
}
-
-
static GtkWidget *
create_file_menu (PsppireDataWindow *dw)
{
return menuitem;
}
+
static GtkWidget *
create_edit_menu (PsppireDataWindow *dw)
{
return menuitem;
}
-
static void
psppire_data_window_finish_init (PsppireDataWindow *de,
struct dataset *ds)
PSPPIRE_DATA_EDITOR (psppire_data_editor_new (de->dict, de->data_store));
g_signal_connect (de, "realize",
- G_CALLBACK (set_data_page), de);
+ G_CALLBACK (on_realize), de);
g_signal_connect_swapped (de->data_store, "case-changed",
G_CALLBACK (set_unsaved), de);
- g_signal_connect_swapped (de->data_store, "case-inserted",
- G_CALLBACK (set_unsaved), de);
-
- g_signal_connect_swapped (de->data_store, "cases-deleted",
- G_CALLBACK (set_unsaved), de);
-
dataset_set_callbacks (de->dataset, &cbs, de);
connect_help (de->builder);
G_CALLBACK (on_split_change),
de);
- g_signal_connect_swapped (de->dict, "backend-changed",
+ g_signal_connect_swapped (de->dict, "items-changed",
G_CALLBACK (enable_save), de);
g_signal_connect_swapped (de->dict, "variable-inserted",
G_CALLBACK (enable_save), de);
ll_push_head (&all_data_windows, &de->ll);
}
+
static void
psppire_data_window_dispose (GObject *object)
{
}
+
GtkWidget*
psppire_data_window_new (struct dataset *ds)
{
return dw;
}
+
+
bool
psppire_data_window_is_empty (PsppireDataWindow *dw)
{
return psppire_dict_get_var_cnt (dw->dict) == 0;
}
+
static void
psppire_data_window_iface_init (PsppireWindowIface *iface)
{
\f
+
PsppireDataWindow *
psppire_default_data_window (void)
{
return ll_data (ll_head (&all_data_windows), PsppireDataWindow, ll);
}
+
+
void
psppire_data_window_set_default (PsppireDataWindow *pdw)
{
ll_push_tail (&all_data_windows, &pdw->ll);
}
+
+
PsppireDataWindow *
psppire_data_window_for_dataset (struct dataset *ds)
{