Remove awkward dependency from psppire-selector.c
authorJohn Darrington <john@darrington.wattle.id.au>
Sat, 12 Dec 2009 11:55:57 +0000 (12:55 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Sat, 12 Dec 2009 11:55:57 +0000 (12:55 +0100)
Removed the default selection functions from being
statically linked to psppire-selector.c  - apart from
being inelegant this caused a lot of unncessary dependencies
in the glade module.

glade/automake.mk
glade/var-view.c
src/ui/gui/psppire-selector.c
src/ui/gui/psppire-selector.h
src/ui/gui/psppire.c

index 1ef6b32c9d991d7e1974e3f12d15f2b45d0a1e97..bb16288620d848e3bdeecba69e4e630bca182029 100644 (file)
@@ -16,8 +16,6 @@ libglade_psppire_la_SOURCES = \
        glade/acr.c \
        glade/dictview.c \
        glade/var-view.c \
-        src/ui/gui/psppire-var-ptr.c \
-       src/ui/gui/dict-display.c \
        src/ui/gui/psppire-conf.c \
        src/ui/gui/psppire-acr.c \
        src/ui/gui/psppire-buttonbox.c \
index 272f7dbecc0a832bac5bfe3a1184fc96295fb7ce..7eb6c627266ca52199646c533716e503fac2aa66 100644 (file)
@@ -7,7 +7,14 @@
 #include <gladeui/glade.h>
 
 
-
+/* Dummy function to keep the linker happy.
+   Glade never actually needs to use this return value.
+ */
+GType
+psppire_var_ptr_get_type (void)
+{
+  return 0;
+}
 
 void
 glade_psppire_var_view_post_create (GladeWidgetAdaptor *adaptor,
index 367502b6ea219dca40b1aaeb07bb65a806996de4..2b2b2ed5ceeb9f23fe4dcca11fd6fd216c3b8832 100644 (file)
@@ -221,8 +221,6 @@ psppire_selector_get_property (GObject         *object,
     };
 }
 
-
-
 static void
 psppire_selector_class_init (PsppireSelectorClass *class)
 {
@@ -299,6 +297,8 @@ psppire_selector_class_init (PsppireSelectorClass *class)
                  g_cclosure_marshal_VOID__VOID,
                  G_TYPE_NONE,
                  0);
+
+  class->default_selection_funcs = g_hash_table_new (g_direct_hash, g_direct_equal);
 }
 
 
@@ -320,6 +320,7 @@ psppire_selector_base_finalize(PsppireSelectorClass *class,
                                gpointer class_data)
 {
   g_hash_table_destroy (class->source_hash);
+  g_hash_table_destroy (class->default_selection_funcs);
 }
 
 /* Callback for when the source treeview is activated (double clicked) */
@@ -364,6 +365,9 @@ on_realize (PsppireSelector *selector)
 
   GList *list = g_hash_table_lookup (class->source_hash, selector->source);
 
+  if ( NULL == list)
+    return;
+
   if ( g_list_first (list)->data == selector)
     {
       if ( selector->row_activate_id )
@@ -978,21 +982,36 @@ update_subjects (PsppireSelector *selector)
   else
     g_error ("Unsupported destination widget: %s", G_OBJECT_TYPE_NAME (selector->dest));
 
+
   /* FIXME: Remove this dependency */
   if ( PSPPIRE_IS_DICT_VIEW (selector->source) )
     {
-      if ( PSPPIRE_IS_VAR_VIEW (selector->dest))
-       psppire_selector_set_select_func (PSPPIRE_SELECTOR (selector),
-                                         insert_source_row_into_tree_view,
-                                         NULL);
-      else if (GTK_IS_ENTRY (selector->dest))
+      GObjectClass *class = G_OBJECT_GET_CLASS (selector);
+      GType type = G_OBJECT_TYPE (selector->dest);
+
+      SelectItemsFunc *func  = 
+       g_hash_table_lookup (PSPPIRE_SELECTOR_CLASS (class)->default_selection_funcs, (gpointer) type);
+
+      if ( func )
        psppire_selector_set_select_func (PSPPIRE_SELECTOR (selector),
-                                         insert_source_row_into_entry,
-                                         NULL);
+                                         func, NULL);
     }
+}
+
+
+void
+psppire_selector_set_default_selection_func (GType type, SelectItemsFunc *func)
+{
+  GObjectClass *class = g_type_class_ref (PSPPIRE_SELECTOR_TYPE);
 
+  g_hash_table_insert (PSPPIRE_SELECTOR_CLASS (class)->default_selection_funcs, (gpointer) type, func);
+
+  g_type_class_unref (class);
 }
 
+
+
+
 /* Set FILTER_FUNC for this selector */
 void
 psppire_selector_set_filter_func (PsppireSelector *selector,
index c2d18424738c93aa01a47ab8be111fc824b90bb3..bb267cd49cf08631a02e5cfd07e19cf54f31df4a 100644 (file)
@@ -115,6 +115,9 @@ struct _PsppireSelectorClass
   /* This is a hash of Lists of FilterItemsFunc pointers, keyed by address of
      the source widget */
   GHashTable *source_hash;
+
+  /* A hash of SelectItemFuncs indexed by GType */
+  GHashTable *default_selection_funcs;
 };
 
 GType      psppire_selector_get_type        (void);
@@ -148,6 +151,8 @@ typedef enum {
   (psppire_selector_orientation_get_type())
 
 
+void psppire_selector_set_default_selection_func (GType type, SelectItemsFunc *);
+
 
 G_END_DECLS
 
index 1cd7ee803c736a740b373a53b035c7dcef6bd90a..8491851383f4405805bbf71d0a35d5e172500b29 100644 (file)
@@ -47,6 +47,9 @@
 
 #include <gtk/gtk.h>
 #include "psppire-dict.h"
+#include "dict-display.h"
+#include "psppire-selector.h"
+#include "psppire-var-view.h"
 #include "psppire-var-store.h"
 #include "psppire-data-store.h"
 #include "executor.h"
@@ -146,6 +149,10 @@ initialize (struct command_line_processor *clp, int argc, char **argv)
 
   the_recent_mgr = gtk_recent_manager_get_default ();
 
+  psppire_selector_set_default_selection_func (GTK_TYPE_ENTRY, insert_source_row_into_entry);
+  psppire_selector_set_default_selection_func (PSPPIRE_VAR_VIEW_TYPE, insert_source_row_into_tree_view);
+  psppire_selector_set_default_selection_func (GTK_TYPE_TREE_VIEW, insert_source_row_into_tree_view);
+
   the_data_window = psppire_data_window_new ();
 
   command_line_processor_replace_aux (clp, &post_init_argp, the_source_stream);