Compare commits
3 Commits
amolenaar/
...
dropdown-s
Author | SHA1 | Date | |
---|---|---|---|
|
9dfa663990 | ||
|
831b1e1cde | ||
|
801a261250 |
@@ -360,7 +360,7 @@ combo_changed (GtkDropDown *combo,
|
|||||||
char **accels;
|
char **accels;
|
||||||
char *str;
|
char *str;
|
||||||
|
|
||||||
action = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_drop_down_get_selected_item (combo)));
|
action = gtk_drop_down_get_selected_string (combo);
|
||||||
|
|
||||||
if (!action)
|
if (!action)
|
||||||
return;
|
return;
|
||||||
@@ -400,7 +400,7 @@ response (GtkDialog *dialog,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
action = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_drop_down_get_selected_item (combo)));
|
action = gtk_drop_down_get_selected_string (combo);
|
||||||
|
|
||||||
if (!action)
|
if (!action)
|
||||||
return;
|
return;
|
||||||
|
@@ -133,6 +133,7 @@ enum
|
|||||||
PROP_MODEL,
|
PROP_MODEL,
|
||||||
PROP_SELECTED,
|
PROP_SELECTED,
|
||||||
PROP_SELECTED_ITEM,
|
PROP_SELECTED_ITEM,
|
||||||
|
PROP_SELECTED_STRING,
|
||||||
PROP_ENABLE_SEARCH,
|
PROP_ENABLE_SEARCH,
|
||||||
PROP_EXPRESSION,
|
PROP_EXPRESSION,
|
||||||
PROP_SHOW_ARROW,
|
PROP_SHOW_ARROW,
|
||||||
@@ -247,6 +248,7 @@ selection_item_changed (GtkSingleSelection *selection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]);
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]);
|
||||||
|
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_STRING]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -358,6 +360,10 @@ gtk_drop_down_get_property (GObject *object,
|
|||||||
g_value_set_object (value, gtk_drop_down_get_selected_item (self));
|
g_value_set_object (value, gtk_drop_down_get_selected_item (self));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_SELECTED_STRING:
|
||||||
|
g_value_set_string (value, gtk_drop_down_get_selected_string (self));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_ENABLE_SEARCH:
|
case PROP_ENABLE_SEARCH:
|
||||||
g_value_set_boolean (value, self->enable_search);
|
g_value_set_boolean (value, self->enable_search);
|
||||||
break;
|
break;
|
||||||
@@ -402,6 +408,10 @@ gtk_drop_down_set_property (GObject *object,
|
|||||||
gtk_drop_down_set_selected (self, g_value_get_uint (value));
|
gtk_drop_down_set_selected (self, g_value_get_uint (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_SELECTED_STRING:
|
||||||
|
gtk_drop_down_set_selected_string (self, g_value_get_string (value));
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_ENABLE_SEARCH:
|
case PROP_ENABLE_SEARCH:
|
||||||
gtk_drop_down_set_enable_search (self, g_value_get_boolean (value));
|
gtk_drop_down_set_enable_search (self, g_value_get_boolean (value));
|
||||||
break;
|
break;
|
||||||
@@ -545,6 +555,22 @@ gtk_drop_down_class_init (GtkDropDownClass *klass)
|
|||||||
G_TYPE_OBJECT,
|
G_TYPE_OBJECT,
|
||||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GtkDropDown:selected-string: (attributes org.gtk.Property.get=gtk_drop_down_get_selected_string org.gtk.Property.set=gtk_drop_down_set_selected_string)
|
||||||
|
*
|
||||||
|
* The value of the string property of the selected item,
|
||||||
|
* if it is a [class@Gtk.StringObject].
|
||||||
|
*
|
||||||
|
* This is only useful for dropdowns with a [class@Gtk.StringList] as model,
|
||||||
|
* such as those created by [ctor@Gtk.DropDown.new_from_strings].
|
||||||
|
*
|
||||||
|
* Since: 4.10
|
||||||
|
*/
|
||||||
|
properties[PROP_SELECTED_STRING] =
|
||||||
|
g_param_spec_string ("selected-string", NULL, NULL,
|
||||||
|
NULL,
|
||||||
|
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GtkDropDown:enable-search: (attributes org.gtk.Property.get=gtk_drop_down_get_enable_search org.gtk.Property.set=gtk_drop_down_set_enable_search)
|
* GtkDropDown:enable-search: (attributes org.gtk.Property.get=gtk_drop_down_get_enable_search org.gtk.Property.set=gtk_drop_down_set_enable_search)
|
||||||
*
|
*
|
||||||
@@ -784,8 +810,7 @@ gtk_drop_down_new (GListModel *model,
|
|||||||
* gtk_drop_down_new_from_strings:
|
* gtk_drop_down_new_from_strings:
|
||||||
* @strings: (array zero-terminated=1): The strings to put in the dropdown
|
* @strings: (array zero-terminated=1): The strings to put in the dropdown
|
||||||
*
|
*
|
||||||
* Creates a new `GtkDropDown` that is populated with
|
* Creates a new `GtkDropDown` that is populated with the strings.
|
||||||
* the strings.
|
|
||||||
*
|
*
|
||||||
* Returns: a new `GtkDropDown`
|
* Returns: a new `GtkDropDown`
|
||||||
*/
|
*/
|
||||||
@@ -1016,6 +1041,81 @@ gtk_drop_down_get_selected_item (GtkDropDown *self)
|
|||||||
return gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (self->selection));
|
return gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (self->selection));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_drop_down_get_selected_string: (attributes org.gtk.Method.get_property=selected-string)
|
||||||
|
* @self: a `GtkDropDown`
|
||||||
|
*
|
||||||
|
* Gets the string value for the selected [class@Gtk.StringObject].
|
||||||
|
*
|
||||||
|
* If no item is selected, or items are of another type, %NULL is returned.
|
||||||
|
*
|
||||||
|
* This function is meant for dropdowns with a [class@Gtk.StringList] as model,
|
||||||
|
* such as those created by [ctor@Gtk.DropDown.new_from_strings].
|
||||||
|
*
|
||||||
|
* Returns: (transfer none) (nullable): The string value for selected item
|
||||||
|
*
|
||||||
|
* Since: 4.10
|
||||||
|
*/
|
||||||
|
const char *
|
||||||
|
gtk_drop_down_get_selected_string (GtkDropDown *self)
|
||||||
|
{
|
||||||
|
gpointer item;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GTK_IS_DROP_DOWN (self), NULL);
|
||||||
|
|
||||||
|
if (self->selection == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
item = gtk_single_selection_get_selected_item (GTK_SINGLE_SELECTION (self->selection));
|
||||||
|
|
||||||
|
if (GTK_IS_STRING_OBJECT (item))
|
||||||
|
return gtk_string_object_get_string (GTK_STRING_OBJECT (item));
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_drop_down_set_selected_string:
|
||||||
|
* @self: a `GtkDropDown`
|
||||||
|
* @string: the string to select
|
||||||
|
*
|
||||||
|
* Selects the first [class@Gtk.StringObject] whose string property
|
||||||
|
* matches @string.
|
||||||
|
*
|
||||||
|
* If items are not `GtkStringObjects`, the selection is not changed.
|
||||||
|
*
|
||||||
|
* This function is meant for dropdowns with a [class@Gtk.StringList] as model,
|
||||||
|
* such as those created by [ctor@Gtk.DropDown.new_from_strings].
|
||||||
|
*
|
||||||
|
* Since: 4.10
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gtk_drop_down_set_selected_string (GtkDropDown *self,
|
||||||
|
const char *string)
|
||||||
|
{
|
||||||
|
g_return_if_fail (GTK_IS_DROP_DOWN (self));
|
||||||
|
g_return_if_fail (string != NULL);
|
||||||
|
|
||||||
|
if (self->selection == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (guint i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->selection)); i++)
|
||||||
|
{
|
||||||
|
gpointer item = g_list_model_get_item (G_LIST_MODEL (self->selection), i);
|
||||||
|
|
||||||
|
g_object_unref (item);
|
||||||
|
|
||||||
|
if (!GTK_IS_STRING_OBJECT (item))
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (g_str_equal (gtk_string_object_get_string (GTK_STRING_OBJECT (item)), string))
|
||||||
|
{
|
||||||
|
gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (self->selection), i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_drop_down_set_enable_search: (attributes org.gtk.Method.set_property=enable-search)
|
* gtk_drop_down_set_enable_search: (attributes org.gtk.Method.set_property=enable-search)
|
||||||
* @self: a `GtkDropDown`
|
* @self: a `GtkDropDown`
|
||||||
|
@@ -52,6 +52,13 @@ guint gtk_drop_down_get_selected (GtkDropDown
|
|||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
gpointer gtk_drop_down_get_selected_item (GtkDropDown *self);
|
gpointer gtk_drop_down_get_selected_item (GtkDropDown *self);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
const char * gtk_drop_down_get_selected_string (GtkDropDown *self);
|
||||||
|
|
||||||
|
GDK_AVAILABLE_IN_4_10
|
||||||
|
void gtk_drop_down_set_selected_string (GtkDropDown *self,
|
||||||
|
const char *string);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
void gtk_drop_down_set_factory (GtkDropDown *self,
|
void gtk_drop_down_set_factory (GtkDropDown *self,
|
||||||
GtkListItemFactory *factory);
|
GtkListItemFactory *factory);
|
||||||
|
@@ -7338,8 +7338,6 @@ gtk_file_chooser_widget_add_choice (GtkFileChooser *chooser,
|
|||||||
gtk_box_append (GTK_BOX (box), gtk_label_new (label));
|
gtk_box_append (GTK_BOX (box), gtk_label_new (label));
|
||||||
|
|
||||||
combo = gtk_drop_down_new_from_strings ((const char * const *)option_labels);
|
combo = gtk_drop_down_new_from_strings ((const char * const *)option_labels);
|
||||||
g_object_set_data_full (G_OBJECT (combo), "options",
|
|
||||||
g_strdupv ((char **)options), (GDestroyNotify)g_strfreev);
|
|
||||||
g_hash_table_insert (impl->choices, g_strdup (id), combo);
|
g_hash_table_insert (impl->choices, g_strdup (id), combo);
|
||||||
gtk_box_append (GTK_BOX (box), combo);
|
gtk_box_append (GTK_BOX (box), combo);
|
||||||
|
|
||||||
@@ -7396,21 +7394,8 @@ gtk_file_chooser_widget_set_choice (GtkFileChooser *chooser,
|
|||||||
|
|
||||||
if (GTK_IS_BOX (widget))
|
if (GTK_IS_BOX (widget))
|
||||||
{
|
{
|
||||||
guint i;
|
GtkWidget *dropdown = gtk_widget_get_last_child (widget);
|
||||||
const char **options;
|
gtk_drop_down_set_selected_string (GTK_DROP_DOWN (dropdown), option);
|
||||||
GtkWidget *dropdown;
|
|
||||||
|
|
||||||
dropdown = gtk_widget_get_last_child (widget);
|
|
||||||
|
|
||||||
options = (const char **) g_object_get_data (G_OBJECT (dropdown), "options");
|
|
||||||
for (i = 0; options[i]; i++)
|
|
||||||
{
|
|
||||||
if (strcmp (option, options[i]) == 0)
|
|
||||||
{
|
|
||||||
gtk_drop_down_set_selected (GTK_DROP_DOWN (dropdown), i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (GTK_IS_CHECK_BUTTON (widget))
|
else if (GTK_IS_CHECK_BUTTON (widget))
|
||||||
gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), g_str_equal (option, "true"));
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (widget), g_str_equal (option, "true"));
|
||||||
@@ -7428,19 +7413,9 @@ gtk_file_chooser_widget_get_choice (GtkFileChooser *chooser,
|
|||||||
|
|
||||||
widget = (GtkWidget *)g_hash_table_lookup (impl->choices, id);
|
widget = (GtkWidget *)g_hash_table_lookup (impl->choices, id);
|
||||||
if (GTK_IS_DROP_DOWN (widget))
|
if (GTK_IS_DROP_DOWN (widget))
|
||||||
{
|
return gtk_drop_down_get_selected_string (GTK_DROP_DOWN (widget));
|
||||||
const char **options;
|
|
||||||
guint selected;
|
|
||||||
|
|
||||||
options = (const char **) g_object_get_data (G_OBJECT (widget), "options");
|
|
||||||
selected = gtk_drop_down_get_selected (GTK_DROP_DOWN (widget));
|
|
||||||
|
|
||||||
return options[selected];
|
|
||||||
}
|
|
||||||
else if (GTK_IS_CHECK_BUTTON (widget))
|
else if (GTK_IS_CHECK_BUTTON (widget))
|
||||||
{
|
return gtk_check_button_get_active (GTK_CHECK_BUTTON (widget)) ? "true" : "false";
|
||||||
return gtk_check_button_get_active (GTK_CHECK_BUTTON (widget)) ? "true" : "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user