Implemented the goto-case dialog
[pspp-builds.git] / src / ui / gui / data-editor.c
index 63a19a63a1ce2a8c19b8e8b338885136f95bb927..982b6983a8cf8ebe46c2d4e5545716d3816ed700 100644 (file)
@@ -1,21 +1,18 @@
-/*
-    PSPPIRE --- A Graphical User Interface for PSPP
-    Copyright (C) 2006, 2007  Free Software Foundation
+/* PSPPIRE - a graphical user interface for PSPP.
+   Copyright (C) 2006, 2007  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
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
+   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
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
 
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-    02110-1301, USA. */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 #include <stdlib.h>
@@ -36,6 +33,7 @@
 #include "transpose-dialog.h"
 #include "sort-cases-dialog.h"
 #include "compute-dialog.h"
+#include "goto-case-dialog.h"
 #include "comments-dialog.h"
 #include "variable-info-dialog.h"
 #include "dict-display.h"
@@ -251,6 +249,13 @@ new_data_editor (void)
                    G_CALLBACK (insert_variable), de);
 
 
+
+  g_signal_connect (de->insert_variable, "activate",
+                   G_CALLBACK (insert_variable), de);
+
+
+
+
   gtk_action_connect_proxy (de->insert_variable,
                            get_widget_assert (de->xml, "button-insert-variable")
                            );
@@ -259,6 +264,26 @@ new_data_editor (void)
                            get_widget_assert (de->xml, "data_insert-variable")
                            );
 
+  de->invoke_goto_dialog =
+    gtk_action_new ("goto-case-dialog",
+                   _("Goto Case"),
+                   _("Jump to a Case in the Data Sheet"),
+                   "gtk-jump-to");
+
+
+  gtk_action_connect_proxy (de->invoke_goto_dialog,
+                           get_widget_assert (de->xml, "button-goto-case")
+                           );
+
+  gtk_action_connect_proxy (de->invoke_goto_dialog,
+                           get_widget_assert (de->xml, "data_goto-case")
+                           );
+
+
+  g_signal_connect (de->invoke_goto_dialog, "activate",
+                   G_CALLBACK (goto_case_dialog), de);
+
+
   de->invoke_weight_cases_dialog =
     gtk_action_new ("weight-cases-dialog",
                    _("Weights"),
@@ -622,13 +647,12 @@ select_sheet (struct data_editor *de, guint page_num)
       gtk_widget_show (view_data);
       gtk_widget_set_sensitive (insert_variable, TRUE);
       gtk_widget_set_sensitive (insert_cases, FALSE);
+      gtk_action_set_sensitive (de->invoke_goto_dialog, FALSE);
       break;
     case PAGE_DATA_SHEET:
       gtk_widget_show (view_variables);
       gtk_widget_hide (view_data);
-#if 0
-      gtk_widget_set_sensitive (insert_cases, TRUE);
-#endif
+      gtk_action_set_sensitive (de->invoke_goto_dialog, TRUE);
       break;
     default:
       g_assert_not_reached ();
@@ -1287,7 +1311,8 @@ update_data_ref_entry (const GtkSheet *sheet, gint row, gint col, gpointer data)
 {
   GladeXML *data_editor_xml = data;
 
-  PsppireDataStore *data_store = PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
+  PsppireDataStore *data_store =
+    PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet));
 
   g_return_val_if_fail (data_editor_xml, FALSE);
 
@@ -1296,38 +1321,44 @@ update_data_ref_entry (const GtkSheet *sheet, gint row, gint col, gpointer data)
       const struct variable *var =
        psppire_dict_get_variable (data_store->dict, col);
 
-      {
-       /* The entry where the reference to the current cell is displayed */
-       GtkEntry *cell_ref_entry =
-         GTK_ENTRY (get_widget_assert (data_editor_xml,
-                                       "cell_ref_entry"));
+      /* The entry where the reference to the current cell is displayed */
+      GtkEntry *cell_ref_entry =
+       GTK_ENTRY (get_widget_assert (data_editor_xml,
+                                     "cell_ref_entry"));
+      GtkEntry *datum_entry =
+       GTK_ENTRY (get_widget_assert (data_editor_xml,
+                                     "datum_entry"));
 
-       gchar *text = g_strdup_printf ("%d: %s", row,
-                                      var ? var_get_name (var) : "");
+      if ( var )
+       {
+         gchar *text = g_strdup_printf ("%d: %s", row + FIRST_CASE_NUMBER,
+                                        var_get_name (var));
 
-       gchar *s = pspp_locale_to_utf8 (text, -1, 0);
+         gchar *s = pspp_locale_to_utf8 (text, -1, 0);
 
-       g_free (text);
+         g_free (text);
 
-       gtk_entry_set_text (cell_ref_entry, s);
+         gtk_entry_set_text (cell_ref_entry, s);
 
-       g_free (s);
-      }
+         g_free (s);
+       }
+      else
+       gtk_entry_set_text (cell_ref_entry, "");
 
-      {
-       GtkEntry *datum_entry =
-         GTK_ENTRY (get_widget_assert (data_editor_xml,
-                                       "datum_entry"));
 
-       gchar *text =
-         psppire_data_store_get_string (data_store, row,
-                                        var_get_dict_index(var));
-       g_strchug (text);
+      if ( var )
+       {
+         gchar *text =
+           psppire_data_store_get_string (data_store, row,
+                                          var_get_dict_index(var));
+         g_strchug (text);
 
-       gtk_entry_set_text (datum_entry, text);
+         gtk_entry_set_text (datum_entry, text);
 
-       free (text);
-      }
+         free (text);
+       }
+      else
+       gtk_entry_set_text (datum_entry, "");
     }
 
   return FALSE;