[planner: 53/61] resource-view: Port resource group cell to GtkCellRendererCombo
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 53/61] resource-view: Port resource group cell to GtkCellRendererCombo
- Date: Sat, 12 Jun 2021 17:30:28 +0000 (UTC)
commit 408a796ac360276b6064daa919a39359effc4c70
Author: Mart Raudsepp <leio gentoo org>
Date: Sat Mar 20 19:30:51 2021 +0200
resource-view: Port resource group 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 | 207 +++++++++++++++++++++-----------------------
1 file changed, 99 insertions(+), 108 deletions(-)
---
diff --git a/src/planner-resource-view.c b/src/planner-resource-view.c
index 94243273..5d21580e 100644
--- a/src/planner-resource-view.c
+++ b/src/planner-resource-view.c
@@ -32,7 +32,6 @@
#include <libplanner/mrp-project.h>
#include "libplanner/mrp-paths.h"
#include "planner-resource-view.h"
-#include "planner-cell-renderer-list.h"
#include "planner-group-dialog.h"
#include "planner-format.h"
#include "planner-resource-dialog.h"
@@ -47,6 +46,7 @@ struct _PlannerResourceViewPriv {
GtkTreeView *tree_view;
GHashTable *property_to_column;
+ GtkCellRenderer *group_combo;
GtkWidget *group_dialog;
GtkWidget *resource_input_dialog;
@@ -73,6 +73,12 @@ enum {
NUM_TYPE_COLUMNS
};
+enum {
+ COLUMN_GROUP_TEXT,
+ COLUMN_GROUP_GROUP,
+ NUM_GROUP_COLUMNS
+};
+
static void resource_view_finalize (GObject *object);
static void resource_view_insert_resource_cb (GtkAction *action,
gpointer data);
@@ -109,10 +115,15 @@ static void resource_view_cell_type_changed (GtkCellRendererCom
gchar *path_string,
GtkTreeIter *new_iter,
gpointer user_data);
-static void resource_view_cell_group_edited (PlannerCellRendererList *cell,
+static void resource_view_cell_group_changed (GtkCellRendererCombo *combo,
gchar *path_string,
- gchar *new_text,
+ GtkTreeIter *new_iter,
gpointer user_data);
+static void resource_view_cell_groups_changed_cb (PlannerResourceView *view,
+ GParamSpec *spec,
+ gpointer user_data);
+static GtkTreeModel * resource_view_cell_group_create_model (PlannerResourceView *self,
+ MrpProject *project);
static void resource_view_cell_cost_edited (GtkCellRendererText *cell,
gchar *path_string,
gchar *new_text,
@@ -122,15 +133,6 @@ static void resource_view_property_value_edited (GtkCellRendererTex
gchar *new_text,
ColPropertyData *data);
static GtkTreeModel * resource_view_cell_type_create_model ();
-static void resource_view_cell_group_show_popup (PlannerCellRendererList *cell,
- const gchar *path_string,
- gint x1,
- gint y1,
- gint x2,
- gint y2,
- PlannerView *view);
-static void resource_view_cell_group_hide_popup (PlannerCellRendererList *cell,
- PlannerView *view);
static void resource_view_edit_groups_cb (GtkAction *action,
gpointer data);
static void resource_view_project_loaded_cb (MrpProject *project,
@@ -504,6 +506,15 @@ resource_view_get_widget (PlannerView *view)
G_CALLBACK (resource_view_resource_removed_cb),
view);
+ g_signal_connect_swapped (project,
+ "group_added",
+ G_CALLBACK (resource_view_cell_groups_changed_cb),
+ view);
+ g_signal_connect_swapped (project,
+ "group_removed",
+ G_CALLBACK (resource_view_cell_groups_changed_cb),
+ view);
+
model = GTK_TREE_MODEL (gtk_list_store_new (NUM_OF_COLS,
G_TYPE_POINTER));
@@ -1098,12 +1109,14 @@ resource_view_button_press_event (GtkTreeView *tv,
static void
resource_view_setup_tree_view (PlannerView *view)
{
+ PlannerResourceView *resource_view;
GtkTreeView *tree_view;
GtkTreeViewColumn *col;
GtkTreeModel *model;
GtkCellRenderer *cell;
- tree_view = GTK_TREE_VIEW (PLANNER_RESOURCE_VIEW (view)->priv->tree_view);
+ resource_view = PLANNER_RESOURCE_VIEW (view);
+ tree_view = GTK_TREE_VIEW (resource_view->priv->tree_view);
gtk_tree_view_set_rules_hint (tree_view, TRUE);
@@ -1207,8 +1220,19 @@ resource_view_setup_tree_view (PlannerView *view)
view);
/* Group */
- cell = planner_cell_renderer_list_new ();
- g_object_set (cell, "editable", TRUE, NULL);
+ cell = gtk_cell_renderer_combo_new ();
+ resource_view->priv->group_combo = cell;
+ model = resource_view_cell_group_create_model (resource_view,
+ planner_window_get_project (view->main_window));
+
+ g_object_set (cell,
+ "editable", TRUE,
+ "has-entry", FALSE,
+ "model", model,
+ "text-column", COLUMN_GROUP_TEXT,
+ NULL);
+
+ g_object_unref (model);
col = gtk_tree_view_column_new_with_attributes (_("Group"),
cell, NULL);
@@ -1228,17 +1252,9 @@ resource_view_setup_tree_view (PlannerView *view)
view);
g_signal_connect (cell,
- "edited",
- G_CALLBACK (resource_view_cell_group_edited),
- view);
- g_signal_connect (cell,
- "show-popup",
- G_CALLBACK (resource_view_cell_group_show_popup),
+ "changed",
+ G_CALLBACK (resource_view_cell_group_changed),
view);
- g_signal_connect_after (cell,
- "hide-popup",
- G_CALLBACK (resource_view_cell_group_hide_popup),
- view);
/* Email */
cell = gtk_cell_renderer_text_new ();
@@ -1664,6 +1680,7 @@ resource_view_cell_type_create_model ()
GtkListStore *model;
GtkTreeIter iter;
+ /* TODO: Unify the model with the combobox in "Edit resource properties" */
model = gtk_list_store_new (NUM_TYPE_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
gtk_list_store_append (model, &iter);
@@ -1680,19 +1697,18 @@ resource_view_cell_type_create_model ()
}
static void
-resource_view_cell_group_edited (PlannerCellRendererList *cell,
- gchar *path_string,
- gchar *new_text,
- gpointer user_data)
+resource_view_cell_group_changed (GtkCellRendererCombo *combo,
+ gchar *path_string,
+ GtkTreeIter *new_iter,
+ gpointer user_data)
{
PlannerView *view;
MrpResource *resource;
MrpGroup *group;
GtkTreeView *tree_view;
- GtkTreeModel *model;
+ GtkTreeModel *model, *combo_model;
GtkTreePath *path;
GtkTreeIter iter;
- GList *list;
GValue value = { 0 };
view = PLANNER_VIEW (user_data);
@@ -1707,15 +1723,8 @@ resource_view_cell_group_edited (PlannerCellRendererList *cell,
gtk_tree_model_get (model, &iter, COL_RESOURCE, &resource, -1);
- list = g_list_nth (cell->user_data, cell->selected_index);
- if (list == NULL) {
- /* We should probably parse the string here and set
- * the right group. See #110.
- */
- return;
- }
-
- group = list->data;
+ g_object_get (combo, "model", &combo_model, NULL);
+ gtk_tree_model_get (combo_model, new_iter, COLUMN_GROUP_GROUP, &group, -1);
g_value_init (&value, MRP_TYPE_GROUP);
g_value_set_object (&value, group);
@@ -1819,88 +1828,66 @@ resource_view_property_value_edited (GtkCellRendererText *cell,
}
static void
-resource_view_cell_group_show_popup (PlannerCellRendererList *cell,
- const gchar *path_string,
- gint x1,
- gint y1,
- gint x2,
- gint y2,
- PlannerView *view)
+resource_view_tree_setup_groups_model (PlannerResourceView *self,
+ MrpProject *project)
{
- GtkTreeView *tree_view;
- GtkTreeModel *model;
- GtkTreeIter iter;
- GtkTreePath *path;
- GList *list;
- MrpProject *project;
- MrpResource *resource;
- MrpGroup *group;
- MrpGroup *current_group;
- GList *groups, *l;
- gchar *name;
- gint i, index;
-
- tree_view = PLANNER_RESOURCE_VIEW (view)->priv->tree_view;
-
- model = gtk_tree_view_get_model (tree_view);
+ GtkTreeModel *model;
- path = gtk_tree_path_new_from_string (path_string);
+ model = resource_view_cell_group_create_model (self, project);
+ g_object_set (self->priv->group_combo, "model", model, NULL);
+ g_object_unref (model);
+}
- gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path);
+static void
+resource_view_cell_groups_changed_cb (PlannerResourceView *view,
+ GParamSpec *spec,
+ gpointer user_data)
+{
+ MrpProject *project;
+ project = planner_window_get_project (PLANNER_VIEW (view)->main_window);
+ resource_view_tree_setup_groups_model (view, project);
+}
- project = planner_window_get_project (view->main_window);
+static GtkTreeModel *
+resource_view_cell_group_create_model (PlannerResourceView *view,
+ MrpProject *project)
+{
+ GtkListStore *model;
+ GtkTreeIter iter;
+ GList *groups, *l;
+ MrpGroup *group;
+ gchar *group_name;
- gtk_tree_model_get (model, &iter, COL_RESOURCE, &resource, -1);
+ /* TODO: Unify the model with the combobox in "Edit resource properties" */
+ model = gtk_list_store_new (NUM_GROUP_COLUMNS, G_TYPE_STRING, MRP_TYPE_GROUP);
- mrp_object_get (resource,
- "group", ¤t_group,
- NULL);
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COLUMN_GROUP_TEXT, _("(None)"),
+ COLUMN_GROUP_GROUP, NULL,
+ -1);
- i = 0;
- index = 0;
- list = NULL;
- groups = g_list_copy (mrp_project_get_groups (project));
- groups = g_list_prepend (groups, NULL);
+ groups = mrp_project_get_groups (project);
for (l = groups; l; l = l->next) {
group = l->data;
+ mrp_object_get (group, "name", &group_name, NULL);
- if (group != NULL) {
- mrp_object_get (group, "name", &name, NULL);
- g_object_ref (group);
- } else {
- name = g_strdup (_("(None)"));
- }
-
- list = g_list_prepend (list, name);
-
- if (current_group == group) {
- index = i;
- }
-
- i++;
- }
-
- cell->list = g_list_reverse (list);
- cell->user_data = groups;
- cell->selected_index = index;
-}
-
-static void
-resource_view_cell_group_hide_popup (PlannerCellRendererList *cell,
- PlannerView *view)
-{
- GList *l;
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COLUMN_GROUP_TEXT, group_name,
+ COLUMN_GROUP_GROUP, group,
+ -1);
+ g_free (group_name);
- for (l = cell->user_data; l; l = l->next) {
- if (l->data) {
- g_object_unref (l->data);
- }
+ g_signal_connect_swapped (group,
+ "notify::name",
+ G_CALLBACK (resource_view_cell_groups_changed_cb),
+ view);
}
- g_list_free (cell->user_data);
- cell->user_data = NULL;
+ return GTK_TREE_MODEL (model);
}
static void
@@ -1927,11 +1914,13 @@ resource_view_edit_groups_cb (GtkAction *action,
static void
resource_view_project_loaded_cb (MrpProject *project, PlannerView *view)
{
+ PlannerResourceView *resource_view;
GtkTreeModel *model;
GList *resources, *l;
GtkTreeView *tree_view;
- tree_view = PLANNER_RESOURCE_VIEW (view)->priv->tree_view;
+ resource_view = PLANNER_RESOURCE_VIEW (view);
+ tree_view = resource_view->priv->tree_view;
model = GTK_TREE_MODEL (gtk_list_store_new (NUM_OF_COLS,
G_TYPE_POINTER));
@@ -1948,6 +1937,8 @@ resource_view_project_loaded_cb (MrpProject *project, PlannerView *view)
}
gtk_tree_view_set_model (tree_view, model);
g_object_unref (model);
+
+ resource_view_tree_setup_groups_model (resource_view, project);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]