X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fui%2Fgui%2Fpsppire-selector.c;h=372ef3c531f18adef3fde1c4dd470e860bffc098;hb=42993d3ae61750a8f1e291297d8ac91465afcff2;hp=7e0ade25009dd019125f8e7cc8b4a96df4c2f967;hpb=a9a69251edd625a50f271af5d64c157533b5fe48;p=pspp
diff --git a/src/ui/gui/psppire-selector.c b/src/ui/gui/psppire-selector.c
index 7e0ade2500..372ef3c531 100644
--- a/src/ui/gui/psppire-selector.c
+++ b/src/ui/gui/psppire-selector.c
@@ -1,5 +1,5 @@
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2007, 2009 Free Software Foundation
+ Copyright (C) 2007, 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
@@ -12,7 +12,8 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program. If not, see . */
+ along with this program. If not, see .
+*/
/*
This module provides a widget, PsppireSelector derived from
@@ -57,19 +58,15 @@
#include
-#include
-#include
-#include
+#include "psppire-dictview.h"
+#include "psppire-var-view.h"
+#include "psppire-dict.h"
+#include "psppire-select-dest.h"
-#include "psppire-selector.h"
+#include
-#include
-#include
-#include
-#include
+#include "psppire-selector.h"
-static void psppire_selector_base_finalize (PsppireSelectorClass *, gpointer);
-static void psppire_selector_base_init (PsppireSelectorClass *class);
static void psppire_selector_class_init (PsppireSelectorClass *class);
static void psppire_selector_init (PsppireSelector *selector);
@@ -83,6 +80,26 @@ enum {SELECTED, /* Emitted when an item is inserted into dest */
static guint signals [n_SIGNALS];
+/* Callback for when an item disappears from the source list.
+ By implication, this means that the item has been inserted into the
+ destination.
+ */
+static void
+on_row_deleted (PsppireSelector *selector)
+{
+ g_signal_emit (selector, signals [SELECTED], 0);
+}
+
+/* Callback for when a new item appears in the source list.
+ By implication, this means that an item has been deleted from the
+ destination.
+ */
+static void
+on_row_inserted (PsppireSelector *selector)
+{
+ g_signal_emit (selector, signals [DE_SELECTED], 0);
+}
+
GType
psppire_selector_get_type (void)
@@ -94,8 +111,8 @@ psppire_selector_get_type (void)
static const GTypeInfo psppire_selector_info =
{
sizeof (PsppireSelectorClass),
- (GBaseInitFunc) psppire_selector_base_init,
- (GBaseFinalizeFunc) psppire_selector_base_finalize,
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
(GClassInitFunc)psppire_selector_class_init,
(GClassFinalizeFunc) NULL,
NULL,
@@ -114,18 +131,43 @@ psppire_selector_get_type (void)
static GObjectClass * parent_class = NULL;
+
+
+#define SELECTOR_DEBUGGING 0
+
static void
-psppire_selector_finalize (GObject *obj)
+dump_hash_entry (gpointer key, gpointer value, gpointer obj)
{
- /* Chain up to the parent class */
- G_OBJECT_CLASS (parent_class)->finalize (obj);
+ GList *item = NULL;
+ g_print ("Source %p; ", key);
+
+ for (item = g_list_first (value);
+ item != NULL;
+ item = g_list_next (item))
+ {
+ g_print ("%p(%p) ", item->data, item);
+ }
+ g_print ("\n");
}
+/* This function is for debugging only */
+void
+psppire_selector_show_map (PsppireSelector *obj)
+{
+ PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
+
+ g_print ("%s %p\n", __FUNCTION__, obj);
+ g_hash_table_foreach (class->source_hash, dump_hash_entry, obj);
+}
+
+
static void
psppire_selector_dispose (GObject *obj)
{
PsppireSelector *sel = PSPPIRE_SELECTOR (obj);
+ PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
+ GList *list;
if (sel->dispose_has_run)
return;
@@ -133,6 +175,21 @@ psppire_selector_dispose (GObject *obj)
/* Make sure dispose does not run twice. */
sel->dispose_has_run = TRUE;
+ /* Remove ourself from the source map. If we are the only entry for this source
+ widget, that will result in an empty list for the source. In that case, we
+ remove the entire entry too. */
+ if ((list = g_hash_table_lookup (class->source_hash, sel->source)))
+ {
+ GList *newlist = g_list_remove_link (list, sel->source_litem);
+ g_list_free (sel->source_litem);
+ if (newlist == NULL)
+ g_hash_table_remove (class->source_hash, sel->source);
+ else
+ g_hash_table_replace (class->source_hash, sel->source, newlist);
+
+ sel->source_litem = NULL;
+ }
+
g_object_unref (sel->dest);
g_object_unref (sel->source);
@@ -146,12 +203,15 @@ enum
{
PROP_0,
PROP_ORIENTATION,
+ PROP_PRIMARY,
PROP_SOURCE_WIDGET,
PROP_DEST_WIDGET
};
-static void on_activate (PsppireSelector *selector, gpointer data);
+static void on_click (GtkButton *b);
+static void on_realize (GtkWidget *selector);
+
static void update_subjects (PsppireSelector *selector);
@@ -170,6 +230,10 @@ psppire_selector_set_property (GObject *object,
selector->orientation = g_value_get_enum (value);
set_direction (selector, selector->direction);
break;
+ case PROP_PRIMARY:
+ selector->primary_requested = TRUE;
+ update_subjects (selector);
+ break;
case PROP_SOURCE_WIDGET:
selector->source = g_value_dup_object (value);
update_subjects (selector);
@@ -210,12 +274,12 @@ psppire_selector_get_property (GObject *object,
};
}
-
-
static void
psppire_selector_class_init (PsppireSelectorClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
+ GtkButtonClass *button_class = GTK_BUTTON_CLASS (class);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GParamSpec *orientation_spec =
g_param_spec_enum ("orientation",
"Orientation",
@@ -224,6 +288,15 @@ psppire_selector_class_init (PsppireSelectorClass *class)
PSPPIRE_SELECT_SOURCE_BEFORE_DEST /* default value */,
G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
+
+ /* Meaningfull only if more than one selector shares this selectors source */
+ GParamSpec *primary_spec =
+ g_param_spec_boolean ("primary",
+ "Primary",
+ "Whether this selector should be the primary selector for the source",
+ FALSE,
+ G_PARAM_READWRITE);
+
GParamSpec *source_widget_spec =
g_param_spec_object ("source-widget",
"Source Widget",
@@ -239,6 +312,10 @@ psppire_selector_class_init (PsppireSelectorClass *class)
G_PARAM_READWRITE);
+ button_class->clicked = on_click;
+ widget_class->realize = on_realize;
+
+
object_class->set_property = psppire_selector_set_property;
object_class->get_property = psppire_selector_get_property;
@@ -246,6 +323,10 @@ psppire_selector_class_init (PsppireSelectorClass *class)
PROP_ORIENTATION,
orientation_spec);
+ g_object_class_install_property (object_class,
+ PROP_PRIMARY,
+ primary_spec);
+
g_object_class_install_property (object_class,
PROP_SOURCE_WIDGET,
source_widget_spec);
@@ -275,52 +356,107 @@ psppire_selector_class_init (PsppireSelectorClass *class)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
+
+ object_class->dispose = psppire_selector_dispose;
+
+ class->source_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
+ class->default_selection_funcs = g_hash_table_new (g_direct_hash, g_direct_equal);
}
+/* Callback for when the source treeview is activated (double clicked) */
static void
-psppire_selector_base_init (PsppireSelectorClass *class)
+on_row_activate (GtkTreeView *tree_view,
+ GtkTreePath *path,
+ GtkTreeViewColumn *column,
+ gpointer data)
{
- GObjectClass *object_class = G_OBJECT_CLASS (class);
+ on_click (GTK_BUTTON (data));
+}
- object_class->finalize = psppire_selector_finalize;
- object_class->dispose = psppire_selector_dispose;
+/* Callback for when the source selection changes */
+static void
+on_source_select (GtkTreeSelection *treeselection, gpointer data)
+{
+ PsppireSelector *selector = data;
- class->source_hash = g_hash_table_new (g_direct_hash, g_direct_equal);
-}
+ set_direction (selector, PSPPIRE_SELECTOR_SOURCE_TO_DEST);
+ if ( selector->allow_selection )
+ {
+ gtk_widget_set_sensitive (GTK_WIDGET (selector),
+ selector->allow_selection (selector->source, selector->dest));
+ }
+ else if ( GTK_IS_ENTRY (selector->dest) )
+ {
+ gtk_widget_set_sensitive (GTK_WIDGET (selector),
+ gtk_tree_selection_count_selected_rows
+ (treeselection) <= 1 );
+ }
+}
static void
-psppire_selector_base_finalize(PsppireSelectorClass *class,
- gpointer class_data)
+on_realize (GtkWidget *w)
{
- g_hash_table_destroy (class->source_hash);
-}
+ PsppireSelector *selector = PSPPIRE_SELECTOR (w);
+ PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
+ GtkTreeSelection* selection ;
+ GList *list = g_hash_table_lookup (class->source_hash, selector->source);
+
+ if (GTK_WIDGET_CLASS (parent_class)->realize)
+ GTK_WIDGET_CLASS (parent_class)->realize (w);
+
+ if ( NULL == list)
+ return;
+
+ if ( g_list_first (list)->data == selector)
+ {
+ if ( selector->row_activate_id )
+ g_signal_handler_disconnect (selector->source, selector->row_activate_id);
+
+ selector->row_activate_id =
+ g_signal_connect (selector->source, "row-activated", G_CALLBACK (on_row_activate), selector);
+ }
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (selector->source));
+
+ if ( selector->source_select_id )
+ g_signal_handler_disconnect (selection, selector->source_select_id);
+
+ selector->source_select_id =
+ g_signal_connect (selection, "changed", G_CALLBACK (on_source_select), selector);
+}
static void
psppire_selector_init (PsppireSelector *selector)
{
- selector->arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
- selector->filtered_source = NULL;
+ selector->primary_requested = FALSE;
+ selector->select_user_data = NULL;
+ selector->select_items = NULL;
+ selector->allow_selection = NULL;
+ selector->filter = NULL;
- selector->action = gtk_action_new ("select", NULL, NULL, "pspp-stock-select");
+ selector->arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
- gtk_action_connect_proxy (selector->action, GTK_WIDGET (selector));
gtk_container_add (GTK_CONTAINER (selector), selector->arrow);
gtk_widget_show (selector->arrow);
- g_signal_connect_swapped (selector->action, "activate", G_CALLBACK (on_activate), selector);
-
selector->selecting = FALSE;
selector->source = NULL;
selector->dest = NULL;
selector->dispose_has_run = FALSE;
+
+
+ selector->row_activate_id = 0;
+ selector->source_select_id = 0;
+
+ selector->source_litem = NULL;
}
@@ -383,27 +519,6 @@ set_direction (PsppireSelector *selector, enum psppire_selector_dir d)
}
}
-/* Callback for when the source selection changes */
-static void
-on_source_select (GtkTreeSelection *treeselection, gpointer data)
-{
- PsppireSelector *selector = data;
-
- set_direction (selector, PSPPIRE_SELECTOR_SOURCE_TO_DEST);
-
- if ( selector->allow_selection )
- {
- gtk_action_set_sensitive (selector->action,
- selector->allow_selection (selector->source, selector->dest));
- }
- else if ( GTK_IS_ENTRY (selector->dest) )
- {
- gtk_action_set_sensitive (selector->action,
- gtk_tree_selection_count_selected_rows
- (treeselection) <= 1 );
- }
-}
-
/* Callback for when the destination treeview selection changes */
static void
on_dest_treeview_select (GtkTreeSelection *treeselection, gpointer data)
@@ -476,6 +591,18 @@ de_select_selection_tree_view (PsppireSelector *selector)
}
+/* Callback which causes the filter to be refiltered.
+ Called when the DEST GtkEntry is activated (Enter is pressed), or when it
+ looses focus.
+*/
+static gboolean
+refilter (PsppireSelector *selector)
+{
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector->source));
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (model));
+ return FALSE;
+}
+
/* Removes something from the DEST widget */
static void
de_select_selection (PsppireSelector *selector)
@@ -493,7 +620,7 @@ de_select_selection (PsppireSelector *selector)
selector->selecting = FALSE;
- gtk_tree_model_filter_refilter (selector->filtered_source);
+ refilter (selector);
g_signal_emit (selector, signals [DE_SELECTED], 0);
}
@@ -507,14 +634,18 @@ select_selection (PsppireSelector *selector)
GtkTreeSelection* selection =
gtk_tree_view_get_selection ( GTK_TREE_VIEW (selector->source));
- GList *selected_rows =
- gtk_tree_selection_get_selected_rows (selection, NULL);
+ GList *selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
- GtkTreeModel *childmodel = gtk_tree_model_filter_get_model
- (selector->filtered_source);
+ GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector->source));
+
+ GtkTreeModel *childmodel = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
g_return_if_fail (selector->select_items);
+ if (selector->allow_selection &&
+ ! selector->allow_selection (selector->source, selector->dest))
+ return;
+
selector->selecting = TRUE;
for (item = g_list_first (selected_rows);
@@ -525,14 +656,12 @@ select_selection (PsppireSelector *selector)
GtkTreeIter iter;
GtkTreePath *path = item->data;
- gtk_tree_model_get_iter (GTK_TREE_MODEL (selector->filtered_source),
- &iter, path);
+ g_return_if_fail (model);
- gtk_tree_model_filter_convert_iter_to_child_iter
- (selector->filtered_source,
- &child_iter,
- &iter);
+ gtk_tree_model_get_iter (model, &iter, path);
+ gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model),
+ &child_iter, &iter);
selector->select_items (child_iter,
selector->dest,
childmodel,
@@ -543,31 +672,21 @@ select_selection (PsppireSelector *selector)
g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
g_list_free (selected_rows);
- gtk_tree_model_filter_refilter (selector->filtered_source);
+ refilter (selector);
g_signal_emit (selector, signals [SELECTED], 0);
selector->selecting = FALSE;
}
-/* Callback for when the source treeview is activated (double clicked) */
-static void
-on_row_activate (GtkTreeView *tree_view,
- GtkTreePath *path,
- GtkTreeViewColumn *column,
- gpointer data)
-{
- PsppireSelector *selector = data;
-
- gtk_action_activate (selector->action);
-}
-
/* Callback for when the selector button is clicked,
or other event which causes the selector's action to occur.
*/
static void
-on_activate (PsppireSelector *selector, gpointer data)
+on_click (GtkButton *b)
{
+ PsppireSelector *selector = PSPPIRE_SELECTOR (b);
+
switch (selector->direction)
{
case PSPPIRE_SELECTOR_SOURCE_TO_DEST:
@@ -580,27 +699,26 @@ on_activate (PsppireSelector *selector, gpointer data)
g_assert_not_reached ();
break;
}
+
+ if (GTK_BUTTON_CLASS (parent_class)->clicked)
+ GTK_BUTTON_CLASS (parent_class)->clicked (b);
}
-/* Default visibility filter for GtkTreeView DEST widget */
static gboolean
-is_item_in_dest (GtkTreeModel *model, GtkTreeIter *iter,
- PsppireSelector *selector)
+is_item_in_dest (GtkTreeModel *model, GtkTreeIter *iter, PsppireSelector *selector)
{
- GtkTreeModel *dest_model;
- GtkTreeIter dest_iter;
+ gboolean result = FALSE;
GtkTreeIter source_iter;
- gint index;
- GtkTreePath *path ;
GtkTreeModel *source_model;
+ GValue value = {0};
- if ( GTK_IS_TREE_MODEL_FILTER (model) )
+ if (GTK_IS_TREE_MODEL_FILTER (model))
{
source_model = gtk_tree_model_filter_get_model
(GTK_TREE_MODEL_FILTER (model));
gtk_tree_model_filter_convert_iter_to_child_iter
- ( GTK_TREE_MODEL_FILTER (model), &source_iter, iter );
+ (GTK_TREE_MODEL_FILTER (model), &source_iter, iter);
}
else
{
@@ -608,40 +726,17 @@ is_item_in_dest (GtkTreeModel *model, GtkTreeIter *iter,
source_iter = *iter;
}
- dest_model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector->dest));
-
- path = gtk_tree_model_get_path (source_model, &source_iter);
-
- index = *gtk_tree_path_get_indices (path);
-
- gtk_tree_path_free (path);
+ gtk_tree_model_get_value (source_model, &source_iter, DICT_TVM_COL_VAR, &value);
- if ( ! gtk_tree_model_get_iter_first (dest_model, &dest_iter) )
- return FALSE;
+ result = psppire_select_dest_widget_contains_var (PSPPIRE_SELECT_DEST_WIDGET (selector->dest),
+ &value);
- do
- {
- int x;
- GValue value = {0};
- GValue int_value = {0};
- gtk_tree_model_get_value (dest_model, &dest_iter, 0, &value);
-
- g_value_init (&int_value, G_TYPE_INT);
-
- g_value_transform (&value, &int_value);
+ g_value_unset (&value);
- x = g_value_get_int (&int_value);
+ return result;
+}
- g_value_unset (&int_value);
- g_value_unset (&value);
- if ( x == index )
- return TRUE;
- }
- while (gtk_tree_model_iter_next (dest_model, &dest_iter));
-
- return FALSE;
-}
/* Visibility function for items in the SOURCE widget.
Returns TRUE iff *all* the selectors for which SOURCE is associated
@@ -673,55 +768,90 @@ is_source_item_visible (GtkTreeModel *childmodel,
/* set the source widget to SOURCE */
static void
-set_tree_view_source (PsppireSelector *selector,
- GtkTreeView *source)
+set_tree_view_source (PsppireSelector *selector)
{
- GtkTreeSelection* selection ;
GList *list = NULL;
PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
-
- if ( ! (list = g_hash_table_lookup (class->source_hash, source)))
+
+ if ( ! (list = g_hash_table_lookup (class->source_hash, selector->source)))
{
- selector->filtered_source =
- GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new
- (gtk_tree_view_get_model (source), NULL));
-
- gtk_tree_view_set_model (source, NULL);
-
- gtk_tree_view_set_model (source,
- GTK_TREE_MODEL (selector->filtered_source));
+ /* Base case: This widget is currently not the source of
+ any selector. Create a hash entry and make this selector
+ the first selector in the list */
list = g_list_append (list, selector);
- g_hash_table_insert (class->source_hash, source, list);
-
+ g_hash_table_insert (class->source_hash, selector->source, list);
- gtk_tree_model_filter_set_visible_func (selector->filtered_source,
- is_source_item_visible,
- selector,
- NULL);
+ /* Save the list item so that it can be removed later */
+ selector->source_litem = list;
}
else
{ /* Append this selector to the list and push the
pair onto the hash table */
- selector->filtered_source = GTK_TREE_MODEL_FILTER (
- gtk_tree_view_get_model (source));
-
- list = g_list_append (list, selector);
- g_hash_table_replace (class->source_hash, source, list);
+ if ( NULL == g_list_find (list, selector) )
+ {
+ if ( selector->primary_requested )
+ {
+ list = g_list_prepend (list, selector);
+ selector->source_litem = list;
+ }
+ else
+ {
+ list = g_list_append (list, selector);
+ selector->source_litem = g_list_last (list);
+ }
+ g_hash_table_replace (class->source_hash, selector->source, list);
+ }
}
+}
- selection = gtk_tree_view_get_selection (source);
- g_signal_connect (source, "row-activated", G_CALLBACK (on_row_activate),
- selector);
- g_signal_connect (selection, "changed", G_CALLBACK (on_source_select),
- selector);
+/* This function is a callback which occurs when the
+ SOURCE's model has changed */
+static void
+update_model (
+ GtkTreeView *source,
+ GParamSpec *psp,
+ PsppireSelector *selector
+ )
+{
+ GtkTreeModel *model = gtk_tree_view_get_model (source);
+
+ g_assert (source == GTK_TREE_VIEW (selector->source));
+
+ if (model && (model == g_object_get_data (G_OBJECT (source), "model-copy")))
+ return;
+
+ if (model != NULL)
+ {
+ GtkTreeModel *new_model = gtk_tree_model_filter_new (model, NULL);
+
+ g_object_set_data (G_OBJECT (source), "model-copy", new_model);
+
+ gtk_tree_view_set_model (source, new_model);
+
+ gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (new_model),
+ is_source_item_visible,
+ selector,
+ NULL);
+
+ g_signal_connect_swapped (new_model,
+ "row-deleted",
+ G_CALLBACK (on_row_deleted), selector);
+
+ g_signal_connect_swapped (new_model,
+ "row-inserted",
+ G_CALLBACK (on_row_inserted), selector);
+
+ g_object_unref (new_model);
+ }
}
+
/*
Callback for when the destination treeview's data changes
*/
@@ -735,7 +865,7 @@ on_dest_data_change (GtkTreeModel *tree_model,
if ( selector->selecting) return;
- gtk_tree_model_filter_refilter (selector->filtered_source);
+ refilter (selector);
}
@@ -748,20 +878,23 @@ on_dest_data_delete (GtkTreeModel *tree_model,
if ( selector->selecting ) return;
- gtk_tree_model_filter_refilter (selector->filtered_source);
+ refilter (selector);
}
static void
-xxx (PsppireSelector *selector)
+on_dest_model_changed (PsppireSelector *selector)
{
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector->dest));
- g_signal_connect (model, "row-changed", G_CALLBACK (on_dest_data_change),
- selector);
-
- g_signal_connect (model, "row-deleted", G_CALLBACK (on_dest_data_delete),
- selector);
+ if ( model )
+ {
+ g_signal_connect (model, "row-changed", G_CALLBACK (on_dest_data_change),
+ selector);
+
+ g_signal_connect (model, "row-deleted", G_CALLBACK (on_dest_data_delete),
+ selector);
+ }
}
/* Set the destination widget to DEST */
@@ -777,22 +910,13 @@ set_tree_view_dest (PsppireSelector *selector,
g_signal_connect (selection, "changed", G_CALLBACK (on_dest_treeview_select),
selector);
-
+ on_dest_model_changed (selector);
g_signal_connect_swapped (dest, "notify::model",
- G_CALLBACK (xxx), selector);
-
+ G_CALLBACK (on_dest_model_changed), selector);
}
-/* Callback which causes the filter to be refiltered.
- Called when the DEST GtkEntry is activated (Enter is pressed), or when it
- looses focus.
-*/
-static gboolean
-refilter (PsppireSelector *selector)
-{
- gtk_tree_model_filter_refilter (selector->filtered_source);
- return FALSE;
-}
+
+
/* Callback for when the DEST GtkEntry is selected (clicked) */
static gboolean
@@ -808,28 +932,6 @@ on_entry_dest_select (GtkWidget *widget, GdkEventFocus *event, gpointer data)
-/* Callback for when an item disappears from the source list.
- By implication, this means that the item has been inserted into the
- destination.
- */
-static void
-on_row_deleted (PsppireSelector *selector)
-{
- g_signal_emit (selector, signals [SELECTED], 0);
-}
-
-/* Callback for when a new item appears in the source list.
- By implication, this means that an item has been deleted from the
- destination.
- */
-static void
-on_row_inserted (PsppireSelector *selector)
-{
- g_signal_emit (selector, signals [DE_SELECTED], 0);
-}
-
-
-
/* Set DEST to be the destination GtkEntry widget */
static void
set_entry_dest (PsppireSelector *selector,
@@ -848,35 +950,39 @@ set_entry_dest (PsppireSelector *selector,
selector);
- g_signal_connect_swapped (selector->filtered_source, "row-deleted",
- G_CALLBACK (on_row_deleted), selector);
+}
- g_signal_connect_swapped (selector->filtered_source, "row-inserted",
- G_CALLBACK (on_row_inserted), selector);
+static void
+set_default_filter (PsppireSelector *selector)
+{
+ if ( selector->filter == NULL)
+ {
+ if (GTK_IS_TREE_VIEW (selector->dest))
+ selector->filter = is_item_in_dest;
+ }
}
+
static void
update_subjects (PsppireSelector *selector)
{
- GtkTreeModel *model = NULL;
-
if ( NULL == selector->dest )
return;
+ set_default_filter (selector);
+
if ( NULL == selector->source )
return;
- g_signal_connect_swapped (selector->source, "notify::model",
- G_CALLBACK (update_subjects), selector);
-
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (selector->source));
-
- if ( NULL == model)
- return;
+ if ( GTK_IS_TREE_VIEW (selector->source))
+ {
+ set_tree_view_source (selector);
+ g_signal_connect (selector->source, "notify::model",
+ G_CALLBACK (update_model), selector);
- if ( GTK_IS_TREE_VIEW (selector->source))
- set_tree_view_source (selector, GTK_TREE_VIEW (selector->source) );
+ update_model (GTK_TREE_VIEW (selector->source), 0, selector);
+ }
else
g_error ("Unsupported source widget: %s", G_OBJECT_TYPE_NAME (selector->source));
@@ -897,25 +1003,52 @@ 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) )
+ {
+ 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),
+ func, NULL);
+ }
}
-/* Set SELECT_FUNC and FILTER_FUNC for this selector */
void
-psppire_selector_set_subjects (PsppireSelector *selector,
- SelectItemsFunc *select_func,
- FilterItemsFunc *filter_func,
- gpointer user_data)
+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,
+ FilterItemsFunc *filter_func)
{
selector->filter = filter_func ;
- selector->select_user_data = user_data;
+}
- if ( filter_func == NULL)
- {
- if (GTK_IS_TREE_VIEW (selector->dest))
- selector->filter = is_item_in_dest;
- }
+/* Set SELECT_FUNC for this selector */
+void
+psppire_selector_set_select_func (PsppireSelector *selector,
+ SelectItemsFunc *select_func,
+ gpointer user_data)
+{
+ selector->select_user_data = user_data;
selector->select_items = select_func;
}
@@ -928,7 +1061,6 @@ psppire_selector_set_allow (PsppireSelector *selector, AllowSelectionFunc *allow
}
-
GType
psppire_selector_orientation_get_type (void)
{