Allow dictionary 'var_deleted' callback to examine the deleted var.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 20 Mar 2012 06:00:05 +0000 (23:00 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 17 Apr 2012 02:22:16 +0000 (19:22 -0700)
The dictionary 'var_deleted' callback is the last chance to look at
a variable as it is getting deleted from a dictionary.  For some of
the information in the variable, it legitimately doesn't make any
sense to get it from the variable itself at this point, e.g. the
index into the dictionary or the case, since it no longer is in
a dictionary.  But for most of it, it's reasonable to get it from
the variable itself, but the callback doesn't provide any way to
do that, because it doesn't pass in the variable, just a dictionary
index that is no longer correct.

This commit changes the 'var_deleted' interface to pass in the
variable plus the information that can no longer be obtained from
the variable itself.  An upcoming change to the GUI will make use
of this.

This commit also adapts all the existing users to the new interface.

src/data/dictionary.c
src/data/dictionary.h
src/ui/gui/marshaller-list
src/ui/gui/psppire-data-editor.c
src/ui/gui/psppire-data-store.c
src/ui/gui/psppire-dict.c
src/ui/gui/psppire-var-store.c

index b64d84a2ca58622eb06c99ede072579b71d476ed..b9efb2b1f74cde7e72f58aa41cce7a0503dfa488 100644 (file)
@@ -600,7 +600,6 @@ dict_delete_var (struct dictionary *d, struct variable *v)
 {
   int dict_index = var_get_dict_index (v);
   const int case_index = var_get_case_index (v);
-  const int width = var_get_width (v);
 
   assert (dict_contains_var (d, v));
 
@@ -628,13 +627,14 @@ dict_delete_var (struct dictionary *d, struct variable *v)
 
   /* Free memory. */
   var_clear_vardict (v);
-  var_destroy (v);
 
   if ( d->changed ) d->changed (d, d->changed_data);
 
   invalidate_proto (d);
   if (d->callbacks &&  d->callbacks->var_deleted )
-    d->callbacks->var_deleted (d, dict_index, case_index, width, d->cb_data);
+    d->callbacks->var_deleted (d, v, dict_index, case_index, d->cb_data);
+
+  var_destroy (v);
 }
 
 /* Deletes the COUNT variables listed in VARS from D.  This is
index 2a196950a97a3d6bae5aa86bb3dab83733576df8..d50921201bb8e3d366198997ed223f9134324703 100644 (file)
@@ -177,7 +177,8 @@ void dict_destroy_internal_var (struct variable *);
 struct dict_callbacks
  {
   void (*var_added) (struct dictionary *, int, void *);
-  void (*var_deleted) (struct dictionary *, int, int, int, void *);
+  void (*var_deleted) (struct dictionary *, const struct variable *,
+                       int dict_index, int case_index, void *);
   void (*var_changed) (struct dictionary *, int, void *);
   void (*var_resized) (struct dictionary *, int, int, void *);
   void (*weight_changed) (struct dictionary *, int, void *);
index cb7c9113afe67df6cb514b702a2db820f5231603..f21c407acf9aae9c504de2b5c70b1f37fd71477e 100644 (file)
@@ -7,7 +7,7 @@ BOOLEAN:VOID
 VOID:BOXED,BOXED
 VOID:INT,INT
 VOID:INT,LONG
-VOID:INT,INT,INT
 VOID:INT,INT,INT,INT
 VOID:INT,POINTER
 VOID:OBJECT,OBJECT
+VOID:POINTER,INT,INT
index 6f1c0afd5cbf2566918ebed8cc358dc2767c5bf8..16b1393df3977593f2e94c226ead0fedd478c6e5 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
 
    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
@@ -337,17 +337,18 @@ insert_variable_callback (PsppireDict *dict, gint x, gpointer data)
 
 
 static void
-delete_variable_callback (PsppireDict *dict, gint posn,
-                         gint x UNUSED, gint y UNUSED, gpointer data)
+delete_variable_callback (PsppireDict *dict,
+                          const struct variable *var UNUSED,
+                          gint dict_idx, gint case_idx UNUSED, gpointer data)
 {
   PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (data);
 
   PsppireAxis *var_vaxis;
   g_object_get (de->var_sheet, "vertical-axis", &var_vaxis, NULL);
 
-  psppire_axis_delete (var_vaxis, posn, 1);
+  psppire_axis_delete (var_vaxis, dict_idx, 1);
 
-  psppire_axis_delete (de->haxis, posn, 1);
+  psppire_axis_delete (de->haxis, dict_idx, 1);
 }
 
 
index 43e101e75336b40f6f09e1c5a0184d7f97517b30..fb89dfa20e928c68557a82186b63680e5601b84b 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2006, 2008, 2009, 2010  Free Software Foundation
+   Copyright (C) 2006, 2008, 2009, 2010, 2012  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
@@ -301,8 +301,8 @@ psppire_data_store_sheet_model_init (PsppireSheetModelIface *iface)
    A callback which occurs after a variable has been deleted.
  */
 static void
-delete_variable_callback (GObject *obj, gint dict_index,
-                         gint case_index, gint width,
+delete_variable_callback (GObject *obj, const struct variable *var UNUSED,
+                          gint dict_index, gint case_index,
                          gpointer data)
 {
   PsppireDataStore *store  = PSPPIRE_DATA_STORE (data);
index e731b185eaa6e8f6d702788b0393dc1f9b0f3fd8..ea67c85ce5c130f122685d5a29574c9a7d1583d6 100644 (file)
@@ -159,10 +159,10 @@ psppire_dict_class_init (PsppireDictClass *class)
                  G_SIGNAL_RUN_FIRST,
                  0,
                  NULL, NULL,
-                 psppire_marshal_VOID__INT_INT_INT,
+                 psppire_marshal_VOID__POINTER_INT_INT,
                  G_TYPE_NONE,
                  3,
-                 G_TYPE_INT,
+                 G_TYPE_POINTER,
                  G_TYPE_INT,
                  G_TYPE_INT);
 
@@ -248,10 +248,11 @@ addcb (struct dictionary *d, int idx, void *pd)
 }
 
 static void
-delcb (struct dictionary *d, int dict_idx, int case_idx, int width, void *pd)
+delcb (struct dictionary *d, const struct variable *var,
+       int dict_idx, int case_idx, void *pd)
 {
   g_signal_emit (pd, signals [VARIABLE_DELETED], 0,
-                 dict_idx, case_idx, width );
+                 var, dict_idx, case_idx);
 }
 
 static void
index f924c17027fbf3c78547e63271fb4e38477ad4b4..bc348efa22db9dfc2bb19a3e438d15c018225cc0 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2006, 2009, 2010, 2011  Free Software Foundation
+   Copyright (C) 2006, 2009, 2010, 2011, 2012  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
@@ -52,7 +52,8 @@ var_change_callback (GtkWidget *w, gint n, gpointer data)
 
 
 static void
-var_delete_callback (GtkWidget *w, gint dict_idx, gint case_idx, gint val_cnt, gpointer data)
+var_delete_callback (GtkWidget *w, const struct variable *var UNUSED,
+                     gint dict_idx, gint case_idx UNUSED, gpointer data)
 {
   PsppireSheetModel *model = PSPPIRE_SHEET_MODEL (data);