};
+static void on_activate (PsppireSelector *selector, gpointer data);
+
+
static void
psppire_selector_set_property (GObject *object,
guint prop_id,
g_param_spec_enum ("orientation",
"Orientation",
"Where the selector is relative to its subjects",
- G_TYPE_PSPPIRE_SELECTOR_ORIENTATION,
+ PSPPIRE_TYPE_SELECTOR_ORIENTATION,
PSPPIRE_SELECT_SOURCE_BEFORE_DEST /* default value */,
G_PARAM_CONSTRUCT_ONLY |G_PARAM_READWRITE);
}
+
static void
psppire_selector_init (PsppireSelector *selector)
{
selector->arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
selector->filtered_source = NULL;
+ selector->action = gtk_action_new ("select", NULL, NULL, "pspp-stock-select");
+
+ 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;
}
set_direction (selector, PSPPIRE_SELECTOR_SOURCE_TO_DEST);
- if ( GTK_IS_ENTRY (selector->dest) )
+ if ( selector->allow_selection )
{
- gtk_widget_set_sensitive (GTK_WIDGET (selector),
+ 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 );
}
{
PsppireSelector *selector = data;
+ gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (selector->source)));
+
set_direction (selector, PSPPIRE_SELECTOR_DEST_TO_SOURCE);
}
selector->select_items (child_iter,
selector->dest,
- childmodel);
+ childmodel,
+ selector->select_user_data
+ );
}
g_list_foreach (selected_rows, (GFunc) gtk_tree_path_free, NULL);
{
PsppireSelector *selector = data;
- select_selection (selector);
+ gtk_action_activate (selector->action);
}
-/* Callback for when the selector button is clicked */
+/* Callback for when the selector button is clicked,
+ or other event which causes the selector's action to occur.
+ */
static void
-on_click (PsppireSelector *selector, gpointer data)
+on_activate (PsppireSelector *selector, gpointer data)
{
switch (selector->direction)
{
do
{
+ int x;
GValue value = {0};
+ GValue int_value = {0};
gtk_tree_model_get_value (dest_model, &dest_iter, 0, &value);
- if ( g_value_get_int (&value) == index)
+ g_value_init (&int_value, G_TYPE_INT);
+
+ g_value_transform (&value, &int_value);
+
+ x = g_value_get_int (&int_value);
+
+ g_value_unset (&int_value);
+ g_value_unset (&value);
+
+ if ( x == index )
return TRUE;
}
while (gtk_tree_model_iter_next (dest_model, &dest_iter));
{
PsppireSelector * selector = data;
+ gtk_tree_selection_unselect_all (gtk_tree_view_get_selection (GTK_TREE_VIEW (selector->source)));
set_direction (selector, PSPPIRE_SELECTOR_DEST_TO_SOURCE);
return FALSE;
GtkWidget *source,
GtkWidget *dest,
SelectItemsFunc *select_func,
- FilterItemsFunc *filter_func )
+ FilterItemsFunc *filter_func,
+ gpointer user_data)
{
g_assert(selector);
selector->source = source;
selector->dest = dest;
+ selector->select_user_data = user_data;
if ( filter_func == NULL)
{
selector->filter = is_item_in_dest;
}
- g_signal_connect (selector, "clicked", G_CALLBACK (on_click), NULL);
-
if ( GTK_IS_TREE_VIEW (source))
set_tree_view_source (selector, GTK_TREE_VIEW (source) );
else
g_assert ( GTK_IS_TREE_MODEL_FILTER (selector->filtered_source));
- if ( GTK_IS_TREE_VIEW (dest))
+ if ( NULL == dest)
+ ;
+ else if ( GTK_IS_TREE_VIEW (dest))
set_tree_view_dest (selector, GTK_TREE_VIEW (dest));
else if ( GTK_IS_ENTRY (dest))
+void
+psppire_selector_set_allow (PsppireSelector *selector , AllowSelectionFunc *allow)
+{
+ selector->allow_selection = allow;
+}
+
+
+
GType
psppire_selector_orientation_get_type (void)
{