From: John Darrington Date: Sun, 14 Aug 2016 07:19:23 +0000 (+0200) Subject: Populate the datum entry on cell change X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;ds=sidebyside;h=e8d52510a02525939dbde828cf62ed44374d6920;p=pspp Populate the datum entry on cell change --- diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index c108de5563..f3a3059cb9 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -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 diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 1c934e0fb8..1664da735e 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -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) { diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index 6b6d755e6e..c0783f4650 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -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 *,