From 338a3ecb26f25819c1cb1667a39ab40065f72fdb Mon Sep 17 00:00:00 2001 From: John Darrington Date: Wed, 18 Jul 2007 04:27:29 +0000 Subject: [PATCH] Enabled deleting of variables from the datasheet --- lib/gtksheet/gtksheet.c | 4 + src/ui/gui/data-editor.c | 153 +++++++++++++++++++-------------- src/ui/gui/data-editor.glade | 12 ++- src/ui/gui/data-editor.h | 3 + src/ui/gui/psppire-case-file.c | 2 +- 5 files changed, 107 insertions(+), 67 deletions(-) diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index 00978dd0..72115b89 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -4754,6 +4754,7 @@ gtk_sheet_unselect_range (GtkSheet * sheet) { gtk_sheet_real_unselect_range (sheet, NULL); sheet->state = GTK_STATE_NORMAL; + gtk_sheet_activate_cell (sheet, sheet->active_cell.row, sheet->active_cell.col); } @@ -4772,6 +4773,9 @@ gtk_sheet_real_unselect_range (GtkSheet * sheet, if (range->row0 < 0 || range->rowi < 0) return; if (range->col0 < 0 || range->coli < 0) return; + g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_COLUMN], 0, -1); + g_signal_emit (G_OBJECT (sheet), sheet_signals[SELECT_ROW], 0, -1); + if (gtk_sheet_range_isvisible (sheet, *range)) gtk_sheet_draw_backing_pixmap (sheet, *range); diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index 36150579..2e44c67c 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -58,9 +58,9 @@ static gint update_data_ref_entry (const GtkSheet *sheet, static void register_data_editor_actions (struct data_editor *de); static void insert_variable (GtkAction *, gpointer data); - static void insert_case (GtkAction *a, gpointer data); - +static void delete_cases (GtkAction *a, gpointer data); +static void delete_variables (GtkAction *a, gpointer data); /* Switch between the VAR SHEET and the DATA SHEET */ @@ -99,30 +99,24 @@ static void value_labels_toggled (GtkToggleToolButton *, gpointer); static void file_quit (GtkCheckMenuItem *, gpointer ); -static void on_clear_activate (GtkMenuItem *, gpointer); - static void -enable_edit_clear (GtkWidget *w, gint row, gpointer data) +enable_delete_cases (GtkWidget *w, gint var, gpointer data) { struct data_editor *de = data; - GtkWidget *menuitem = get_widget_assert (de->xml, "edit_clear"); - - gtk_widget_set_sensitive (menuitem, TRUE); + gtk_action_set_visible (de->delete_cases, var != -1); } -static gboolean -disable_edit_clear (GtkWidget *w, gint x, gint y, gpointer data) + +static void +enable_delete_variables (GtkWidget *w, gint var, gpointer data) { struct data_editor *de = data; - GtkWidget *menuitem = get_widget_assert (de->xml, "edit_clear"); - - gtk_widget_set_sensitive (menuitem, FALSE); - - return FALSE; + gtk_action_set_visible (de->delete_variables, var != -1); } + static void open_data_file (const gchar *, struct data_editor *); @@ -241,6 +235,37 @@ new_data_editor (void) register_data_editor_actions (de); + + de->delete_cases = + gtk_action_new ("clear-cases", + _("Clear"), + _("Delete the cases at the selected position(s)"), + "pspp-clear-cases"); + + g_signal_connect (de->delete_cases, "activate", + G_CALLBACK (delete_cases), de); + + gtk_action_connect_proxy (de->delete_cases, + get_widget_assert (de->xml, "edit_clear-cases")); + + + gtk_action_set_visible (de->delete_cases, FALSE); + + de->delete_variables = + gtk_action_new ("clear-variables", + _("Clear"), + _("Delete the variables at the selected position(s)"), + "pspp-clear-variables"); + + g_signal_connect (de->delete_variables, "activate", + G_CALLBACK (delete_variables), de); + + gtk_action_connect_proxy (de->delete_variables, + get_widget_assert (de->xml, "edit_clear-variables") + ); + + gtk_action_set_visible (de->delete_variables, FALSE); + de->insert_variable = gtk_action_new ("insert-variable", _("Insert Variable"), @@ -447,14 +472,6 @@ new_data_editor (void) G_CALLBACK (gtk_action_activate), de->action_data_save_as); - - g_signal_connect (get_widget_assert (de->xml,"edit_clear"), - "activate", - G_CALLBACK (on_clear_activate), - de); - - - gtk_action_connect_proxy (de->invoke_weight_cases_dialog, get_widget_assert (de->xml, "data_weight-cases") ); @@ -500,31 +517,26 @@ new_data_editor (void) de); g_signal_connect (data_sheet, - "select-row", - GTK_SIGNAL_FUNC (enable_edit_clear), + "select-column", + G_CALLBACK (enable_delete_variables), de); g_signal_connect (data_sheet, - "activate", - GTK_SIGNAL_FUNC (disable_edit_clear), + "select-row", + G_CALLBACK (enable_delete_cases), de); + g_signal_connect (var_sheet, "double-click-row", GTK_SIGNAL_FUNC (click2row), de); - g_signal_connect (var_sheet, + g_signal_connect_after (var_sheet, "select-row", - GTK_SIGNAL_FUNC (enable_edit_clear), - de); - - g_signal_connect (get_widget_assert (de->xml, "variable_sheet"), - "activate", - GTK_SIGNAL_FUNC (disable_edit_clear), + G_CALLBACK (enable_delete_variables), de); - g_signal_connect (get_widget_assert (de->xml, "notebook"), "switch-page", G_CALLBACK (data_var_select), de); @@ -853,28 +865,48 @@ file_quit (GtkCheckMenuItem *menuitem, gpointer data) gtk_main_quit (); } - -/* Callback for when the Clear item in the edit menu is activated */ static void -on_clear_activate (GtkMenuItem *menuitem, gpointer data) +delete_cases (GtkAction *action, gpointer data) { struct data_editor *de = data; + GtkSheet *data_sheet = + GTK_SHEET (get_widget_assert (de->xml, "data_sheet")); + + GtkSheetRange range; + + PsppireDataStore *data_store = PSPPIRE_DATA_STORE + (gtk_sheet_get_model (data_sheet) ); + + + /* This shouldn't be able to happen, because the action + should be disabled */ + g_return_if_fail (gtk_sheet_get_state (data_sheet) + == GTK_SHEET_ROW_SELECTED ); + + gtk_sheet_get_selected_range (data_sheet, &range); + + gtk_sheet_unselect_range (data_sheet); - GtkSheet *sheet = NULL; - GtkSheetRange range ; + psppire_data_store_delete_cases (data_store, range.row0, + 1 + range.rowi - range.row0); + +} + +static void +delete_variables (GtkAction *a, gpointer data) +{ + struct data_editor *de = data; + GtkSheetRange range; GtkNotebook *notebook = GTK_NOTEBOOK (get_widget_assert (de->xml, "notebook")); const gint page = gtk_notebook_get_current_page (notebook); - sheet = GTK_SHEET - (get_widget_assert (de->xml, - (page == PAGE_VAR_SHEET) ? "variable_sheet" : "data_sheet")); - - /* This shouldn't be able to happen, because the menuitem - should be disabled */ - g_return_if_fail (gtk_sheet_get_state (sheet) == GTK_SHEET_ROW_SELECTED ); + GtkSheet *sheet = GTK_SHEET (get_widget_assert (de->xml, + (page == PAGE_VAR_SHEET) ? + "variable_sheet" : + "data_sheet")); gtk_sheet_get_selected_range (sheet, &range); @@ -883,9 +915,8 @@ on_clear_activate (GtkMenuItem *menuitem, gpointer data) { case PAGE_VAR_SHEET: { - PsppireVarStore *vs = PSPPIRE_VAR_STORE - (gtk_sheet_get_model (sheet) ); - + PsppireVarStore *vs = + PSPPIRE_VAR_STORE (gtk_sheet_get_model (sheet)); psppire_dict_delete_variables (vs->dict, range.row0, @@ -896,23 +927,17 @@ on_clear_activate (GtkMenuItem *menuitem, gpointer data) break; case PAGE_DATA_SHEET: { - PsppireDataStore *data_store = PSPPIRE_DATA_STORE - (gtk_sheet_get_model (sheet) ); - - - /* This shouldn't be able to happen, because the menuitem - should be disabled */ - g_return_if_fail (gtk_sheet_get_state (sheet) - == GTK_SHEET_ROW_SELECTED ); - + PsppireDataStore *ds = + PSPPIRE_DATA_STORE (gtk_sheet_get_model (sheet)); - psppire_data_store_delete_cases (data_store, range.row0, - 1 + range.rowi - range.row0); + psppire_dict_delete_variables (ds->dict, + range.col0, + 1 + + range.coli - + range.col0 ); } break; - default: - g_assert_not_reached (); - } + }; gtk_sheet_unselect_range (sheet); } diff --git a/src/ui/gui/data-editor.glade b/src/ui/gui/data-editor.glade index 8ca8aab4..c34f4d54 100644 --- a/src/ui/gui/data-editor.glade +++ b/src/ui/gui/data-editor.glade @@ -169,10 +169,18 @@ - + True False - Cl_ear + Cl_ear Variables + True + + + + + True + False + _Clear Cases True diff --git a/src/ui/gui/data-editor.h b/src/ui/gui/data-editor.h index 27dff55e..582ae227 100644 --- a/src/ui/gui/data-editor.h +++ b/src/ui/gui/data-editor.h @@ -43,6 +43,9 @@ struct data_editor GtkAction *insert_variable; GtkAction *insert_case; + GtkAction *delete_variables; + GtkAction *delete_cases; + GladeXML *xml; gboolean save_as_portable; diff --git a/src/ui/gui/psppire-case-file.c b/src/ui/gui/psppire-case-file.c index 455ac2b7..878d7fa0 100644 --- a/src/ui/gui/psppire-case-file.c +++ b/src/ui/gui/psppire-case-file.c @@ -171,7 +171,7 @@ psppire_case_file_delete_cases (PsppireCaseFile *cf, casenumber n_cases, casenum datasheet_delete_rows (cf->datasheet, first, n_cases); - g_signal_emit (cf, signals [CASES_DELETED], 0, n_cases, first); + g_signal_emit (cf, signals [CASES_DELETED], 0, first, n_cases); return TRUE; } -- 2.30.2