psppire_data_window: Don't crash when trying to delete cases when none are selected
[pspp] / src / ui / gui / psppire-data-window.c
index b4c9b09dac21251a56d6bbe2b651742e79dbed18..08c7375a67d9f62d121118e76b61145ce62395cd 100644 (file)
@@ -1,5 +1,6 @@
 /* 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
@@ -32,6 +33,7 @@
 #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 "gl/c-strcasestr.h"
 #include "gl/xvasprintf.h"
 
-#include "ui/gui/efficient-sheet/jmd-sheet.h"
+#include <ssw-sheet.h>
 
 #include "find-dialog.h"
+#include "options-dialog.h"
 #include "psppire-dialog-action-1sks.h"
 #include "psppire-dialog-action-aggregate.h"
 #include "psppire-dialog-action-autorecode.h"
@@ -66,6 +69,7 @@
 #include "psppire-dialog-action-frequencies.h"
 #include "psppire-dialog-action-histogram.h"
 #include "psppire-dialog-action-indep-samps.h"
+#include "psppire-dialog-action-k-independent.h"
 #include "psppire-dialog-action-k-related.h"
 #include "psppire-dialog-action-kmeans.h"
 #include "psppire-dialog-action-logistic.h"
@@ -202,7 +206,7 @@ transformation_change_callback (bool transformations_pending,
                                                  "transform-pending");
 
     g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
-                                transformations_pending); 
+                                transformations_pending);
   }
 
   if ( transformations_pending)
@@ -381,15 +385,15 @@ load_file (PsppireWindow *de, const gchar *file_name, const char *encoding,
     {
       gchar *utf8_file_name;
       struct string filename;
-      
+
       utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
 
       if (NULL == utf8_file_name)
        return FALSE;
 
-      ds_init_empty (&filename);    
+      ds_init_empty (&filename);
       syntax_gen_string (&filename, ss_cstr (utf8_file_name));
-      
+
       g_free (utf8_file_name);
 
       if (encoding && encoding[0])
@@ -414,7 +418,7 @@ load_file (PsppireWindow *de, const gchar *file_name, const char *encoding,
        mime_type = "application/x-spss-por";
       else if (name_has_sav_suffix (file_name))
        mime_type = "application/x-spss-sav";
-      
+
       add_most_recent (file_name, mime_type, encoding);
     }
 
@@ -703,7 +707,7 @@ static void
 status_bar_activate (GAction *action, GVariant *param,  PsppireDataWindow  *de)
 {
   GtkWidget *statusbar = get_widget_assert (de->builder, "status-bar");
-  
+
   GVariant *state = g_action_get_state (action);
   const gboolean visible = g_variant_get_boolean (state);
   g_action_change_state (action, g_variant_new_boolean (!visible));
@@ -745,7 +749,7 @@ on_switch_page (GtkNotebook *notebook, GtkWidget *page, guint pn, gpointer ud)
       gtk_widget_show (GTK_WIDGET (de->mi_clear_cases));
 
       break;
-      
+
     case 1:
       g_action_change_state (action, g_variant_new_string ("VARS"));
       gtk_widget_hide (GTK_WIDGET (de->ti_insert_case));
@@ -757,9 +761,9 @@ on_switch_page (GtkNotebook *notebook, GtkWidget *page, guint pn, gpointer ud)
       gtk_widget_hide (GTK_WIDGET (de->mi_find));
       gtk_widget_hide (GTK_WIDGET (de->mi_find_separator));
       gtk_widget_hide (GTK_WIDGET (de->mi_clear_cases));
-      
+
       break;
-    }      
+    }
 }
 
 
@@ -789,7 +793,7 @@ fonts_activate (PsppireDataWindow  *de)
   GtkWidget *dialog =  gtk_font_chooser_dialog_new (NULL, GTK_WINDOW (toplevel));
   GtkStyleContext *style = gtk_widget_get_style_context (GTK_WIDGET(de->data_editor));
   const PangoFontDescription *current_font ;
-  
+
   gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL, "font", &current_font, NULL);
 
   gtk_font_chooser_set_font_desc (GTK_FONT_CHOOSER (dialog), current_font);
@@ -821,7 +825,7 @@ value_labels_activate (GAction *action, GVariant *param,  PsppireDataWindow  *de
   GVariant *new_state  = g_action_get_state (action);
   labels_active = g_variant_get_boolean (new_state);
   g_object_set (de->data_editor, "value-labels", labels_active, NULL);
-  
+
   gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (de->ti_value_labels_button),
                                     labels_active);
 }
@@ -916,7 +920,7 @@ on_recent_files_select (GtkMenuShell *menushell,   gpointer user_data)
 
   free (encoding);
 
-  if ( psppire_window_load (PSPPIRE_WINDOW (se), file, encoding, NULL) ) 
+  if ( psppire_window_load (PSPPIRE_WINDOW (se), file, encoding, NULL) )
     gtk_widget_show (se);
   else
     gtk_widget_destroy (se);
@@ -966,15 +970,10 @@ file_import (PsppireDataWindow *dw)
   GtkWidget *w = psppire_import_assistant_new (GTK_WINDOW (dw));
   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;
-  
-  switch (asst->response)
+
+  int response = psppire_import_assistant_run (asst);
+
+  switch (response)
     {
     case GTK_RESPONSE_APPLY:
       {
@@ -989,8 +988,7 @@ file_import (PsppireDataWindow *dw)
     default:
       break;
     }
-    
- end:  
+
   gtk_widget_destroy (GTK_WIDGET (asst));
 }
 
@@ -1002,7 +1000,7 @@ connect_dialog_action (GType type, PsppireDataWindow *de)
   GAction *act = g_object_new (type,
                               "top-level", de,
                               NULL);
-  
+
   g_action_map_add_action (G_ACTION_MAP (de), act);
 }
 
@@ -1016,7 +1014,7 @@ static void
 connect_action_to_menuitem (GActionMap *map, const gchar *action_name, GtkWidget *w, const gchar *accel)
 {
   GAction *a = g_action_map_lookup_action (map, action_name);
-  
+
   if (NULL == a)
     g_error ("Action \"%s\" not found in map", action_name);
 
@@ -1043,22 +1041,21 @@ connect_action_to_menuitem (GActionMap *map, const gchar *action_name, GtkWidget
        detailed_action_name = g_strdup_printf ("win.%s", action_name);
       else if (GTK_IS_APPLICATION (map))
        detailed_action_name = g_strdup_printf ("app.%s", action_name);
-      
+
       gtk_application_set_accels_for_action (app,
                                             detailed_action_name,
                                             accels);
       free (detailed_action_name);
     }
-  
+
   g_signal_connect_swapped (w, "activate", G_CALLBACK (g_action_activate_null), a);
  }
 
 
 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);
 }
 
 
@@ -1066,14 +1063,14 @@ static void
 on_cut (PsppireDataWindow *dw)
 {
   int p = gtk_notebook_get_current_page (GTK_NOTEBOOK (dw->data_editor));
-  if (p == 0)
-    {
+  if (p == PSPPIRE_DATA_EDITOR_DATA_VIEW)
+  {
       PsppireDict *dict = NULL;
       g_object_get (dw->data_editor, "dictionary", &dict, NULL);
-      
+
       gint x, y;
-      JmdSheet *sheet = JMD_SHEET (dw->data_editor->data_sheet);
-      JmdRange sel = *sheet->selection;
+      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)),
@@ -1094,7 +1091,7 @@ on_cut (PsppireDataWindow *dw)
            }
          g_string_append (str, "\n");
        }
-      
+
       gtk_clipboard_set_text (clip, str->str, str->len);
       g_string_free (str, TRUE);
 
@@ -1115,33 +1112,17 @@ on_cut (PsppireDataWindow *dw)
     }
 }
 
-
-
 static void
 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)
     {
       GtkClipboard *clip =
        gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (dw)),
                                   GDK_SELECTION_CLIPBOARD);
 
-      jmd_sheet_set_clip (JMD_SHEET (dw->data_editor->data_sheet), clip);
-    }
-}
-
-
-static void
-trf (GtkClipboard *clip,
-         GdkAtom *atoms,
-         gint n_atoms,
-         gpointer data)
-{
-  int i;
-  for (i = 0; i < n_atoms; ++i)
-    {
-      g_print ("%s\n", gdk_atom_name (atoms[i]));
+      ssw_sheet_set_clip (SSW_SHEET (dw->data_editor->data_sheet), clip);
     }
 }
 
@@ -1149,91 +1130,79 @@ static void
 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)
     {
-      GtkClipboard *clip =
-       gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (dw)),
-                                  GDK_SELECTION_CLIPBOARD);
-
-      gtk_clipboard_request_targets (clip, trf, dw);
+      psppire_data_editor_paste (dw->data_editor);
     }
 }
 
-
 static void
 on_clear_cases (PsppireDataWindow *dw)
 {
-#if SHEET_MERGE
-  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));
     }
-#endif
 }
 
 static void
 on_clear_variables (PsppireDataWindow *dw)
 {
-#if SHEET_MERGE
-  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);
     }
-#endif
 }
 
-
-
 static void
 insert_variable (PsppireDataWindow *dw)
 {
-#if SHEET_MERGE
-  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);
     }
-#endif
 }
 
-
-
 static void
 insert_case_at_row (PsppireDataWindow *dw)
 {
-#if SHEET_MERGE
-  PsppireDataSheet *ds = psppire_data_editor_get_active_data_sheet (dw->data_editor);
-
-  psppire_data_sheet_insert_case (ds);
-#endif
+  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)
 {
-  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)
     {
-      goto_case_dialog (JMD_SHEET (dw->data_editor->data_sheet));
+      goto_case_dialog (PSPPIRE_DATA_SHEET (de->data_sheet));
     }
 }
 
-
 static GtkWidget *
 create_file_menu (PsppireDataWindow *dw)
 {
@@ -1247,23 +1216,23 @@ create_file_menu (PsppireDataWindow *dw)
     GtkWidget *new_menu = gtk_menu_new ();
 
     g_object_set (new, "submenu", new_menu, NULL);
-       
+
     GtkWidget *syntax  = gtk_menu_item_new_with_mnemonic (_("_Syntax"));
     connect_action_to_menuitem (G_ACTION_MAP (g_application_get_default ()), "new-syntax", syntax, 0);
-    
+
     GtkWidget *data = gtk_menu_item_new_with_mnemonic (_("_Data"));
     connect_action_to_menuitem (G_ACTION_MAP (g_application_get_default ()), "new-data", data, 0);
 
     gtk_menu_attach (GTK_MENU (new_menu), syntax,    0, 1, 0, 1);
     gtk_menu_attach (GTK_MENU (new_menu), data,      0, 1, 1, 2);
   }
-  
+
   GtkWidget *open = gtk_menu_item_new_with_mnemonic (_("_Open"));
   connect_action_to_menuitem (G_ACTION_MAP (dw), "open", open, "<Ctrl>O");
-  
+
   GtkWidget *import = gtk_menu_item_new_with_mnemonic (_("_Import Data..."));
   connect_action_to_menuitem (G_ACTION_MAP (dw), "file-import", import, 0);
-  
+
   gtk_menu_attach (GTK_MENU (menu), open,       0, 1, 1, 2);
   gtk_menu_attach (GTK_MENU (menu), import,     0, 1, 2, 3);
 
@@ -1271,14 +1240,14 @@ create_file_menu (PsppireDataWindow *dw)
 
   GtkWidget *save = gtk_menu_item_new_with_mnemonic (_("_Save..."));
   connect_action_to_menuitem (G_ACTION_MAP (dw), "save", save, "<Ctrl>S");
-  
+
   GtkWidget *save_as = gtk_menu_item_new_with_mnemonic (_("Save _As..."));
   connect_action_to_menuitem (G_ACTION_MAP (dw), "save-as", save_as, "<Shift><Ctrl>S");
-  
+
   GtkWidget *rename_dataset = gtk_menu_item_new_with_mnemonic (_("_Rename Dataset..."));
   connect_action_to_menuitem (G_ACTION_MAP (dw), "rename-dataset", rename_dataset, 0);
 
-  
+
   gtk_menu_attach (GTK_MENU (menu), save,        0, 1, 4, 5);
   gtk_menu_attach (GTK_MENU (menu), save_as,     0, 1, 5, 6);
   gtk_menu_attach (GTK_MENU (menu), rename_dataset,     0, 1, 6, 7);
@@ -1292,7 +1261,7 @@ create_file_menu (PsppireDataWindow *dw)
     GtkWidget *dd_menu = gtk_menu_new ();
 
     g_object_set (display_data, "submenu", dd_menu, NULL);
-    
+
     GtkWidget *working_file  = gtk_menu_item_new_with_mnemonic (_("Working File"));
     connect_action_to_menuitem (G_ACTION_MAP (dw), "info-working", working_file, 0);
     GtkWidget *external_file = gtk_menu_item_new_with_mnemonic (_("_External File..."));
@@ -1301,7 +1270,7 @@ create_file_menu (PsppireDataWindow *dw)
     gtk_menu_attach (GTK_MENU (dd_menu), working_file,    0, 1, 0, 1);
     gtk_menu_attach (GTK_MENU (dd_menu), external_file,   0, 1, 1, 2);
   }
-  
+
   gtk_menu_attach (GTK_MENU (menu), gtk_separator_menu_item_new (), 0, 1, 9, 10);
 
   {
@@ -1316,13 +1285,13 @@ create_file_menu (PsppireDataWindow *dw)
 
     gtk_menu_attach (GTK_MENU (menu), mi_data,       0, 1, 10, 11);
     gtk_menu_attach (GTK_MENU (menu), mi_files,      0, 1, 11, 12);
-    
+
     g_object_set (menu_data, "show-tips",  TRUE, NULL);
     g_object_set (menu_files, "show-tips",  TRUE, NULL);
 
     g_object_set (mi_data, "submenu",  menu_data, NULL);
     g_object_set (mi_files, "submenu", menu_files, NULL);
-    
+
     {
       GtkRecentFilter *filter = gtk_recent_filter_new ();
 
@@ -1359,10 +1328,10 @@ create_file_menu (PsppireDataWindow *dw)
     connect_action_to_menuitem (G_ACTION_MAP (g_application_get_default ()),
                                "quit", quit, "<Ctrl>Q");
   }
-  
+
   g_object_set (menuitem, "submenu", menu, NULL);
   gtk_widget_show_all (menuitem);
-  
+
   return menuitem;
 }
 
@@ -1390,13 +1359,13 @@ create_edit_menu (PsppireDataWindow *dw)
   GAction *a = g_action_map_lookup_action (G_ACTION_MAP (dw),  "PsppireDialogActionVarInfo");
   g_assert (a);
   g_signal_connect_swapped (go_to_variable, "activate", G_CALLBACK (psppire_dialog_action_activate_null), a);
-  
+
   gtk_menu_attach (GTK_MENU (menu), go_to_variable,         0, 1, i, i + 1); ++i;
   gtk_menu_attach (GTK_MENU (menu), dw->mi_go_to_case,      0, 1, i, i + 1); ++i;
 
   {
     GtkAccelGroup *ag = gtk_accel_group_new ();
-    
+
     dw->mi_edit_separator = gtk_separator_menu_item_new ();
     gtk_menu_attach (GTK_MENU (menu), dw->mi_edit_separator, 0, 1, i, i + 1); ++i;
 
@@ -1407,13 +1376,13 @@ create_edit_menu (PsppireDataWindow *dw)
     gtk_window_add_accel_group (GTK_WINDOW (dw), ag);
     gtk_widget_add_accelerator (dw->mi_cut, "activate", ag,
                                'X', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-    
+
     dw->mi_copy = gtk_menu_item_new_with_mnemonic (_("_Copy"));
     gtk_menu_attach (GTK_MENU (menu), dw->mi_copy,     0, 1, i, i + 1); ++i;
     g_signal_connect_swapped (dw->mi_copy, "activate", G_CALLBACK (on_copy), dw);
     gtk_widget_add_accelerator (dw->mi_copy, "activate", ag,
                                'C', GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
-       
+
     dw->mi_paste = gtk_menu_item_new_with_mnemonic (_("_Paste"));
     gtk_menu_attach (GTK_MENU (menu), dw->mi_paste,     0, 1, i, i + 1); ++i;
     g_signal_connect_swapped (dw->mi_paste, "activate", G_CALLBACK (on_paste), dw);
@@ -1423,25 +1392,32 @@ create_edit_menu (PsppireDataWindow *dw)
     dw->mi_clear_variables = gtk_menu_item_new_with_mnemonic (_("Clear _Variables"));
     gtk_menu_attach (GTK_MENU (menu), dw->mi_clear_variables,     0, 1, i, i + 1); ++i;
     g_signal_connect_swapped (dw->mi_clear_variables, "activate", G_CALLBACK (on_clear_variables), dw);
-    
+
     dw->mi_clear_cases = gtk_menu_item_new_with_mnemonic (_("Cl_ear Cases"));
     gtk_menu_attach (GTK_MENU (menu), dw->mi_clear_cases,     0, 1, i, i + 1); ++i;
     g_signal_connect_swapped (dw->mi_clear_cases, "activate", G_CALLBACK (on_clear_cases), dw);
   }
-  
+
   {
     dw->mi_find_separator = gtk_separator_menu_item_new ();
     gtk_menu_attach (GTK_MENU (menu), dw->mi_find_separator, 0, 1, i, i + 1); ++i;
-  
+
     dw->mi_find = gtk_menu_item_new_with_mnemonic (_("_Find..."));
     g_signal_connect_swapped (dw->mi_find, "activate", G_CALLBACK (find_dialog), dw);
-    gtk_menu_attach (GTK_MENU (menu), dw->mi_find,      0, 1,  i, i + 1); ++i;
+    gtk_menu_attach (GTK_MENU (menu), dw->mi_find,    0, 1,  i, i + 1); ++i;
   }
-  
+
+  {
+    dw->mi_options = gtk_menu_item_new_with_mnemonic (_("_Options..."));
+    g_signal_connect_swapped (dw->mi_options, "activate",
+                             G_CALLBACK (options_dialog), dw);
+    gtk_menu_attach (GTK_MENU (menu), dw->mi_options, 0, 1,  i, i + 1); ++i;
+  }
+
   g_object_set (menuitem, "submenu", menu, NULL);
-  
+
   gtk_widget_show_all (menuitem);
-  
+
   return menuitem;
 }
 
@@ -1475,19 +1451,13 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
 
   de->data_editor =
     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);
@@ -1511,7 +1481,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
                    G_CALLBACK (on_split_change),
                    de);
 
-  g_signal_connect_swapped (de->dict, "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);
@@ -1524,7 +1494,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_FLIP,  de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_AGGREGATE,  de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_WEIGHT,  de);
-  
+
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_COMPUTE,  de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_COUNT,  de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_AUTORECODE,  de);
@@ -1533,7 +1503,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_RECODE_SAME,  de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_RECODE_DIFFERENT,  de);
 
-    
+
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_DESCRIPTIVES,  de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_FREQUENCIES,  de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_EXAMINE,  de);
@@ -1554,7 +1524,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_REGRESSION, de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_LOGISTIC, de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_ROC, de);
-  
+
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_COMMENTS, de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_VAR_INFO, de);
 
@@ -1568,13 +1538,14 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_1SKS, de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_TWO_SAMPLE, de);
   connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_K_RELATED, de);
+  connect_dialog_action (PSPPIRE_TYPE_DIALOG_ACTION_K_INDEPENDENT, de);
 
   {
     GSimpleAction *file_import_action = g_simple_action_new ("file-import", NULL);
     g_signal_connect_swapped (file_import_action, "activate", G_CALLBACK (file_import), de);
     g_action_map_add_action (G_ACTION_MAP (de), G_ACTION (file_import_action));
   }
-  
+
   {
     GSimpleAction *save = g_simple_action_new ("save", NULL);
     g_signal_connect_swapped (save, "activate", G_CALLBACK (psppire_window_save), de);
@@ -1623,7 +1594,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
     g_action_map_add_action (G_ACTION_MAP (de), G_ACTION (act_gridlines));
   }
 
-  
+
   {
     GSimpleAction *act_view_data = g_simple_action_new_stateful ("view_dv", G_VARIANT_TYPE_STRING,
                                                                 g_variant_new_string ("DATA"));
@@ -1679,7 +1650,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
     g_signal_connect_swapped (find, "activate", G_CALLBACK (find_dialog), de);
     g_action_map_add_action (G_ACTION_MAP (de), G_ACTION (find));
   }
-  
+
   {
     int idx = 0;
     {
@@ -1713,12 +1684,12 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
 
     {
       de->ti_jump_to_case = gtk_tool_button_new (NULL, "Jump to Case");
-      
+
       GAction *a = g_action_map_lookup_action (G_ACTION_MAP (de),  "jump-to-case");
       g_assert (a);
       g_signal_connect_swapped (de->ti_jump_to_case, "clicked",
                                G_CALLBACK (g_action_activate_null), a);
-      
+
       gtk_toolbar_insert (GTK_TOOLBAR (hb), de->ti_jump_to_case, idx++);
       gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (de->ti_jump_to_case), "edit-go-to-case");
       gtk_widget_set_tooltip_text (GTK_WIDGET (de->ti_jump_to_case), _("Jump to a case in the data sheet"));
@@ -1732,7 +1703,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de,
       g_signal_connect_swapped (de->ti_find, "clicked",
                                G_CALLBACK (g_action_activate_null), a);
 
-      
+
       gtk_toolbar_insert (GTK_TOOLBAR (hb), de->ti_find, idx++);
       gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (de->ti_find), "edit-find");
       gtk_widget_set_tooltip_text (GTK_WIDGET (de->ti_find), _("Search for values in the data"));
@@ -1951,7 +1922,7 @@ psppire_data_window_new (struct dataset *ds)
 
   GApplication *app = g_application_get_default ();
   gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (dw));
-  
+
   return dw;
 }
 
@@ -2013,13 +1984,25 @@ psppire_data_window_for_dataset (struct dataset *ds)
   return NULL;
 }
 
+PsppireDataWindow *
+psppire_data_window_for_data_store (PsppireDataStore *data_store)
+{
+  PsppireDataWindow *pdw;
+
+  ll_for_each (pdw, PsppireDataWindow, ll, &all_data_windows)
+    if (pdw->data_store == data_store)
+      return pdw;
+
+  return NULL;
+}
+
 GtkWindow *
 create_data_window (void)
 {
   GtkWidget *w = psppire_data_window_new (NULL);
 
   gtk_widget_show (w);
-  
+
   return GTK_WINDOW (w);
 }