Fixed the two biggest sources of GtkCritical errors.
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 7 Aug 2007 00:56:59 +0000 (00:56 +0000)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 7 Aug 2007 00:56:59 +0000 (00:56 +0000)
src/ui/gui/ChangeLog
src/ui/gui/helper.c
src/ui/gui/psppire-case-file.c
src/ui/gui/psppire-data-store.c
src/ui/gui/psppire-data-store.h

index 6a368e00e28d6f24f343a5df65ff848c31b5c324..3b4a450b37ac619c1ec0978ee7592bc9f7746132 100644 (file)
@@ -1,3 +1,16 @@
+2007-08-07  John Darrington <john@darrington.wattle.id.au>
+
+       * helper.c (execute_syntax): Set the active file data to NULL at the 
+       end of the procedure.  Thanks to Ben for suggesting this.
+
+       * psppire-case-file.c: Added assertions to the remaining functions 
+       on inaccessible objects.
+
+       * psppire-data-store.c psppire-data-store.h: Disconnect or block 
+       signals on dictionary and case_file, when make_reader has been called. 
+       Reconnect or unblock them when a new datasheet has been set for the 
+       data_store.
+       
 2007-08-06  John Darrington <john@darrington.wattle.id.au>
 
        * syntax-editor.glade: Changed some properties to be less annoying.
index 274635d7913b1412ce206416af7d393d64c1a4bb..98bd41798445025d2c9ca0b42b9a8121b34863de 100644 (file)
@@ -201,6 +201,8 @@ execute_syntax (struct getl_interface *sss)
     psppire_data_store_set_case_file (the_data_store, pcf);
   }
 
+  proc_set_active_file_data (the_dataset, NULL);
+
   som_flush ();
 }
 
index a44309eed8c67fb14a68bb3e818194d1f8684bc3..bb6f8b5545ca72efd83ff461cf5f5e03e9799fd3 100644 (file)
@@ -168,6 +168,7 @@ psppire_case_file_delete_cases (PsppireCaseFile *cf, casenumber n_cases, casenum
 {
   g_return_val_if_fail (cf, FALSE);
   g_return_val_if_fail (cf->datasheet, FALSE);
+  g_return_val_if_fail (cf->accessible, FALSE);
 
   g_return_val_if_fail (first + n_cases <=
                        psppire_case_file_get_case_count (cf), FALSE);
@@ -190,6 +191,7 @@ psppire_case_file_insert_case (PsppireCaseFile *cf,
 
   g_return_val_if_fail (cf, FALSE);
   g_return_val_if_fail (cf->datasheet, FALSE);
+  g_return_val_if_fail (cf->accessible, FALSE);
 
   case_clone (&tmp, cc);
   result = datasheet_insert_rows (cf->datasheet, posn, &tmp, 1);
@@ -204,7 +206,7 @@ psppire_case_file_insert_case (PsppireCaseFile *cf,
 
 
 /* Append a case to the case file */
-gboolean
+static gboolean
 psppire_case_file_append_case (PsppireCaseFile *cf,
                              struct ccase *c)
 {
@@ -214,6 +216,7 @@ psppire_case_file_append_case (PsppireCaseFile *cf,
 
   g_return_val_if_fail (cf, FALSE);
   g_return_val_if_fail (cf->datasheet, FALSE);
+  g_return_val_if_fail (cf->accessible, FALSE);
 
   posn = datasheet_get_row_cnt (cf->datasheet);
 
index f79f44737e4b52c265c1139218204783b4c2a307..1e6568b78afa6bfe6247142da7d0a3f7ac649b00 100644 (file)
@@ -178,6 +178,8 @@ psppire_data_store_init (PsppireDataStore *data_store)
   data_store->dict = 0;
   data_store->case_file = 0;
   data_store->width_of_m = 10;
+
+
 }
 
 const PangoFontDescription *
@@ -384,36 +386,55 @@ psppire_data_store_new (PsppireDict *dict)
 
 
 void
-psppire_data_store_set_case_file (PsppireDataStore *data_store,
+psppire_data_store_set_case_file (PsppireDataStore *ds,
                                  PsppireCaseFile *cf)
 {
-  if ( data_store->case_file)
+  gint i;
+  if ( ds->case_file)
     {
-      g_object_unref (data_store->case_file);
+      g_object_unref (ds->case_file);
     }
 
-  data_store->case_file = cf;
+  ds->case_file = cf;
 
-  g_sheet_model_range_changed (G_SHEET_MODEL (data_store),
+  g_sheet_model_range_changed (G_SHEET_MODEL (ds),
                               -1, -1, -1, -1);
 
+  for (i = 0 ; i < n_cf_signals ; ++i )
+    {
+      if ( ds->cf_handler_id [i] > 0 )
+       g_signal_handler_disconnect (ds->case_file,
+                                    ds->cf_handler_id[i]);
+    }
+
 
-  g_signal_connect (data_store->case_file, "cases-deleted",
-                  G_CALLBACK (delete_cases_callback),
-                  data_store);
+  if ( ds->dict )
+    for (i = 0 ; i < n_dict_signals; ++i )
+      {
+       if ( ds->dict_handler_id [i] > 0)
+         {
+           g_signal_handler_unblock (ds->dict,
+                                     ds->dict_handler_id[i]);
+         }
+      }
 
-  g_signal_connect (data_store->case_file, "case-inserted",
-                  G_CALLBACK (insert_case_callback),
-                  data_store);
+  ds->cf_handler_id [CASES_DELETED] =
+    g_signal_connect (ds->case_file, "cases-deleted",
+                     G_CALLBACK (delete_cases_callback),
+                     ds);
 
+  ds->cf_handler_id [CASE_INSERTED] =
+    g_signal_connect (ds->case_file, "case-inserted",
+                     G_CALLBACK (insert_case_callback),
+                     ds);
 
-  g_signal_connect (data_store->case_file, "case-changed",
-                  G_CALLBACK (changed_case_callback),
-                  data_store);
+  ds->cf_handler_id [CASE_CHANGED] =
+    g_signal_connect (ds->case_file, "case-changed",
+                     G_CALLBACK (changed_case_callback),
+                     ds);
 }
 
 
-
 /**
  * psppire_data_store_replace_set_dictionary:
  * @data_store: The variable store
@@ -425,28 +446,59 @@ psppire_data_store_set_case_file (PsppireDataStore *data_store,
 void
 psppire_data_store_set_dictionary (PsppireDataStore *data_store, PsppireDict *dict)
 {
+  int i;
+
+  /* Disconnect any existing handlers */
+  if ( data_store->dict )
+    for (i = 0 ; i < n_dict_signals; ++i )
+      {
+       g_signal_handler_disconnect (data_store->dict,
+                                    data_store->dict_handler_id[i]);
+      }
+
   data_store->dict = dict;
 
-  g_signal_connect (dict, "variable-inserted",
-                  G_CALLBACK (insert_variable_callback),
-                  data_store);
+  if ( dict != NULL)
+    {
 
-  g_signal_connect (dict, "variable-deleted",
-                  G_CALLBACK (delete_variable_callback),
-                  data_store);
+      data_store->dict_handler_id [VARIABLE_INSERTED] =
+       g_signal_connect (dict, "variable-inserted",
+                         G_CALLBACK (insert_variable_callback),
+                         data_store);
+
+      data_store->dict_handler_id [VARIABLE_DELETED] =
+       g_signal_connect (dict, "variable-deleted",
+                         G_CALLBACK (delete_variable_callback),
+                         data_store);
+
+      data_store->dict_handler_id [VARIABLE_CHANGED] =
+       g_signal_connect (dict, "variable-changed",
+                         G_CALLBACK (variable_changed_callback),
+                         data_store);
+
+      data_store->dict_handler_id [SIZE_CHANGED] =
+       g_signal_connect (dict, "dict-size-changed",
+                         G_CALLBACK (dict_size_change_callback),
+                         data_store);
+    }
 
-  g_signal_connect (dict, "variable-changed",
-                  G_CALLBACK (variable_changed_callback),
-                  data_store);
 
-  g_signal_connect (dict, "dict-size-changed",
-                   G_CALLBACK (dict_size_change_callback),
-                   data_store);
 
   /* The entire model has changed */
   g_sheet_model_range_changed (G_SHEET_MODEL (data_store), -1, -1, -1, -1);
 
   g_sheet_column_columns_changed (G_SHEET_COLUMN (data_store), 0, -1);
+
+
+  if ( data_store->dict )
+    for (i = 0 ; i < n_dict_signals; ++i )
+      {
+       if ( data_store->dict_handler_id [i] > 0)
+         {
+           g_signal_handler_block (data_store->dict,
+                                   data_store->dict_handler_id[i]);
+         }
+      }
 }
 
 static void
@@ -673,8 +725,22 @@ psppire_data_store_clear (PsppireDataStore *data_store)
 struct casereader *
 psppire_data_store_get_reader (PsppireDataStore *ds)
 {
+  int i;
   struct casereader *reader ;
 
+  for (i = 0 ; i < n_cf_signals ; ++i )
+    {
+      g_signal_handler_disconnect (ds->case_file, ds->cf_handler_id[i]);
+      ds->cf_handler_id[i] = 0 ;
+    }
+
+  if ( ds->dict )
+    for (i = 0 ; i < n_dict_signals; ++i )
+      {
+       g_signal_handler_block (ds->dict,
+                               ds->dict_handler_id[i]);
+      }
+
   reader = psppire_case_file_make_reader (ds->case_file);
 
   return reader;
@@ -835,7 +901,7 @@ geometry_pixel_to_row (const GSheetRow *geo, guint pixel, gpointer data)
   glong row  = pixel / ROW_HEIGHT;
 
   if (row >= geometry_get_row_count (geo, data))
-    row = geometry_get_row_count (geo, data) -1;
+    row = geometry_get_row_count (geo, data) - 1;
 
   return row;
 }
index 8e29db33ab9033311b6b662b71c301bb51315ead..ed4f0fd17c65f9f7ca4ea8942d0c47b7a34b7252 100644 (file)
@@ -56,6 +56,26 @@ typedef struct _PsppireDataStoreClass  PsppireDataStoreClass;
 
 struct dictionary;
 
+
+enum cf_signal_handler {
+  CASES_DELETED,
+  CASE_INSERTED,
+  CASE_CHANGED,
+  n_cf_signals
+};
+
+
+enum dict_signal_handler {
+  VARIABLE_INSERTED,
+  VARIABLE_CHANGED,
+  VARIABLE_DELETED,
+  SIZE_CHANGED,
+  n_dict_signals
+};
+
+void do_this_thing (PsppireDict *, struct dictionary *, void *);
+
+
 struct _PsppireDataStore
 {
   GObject parent;
@@ -72,6 +92,9 @@ struct _PsppireDataStore
 
   /* Geometry */
   gint margin_width;
+
+  gint cf_handler_id [n_cf_signals];
+  gint dict_handler_id [n_dict_signals];
 };
 
 struct _PsppireDataStoreClass