[planner: 28/61] resource-dialog: Port group selector to GtkComboBox
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 28/61] resource-dialog: Port group selector to GtkComboBox
- Date: Sat, 12 Jun 2021 17:30:25 +0000 (UTC)
commit 3881c20bf0bf6422296b74d1e11ae6c8e6c8fe14
Author: Mart Raudsepp <leio gentoo org>
Date: Sat Dec 26 23:24:17 2020 +0200
resource-dialog: Port group selector to GtkComboBox
GtkOptionMenu (used before) has been deprecated for most of gtk2 times
and does not exist in gtk3.
data/ui/resource-dialog.ui | 3 +-
src/planner-resource-dialog.c | 104 ++++++++++++++++++++++++------------------
2 files changed, 60 insertions(+), 47 deletions(-)
---
diff --git a/data/ui/resource-dialog.ui b/data/ui/resource-dialog.ui
index de069a53..c8f3b23d 100644
--- a/data/ui/resource-dialog.ui
+++ b/data/ui/resource-dialog.ui
@@ -192,10 +192,9 @@
</packing>
</child>
<child>
- <object class="GtkOptionMenu" id="menu_group">
+ <object class="GtkComboBox" id="menu_group">
<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 73d9c845..fdc6b912 100644
--- a/src/planner-resource-dialog.c
+++ b/src/planner-resource-dialog.c
@@ -292,47 +292,64 @@ resource_dialog_setup_option_menu (GtkWidget *option_menu,
}
static void
-resource_dialog_setup_option_groups (GtkWidget *menu_groups,
- GList *groups)
+menu_groups_name (GtkCellLayout *layout,
+ GtkCellRenderer *cell,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
{
- GtkWidget *menu;
- GtkWidget *menu_item;
- gchar *name;
- GList *l;
-
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (menu_groups));
+ MrpGroup *group;
+ const gchar *name;
- if (menu) {
- gtk_widget_destroy (menu);
+ gtk_tree_model_get (model, iter, 0, &group, -1);
+ if (!group) {
+ name = _("(None)");
+ } else {
+ name = mrp_group_get_name (group);
+ if (!name) {
+ name = _("(No name)");
+ }
}
+ g_object_set (cell,
+ "text", name,
+ NULL);
+}
- menu = gtk_menu_new ();
+static void
+resource_dialog_setup_option_groups (GtkWidget *menu_groups,
+ GList *groups)
+{
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GList *l;
+ GtkCellRenderer *renderer;
+
+ store = gtk_list_store_new (1, MRP_TYPE_GROUP);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (menu_groups), GTK_TREE_MODEL (store));
+ g_object_unref (store);
/* Put "no group" at the top. */
- menu_item = gtk_menu_item_new_with_label (_("(None)"));
- gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, NULL,
+ -1);
for (l = groups; l; l = l->next) {
- g_object_get (G_OBJECT (l->data),
- "name", &name,
- NULL);
-
- if (name == NULL) {
- name = g_strdup (_("(No name)"));
- }
+ MrpGroup *group = l->data;
- menu_item = gtk_menu_item_new_with_label (name);
- gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
- g_object_set_data (G_OBJECT (menu_item),
- "data",
- l->data);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, group,
+ -1);
}
- gtk_widget_show (menu);
- gtk_option_menu_set_menu (GTK_OPTION_MENU (menu_groups), menu);
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (menu_groups),
+ renderer, TRUE);
+ gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (menu_groups),
+ renderer,
+ menu_groups_name,
+ NULL, NULL);
}
static gint
@@ -352,19 +369,17 @@ resource_dialog_option_menu_get_type_selected (GtkWidget *option_menu)
}
static MrpGroup *
-resource_dialog_option_menu_get_group_selected (GtkWidget *option_menu)
+resource_dialog_get_group_selected (GtkWidget *combo)
{
- GtkWidget *menu;
- GtkWidget *item;
- MrpGroup *ret;
-
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
-
- item = gtk_menu_get_active (GTK_MENU (menu));
-
- ret = g_object_get_data (G_OBJECT (item), "data");
+ GtkTreeIter iter;
+ MrpGroup *group;
- return ret;
+ gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
+ gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo)),
+ &iter,
+ 0, &group,
+ -1);
+ return group;
}
static void
@@ -1039,7 +1054,7 @@ resource_dialog_notify_group_cb (MrpResource *resource,
index = g_list_index (groups, group) + 1;
}
- gtk_option_menu_set_history (GTK_OPTION_MENU (data->group_menu), index);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (data->group_menu), index);
g_signal_handlers_unblock_by_func (data->group_menu,
resource_dialog_group_changed_cb,
@@ -1053,7 +1068,7 @@ resource_dialog_group_changed_cb (GtkWidget *w,
MrpGroup *group;
GValue value = { 0 };
- group = resource_dialog_option_menu_get_group_selected (data->group_menu);
+ group = resource_dialog_get_group_selected (data->group_menu);
g_value_init (&value, MRP_TYPE_GROUP);
g_value_set_object (&value, group);
@@ -1855,8 +1870,7 @@ planner_resource_dialog_new (PlannerWindow *window,
index = g_list_index (groups, group) + 1;
}
- gtk_option_menu_set_history (GTK_OPTION_MENU (data->group_menu),
- index);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (data->group_menu), index);
g_signal_connect (data->group_menu,
"changed",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]