From 26acd16acda48dd3f8f4702e28d605f606bfa130 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Thu, 30 Mar 2017 13:36:03 +0200 Subject: [PATCH] Use the "items-changed" signal instead of "changed" --- src/ui/gui/psppire-data-editor.c | 13 +++++++++++++ src/ui/gui/psppire-data-store.c | 25 ++++++------------------- src/ui/gui/psppire-data-window.c | 5 +---- src/ui/gui/psppire-dict.c | 29 +++++++---------------------- 4 files changed, 27 insertions(+), 45 deletions(-) diff --git a/src/ui/gui/psppire-data-editor.c b/src/ui/gui/psppire-data-editor.c index 00ce1a0170..2af53171cd 100644 --- a/src/ui/gui/psppire-data-editor.c +++ b/src/ui/gui/psppire-data-editor.c @@ -537,6 +537,17 @@ gchar *myconvfunc (GtkTreeModel *m, gint col, gint row, const GValue *v); void myreversefunc (GtkTreeModel *model, gint col, gint row, const gchar *in, GValue *out); +static void +delete_cases (PsppireDataEditor *de) +{ + JmdRange *range = JMD_SHEET(de->data_sheet)->selection; + + psppire_data_store_delete_cases (de->data_store, range->start_y, + range->end_y - range->start_y + 1); + + gtk_widget_queue_draw (GTK_WIDGET (de)); +} + static void insert_new_case (PsppireDataEditor *de) { @@ -564,6 +575,8 @@ create_row_header_popup_menu (PsppireDataEditor *de) de->clear_cases_menu_item = gtk_menu_item_new_with_mnemonic (_("Cl_ear Cases")); gtk_widget_set_sensitive (de->clear_cases_menu_item, FALSE); gtk_menu_shell_append (GTK_MENU_SHELL (menu), de->clear_cases_menu_item); + g_signal_connect_swapped (de->clear_cases_menu_item, "activate", + G_CALLBACK (delete_cases), de); gtk_widget_show_all (menu); return menu; diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index a2a7204724..ad67844fba 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -69,7 +69,6 @@ static GObjectClass *parent_class = NULL; enum { ITEMS_CHANGED, - CASES_DELETED, CASE_CHANGED, n_SIGNALS }; @@ -275,7 +274,7 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) object_class->dispose = psppire_data_store_dispose; signals [ITEMS_CHANGED] = - g_signal_new ("changed", + g_signal_new ("items-changed", G_TYPE_FROM_CLASS (class), G_SIGNAL_RUN_FIRST, 0, @@ -283,9 +282,9 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) psppire_marshal_VOID__UINT_UINT_UINT, G_TYPE_NONE, 3, - G_TYPE_UINT, - G_TYPE_UINT, - G_TYPE_UINT); + G_TYPE_UINT, /* Index of the start of the change */ + G_TYPE_UINT, /* The number of items deleted */ + G_TYPE_UINT); /* The number of items inserted */ signals [CASE_CHANGED] = g_signal_new ("case-changed", @@ -297,18 +296,6 @@ psppire_data_store_class_init (PsppireDataStoreClass *class) G_TYPE_NONE, 1, G_TYPE_INT); - - signals [CASES_DELETED] = - g_signal_new ("cases-deleted", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - psppire_marshal_VOID__INT_INT, - G_TYPE_NONE, - 2, - G_TYPE_INT, - G_TYPE_INT); } @@ -681,7 +668,7 @@ psppire_data_store_clear (PsppireDataStore *ds) psppire_dict_clear (ds->dict); - g_signal_emit (ds, signals [CASES_DELETED], 0, 0, -1); + g_signal_emit (ds, signals [ITEMS_CHANGED], 0, 0, -1, 0); } @@ -734,7 +721,7 @@ psppire_data_store_delete_cases (PsppireDataStore *ds, casenumber first, datasheet_delete_rows (ds->datasheet, first, n_cases); - g_signal_emit (ds, signals [CASES_DELETED], 0, first, n_cases); + g_signal_emit (ds, signals[ITEMS_CHANGED], 0, first, n_cases, 0); return TRUE; } diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 391cd4e3d3..b31973a217 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -1491,9 +1491,6 @@ psppire_data_window_finish_init (PsppireDataWindow *de, g_signal_connect_swapped (de->data_store, "case-changed", G_CALLBACK (set_unsaved), de); - g_signal_connect_swapped (de->data_store, "cases-deleted", - G_CALLBACK (set_unsaved), de); - dataset_set_callbacks (de->dataset, &cbs, de); connect_help (de->builder); @@ -1517,7 +1514,7 @@ psppire_data_window_finish_init (PsppireDataWindow *de, G_CALLBACK (on_split_change), de); - g_signal_connect_swapped (de->dict, "changed", + g_signal_connect_swapped (de->dict, "items-changed", G_CALLBACK (enable_save), de); g_signal_connect_swapped (de->dict, "variable-inserted", G_CALLBACK (enable_save), de); diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 0a0c3ae0b4..c8c8b3eb45 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -1,5 +1,6 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2004, 2006, 2007, 2009, 2010, 2011, 2012, 2016 Free Software Foundation + Copyright (C) 2004, 2006, 2007, 2009, 2010, 2011, 2012, + 2016, 2017 Free Software Foundation This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -49,8 +50,6 @@ GType role_enum_type; enum { - ITEMS_CHANGED, - VARIABLE_CHANGED, VARIABLE_INSERTED, VARIABLE_DELETED, @@ -182,20 +181,6 @@ psppire_dict_class_init (PsppireDictClass *class) object_class->dispose = psppire_dict_dispose; - signals [ITEMS_CHANGED] = - g_signal_new ("changed", - G_TYPE_FROM_CLASS (class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, - psppire_marshal_VOID__UINT_UINT_UINT, - G_TYPE_NONE, - 3, - G_TYPE_UINT, - G_TYPE_UINT, - G_TYPE_UINT); - - signals [VARIABLE_CHANGED] = g_signal_new ("variable-changed", G_TYPE_FROM_CLASS (class), @@ -293,7 +278,7 @@ addcb (struct dictionary *d, int idx, void *pd) if ( ! dict->disable_insert_signal) { g_signal_emit (dict, signals [VARIABLE_INSERTED], 0, idx); - g_signal_emit (dict, signals [ITEMS_CHANGED], 0, idx, 1, 1); + g_signal_emit_by_name (dict, "items-changed", idx, 1, 1); } } @@ -303,14 +288,14 @@ delcb (struct dictionary *d, const struct variable *var, { g_signal_emit (pd, signals [VARIABLE_DELETED], 0, var, dict_idx, case_idx); - g_signal_emit (pd, signals [ITEMS_CHANGED], 0, dict_idx, 1, 0); + g_signal_emit_by_name (pd, "items-changed", dict_idx, 1, 0); } static void mutcb (struct dictionary *d, int idx, unsigned int what, const struct variable *oldvar, void *pd) { g_signal_emit (pd, signals [VARIABLE_CHANGED], 0, idx, what, oldvar); - g_signal_emit (pd, signals [ITEMS_CHANGED], 0, idx, 1, 1); + g_signal_emit_by_name (pd, "items-changed", idx, 1, 1); } static void @@ -385,7 +370,7 @@ psppire_dict_replace_dictionary (PsppireDict *dict, struct dictionary *d) dict_set_callbacks (dict->dict, &gui_callbacks, dict); - g_signal_emit (dict, signals [ITEMS_CHANGED], 0, 0, old_n, new_n); + g_signal_emit_by_name (dict, "items-changed", 0, old_n, new_n); } @@ -449,7 +434,7 @@ psppire_dict_insert_variable (PsppireDict *d, gint idx, const gchar *name) d->disable_insert_signal = FALSE; g_signal_emit (d, signals[VARIABLE_INSERTED], 0, idx); - g_signal_emit (d, signals [ITEMS_CHANGED], 0, idx, 0, 1); + g_signal_emit_by_name (d, "items-changed", idx, 0, 1); return var; } -- 2.30.2