X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-editor.c;h=70086b500070d1b557eee74928b5231df83863b9;hb=refs%2Fbuilds%2F20121208032040%2Fpspp;hp=575307e8c84a7509eb1b2da728aea8578caa8808;hpb=0fe886a656b0ee57b4d542b7c16b3c56288b6fc6;p=pspp diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 575307e8c8..70086b5000 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -24,6 +24,7 @@ #include "data/datasheet.h" #include "data/value-labels.h" #include "libpspp/range-set.h" +#include "libpspp/str.h" #include "ui/gui/helper.h" #include "ui/gui/pspp-sheet-selection.h" #include "ui/gui/psppire-data-sheet.h" @@ -91,10 +92,10 @@ psppire_data_editor_dispose (GObject *obj) de->data_store = NULL; } - if (de->var_store) + if (de->dict) { - g_object_unref (de->var_store); - de->var_store = NULL; + g_object_unref (de->dict); + de->dict = NULL; } if (de->font != NULL) @@ -117,7 +118,7 @@ enum { PROP_0, PROP_DATA_STORE, - PROP_VAR_STORE, + PROP_DICTIONARY, PROP_VALUE_LABELS, PROP_SPLIT_WINDOW, PROP_UI_MANAGER @@ -132,7 +133,7 @@ psppire_data_editor_refresh_model (PsppireDataEditor *de) FOR_EACH_DATA_SHEET (data_sheet, i, de) psppire_data_sheet_set_data_store (data_sheet, de->data_store); - psppire_var_sheet_set_dictionary (var_sheet, de->var_store->dictionary); + psppire_var_sheet_set_dictionary (var_sheet, de->dict); } static void @@ -167,13 +168,14 @@ psppire_data_editor_set_property (GObject *object, G_CALLBACK (refresh_entry), de); break; - case PROP_VAR_STORE: - if ( de->var_store) g_object_unref (de->var_store); - de->var_store = g_value_get_pointer (value); - g_object_ref (de->var_store); + case PROP_DICTIONARY: + if (de->dict) + g_object_unref (de->dict); + de->dict = g_value_get_pointer (value); + g_object_ref (de->dict); psppire_var_sheet_set_dictionary (PSPPIRE_VAR_SHEET (de->var_sheet), - de->var_store->dictionary); + de->dict); break; case PROP_VALUE_LABELS: FOR_EACH_DATA_SHEET (data_sheet, i, de) @@ -203,8 +205,8 @@ psppire_data_editor_get_property (GObject *object, case PROP_DATA_STORE: g_value_set_pointer (value, de->data_store); break; - case PROP_VAR_STORE: - g_value_set_pointer (value, de->var_store); + case PROP_DICTIONARY: + g_value_set_pointer (value, de->dict); break; case PROP_VALUE_LABELS: g_value_set_boolean (value, @@ -241,7 +243,7 @@ static void psppire_data_editor_class_init (PsppireDataEditorClass *klass) { GParamSpec *data_store_spec ; - GParamSpec *var_store_spec ; + GParamSpec *dict_spec ; GParamSpec *value_labels_spec; GParamSpec *split_window_spec; GParamSpec *ui_manager_spec; @@ -269,15 +271,15 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass) PROP_DATA_STORE, data_store_spec); - var_store_spec = - g_param_spec_pointer ("var-store", - "Variable Store", - "A pointer to the variable store associated with this editor", + dict_spec = + g_param_spec_pointer ("dictionary", + "Dictionary", + "A pointer to the dictionary associated with this editor", G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE ); g_object_class_install_property (object_class, - PROP_VAR_STORE, - var_store_spec); + PROP_DICTIONARY, + dict_spec); value_labels_spec = g_param_spec_boolean ("value-labels", @@ -337,7 +339,7 @@ on_var_sheet_var_double_clicked (PsppireVarSheet *var_sheet, gint dict_index, PSPPIRE_DATA_EDITOR_DATA_VIEW); data_sheet = psppire_data_editor_get_active_data_sheet (de); - psppire_data_sheet_show_variable (data_sheet, dict_index); + psppire_data_sheet_goto_variable (data_sheet, dict_index); return TRUE; } @@ -426,21 +428,21 @@ refresh_entry (PsppireDataEditor *de) } else { - GString *string; - - string = g_string_sized_new (25); - g_string_append_printf (string, - ngettext ("%'d case", "%'d cases", n_cases), - n_cases); - g_string_append_c (string, ' '); - g_string_append_unichar (string, 0xd7); /* U+00D7 MULTIPLICATION SIGN */ - g_string_append_c (string, ' '); - g_string_append_printf (string, - ngettext ("%'d variable", "%'d variables", - n_vars), - n_vars); - ref_cell_text = string->str; - g_string_free (string, FALSE); + struct string s; + + /* The glib string library does not understand the ' printf modifier + on all platforms, but the "struct string" library does (because + Gnulib fixes that problem), so use the latter. */ + ds_init_empty (&s); + ds_put_format (&s, ngettext ("%'d case", "%'d cases", n_cases), + n_cases); + ds_put_byte (&s, ' '); + ds_put_unichar (&s, 0xd7); /* U+00D7 MULTIPLICATION SIGN */ + ds_put_byte (&s, ' '); + ds_put_format (&s, ngettext ("%'d variable", "%'d variables", + n_vars), + n_vars); + ref_cell_text = ds_steal_cstr (&s); } psppire_value_entry_set_variable (PSPPIRE_VALUE_ENTRY (de->datum_entry), @@ -562,13 +564,16 @@ disconnect_data_sheets (PsppireDataEditor *de) } static GtkWidget * -make_data_sheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines) +make_data_sheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines, + gboolean show_value_labels) { PsppSheetSelection *selection; GtkWidget *ds; ds = psppire_data_sheet_new (); pspp_sheet_view_set_grid_lines (PSPP_SHEET_VIEW (ds), grid_lines); + psppire_data_sheet_set_value_labels (PSPPIRE_DATA_SHEET (ds), + show_value_labels); g_signal_connect_swapped (ds, "notify::value-labels", G_CALLBACK (refresh_entry), de); @@ -583,11 +588,12 @@ make_data_sheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines) } static GtkWidget * -make_single_datasheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines) +make_single_datasheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines, + gboolean show_value_labels) { GtkWidget *data_sheet_scroller; - de->data_sheets[0] = make_data_sheet (de, grid_lines); + de->data_sheets[0] = make_data_sheet (de, grid_lines, show_value_labels); de->data_sheets[1] = de->data_sheets[2] = de->data_sheets[3] = NULL; /* Put data sheet in scroller. */ @@ -600,7 +606,8 @@ make_single_datasheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines) } static GtkWidget * -make_split_datasheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines) +make_split_datasheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines, + gboolean show_value_labels) { /* Panes, in the order in which we want to create them. */ enum @@ -623,7 +630,7 @@ make_split_datasheet (PsppireDataEditor *de, GtkTreeViewGridLines grid_lines) GtkPolicyType hpolicy, vpolicy; GtkWidget *scroller; - de->data_sheets[i] = make_data_sheet (de, grid_lines); + de->data_sheets[i] = make_data_sheet (de, grid_lines, show_value_labels); ds[i] = PSPP_SHEET_VIEW (de->data_sheets[i]); if (i == BL) @@ -694,6 +701,7 @@ psppire_data_editor_init (PsppireDataEditor *de) de->font = NULL; de->ui_manager = NULL; + de->old_vbox_widget = NULL; g_object_set (de, "tab-pos", GTK_POS_BOTTOM, NULL); @@ -711,7 +719,7 @@ psppire_data_editor_init (PsppireDataEditor *de) de->split = FALSE; de->datasheet_vbox_widget - = make_single_datasheet (de, GTK_TREE_VIEW_GRID_LINES_BOTH); + = make_single_datasheet (de, GTK_TREE_VIEW_GRID_LINES_BOTH, FALSE); de->vbox = gtk_vbox_new (FALSE, 0); gtk_box_pack_start (GTK_BOX (de->vbox), hbox, FALSE, FALSE, 0); @@ -743,11 +751,11 @@ psppire_data_editor_init (PsppireDataEditor *de) } GtkWidget* -psppire_data_editor_new (PsppireVarStore *var_store, +psppire_data_editor_new (PsppireDict *dict, PsppireDataStore *data_store) { return g_object_new (PSPPIRE_DATA_EDITOR_TYPE, - "var-store", var_store, + "dictionary", dict, "data-store", data_store, NULL); } @@ -803,6 +811,7 @@ void psppire_data_editor_split_window (PsppireDataEditor *de, gboolean split) { GtkTreeViewGridLines grid_lines; + gboolean labels; if (split == de->split) return; @@ -810,14 +819,24 @@ psppire_data_editor_split_window (PsppireDataEditor *de, gboolean split) grid_lines = pspp_sheet_view_get_grid_lines ( PSPP_SHEET_VIEW (de->data_sheets[0])); + labels = psppire_data_sheet_get_value_labels (PSPPIRE_DATA_SHEET ( + de->data_sheets[0])); disconnect_data_sheets (de); - gtk_widget_destroy (de->datasheet_vbox_widget); + if (de->old_vbox_widget) + g_object_unref (de->old_vbox_widget); + de->old_vbox_widget = de->datasheet_vbox_widget; + g_object_ref (de->old_vbox_widget); + /* FIXME: old_vbox_widget needs to be unreffed in dispose. + (currently it seems to provoke an error if I do that. + I don't know why. */ + gtk_container_remove (GTK_CONTAINER (de->vbox), de->datasheet_vbox_widget); if (split) - de->datasheet_vbox_widget = make_split_datasheet (de, grid_lines); + de->datasheet_vbox_widget = make_split_datasheet (de, grid_lines, labels); else - de->datasheet_vbox_widget = make_single_datasheet (de, grid_lines); + de->datasheet_vbox_widget = make_single_datasheet (de, grid_lines, labels); + psppire_data_editor_refresh_model (de); gtk_box_pack_start (GTK_BOX (de->vbox), de->datasheet_vbox_widget, @@ -843,7 +862,7 @@ psppire_data_editor_goto_variable (PsppireDataEditor *de, gint dict_index) { case PSPPIRE_DATA_EDITOR_DATA_VIEW: data_sheet = psppire_data_editor_get_active_data_sheet (de); - psppire_data_sheet_show_variable (data_sheet, dict_index); + psppire_data_sheet_goto_variable (data_sheet, dict_index); break; case PSPPIRE_DATA_EDITOR_VARIABLE_VIEW: