X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-selector.c;h=2b2b2ed5ceeb9f23fe4dcca11fd6fd216c3b8832;hb=82cdb6b894ba84fad617196cdba815c9aa15605f;hp=d871d5d1511a69c894525be369e933ca85d6a2b6;hpb=03134dc262125d1785891d6111eec58ca09b3b54;p=pspp-builds.git
diff --git a/src/ui/gui/psppire-selector.c b/src/ui/gui/psppire-selector.c
index d871d5d1..2b2b2ed5 100644
--- a/src/ui/gui/psppire-selector.c
+++ b/src/ui/gui/psppire-selector.c
@@ -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,6 +58,11 @@
#include
+#include "psppire-dictview.h"
+#include "psppire-var-view.h"
+
+
+
#include
#include
#include
@@ -146,6 +152,7 @@ enum
{
PROP_0,
PROP_ORIENTATION,
+ PROP_PRIMARY,
PROP_SOURCE_WIDGET,
PROP_DEST_WIDGET
};
@@ -170,6 +177,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,8 +221,6 @@ psppire_selector_get_property (GObject *object,
};
}
-
-
static void
psppire_selector_class_init (PsppireSelectorClass *class)
{
@@ -224,6 +233,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",
@@ -246,6 +264,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,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);
}
@@ -296,13 +320,77 @@ 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) */
+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 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 );
+ }
}
+static void
+on_realize (PsppireSelector *selector)
+{
+ PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
+ GtkTreeSelection* selection ;
+
+ 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 )
+ 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->primary_requested = FALSE;
selector->select_user_data = NULL;
selector->select_items = NULL;
selector->allow_selection = NULL;
@@ -330,6 +418,10 @@ psppire_selector_init (PsppireSelector *selector)
selector->row_activate_id = 0;
selector->source_select_id = 0;
+
+ g_signal_connect (selector, "realize",
+ G_CALLBACK (on_realize), NULL);
+
}
@@ -392,27 +484,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)
@@ -559,18 +630,6 @@ select_selection (PsppireSelector *selector)
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.
*/
@@ -591,6 +650,13 @@ on_activate (PsppireSelector *selector, gpointer data)
}
}
+static gboolean
+permissive_filter (GtkTreeModel *model, GtkTreeIter *iter,
+ PsppireSelector *selector)
+{
+ return FALSE;
+}
+
/* Default visibility filter for GtkTreeView DEST widget */
static gboolean
is_item_in_dest (GtkTreeModel *model, GtkTreeIter *iter,
@@ -685,7 +751,7 @@ static void
set_tree_view_source (PsppireSelector *selector,
GtkTreeView *source)
{
- GtkTreeSelection* selection ;
+
GList *list = NULL;
PsppireSelectorClass *class = g_type_class_peek (PSPPIRE_SELECTOR_TYPE);
@@ -715,23 +781,17 @@ set_tree_view_source (PsppireSelector *selector,
selector->filtered_source = GTK_TREE_MODEL_FILTER (model);
- 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);
+ else
+ list = g_list_append (list, selector);
+ g_hash_table_replace (class->source_hash, source, list);
+ }
}
- selection = gtk_tree_view_get_selection (source);
-
- if ( selector->row_activate_id )
- g_signal_handler_disconnect (source, selector->row_activate_id);
- selector->row_activate_id =
- g_signal_connect (source, "row-activated", G_CALLBACK (on_row_activate), selector);
-
- 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);
}
@@ -868,6 +928,16 @@ set_entry_dest (PsppireSelector *selector,
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 = permissive_filter;
+ }
+}
+
static void
update_subjects (PsppireSelector *selector)
{
@@ -876,11 +946,7 @@ update_subjects (PsppireSelector *selector)
if ( NULL == selector->dest )
return;
- if ( selector->filter == NULL)
- {
- if (GTK_IS_TREE_VIEW (selector->dest))
- selector->filter = is_item_in_dest;
- }
+ set_default_filter (selector);
if ( NULL == selector->source )
return;
@@ -916,21 +982,44 @@ 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);
+ }
+}
+
+
+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,
FilterItemsFunc *filter_func)
{
selector->filter = filter_func ;
-
- if ( selector->filter == NULL)
- {
- if (GTK_IS_TREE_VIEW (selector->dest))
- selector->filter = is_item_in_dest;
- }
+
+ set_default_filter (selector);
}
@@ -953,7 +1042,6 @@ psppire_selector_set_allow (PsppireSelector *selector, AllowSelectionFunc *allow
}
-
GType
psppire_selector_orientation_get_type (void)
{