Implemented the goto-case dialog
[pspp-builds.git] / src / ui / gui / psppire-data-store.c
index af205ccde2c8613c6653ccfe61449b5b459435c2..22bc10ee8d192b060c1cab761f5d62101fc6793c 100644 (file)
@@ -1,11 +1,9 @@
-/* psppire-data-store.c
-
-   PSPPIRE --- A Graphical User Interface for PSPP
+/* PSPPIRE - a graphical user interface for PSPP.
    Copyright (C) 2006  Free Software Foundation
 
-   This program is free software; you can redistribute it and/or modify
+   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
+   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,
@@ -14,9 +12,7 @@
    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. */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 
 #include <config.h>
 #include <string.h>
@@ -25,7 +21,6 @@
 #define _(msgid) gettext (msgid)
 #define N_(msgid) msgid
 
-#include <data/casewriter.h>
 #include <data/datasheet.h>
 #include <data/data-out.h>
 #include <data/variable.h>
 #include <data/value-labels.h>
 #include <data/data-in.h>
 
-#include <data/file-handle-def.h>
-#include <data/sys-file-writer.h>
-
-
 
 static void psppire_data_store_init            (PsppireDataStore      *data_store);
 static void psppire_data_store_class_init      (PsppireDataStoreClass *class);
@@ -168,8 +159,14 @@ psppire_data_store_get_var_count (const GSheetModel *model)
   return psppire_dict_get_var_cnt (store->dict);
 }
 
+casenumber
+psppire_data_store_get_case_count (PsppireDataStore *store)
+{
+  return psppire_case_file_get_case_count (store->case_file);
+}
+
 static gint
-psppire_data_store_get_case_count (const GSheetModel *model)
+psppire_data_store_get_case_count_from_model (const GSheetModel *model)
 {
   const PsppireDataStore *store = PSPPIRE_DATA_STORE (model);
 
@@ -177,6 +174,8 @@ psppire_data_store_get_case_count (const GSheetModel *model)
 }
 
 
+
+
 static void
 psppire_data_store_init (PsppireDataStore *data_store)
 {
@@ -228,7 +227,7 @@ psppire_data_store_sheet_model_init (GSheetModelIface *iface)
   iface->get_font_desc = psppire_data_store_get_font_desc;
   iface->get_cell_border = NULL;
   iface->get_column_count = psppire_data_store_get_var_count;
-  iface->get_row_count = psppire_data_store_get_case_count;
+  iface->get_row_count = psppire_data_store_get_case_count_from_model;
 }
 
 static
@@ -650,43 +649,6 @@ psppire_data_store_show_labels (PsppireDataStore *store, gboolean show_labels)
 }
 
 
-
-/* FIXME: There's no reason to actually have this function.
-   It should be done by a procedure */
-void
-psppire_data_store_create_system_file (PsppireDataStore *store,
-                             struct file_handle *handle)
-{
-  gint i, var_cnt;
-  const struct sfm_write_options wo = {
-    true, /* writeable */
-    false, /* dont compress */
-    3 /* version */
-  };
-
-  struct casewriter *writer;
-
-  g_assert (handle);
-
-  writer = sfm_open_writer (handle, store->dict->dict, wo);
-
-  if ( ! writer)
-    return;
-
-
-  var_cnt = psppire_data_store_get_var_count (G_SHEET_MODEL (store));
-
-  for (i = 0 ; i < psppire_case_file_get_case_count (store->case_file); ++i )
-    {
-      struct ccase c;
-      psppire_case_file_get_case (store->case_file, i, &c);
-      casewriter_write (writer, &c);
-    }
-  casewriter_destroy (writer);
-}
-
-
-
 void
 psppire_data_store_clear (PsppireDataStore *data_store)
 {
@@ -789,6 +751,27 @@ geometry_get_column_button_label (const GSheetColumn *geom, gint unit)
 }
 
 
+static gchar *
+geometry_get_column_subtitle (const GSheetColumn *geom, gint unit)
+{
+  gchar *text;
+  const struct variable *v ;
+  PsppireDataStore *ds = PSPPIRE_DATA_STORE (geom);
+
+  if ( unit >= psppire_dict_get_var_cnt (ds->dict) )
+    return NULL;
+
+  v = psppire_dict_get_variable (ds->dict, unit);
+
+  if ( ! var_has_label (v))
+    return NULL;
+
+  text =  pspp_locale_to_utf8 (var_get_label (v), -1, 0);
+
+  return text;
+}
+
+
 static gboolean
 geometry_get_sensitivity (const GSheetColumn *geom, gint unit)
 {
@@ -808,6 +791,7 @@ psppire_data_store_sheet_column_init (GSheetColumnIface *iface)
   iface->get_sensitivity = geometry_get_sensitivity;
   iface->get_justification = geometry_get_justification;
   iface->get_button_label = geometry_get_column_button_label;
+  iface->get_subtitle = geometry_get_column_subtitle;
 }
 
 
@@ -850,7 +834,7 @@ geometry_get_row_button_label (const GSheetRow *geom, gint unit, gpointer data)
        TRAILING_ROWS + psppire_case_file_get_case_count (ds->case_file))
     return 0;
 
-  s = g_strdup_printf (_("%d"), unit);
+  s = g_strdup_printf (_("%d"), unit + FIRST_CASE_NUMBER);
 
   text =  pspp_locale_to_utf8 (s, -1, 0);