[planner: 52/61] resource-view: Port resource type cell to GtkCellRendererCombo
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 52/61] resource-view: Port resource type cell to GtkCellRendererCombo
- Date: Sat, 12 Jun 2021 17:30:27 +0000 (UTC)
commit 2179b5669198c72f2b3e665a8dc385179372efe6
Author: Mart Raudsepp <leio gentoo org>
Date: Sun Mar 14 12:10:51 2021 +0200
resource-view: Port resource type cell to GtkCellRendererCombo
PlannerCellRendererList appears to be a custom implementation of a combo
cell renderer, which appears to predate GtkCellRendererCombo.
PlannerCellRendererList and PlannerCellRendererPopup accesses internal
members of GtkCellRendererText and GtkEntry, which won't work with GTK3.
Instead of trying to make it work, port it over to GtkCellRendererCombo
instead, as it serves all our needs, so we don't need a custom cell
renderer here.
Compared to the PlannerCellRendererList, the new code intentionally does
not enable free-form text entry in the resource type cells, as that did
not work at all and seemed to be a side-effect of the custom cell
renderer, as it did not support disabling the free-form text entry.
src/planner-resource-view.c | 113 +++++++++++++++++++-------------------------
1 file changed, 48 insertions(+), 65 deletions(-)
---
diff --git a/src/planner-resource-view.c b/src/planner-resource-view.c
index 273523e1..94243273 100644
--- a/src/planner-resource-view.c
+++ b/src/planner-resource-view.c
@@ -67,6 +67,12 @@ enum {
NUM_OF_COLS
};
+enum {
+ COLUMN_TYPE_TEXT,
+ COLUMN_TYPE_RESOURCE_TYPE,
+ NUM_TYPE_COLUMNS
+};
+
static void resource_view_finalize (GObject *object);
static void resource_view_insert_resource_cb (GtkAction *action,
gpointer data);
@@ -99,9 +105,9 @@ static void resource_view_cell_email_edited (GtkCellRendererTex
gchar *path_string,
gchar *new_text,
gpointer user_data);
-static void resource_view_cell_type_edited (PlannerCellRendererList *cell,
+static void resource_view_cell_type_changed (GtkCellRendererCombo *combo,
gchar *path_string,
- gchar *new_text,
+ GtkTreeIter *new_iter,
gpointer user_data);
static void resource_view_cell_group_edited (PlannerCellRendererList *cell,
gchar *path_string,
@@ -115,13 +121,7 @@ static void resource_view_property_value_edited (GtkCellRendererTex
gchar *path_string,
gchar *new_text,
ColPropertyData *data);
-static void resource_view_cell_type_show_popup (PlannerCellRendererList *cell,
- const gchar *path_string,
- gint x1,
- gint y1,
- gint x2,
- gint y2,
- PlannerView *view);
+static GtkTreeModel * resource_view_cell_type_create_model ();
static void resource_view_cell_group_show_popup (PlannerCellRendererList *cell,
const gchar *path_string,
gint x1,
@@ -1100,6 +1100,7 @@ resource_view_setup_tree_view (PlannerView *view)
{
GtkTreeView *tree_view;
GtkTreeViewColumn *col;
+ GtkTreeModel *model;
GtkCellRenderer *cell;
tree_view = GTK_TREE_VIEW (PLANNER_RESOURCE_VIEW (view)->priv->tree_view);
@@ -1170,12 +1171,23 @@ resource_view_setup_tree_view (PlannerView *view)
view);
/* Type */
- cell = planner_cell_renderer_list_new ();
- g_object_set (cell, "editable", TRUE, NULL);
+ cell = gtk_cell_renderer_combo_new ();
+ model = resource_view_cell_type_create_model ();
+
+ g_object_set (cell,
+ "editable", TRUE,
+ "has-entry", FALSE,
+ "model", model,
+ "text-column", COLUMN_TYPE_TEXT,
+ NULL);
+
+ g_object_unref (model);
col = gtk_tree_view_column_new_with_attributes (_("Type"), cell, NULL);
gtk_tree_view_column_set_resizable (col, TRUE);
+ /* TODO: Consider using "text" attribute instead of custom cell data
+ * func, after making sure it works with the "data-func" property */
gtk_tree_view_column_set_cell_data_func (col, cell,
resource_view_type_data_func,
NULL, NULL);
@@ -1190,12 +1202,8 @@ resource_view_setup_tree_view (PlannerView *view)
view);
g_signal_connect (cell,
- "edited",
- G_CALLBACK (resource_view_cell_type_edited),
- view);
- g_signal_connect (cell,
- "show-popup",
- G_CALLBACK (resource_view_cell_type_show_popup),
+ "changed",
+ G_CALLBACK (resource_view_cell_type_changed),
view);
/* Group */
@@ -1613,16 +1621,16 @@ resource_view_cell_cost_edited (GtkCellRendererText *cell,
}
static void
-resource_view_cell_type_edited (PlannerCellRendererList *cell,
- gchar *path_string,
- gchar *new_text,
- gpointer user_data)
+resource_view_cell_type_changed (GtkCellRendererCombo *combo,
+ gchar *path_string,
+ GtkTreeIter *new_iter,
+ gpointer user_data)
{
PlannerView *view;
MrpResource *resource;
MrpResourceType type;
GtkTreeView *tree_view;
- GtkTreeModel *model;
+ GtkTreeModel *model, *combo_model;
GtkTreePath *path;
GtkTreeIter iter;
GValue value = { 0 };
@@ -1639,11 +1647,8 @@ resource_view_cell_type_edited (PlannerCellRendererList *cell,
gtk_tree_model_get (model, &iter, COL_RESOURCE, &resource, -1);
- if (cell->selected_index == 0) {
- type = MRP_RESOURCE_TYPE_WORK;
- } else {
- type = MRP_RESOURCE_TYPE_MATERIAL;
- }
+ g_object_get (combo, "model", &combo_model, NULL);
+ gtk_tree_model_get (combo_model, new_iter, COLUMN_TYPE_RESOURCE_TYPE, &type, -1);
g_value_init (&value, G_TYPE_INT);
g_value_set_int (&value, type);
@@ -1653,47 +1658,25 @@ resource_view_cell_type_edited (PlannerCellRendererList *cell,
gtk_tree_path_free (path);
}
-static void
-resource_view_cell_type_show_popup (PlannerCellRendererList *cell,
- const gchar *path_string,
- gint x1,
- gint y1,
- gint x2,
- gint y2,
- PlannerView *view)
+static GtkTreeModel *
+resource_view_cell_type_create_model ()
{
- GtkTreeView *tree_view;
- GtkTreeModel *model;
- GtkTreePath *path;
- GtkTreeIter iter;
- MrpResource *resource;
- GList *list;
- MrpResourceType type;
-
- tree_view = GTK_TREE_VIEW (PLANNER_RESOURCE_VIEW (view)->priv->tree_view);
- model = gtk_tree_view_get_model (tree_view);
-
- path = gtk_tree_path_new_from_string (path_string);
-
- gtk_tree_model_get_iter (model, &iter, path);
-
- gtk_tree_model_get (model, &iter, COL_RESOURCE, &resource, -1);
-
- list = NULL;
- list = g_list_append (list, g_strdup (_("Work")));
- list = g_list_append (list, g_strdup (_("Material")));
-
- cell->list = list;
-
- mrp_object_get (resource, "type", &type, NULL);
+ GtkListStore *model;
+ GtkTreeIter iter;
- if (type == MRP_RESOURCE_TYPE_WORK) {
- cell->selected_index = 0;
- } else {
- cell->selected_index = 1;
- }
+ model = gtk_list_store_new (NUM_TYPE_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
- gtk_tree_path_free (path);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COLUMN_TYPE_TEXT, _("Work"),
+ COLUMN_TYPE_RESOURCE_TYPE, MRP_RESOURCE_TYPE_WORK,
+ -1);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COLUMN_TYPE_TEXT, _("Material"),
+ COLUMN_TYPE_RESOURCE_TYPE, MRP_RESOURCE_TYPE_MATERIAL,
+ -1);
+ return GTK_TREE_MODEL (model);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]