Enable the value_labels popup dialog
[pspp] / src / ui / gui / psppire-data-window.c
index c0f8ba5344cea4b48baeca0d9f5224bd883126fa..091af6503ec9fcfa202e0f63a86908562c6631d8 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"
@@ -48,6 +50,7 @@
 #include "ui/gui/efficient-sheet/jmd-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"
@@ -1066,8 +1069,8 @@ 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);
       
@@ -1115,13 +1118,11 @@ 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)),
@@ -1131,109 +1132,82 @@ on_copy (PsppireDataWindow *dw)
     }
 }
 
-
-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]));
-    }
-}
-
 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);
+      JmdRange *range = JMD_SHEET(de->data_sheet)->selection;
+      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);
+      JmdRange *range = JMD_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));
+      JmdRange *range = JMD_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;
+  JmdRange *range = JMD_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 (JMD_SHEET (de->data_sheet));
     }
 }
 
-
 static GtkWidget *
 create_file_menu (PsppireDataWindow *dw)
 {
@@ -1435,7 +1409,14 @@ create_edit_menu (PsppireDataWindow *dw)
   
     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);
@@ -1482,12 +1463,6 @@ psppire_data_window_finish_init (PsppireDataWindow *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 +1486,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);
@@ -2013,6 +1988,18 @@ 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)
 {
@@ -2023,9 +2010,7 @@ create_data_window (void)
   return GTK_WINDOW (w);
 }
 
-
-
-void
+GtkWindow *
 open_data_window (PsppireWindow *victim, const char *file_name,
                   const char *encoding, gpointer hint)
 {
@@ -2042,4 +2027,5 @@ open_data_window (PsppireWindow *victim, const char *file_name,
 
   psppire_window_load (PSPPIRE_WINDOW (window), file_name, encoding, hint);
   gtk_widget_show_all (window);
+  return GTK_WINDOW (window);
 }