From 82cdb6b894ba84fad617196cdba815c9aa15605f Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sat, 12 Dec 2009 12:55:57 +0100 Subject: [PATCH] Remove awkward dependency from psppire-selector.c 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 | 2 -- glade/var-view.c | 9 ++++++++- src/ui/gui/psppire-selector.c | 37 ++++++++++++++++++++++++++--------- src/ui/gui/psppire-selector.h | 5 +++++ src/ui/gui/psppire.c | 7 +++++++ 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/glade/automake.mk b/glade/automake.mk index 1ef6b32c..bb162886 100644 --- a/glade/automake.mk +++ b/glade/automake.mk @@ -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 \ diff --git a/glade/var-view.c b/glade/var-view.c index 272f7dbe..7eb6c627 100644 --- a/glade/var-view.c +++ b/glade/var-view.c @@ -7,7 +7,14 @@ #include - +/* 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, diff --git a/src/ui/gui/psppire-selector.c b/src/ui/gui/psppire-selector.c index 367502b6..2b2b2ed5 100644 --- a/src/ui/gui/psppire-selector.c +++ b/src/ui/gui/psppire-selector.c @@ -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, diff --git a/src/ui/gui/psppire-selector.h b/src/ui/gui/psppire-selector.h index c2d18424..bb267cd4 100644 --- a/src/ui/gui/psppire-selector.h +++ b/src/ui/gui/psppire-selector.h @@ -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 diff --git a/src/ui/gui/psppire.c b/src/ui/gui/psppire.c index 1cd7ee80..84918513 100644 --- a/src/ui/gui/psppire.c +++ b/src/ui/gui/psppire.c @@ -47,6 +47,9 @@ #include #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); -- 2.30.2