[planner: 29/61] resource-dialog: Port type selector to GtkComboBoxText
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 29/61] resource-dialog: Port type selector to GtkComboBoxText
- Date: Sat, 12 Jun 2021 17:30:25 +0000 (UTC)
commit cff94c37ee5eb9d6868d6bba1c1dd368f56e1d5f
Author: Mart Raudsepp <leio gentoo org>
Date: Sun Dec 27 00:04:14 2020 +0200
resource-dialog: Port type selector to GtkComboBoxText
There are only Work and Material types, so just work with a
GtkComboBoxText and its active item indices, instead of tracking the
enum in a GtkListStore with GtkComboBox similar to how the old
GtkOptionMenu code did via g_object_set_data (but all the other code
for this option menu still assumed index placement anyways).
data/ui/resource-dialog.ui | 3 +-
src/planner-resource-dialog.c | 81 ++++++++++---------------------------------
2 files changed, 20 insertions(+), 64 deletions(-)
---
diff --git a/data/ui/resource-dialog.ui b/data/ui/resource-dialog.ui
index c8f3b23d..ae2a5992 100644
--- a/data/ui/resource-dialog.ui
+++ b/data/ui/resource-dialog.ui
@@ -177,10 +177,9 @@
</packing>
</child>
<child>
- <object class="GtkOptionMenu" id="menu_type">
+ <object class="GtkComboBoxText" id="menu_type">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="history">-1</property>
</object>
<packing>
<property name="left_attach">1</property>
diff --git a/src/planner-resource-dialog.c b/src/planner-resource-dialog.c
index fdc6b912..817efd7b 100644
--- a/src/planner-resource-dialog.c
+++ b/src/planner-resource-dialog.c
@@ -248,47 +248,12 @@ resource_dialog_find_calendar (DialogData *data,
}
static void
-resource_dialog_setup_option_menu (GtkWidget *option_menu,
- GCallback func,
- gpointer user_data,
- gconstpointer str1, ...)
-{
- GtkWidget *menu;
- GtkWidget *menu_item;
- gint i;
- va_list args;
- gconstpointer str;
- gint type;
-
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
- if (menu) {
- gtk_widget_destroy (menu);
- }
-
- menu = gtk_menu_new ();
-
- va_start (args, str1);
- for (str = str1, i = 0; str != NULL; str = va_arg (args, gpointer), i++) {
- menu_item = gtk_menu_item_new_with_label (str);
- gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
- type = va_arg (args, gint);
-
- g_object_set_data (G_OBJECT (menu_item),
- "data",
- GINT_TO_POINTER (type));
- if (func) {
- g_signal_connect (menu_item,
- "activate",
- func,
- user_data);
- }
- }
- va_end (args);
+resource_dialog_setup_combobox (GtkWidget *combo)
+{
+ GtkComboBoxText *combo_text = GTK_COMBO_BOX_TEXT (combo);
- gtk_widget_show (menu);
- gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
+ gtk_combo_box_text_append_text (combo_text, _("Work"));
+ gtk_combo_box_text_append_text (combo_text, _("Material"));
}
static void
@@ -353,19 +318,16 @@ resource_dialog_setup_option_groups (GtkWidget *menu_groups,
}
static gint
-resource_dialog_option_menu_get_type_selected (GtkWidget *option_menu)
-{
- GtkWidget *menu;
- GtkWidget *item;
- gint ret;
-
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
-
- item = gtk_menu_get_active (GTK_MENU (menu));
-
- ret = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "data"));
-
- return ret;
+resource_dialog_get_type_selected (GtkWidget *combo)
+{
+ switch (gtk_combo_box_get_active (GTK_COMBO_BOX (combo))) {
+ case 0:
+ return MRP_RESOURCE_TYPE_WORK;
+ case 1:
+ return MRP_RESOURCE_TYPE_MATERIAL;
+ default:
+ return MRP_RESOURCE_TYPE_NONE;
+ }
}
static MrpGroup *
@@ -992,7 +954,7 @@ resource_dialog_notify_type_cb (MrpResource *resource,
break;
}
- gtk_option_menu_set_history (GTK_OPTION_MENU (data->type_menu), index);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_menu), index);
g_signal_handlers_unblock_by_func (data->type_menu,
resource_dialog_type_changed_cb,
@@ -1006,7 +968,7 @@ resource_dialog_type_changed_cb (GtkWidget *w,
MrpResourceType type;
GValue value = { 0 };
- type = resource_dialog_option_menu_get_type_selected (data->type_menu);
+ type = resource_dialog_get_type_selected (data->type_menu);
g_value_init (&value, G_TYPE_INT);
g_value_set_int (&value, type);
@@ -1835,12 +1797,7 @@ planner_resource_dialog_new (PlannerWindow *window,
G_CALLBACK (resource_dialog_short_name_focus_in_cb),
data);
- resource_dialog_setup_option_menu (data->type_menu,
- NULL,
- NULL,
- _("Work"), MRP_RESOURCE_TYPE_WORK,
- _("Material"), MRP_RESOURCE_TYPE_MATERIAL,
- NULL);
+ resource_dialog_setup_combobox (data->type_menu);
/* Select the right type. */
switch (type) {
@@ -1853,7 +1810,7 @@ planner_resource_dialog_new (PlannerWindow *window,
break;
}
- gtk_option_menu_set_history (GTK_OPTION_MENU (data->type_menu), index);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (data->type_menu), index);
g_signal_connect (data->type_menu,
"changed",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]