[planner: 54/61] task-dialog: Port relation type cell to GtkCellRendererCombo
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 54/61] task-dialog: Port relation type cell to GtkCellRendererCombo
- Date: Sat, 12 Jun 2021 17:30:28 +0000 (UTC)
commit 3270cc3db406952249e609e69ae6d0549f781eea
Author: Mart Raudsepp <leio gentoo org>
Date: Sat Mar 20 23:25:34 2021 +0200
task-dialog: Port relation 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-task-dialog.c | 252 ++++++++++++++++++++++++----------------------
1 file changed, 131 insertions(+), 121 deletions(-)
---
diff --git a/src/planner-task-dialog.c b/src/planner-task-dialog.c
index d3783125..a4929f03 100644
--- a/src/planner-task-dialog.c
+++ b/src/planner-task-dialog.c
@@ -62,6 +62,12 @@ typedef struct {
GtkTextBuffer *note_buffer;
} DialogData;
+enum {
+ COLUMN_RELATION_TEXT,
+ COLUMN_RELATION_RELATION,
+ NUM_RELATION_COLUMNS
+};
+
static void task_dialog_close_clicked_cb (GtkWidget *w,
DialogData *data);
@@ -159,20 +165,16 @@ static void task_dialog_resource_units_cell_edited (GtkCellRender
gchar *path_str,
gchar *new_text,
DialogData *data);
-static void task_dialog_pred_cell_edited (GtkCellRendererText *cell,
+static void task_dialog_pred_relation_cell_changed (GtkCellRendererCombo *combo,
+ gchar *path_string,
+ GtkTreeIter *new_iter,
+ DialogData *data);
+static void task_dialog_pred_lag_cell_edited (GtkCellRendererText *cell,
gchar *path_str,
gchar *new_text,
DialogData *data);
static MrpRelationType cell_index_to_relation_type (gint i);
-static void task_dialog_cell_type_show_popup (PlannerCellRendererList *cell,
- const gchar *path_string,
- gint x1,
- gint y1,
- gint x2,
- gint y2,
- DialogData *data);
-static void task_dialog_cell_type_hide_popup (PlannerCellRendererList *cell,
- GtkWidget *view);
+static GtkTreeModel * task_dialog_cell_type_create_model ();
static void task_dialog_add_predecessor_cb (GtkWidget *widget,
DialogData *data);
static void task_dialog_remove_predecessor_cb (GtkWidget *widget,
@@ -2005,28 +2007,27 @@ task_dialog_resource_units_cell_edited (GtkCellRendererText *cell,
}
static void
-task_dialog_pred_cell_edited (GtkCellRendererText *cell,
- gchar *path_str,
- gchar *new_text,
- DialogData *data)
+task_dialog_pred_relation_cell_changed (GtkCellRendererCombo *combo,
+ gchar *path_string,
+ GtkTreeIter *new_iter,
+ DialogData *data)
{
- GtkTreeView *tree;
- GtkTreePath *path;
- GtkTreeIter iter;
- GtkTreeModel *model;
- MrpRelation *relation;
- MrpTask *task_main;
- MrpTask *task_pred;
- PlannerCellRendererList *planner_cell;
- gint column;
- gint lag;
- MrpRelationType type, new_type;
+ GtkTreeView *tree;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ GtkTreeModel *model, *combo_model;
+ MrpRelation *relation;
+ MrpTask *task_main;
+ MrpTask *task_pred;
+ gint lag;
+ MrpRelationType type, new_type;
+ GError *error = NULL;
+ PlannerCmd *cmd;
tree = GTK_TREE_VIEW (data->predecessor_list);
model = gtk_tree_view_get_model (tree);
- path = gtk_tree_path_new_from_string (path_str);
- column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column"));
+ path = gtk_tree_path_new_from_string (path_string);
gtk_tree_model_get_iter (model, &iter, path);
@@ -2038,58 +2039,72 @@ task_dialog_pred_cell_edited (GtkCellRendererText *cell,
lag = mrp_relation_get_lag (relation) / (60*60);
type = mrp_relation_get_relation_type (relation);
- switch (column) {
- case PREDECESSOR_COL_NAME:
- g_assert_not_reached ();
- break;
+ g_object_get (combo, "model", &combo_model, NULL);
+ gtk_tree_model_get (combo_model, new_iter,
+ COLUMN_RELATION_RELATION, &new_type,
+ -1);
+ cmd = planner_task_cmd_edit_predecessor (data->main_window,
+ task_main, task_pred,
+ task_pred,
+ new_type,
+ lag, &error);
- case PREDECESSOR_COL_TYPE: {
- GError *error = NULL;
- PlannerCmd *cmd;
+ if (!cmd) {
+ GtkWidget *dialog;
- planner_cell = PLANNER_CELL_RENDERER_LIST (cell);
+ dialog = gtk_message_dialog_new (
+ NULL,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "%s", error->message);
- new_type = cell_index_to_relation_type (planner_cell->selected_index);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
- cmd = planner_task_cmd_edit_predecessor (data->main_window,
- task_main, task_pred,
- task_pred,
- new_type,
- lag, &error);
+ g_error_free (error);
- if (!cmd) {
- GtkWidget *dialog;
+ /* Restore the previous state. */
+ mrp_task_add_predecessor (task_main,
+ task_pred,
+ type,
+ lag,
+ NULL);
+ }
- dialog = gtk_message_dialog_new (
- NULL,
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s", error->message);
+ gtk_tree_path_free (path);
+}
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
+static void
+task_dialog_pred_lag_cell_edited (GtkCellRendererText *cell,
+ gchar *path_str,
+ gchar *new_text,
+ DialogData *data)
+{
+ GtkTreeView *tree;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ MrpRelation *relation;
+ MrpTask *task_main;
+ MrpTask *task_pred;
+ gint lag;
- g_error_free (error);
+ tree = GTK_TREE_VIEW (data->predecessor_list);
- /* Restore the previous state. */
- mrp_task_add_predecessor (task_main,
- task_pred,
- type,
- lag,
- NULL);
- }
- break;
- }
- case PREDECESSOR_COL_LAG:
- lag = planner_parse_duration_with_day_length (new_text, 24*60*60);
- task_cmd_edit_lag (data->main_window, relation, lag);
- break;
+ model = gtk_tree_view_get_model (tree);
+ path = gtk_tree_path_new_from_string (path_str);
- default:
- g_assert_not_reached ();
- break;
- }
+ gtk_tree_model_get_iter (model, &iter, path);
+
+ task_pred = MRP_TASK (planner_list_model_get_object (PLANNER_LIST_MODEL (model),
+ &iter));
+ task_main = data->task;
+
+ relation = mrp_task_get_relation (task_main, task_pred);
+
+ lag = planner_parse_duration_with_day_length (new_text, 24*60*60);
+ task_cmd_edit_lag (data->main_window, relation, lag);
gtk_tree_path_free (path);
}
@@ -2132,16 +2147,42 @@ relation_type_to_cell_index (MrpRelationType relation)
}
#endif
-static void
-task_dialog_cell_type_show_popup (PlannerCellRendererList *cell,
- const gchar *path_string,
- gint x1,
- gint y1,
- gint x2,
- gint y2,
- DialogData *data)
+static GtkTreeModel *
+task_dialog_cell_type_create_model ()
{
- GtkTreeView *tree;
+ GtkListStore *model;
+ GtkTreeIter iter;
+
+ model = gtk_list_store_new (NUM_RELATION_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COLUMN_RELATION_TEXT, _("FS"),
+ COLUMN_RELATION_RELATION, MRP_RELATION_FS,
+ -1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COLUMN_RELATION_TEXT, _("FF"),
+ COLUMN_RELATION_RELATION, MRP_RELATION_FF,
+ -1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COLUMN_RELATION_TEXT, _("SS"),
+ COLUMN_RELATION_RELATION, MRP_RELATION_SS,
+ -1);
+
+ gtk_list_store_append (model, &iter);
+ gtk_list_store_set (model, &iter,
+ COLUMN_RELATION_TEXT, _("SF"),
+ COLUMN_RELATION_RELATION, MRP_RELATION_SF,
+ -1);
+
+ return GTK_TREE_MODEL (model);
+}
+
+/*
GtkTreeModel *model;
PlannerListModel *list_model;
GtkTreeIter iter;
@@ -2187,22 +2228,7 @@ task_dialog_cell_type_show_popup (PlannerCellRendererList *cell,
break;
}
}
-
-static void
-task_dialog_cell_type_hide_popup (PlannerCellRendererList *cell,
- GtkWidget *view)
-{
- GList *l;
-
- for (l = cell->user_data; l; l = l->next) {
- if (l->data) {
- g_object_unref (l->data);
- }
- }
-
- g_list_free (cell->user_data);
- /* cell->user_data = NULL; */
-}
+*/
static void
task_dialog_schedule_date_selected_cb (GtkWidget *button,
@@ -2631,10 +2657,6 @@ task_dialog_setup_predecessor_list (DialogData *data)
g_object_set (cell, "editable", FALSE, NULL);
- g_object_set_data (G_OBJECT (cell),
- "column",
- GINT_TO_POINTER (PREDECESSOR_COL_NAME));
-
col = gtk_tree_view_column_new_with_attributes (_("Name"),
cell,
"text", PREDECESSOR_COL_NAME,
@@ -2644,29 +2666,21 @@ task_dialog_setup_predecessor_list (DialogData *data)
gtk_tree_view_append_column (tree, col);
/* Type */
- cell = planner_cell_renderer_list_new ();
-
- g_object_set (cell, "editable", TRUE, NULL);
-
- g_object_set_data (G_OBJECT (cell),
- "column",
- GINT_TO_POINTER (PREDECESSOR_COL_TYPE));
+ cell = gtk_cell_renderer_combo_new ();
+ model = task_dialog_cell_type_create_model ();
- g_signal_connect (cell,
- "edited",
- G_CALLBACK (task_dialog_pred_cell_edited),
- data);
+ g_object_set (cell,
+ "editable", TRUE,
+ "has-entry", FALSE,
+ "model", model,
+ "text-column", COLUMN_RELATION_TEXT,
+ NULL);
g_signal_connect (cell,
- "show_popup",
- G_CALLBACK (task_dialog_cell_type_show_popup),
+ "changed",
+ G_CALLBACK (task_dialog_pred_relation_cell_changed),
data);
- g_signal_connect_after (cell,
- "hide_popup",
- G_CALLBACK (task_dialog_cell_type_hide_popup),
- data);
-
col = gtk_tree_view_column_new_with_attributes (_("Type"),
cell,
"text", PREDECESSOR_COL_TYPE,
@@ -2679,13 +2693,9 @@ task_dialog_setup_predecessor_list (DialogData *data)
g_object_set (cell, "editable", TRUE, NULL);
- g_object_set_data (G_OBJECT (cell),
- "column",
- GINT_TO_POINTER (PREDECESSOR_COL_LAG));
-
g_signal_connect (cell,
"edited",
- G_CALLBACK (task_dialog_pred_cell_edited),
+ G_CALLBACK (task_dialog_pred_lag_cell_edited),
data);
col = gtk_tree_view_column_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]