From: John Darrington Date: Tue, 10 Jul 2007 07:40:02 +0000 (+0000) Subject: Enabled deletion of cases from the datasheet. X-Git-Tag: v0.6.0~395 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b810b32ac59e1dcba90b8d4a70d626c4e249bad6;p=pspp-builds.git Enabled deletion of cases from the datasheet. --- diff --git a/lib/gtksheet/gtksheet.c b/lib/gtksheet/gtksheet.c index 73c245c3..082188bc 100644 --- a/lib/gtksheet/gtksheet.c +++ b/lib/gtksheet/gtksheet.c @@ -2215,6 +2215,8 @@ gtk_sheet_select_column (GtkSheet * sheet, gint column) gtk_sheet_real_select_range (sheet, NULL); } + + void gtk_sheet_clip_range (GtkSheet *sheet, const GtkSheetRange *range) { @@ -4707,6 +4709,16 @@ gtk_sheet_real_select_range (GtkSheet * sheet, gtk_signal_emit (GTK_OBJECT (sheet), sheet_signals[SELECT_RANGE], &sheet->range); } + +void +gtk_sheet_get_selected_range (GtkSheet *sheet, + GtkSheetRange *range) +{ + g_return_if_fail (sheet != NULL); + *range = sheet->range; +} + + void gtk_sheet_select_range (GtkSheet * sheet, const GtkSheetRange *range) { diff --git a/lib/gtksheet/gtksheet.h b/lib/gtksheet/gtksheet.h index 9b852530..86c6c2df 100644 --- a/lib/gtksheet/gtksheet.h +++ b/lib/gtksheet/gtksheet.h @@ -353,6 +353,11 @@ gtk_sheet_get_rows_count (GtkSheet *sheet); void gtk_sheet_get_visible_range (GtkSheet *sheet, GtkSheetRange *range); + +void +gtk_sheet_get_selected_range (GtkSheet *sheet, + GtkSheetRange *range); + void gtk_sheet_set_selection_mode (GtkSheet *sheet, gint mode); diff --git a/src/ui/gui/data-editor.c b/src/ui/gui/data-editor.c index d75ea5c9..d6cf50b3 100644 --- a/src/ui/gui/data-editor.c +++ b/src/ui/gui/data-editor.c @@ -494,17 +494,27 @@ new_data_editor (void) G_CALLBACK (reference_manual), e->window); - g_signal_connect (get_widget_assert (de->xml,"data_sheet"), + g_signal_connect (data_sheet, "double-click-column", G_CALLBACK (click2column), de); - g_signal_connect (get_widget_assert (de->xml, "variable_sheet"), + g_signal_connect (data_sheet, + "select-row", + GTK_SIGNAL_FUNC (enable_edit_clear), + de); + + g_signal_connect (data_sheet, + "activate", + GTK_SIGNAL_FUNC (disable_edit_clear), + de); + + g_signal_connect (var_sheet, "double-click-row", GTK_SIGNAL_FUNC (click2row), de); - g_signal_connect (get_widget_assert (de->xml, "variable_sheet"), + g_signal_connect (var_sheet, "select-row", GTK_SIGNAL_FUNC (enable_edit_clear), de); @@ -844,42 +854,67 @@ file_quit (GtkCheckMenuItem *menuitem, gpointer data) } - /* Callback for when the Clear item in the edit menu is activated */ static void on_clear_activate (GtkMenuItem *menuitem, gpointer data) { struct data_editor *de = data; + GtkSheet *sheet = NULL; + GtkSheetRange range ; + GtkNotebook *notebook = GTK_NOTEBOOK (get_widget_assert (de->xml, "notebook")); - switch ( gtk_notebook_get_current_page (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 ); + + + gtk_sheet_get_selected_range (sheet, &range); + + switch ( page ) { case PAGE_VAR_SHEET: { - GtkSheet *var_sheet = - GTK_SHEET (get_widget_assert (de->xml, "variable_sheet")); - PsppireVarStore *vs = PSPPIRE_VAR_STORE - (gtk_sheet_get_model (var_sheet) ); + (gtk_sheet_get_model (sheet) ); - /* This shouldn't be able to happen, because the menuitem - should be disabled */ - g_return_if_fail (var_sheet->state == GTK_SHEET_ROW_SELECTED ); psppire_dict_delete_variables (vs->dict, - var_sheet->range.row0, + range.row0, 1 + - var_sheet->range.rowi - - var_sheet->range.row0 ); + range.rowi - + range.row0 ); + } + 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 ); + + + psppire_data_store_delete_cases (data_store, range.row0, + 1 + range.rowi - range.row0); } break; - case PAGE_DATA_SHEET: - break; - default: - g_assert_not_reached (); + default: + g_assert_not_reached (); } + + gtk_sheet_unselect_range (sheet); } static void diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index c223ccf2..40c3843f 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -455,6 +455,15 @@ psppire_data_store_finalize (GObject *object) (* parent_class->finalize) (object); } +gboolean +psppire_data_store_delete_cases (PsppireDataStore *ds, + casenumber first, casenumber count) +{ + g_return_val_if_fail (ds, FALSE); + + return psppire_case_file_delete_cases (ds->case_file, count, first); +} + /* Insert a blank case before POSN */ diff --git a/src/ui/gui/psppire-data-store.h b/src/ui/gui/psppire-data-store.h index d305ad84..88ae85be 100644 --- a/src/ui/gui/psppire-data-store.h +++ b/src/ui/gui/psppire-data-store.h @@ -99,6 +99,10 @@ void psppire_data_store_clear (PsppireDataStore *data_store); gboolean psppire_data_store_insert_new_case (PsppireDataStore *ds, casenumber posn); + +gboolean psppire_data_store_delete_cases (PsppireDataStore *ds, casenumber first, casenumber count); + + struct casereader * psppire_data_store_get_reader (PsppireDataStore *ds); gchar * psppire_data_store_get_string (PsppireDataStore *ds,