From 4c938ca6e42d409551da41486906ec70ef6fb6c0 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Fri, 29 Jun 2007 05:14:32 +0000 Subject: [PATCH] (Re)enabled cell reference entry and datum entry widgets. --- src/ui/gui/ChangeLog | 6 +++ src/ui/gui/data-editor.c | 66 ++++++++++++++++++++++++--------- src/ui/gui/data-editor.glade | 2 +- src/ui/gui/psppire-data-store.c | 41 ++++++++++++-------- src/ui/gui/psppire-data-store.h | 5 +++ 5 files changed, 87 insertions(+), 33 deletions(-) diff --git a/src/ui/gui/ChangeLog b/src/ui/gui/ChangeLog index cb2cae25..c3b28138 100644 --- a/src/ui/gui/ChangeLog +++ b/src/ui/gui/ChangeLog @@ -1,3 +1,9 @@ +2007-06-29 John Darrington + + * data-editor.c data-editor.glade psppire-data-store.c + psppire-data-store.h: Enabled cell reference entry and datum + entry widgets. + 2007-06-29 John Darrington * data-editor.c data-sheet.c: Moved update_cell_ref_entry from diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index 2f15096c..a8b3d5e3 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -171,7 +171,22 @@ on_recent_files_select (GtkMenuShell *menushell, gpointer user_data) #endif +static void +datum_entry_activate (GtkEntry *entry, gpointer data) +{ + gint row, column; + GtkSheet *data_sheet = GTK_SHEET (data); + PsppireDataStore *store = PSPPIRE_DATA_STORE (gtk_sheet_get_model (data_sheet)); + + const char *text = gtk_entry_get_text (entry); + gtk_sheet_get_active_cell (data_sheet, &row, &column); + + if ( row == -1 || column == -1) + return; + + psppire_data_store_set_string (store, text, row, column); +} /* Create a new data editor. @@ -184,6 +199,7 @@ new_data_editor (void) GtkSheet *var_sheet ; GtkSheet *data_sheet ; PsppireVarStore *vs; + GtkWidget *datum_entry; de = g_malloc0 (sizeof (*de)); @@ -202,6 +218,12 @@ new_data_editor (void) G_CALLBACK (update_data_ref_entry), de->xml); + datum_entry = get_widget_assert (de->xml, "datum_entry"); + + g_signal_connect (G_OBJECT (datum_entry), "activate", + G_CALLBACK (datum_entry_activate), + data_sheet); + g_signal_connect (vs->dict, "weight-changed", G_CALLBACK (on_weight_change), de); @@ -302,9 +324,6 @@ new_data_editor (void) de->action_data_open); - - - #if RECENT_LISTS_AVAILABLE { GtkRecentManager *rm = gtk_recent_manager_get_default (); @@ -1247,34 +1266,47 @@ update_data_ref_entry (const GtkSheet *sheet, gint row, gint col, gpointer data) { GladeXML *data_editor_xml = data; - /* The entry where the reference to the current cell is displayed */ - GtkEntry *cell_ref_entry; - PsppireDataStore *data_store = PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet)); g_return_val_if_fail (data_editor_xml, FALSE); if (data_store) { - const struct variable *pv = + const struct variable *var = psppire_dict_get_variable (data_store->dict, col); - gchar *text ; - gchar *s ; + { + /* 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")); - text = g_strdup_printf ("%d: %s", row, - pv ? var_get_name (pv) : ""); + gchar *text = g_strdup_printf ("%d: %s", row, + var ? var_get_name (var) : ""); - cell_ref_entry = GTK_ENTRY (get_widget_assert (data_editor_xml, - "cell_ref_entry")); + gchar *s = pspp_locale_to_utf8 (text, -1, 0); - 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); + { + 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); + + gtk_entry_set_text (datum_entry, text); + + free (text); + } } return FALSE; diff --git a/src/ui/gui/data-editor.glade b/src/ui/gui/data-editor.glade index 63ddf452..afdfe004 100644 --- a/src/ui/gui/data-editor.glade +++ b/src/ui/gui/data-editor.glade @@ -758,7 +758,7 @@ - + True True diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index c7d94cee..af205ccd 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -58,11 +58,6 @@ static void psppire_data_store_sheet_row_init (GSheetRowIface *iface); static void psppire_data_store_finalize (GObject *object); -static gchar *psppire_data_store_get_string (const GSheetModel *sheet_model, gint row, gint column); - -static gboolean psppire_data_store_set_string (GSheetModel *model, - const gchar *text, gint row, gint column); - static gboolean psppire_data_store_clear_datum (GSheetModel *model, gint row, gint column); @@ -199,13 +194,32 @@ psppire_data_store_get_font_desc (const GSheetModel *model, return store->font_desc; } +static inline gchar * +psppire_data_store_get_string_wrapper (const GSheetModel *model, gint row, + gint column) +{ + return psppire_data_store_get_string (PSPPIRE_DATA_STORE (model), row, column); +} + + +static inline gboolean +psppire_data_store_set_string_wrapper (GSheetModel *model, + const gchar *text, + gint row, gint column) +{ + return psppire_data_store_set_string (PSPPIRE_DATA_STORE (model), text, + row, column); +} + + + static void psppire_data_store_sheet_model_init (GSheetModelIface *iface) { iface->free_strings = TRUE; - iface->get_string = psppire_data_store_get_string; - iface->set_string = psppire_data_store_set_string; + iface->get_string = psppire_data_store_get_string_wrapper; + iface->set_string = psppire_data_store_set_string_wrapper; iface->clear_datum = psppire_data_store_clear_datum; iface->is_editable = NULL; iface->is_visible = NULL; @@ -480,8 +494,8 @@ psppire_data_store_insert_new_case (PsppireDataStore *ds, gint posn) } -static gchar * -psppire_data_store_get_string (const GSheetModel *model, gint row, gint column) +gchar * +psppire_data_store_get_string (PsppireDataStore *store, gint row, gint column) { gint idx; char *text; @@ -489,7 +503,6 @@ psppire_data_store_get_string (const GSheetModel *model, gint row, gint column) const struct variable *pv ; union value *v ; GString *s; - PsppireDataStore *store = PSPPIRE_DATA_STORE (model); g_return_val_if_fail (store->dict, NULL); g_return_val_if_fail (store->case_file, NULL); @@ -575,12 +588,10 @@ psppire_data_store_clear_datum (GSheetModel *model, to ROW, COL with the value TEXT. Returns true if anything was updated, false otherwise. */ -static gboolean -psppire_data_store_set_string (GSheetModel *model, - const gchar *text, gint row, gint col) +gboolean +psppire_data_store_set_string (PsppireDataStore *store, + const gchar *text, gint row, gint col) { - PsppireDataStore *store = PSPPIRE_DATA_STORE (model); - const struct variable *pv = psppire_dict_get_variable (store->dict, col); g_return_val_if_fail (pv, FALSE); diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index 7e2067fd..7f03246a 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -108,7 +108,12 @@ gboolean psppire_data_store_insert_new_case (PsppireDataStore *ds, gint posn); struct casereader * psppire_data_store_get_reader (PsppireDataStore *ds); +gchar * psppire_data_store_get_string (PsppireDataStore *ds, + gint row, gint column); +gboolean psppire_data_store_set_string (PsppireDataStore *ds, + const gchar *text, + gint row, gint column); #ifdef __cplusplus } -- 2.30.2