Populate the datum entry on cell change
authorJohn Darrington <john@darrington.wattle.id.au>
Sun, 14 Aug 2016 07:19:23 +0000 (09:19 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Sun, 14 Aug 2016 07:19:23 +0000 (09:19 +0200)
src/ui/gui/psppire-data-editor.c
src/ui/gui/psppire-data-store.c
src/ui/gui/psppire-data-store.h

index c108de556363f6cd6f4a4262186d3f9330fb6f8e..f3a3059cb906835d69fe3d6d9d0af62f0c078b86 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010, 2011, 2012, 2016 Free Software Foundation, Inc.
 
    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
@@ -458,7 +458,21 @@ on_data_sheet_var_double_clicked (JmdSheet *data_sheet, gint dict_index,
 static void
 refresh_entry (PsppireDataEditor *de)
 {
-  g_print ("%s\n", __FUNCTION__);
+  union value val;
+  gint row, col;
+  jmd_sheet_get_active_cell (JMD_SHEET (de->data_sheet), &col, &row);
+
+  const struct variable *var = psppire_dict_get_variable (de->dict, col);
+  psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (de->datum_entry), var);
+
+  int width = var_get_width (var);
+  if (! psppire_data_store_get_value (PSPPIRE_DATA_STORE (de->data_store),
+                                     row, var, &val))
+    return;
+
+  psppire_value_entry_set_value (PSPPIRE_VALUE_ENTRY (de->datum_entry),
+                                &val, width);
+  value_destroy (&val, width);
 }
 
 static void
@@ -679,41 +693,3 @@ void
 psppire_data_editor_goto_variable (PsppireDataEditor *de, gint dict_index)
 {
 }
-
-#if SHEET_MERGE
-/* Returns the "active" data sheet in DE.  If DE is in single-paned mode, this
-   is the only data sheet.  If DE is in split mode (showing four data sheets),
-   this is the focused data sheet or, if none is focused, the data sheet with
-   selected cells or, if none has selected cells, the upper-left data sheet. */
-PsppireDataSheet *
-psppire_data_editor_get_active_data_sheet (PsppireDataEditor *de)
-{
-  if (de->split)
-    {
-      PsppireDataSheet *data_sheet;
-      GtkWidget *scroller;
-      int i;
-
-      /* If one of the datasheet's scrollers is focused, choose that one. */
-      scroller = gtk_container_get_focus_child (
-        GTK_CONTAINER (de->datasheet_vbox_widget));
-      if (scroller != NULL)
-        return PSPPIRE_DATA_SHEET (gtk_bin_get_child (GTK_BIN (scroller)));
-
-      /* Otherwise if there's a nonempty selection in some data sheet, choose
-         that one. */
-      FOR_EACH_DATA_SHEET (data_sheet, i, de)
-        {
-          PsppSheetSelection *selection;
-
-          selection = pspp_sheet_view_get_selection (
-            PSPP_SHEET_VIEW (data_sheet));
-          if (pspp_sheet_selection_count_selected_rows (selection)
-              && pspp_sheet_selection_count_selected_columns (selection))
-            return data_sheet;
-        }
-    }
-
-  return PSPPIRE_DATA_SHEET (de->data_sheets[0]);
-}
-#endif
index 1c934e0fb837a1a2be646c8ff7f520375807b054..1664da735eadf46df384326ced168c423b1bf9fa 100644 (file)
@@ -592,26 +592,38 @@ psppire_data_store_insert_new_case (PsppireDataStore *ds, casenumber posn)
   return result;
 }
 
-gchar *
-psppire_data_store_get_string (PsppireDataStore *store,
-                               glong row, const struct variable *var,
-                               bool use_value_label)
+gboolean
+psppire_data_store_get_value (PsppireDataStore *store,
+                             glong row, const struct variable *var,
+                             union value *val)
 {
-  gchar *string;
-  union value v;
-  int width;
-
   g_return_val_if_fail (store != NULL, NULL);
   g_return_val_if_fail (store->datasheet != NULL, NULL);
   g_return_val_if_fail (var != NULL, NULL);
 
   if (row < 0 || row >= datasheet_get_n_rows (store->datasheet))
-    return NULL;
+    return FALSE;
 
-  width = var_get_width (var);
-  value_init (&v, width);
-  datasheet_get_value (store->datasheet, row, var_get_case_index (var), &v);
+  int width = var_get_width (var);
+  value_init (val, width);
+  datasheet_get_value (store->datasheet, row, var_get_case_index (var), val);
 
+  return TRUE;
+}
+
+  
+
+gchar *
+psppire_data_store_get_string (PsppireDataStore *store,
+                               glong row, const struct variable *var,
+                               bool use_value_label)
+{
+  gchar *string;
+  union value v;
+  int width = var_get_width (var);
+  if (! psppire_data_store_get_value (store, row, var, &v))
+    return NULL;
+  
   string = NULL;
   if (use_value_label)
     {
index 6b6d755e6eb5ca90cb00ecba4d91e98238031288..c0783f46509a039a6b4b1cd7693df55ee647aa84 100644 (file)
@@ -106,10 +106,18 @@ struct casereader * psppire_data_store_get_reader (PsppireDataStore *ds);
 gchar *psppire_data_store_get_string (PsppireDataStore *,
                                       glong row, const struct variable *,
                                       bool use_value_label);
+
+
+gboolean psppire_data_store_get_value (PsppireDataStore *store,
+                                      glong row, const struct variable *var,
+                                      union value *val);
+
 gboolean psppire_data_store_set_value (PsppireDataStore *,
                                        casenumber casenum,
                                        const struct variable *,
                                        const union value *);
+
+
 gboolean psppire_data_store_set_string (PsppireDataStore *ds,
                                        const gchar *text,
                                        glong row, const struct variable *,