From: John Darrington Date: Thu, 28 Dec 2006 04:21:07 +0000 (+0000) Subject: Re-added Data->Insert_Variable menu item X-Git-Tag: v0.6.0~599 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7579fa32442ac9b623043f8cd995d9b6aa550e51;p=pspp-builds.git Re-added Data->Insert_Variable menu item --- diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 1d15fe8b..a7478596 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -400,8 +400,12 @@ static void set_var_dict_index (struct variable *v, int dict_index) { struct vardict_info vdi = *var_get_vardict (v); + struct dictionary *d = vdi.dict; vdi.dict_index = dict_index; var_set_vardict (v, &vdi); + + if ( d->callbacks && d->callbacks->var_changed ) + d->callbacks->var_changed (d, dict_index, d->cb_data); } /* Sets the case_index in V's vardict to DICT_INDEX. */ @@ -537,20 +541,20 @@ dict_reorder_var (struct dictionary *d, struct variable *v, size_t new_index) listed in ORDER in that order at the beginning of D. The other variables in D, if any, retain their relative positions. */ -void +void dict_reorder_vars (struct dictionary *d, - struct variable *const *order, size_t count) + struct variable *const *order, size_t count) { struct variable **new_var; size_t i; - + assert (d != NULL); assert (count == 0 || order != NULL); assert (count <= d->var_cnt); new_var = xnmalloc (d->var_cnt, sizeof *new_var); memcpy (new_var, order, count * sizeof *new_var); - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { size_t index = var_get_dict_index (order[i]); assert (d->var[index] == order[i]); diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index 76612b5e..10f57885 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -41,6 +41,9 @@ #include "psppire-var-store.h" +static void insert_variable (GtkCheckMenuItem *m, gpointer data); + + /* Switch between the VAR SHEET and the DATA SHEET */ enum {PAGE_DATA_SHEET = 0, PAGE_VAR_SHEET}; @@ -145,6 +148,11 @@ new_data_editor (void) de); + g_signal_connect (get_widget_assert (de->xml,"data_insert-variable"), + "activate", + G_CALLBACK (insert_variable), + de); + g_signal_connect (get_widget_assert (de->xml,"help_about"), "activate", @@ -297,7 +305,7 @@ new_data_window (GtkMenuItem *menuitem, gpointer parent) static void select_sheet (struct data_editor *de, guint page_num) { - GtkWidget *insert_variable = get_widget_assert (de->xml, "insert-variable"); + GtkWidget *insert_variable = get_widget_assert (de->xml, "data_insert-variable"); GtkWidget *insert_cases = get_widget_assert (de->xml, "insert-cases"); GtkWidget *view_data = get_widget_assert (de->xml, "view_data"); @@ -314,8 +322,9 @@ select_sheet (struct data_editor *de, guint page_num) case PAGE_DATA_SHEET: gtk_widget_show (view_variables); gtk_widget_hide (view_data); - gtk_widget_set_sensitive (insert_variable, FALSE); +#if 0 gtk_widget_set_sensitive (insert_cases, TRUE); +#endif break; default: g_assert_not_reached (); @@ -579,3 +588,49 @@ on_clear_activate (GtkMenuItem *menuitem, gpointer data) g_assert_not_reached (); } } + + +/* Insert a new variable before the current row in the variable sheet, + or before the current column in the data sheet, whichever is selected */ +static void +insert_variable (GtkCheckMenuItem *m, gpointer data) +{ + struct data_editor *de = data; + gint posn; + + GtkWidget *notebook = get_widget_assert (de->xml, "notebook"); + + GtkSheet *var_sheet = + GTK_SHEET (get_widget_assert (de->xml, "variable_sheet")); + + + + PsppireVarStore *vs = PSPPIRE_VAR_STORE + (gtk_sheet_get_model (var_sheet) ); + + + switch ( gtk_notebook_get_current_page ( GTK_NOTEBOOK (notebook)) ) + { + case PAGE_VAR_SHEET: + posn = var_sheet->active_cell.row; + break; + case PAGE_DATA_SHEET: + { + GtkSheet *data_sheet = + GTK_SHEET (get_widget_assert (de->xml, "data_sheet")); + + if ( data_sheet->state == GTK_SHEET_COLUMN_SELECTED ) + posn = data_sheet->range.col0; + else + posn = data_sheet->active_cell.col; + } + break; + default: + g_assert_not_reached (); + } + + psppire_dict_insert_variable (vs->dict, posn, NULL); + +} + + diff --git a/src/ui/gui/data-editor.glade b/src/ui/gui/data-editor.glade index 419a9c60..f34d24a9 100644 --- a/src/ui/gui/data-editor.glade +++ b/src/ui/gui/data-editor.glade @@ -207,7 +207,7 @@ True - + True gtk-find 1 @@ -308,17 +308,16 @@ - + True - False _Data True - + - + True False Insert Variable @@ -330,6 +329,7 @@ True + False Insert Cases True @@ -339,12 +339,13 @@ True + False Go To Case True - + True gtk-jump-to 1 @@ -360,12 +361,14 @@ True + False True + False Sort Cases True @@ -411,6 +414,7 @@ True + False diff --git a/src/ui/gui/data-sheet.c b/src/ui/gui/data-sheet.c index 0998de05..0fdba116 100644 --- a/src/ui/gui/data-sheet.c +++ b/src/ui/gui/data-sheet.c @@ -156,6 +156,8 @@ font_change_callback (GObject *obj, gpointer data) ds->width_of_m = calc_m_width (sheet, ds->font_desc); } + + GtkWidget* psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2, gint int1, gint int2) @@ -180,7 +182,6 @@ psppire_data_sheet_create (gchar *widget_name, gchar *string1, gchar *string2, gtk_sheet_set_active_cell (GTK_SHEET (sheet), -1, -1); - gtk_sheet_set_model (GTK_SHEET (sheet), G_SHEET_MODEL (the_data_store)); gtk_widget_show (sheet); diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index d7534858..531b5b92 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -286,6 +286,25 @@ delete_variables_callback (GObject *obj, gint var_num, gint n_vars, gpointer dat var_num, -1); } + +static void +variable_changed_callback (GObject *obj, gint var_num, gpointer data) +{ + PsppireDataStore *store; + + g_return_if_fail (data); + + store = PSPPIRE_DATA_STORE (data); + + g_sheet_column_columns_changed (G_SHEET_COLUMN (store), + var_num, 1); + + + g_sheet_model_range_changed (G_SHEET_MODEL (store), + -1, var_num, + -1, var_num); +} + static void insert_variable_callback (GObject *obj, gint var_num, gpointer data) { @@ -398,6 +417,11 @@ psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *di G_CALLBACK (delete_variables_callback), data_store); + g_signal_connect (dict, "variable-changed", + G_CALLBACK (variable_changed_callback), + data_store); + + g_signal_connect (dict, "dict-size-changed", G_CALLBACK (dict_size_change_callback), data_store); diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 15a3deff..9637e3cf 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -243,10 +243,10 @@ void psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name) { struct variable *var ; + g_return_if_fail (idx >= 0); g_return_if_fail (d); g_return_if_fail (G_IS_PSPPIRE_DICT (d)); - if ( ! name ) name = auto_generate_var_name (d); diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index b84b0c6e..9ce4f38f 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -263,6 +263,7 @@ static void var_change_callback (GtkWidget *w, gint n, gpointer data) { GSheetModel *model = G_SHEET_MODEL (data); + g_sheet_model_range_changed (model, n, 0, n, n_COLS); }