From: John Darrington Date: Fri, 31 Mar 2017 08:03:36 +0000 (+0200) Subject: Enable the deletion of variables from the data sheet X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=403493b1f40ad45303df55ffbc27d08b1d9a8623;p=pspp Enable the deletion of variables from the data sheet --- diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 44cdebc345..188418ebda 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -559,6 +559,17 @@ insert_new_case (PsppireDataEditor *de) gtk_widget_queue_draw (GTK_WIDGET (de)); } +static void +delete_variables (PsppireDataEditor *de) +{ + JmdRange *range = JMD_SHEET(de->data_sheet)->selection; + + psppire_dict_delete_variables (de->dict, range->start_x, + (range->end_x - range->start_x + 1)); + + gtk_widget_queue_draw (GTK_WIDGET (de)); +} + static void insert_new_variable (PsppireDataEditor *de) { @@ -611,10 +622,12 @@ create_column_header_popup_menu (PsppireDataEditor *de) item = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - item = + de->clear_variables_menu_item = gtk_menu_item_new_with_mnemonic (_("Cl_ear Variables")); - gtk_widget_set_sensitive (item, FALSE); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + g_signal_connect_swapped (de->clear_variables_menu_item, "activate", + G_CALLBACK (delete_variables), de); + gtk_widget_set_sensitive (de->clear_variables_menu_item, FALSE); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), de->clear_variables_menu_item); item = gtk_separator_menu_item_new (); gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); @@ -633,16 +646,22 @@ create_column_header_popup_menu (PsppireDataEditor *de) return menu; } - static void -set_clear_cases_sensitivity (JmdSheet *sheet, gpointer selection, gpointer p) +set_menu_items_sensitivity (JmdSheet *sheet, gpointer selection, gpointer p) { JmdRange *range = selection; PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (p); gint width = gtk_tree_model_get_n_columns (sheet->data_model); + gint length = psppire_data_store_get_case_count (de->data_store); + gboolean whole_row_selected = (range->start_x == 0 && range->end_x == width - 1); gtk_widget_set_sensitive (de->clear_cases_menu_item, whole_row_selected); + + + gboolean whole_column_selected = + (range->start_y == 0 && range->end_y == length - 1); + gtk_widget_set_sensitive (de->clear_variables_menu_item, whole_column_selected); } static void @@ -731,7 +750,7 @@ psppire_data_editor_init (PsppireDataEditor *de) G_CALLBACK (show_cases_column_popup), de); g_signal_connect (de->data_sheet, "selection-changed", - G_CALLBACK (set_clear_cases_sensitivity), de); + G_CALLBACK (set_menu_items_sensitivity), de); jmd_sheet_body_set_conversion_func (JMD_SHEET_BODY (JMD_SHEET(de->data_sheet)->selected_body), diff --git a/src/ui/gui/psppire-data-editor.h b/src/ui/gui/psppire-data-editor.h index 56d51aa766..eacf68e28e 100644 --- a/src/ui/gui/psppire-data-editor.h +++ b/src/ui/gui/psppire-data-editor.h @@ -67,6 +67,7 @@ struct _PsppireDataEditor GtkWidget *clear_cases_menu_item; GtkWidget *data_sheet_cases_column_popup; + GtkWidget *clear_variables_menu_item; /* Data sheet tab. */ GtkWidget *vbox; /* Top-level widget in tab. */ diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 630ee4379b..8f2855bb6d 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -99,7 +99,7 @@ __tree_model_get_n_columns (GtkTreeModel *tree_model) { PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model); - return psppire_dict_get_value_cnt (store->dict); + return psppire_dict_get_var_cnt (store->dict); } @@ -327,6 +327,16 @@ psppire_data_store_init (PsppireDataStore *data_store) data_store->stamp = g_random_int (); } + +static void +psppire_data_store_delete_value (PsppireDataStore *store, gint case_index) +{ + g_return_if_fail (store->datasheet); + datasheet_delete_columns (store->datasheet, case_index, 1); + datasheet_insert_column (store->datasheet, NULL, -1, case_index); +} + + /* A callback which occurs after a variable has been deleted. */ @@ -337,10 +347,7 @@ delete_variable_callback (GObject *obj, const struct variable *var UNUSED, { PsppireDataStore *store = PSPPIRE_DATA_STORE (data); - g_return_if_fail (store->datasheet); - - datasheet_delete_columns (store->datasheet, case_index, 1); - datasheet_insert_column (store->datasheet, NULL, -1, case_index); + psppire_data_store_delete_value (store, case_index); } struct resize_datum_aux