[planner: 21/61] default-week-dialog: Port day type selector to GtkComboBox
- From: Mart Raudsepp <mraudsepp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner: 21/61] default-week-dialog: Port day type selector to GtkComboBox
- Date: Sat, 12 Jun 2021 17:30:23 +0000 (UTC)
commit 4136e988298cf561a4235af28f05eb5d54f962d7
Author: Mart Raudsepp <leio gentoo org>
Date: Sun Mar 8 14:17:43 2020 +0200
default-week-dialog: Port day type selector to GtkComboBox
GtkOptionMenu (used before) has been deprecated for most of gtk2 times
and does not exist in gtk3.
data/ui/default-week-dialog.ui | 3 +-
src/planner-default-week-dialog.c | 164 +++++++++++++++++++++-----------------
2 files changed, 91 insertions(+), 76 deletions(-)
---
diff --git a/data/ui/default-week-dialog.ui b/data/ui/default-week-dialog.ui
index b7f0fc2e..fda516da 100644
--- a/data/ui/default-week-dialog.ui
+++ b/data/ui/default-week-dialog.ui
@@ -209,10 +209,9 @@
</packing>
</child>
<child>
- <object class="GtkOptionMenu" id="day_optionmenu">
+ <object class="GtkComboBox" id="daytype_combobox">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="history">-1</property>
</object>
<packing>
<property name="padding">0</property>
diff --git a/src/planner-default-week-dialog.c b/src/planner-default-week-dialog.c
index 1945eaff..07d62836 100644
--- a/src/planner-default-week-dialog.c
+++ b/src/planner-default-week-dialog.c
@@ -62,7 +62,7 @@ typedef struct {
GtkWidget *dialog;
GtkWidget *weekday_combobox;
- GtkWidget *day_option_menu;
+ GtkWidget *daytype_combobox;
GtkWidget *from_label[5];
GtkWidget *to_label[5];
@@ -95,9 +95,9 @@ static void default_week_dialog_response_cb (GtkWidget
static void default_week_dialog_update_labels (DialogData *data);
static void default_week_dialog_weekday_selected_cb (GtkComboBoxText *combotext,
DialogData *data);
-static void default_week_dialog_day_selected_cb (GtkOptionMenu *option_menu,
+static void default_week_dialog_day_selected_cb (GtkComboBox *combo,
DialogData *data);
-static void default_week_dialog_setup_day_option_menu (GtkOptionMenu *option_menu,
+static void default_week_dialog_setup_daytype_combobox (GtkComboBox *combo,
MrpProject *project,
MrpCalendar *calendar);
static void default_week_dialog_setup_weekday_combobox (GtkComboBoxText *combotext);
@@ -149,6 +149,23 @@ default_week_dialog_parent_destroy_cb (GtkWidget *window, GtkWidget *dialog)
gtk_widget_destroy (dialog);
}
+static void
+daytype_combo_name_and_sensitive (GtkCellLayout *layout,
+ GtkCellRenderer *cell,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ MrpDay *day;
+ gboolean sensitive;
+
+ gtk_tree_model_get (model, iter, 0, &day, 1, &sensitive, -1);
+ g_object_set (cell,
+ "text", mrp_day_get_name (day),
+ "sensitive", sensitive,
+ NULL);
+}
+
GtkWidget *
planner_default_week_dialog_new (PlannerWindow *window,
MrpCalendar *calendar)
@@ -158,6 +175,7 @@ planner_default_week_dialog_new (PlannerWindow *window,
GtkWidget *dialog;
GtkWidget *w;
gint i;
+ GtkCellRenderer *renderer;
g_return_val_if_fail (PLANNER_IS_WINDOW (window), NULL);
@@ -199,13 +217,21 @@ planner_default_week_dialog_new (PlannerWindow *window,
gtk_label_set_text (GTK_LABEL (w), mrp_calendar_get_name (calendar));
data->weekday_combobox = GTK_WIDGET (gtk_builder_get_object (builder, "weekday_combobox"));
- data->day_option_menu = GTK_WIDGET (gtk_builder_get_object (builder, "day_optionmenu"));
+ data->daytype_combobox = GTK_WIDGET (gtk_builder_get_object (builder, "daytype_combobox"));
+
+ default_week_dialog_setup_daytype_combobox (GTK_COMBO_BOX (data->daytype_combobox),
+ data->project,
+ calendar);
- default_week_dialog_setup_day_option_menu (GTK_OPTION_MENU (data->day_option_menu),
- data->project,
- calendar);
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (data->daytype_combobox),
+ renderer, TRUE);
+ gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (data->daytype_combobox),
+ renderer,
+ daytype_combo_name_and_sensitive,
+ NULL, NULL);
- g_signal_connect (data->day_option_menu,
+ g_signal_connect (data->daytype_combobox,
"changed",
G_CALLBACK (default_week_dialog_day_selected_cb),
data);
@@ -318,62 +344,51 @@ default_week_dialog_weekday_selected_cb (GtkComboBoxText *combotext,
}
static void
-default_week_dialog_day_selected_cb (GtkOptionMenu *option_menu,
- DialogData *data)
+default_week_dialog_day_selected_cb (GtkComboBox *combo,
+ DialogData *data)
{
default_week_dialog_update_labels (data);
}
static void
-default_week_dialog_setup_day_option_menu (GtkOptionMenu *option_menu,
- MrpProject *project,
- MrpCalendar *calendar)
+default_week_dialog_setup_daytype_combobox (GtkComboBox *combo,
+ MrpProject *project,
+ MrpCalendar *calendar)
{
- GtkWidget *menu;
- GtkWidget *menu_item;
- const gchar *name;
- GList *days, *l;
- MrpDay *day;
- MrpCalendar *parent, *root;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GList *days, *l;
+
+ store = gtk_list_store_new (2, MRP_TYPE_DAY, G_TYPE_BOOLEAN);
+ gtk_combo_box_set_model (combo, GTK_TREE_MODEL (store));
+ g_object_unref (store);
+
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, mrp_day_get_work (),
+ 1, TRUE,
+ -1);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, mrp_day_get_nonwork (),
+ 1, TRUE,
+ -1);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, mrp_day_get_use_base (),
+ 1, !(mrp_calendar_get_parent (calendar) == mrp_project_get_root_calendar
(project)),
+ -1);
days = mrp_day_get_all (project);
- days = g_list_prepend (days, mrp_day_get_use_base ());
- days = g_list_prepend (days, mrp_day_get_nonwork ());
- days = g_list_prepend (days, mrp_day_get_work ());
-
- parent = mrp_calendar_get_parent (calendar);
- root = mrp_project_get_root_calendar (project);
-
- menu = gtk_option_menu_get_menu (option_menu);
-
- if (menu) {
- gtk_widget_destroy (menu);
- }
-
- menu = gtk_menu_new ();
for (l = days; l; l = l->next) {
- day = l->data;
-
- name = mrp_day_get_name (day);
-
- menu_item = gtk_menu_item_new_with_label (name);
- gtk_widget_show (menu_item);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
- /* "Use base" is not possible for toplevel calendars. */
- if (parent == root && day == mrp_day_get_use_base ()) {
- gtk_widget_set_sensitive (menu_item, FALSE);
- }
-
- g_object_set_data (G_OBJECT (menu_item),
- "data",
- l->data);
+ gtk_list_store_append (store, &iter);
+ gtk_list_store_set (store, &iter,
+ 0, MRP_DAY (l->data),
+ 1, TRUE,
+ -1);
}
- gtk_widget_show (menu);
- gtk_option_menu_set_menu (option_menu, menu);
-
/* Need to unref the days here? */
g_list_free (days);
}
@@ -398,36 +413,37 @@ default_week_dialog_setup_weekday_combobox (GtkComboBoxText *combotext)
static MrpDay *
default_week_dialog_get_selected_day (DialogData *data)
{
- GtkWidget *menu;
- GtkWidget *item;
-
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (data->day_option_menu));
-
- item = gtk_menu_get_active (GTK_MENU (menu));
+ GtkTreeIter iter;
+ MrpDay *day;
- return g_object_get_data (G_OBJECT (item), "data");
+ gtk_combo_box_get_active_iter (GTK_COMBO_BOX (data->daytype_combobox), &iter);
+ gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (data->daytype_combobox)),
+ &iter,
+ 0, &day,
+ -1);
+ return day;
}
static void
default_week_dialog_set_selected_day (DialogData *data,
MrpDay *day)
{
- GtkWidget *menu;
- GtkWidget *item;
- GList *children, *l;
- gint i;
-
- menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (data->day_option_menu));
-
- children = GTK_MENU_SHELL (menu)->children;
- for (i = 0, l = children; l; i++, l = l->next) {
- item = l->data;
-
- if (day == g_object_get_data (G_OBJECT (item), "data")) {
- gtk_option_menu_set_history (GTK_OPTION_MENU (data->day_option_menu), i);
- break;
+ GtkComboBox *combo;
+ GtkTreeModel *model;
+ GtkTreeIter iter;
+ MrpDay *iter_day;
+
+ combo = GTK_COMBO_BOX (data->daytype_combobox);
+ model = gtk_combo_box_get_model (combo);
+ gtk_tree_model_get_iter_first (model, &iter);
+
+ do {
+ gtk_tree_model_get (model, &iter, 0, &iter_day, -1);
+ if (iter_day == day) {
+ gtk_combo_box_set_active_iter (combo, &iter);
+ return;
}
- }
+ } while (gtk_tree_model_iter_next (model, &iter));
}
static gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]