[planner: 32/61] task-dialog: Port add-predecessor relation chooser to GtkComboBoxText




commit 426b10a1c2a573f1d127892f6f0b105bdb907206
Author: Mart Raudsepp <leio gentoo org>
Date:   Sun Dec 27 14:37:28 2020 +0200

    task-dialog: Port add-predecessor relation chooser to GtkComboBoxText

 data/ui/add-predecessor.ui |   5 +-
 src/planner-task-dialog.c  | 123 ++++++++++++++-------------------------------
 2 files changed, 41 insertions(+), 87 deletions(-)
---
diff --git a/data/ui/add-predecessor.ui b/data/ui/add-predecessor.ui
index a44d10d2..93816dda 100644
--- a/data/ui/add-predecessor.ui
+++ b/data/ui/add-predecessor.ui
@@ -104,7 +104,7 @@
                 <property name="yalign">0.5</property>
                 <property name="xpad">0</property>
                 <property name="ypad">0</property>
-                <property name="mnemonic_widget">type_optionmenu</property>
+                <property name="mnemonic_widget">type_relation</property>
                 <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
                 <property name="width_chars">-1</property>
                 <property name="single_line_mode">False</property>
@@ -120,10 +120,9 @@
               </packing>
             </child>
             <child>
-              <object class="GtkOptionMenu" id="type_optionmenu">
+              <object class="GtkComboBoxText" id="type_relation">
                 <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-task-dialog.c b/src/planner-task-dialog.c
index da1ca270..d3783125 100644
--- a/src/planner-task-dialog.c
+++ b/src/planner-task-dialog.c
@@ -268,85 +268,27 @@ typedef struct {
 } TaskCmdEditNote;
 
 static void
-task_dialog_setup_option_menu (GtkWidget     *option_menu,
-                              GCallback      func,
-                              gpointer       user_data,
-                              gconstpointer  str1, ...)
-{
-       GtkWidget     *menu;
-       GtkWidget     *menu_item;
-       gint           i;
-       va_list        args;
-       gconstpointer  str;
-       gint           type;
-
-               menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
-       if (menu) {
-               gtk_widget_destroy (menu);
-       }
-
-       menu = gtk_menu_new ();
-
-       va_start (args, str1);
-       for (str = str1, i = 0; str != NULL; str = va_arg (args, gpointer), i++) {
-               menu_item = gtk_menu_item_new_with_label (str);
-               gtk_widget_show (menu_item);
-               gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
-
-               type = va_arg (args, gint);
-
-               g_object_set_data (G_OBJECT (menu_item),
-                                  "data",
-                                  GINT_TO_POINTER (type));
-               if (func) {
-                       g_signal_connect (menu_item,
-                                         "activate",
-                                         func,
-                                         user_data);
-               }
-       }
-       va_end (args);
-
-       gtk_widget_show (menu);
-       gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
+task_dialog_setup_relation_combo (GtkComboBoxText *combo_text)
+{
+       gtk_combo_box_text_append_text (combo_text, _("Finish to start (FS)"));
+       gtk_combo_box_text_append_text (combo_text, _("Finish to finish (FF)"));
+       gtk_combo_box_text_append_text (combo_text, _("Start to start (SS)"));
+       gtk_combo_box_text_append_text (combo_text, _("Start to finish (SF)"));
+       gtk_combo_box_set_active (GTK_COMBO_BOX (combo_text), 0);
 }
 
-static gint
-task_dialog_option_menu_get_selected (GtkWidget *option_menu)
+static MrpRelationType
+task_dialog_relation_get_selected (GtkComboBox *combo)
 {
-       GtkWidget *menu;
-       GtkWidget *item;
-       gint       ret;
-
-       menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
-
-       item = gtk_menu_get_active (GTK_MENU (menu));
-
-       ret = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), "data"));
-
-       return ret;
+       return cell_index_to_relation_type (gtk_combo_box_get_active (combo));
 }
 
 #if 0
 static void
-task_dialog_option_menu_set_selected (GtkWidget *option_menu, gint data)
+task_dialog_relation_set_selected (GtkComboBox     *combo,
+                                   MrpRelationType  relation)
 {
-       GtkWidget *menu;
-       GtkWidget *item;
-       GList     *children, *l;
-       gint       i;
-
-               menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (option_menu));
-
-       children = GTK_MENU_SHELL (menu)->children;
-       for (i = 0, l = children; l; i++, l = l->next) {
-               item = l->data;
-
-               if (GINT_TO_POINTER (data) == g_object_get_data (G_OBJECT (item), "data")) {
-                       gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), i);
-                       break;
-               }
-       }
+       gtk_combo_box_set_active (relation_type_to_cell_index (relation));
 }
 #endif
 
@@ -1898,17 +1840,10 @@ task_dialog_predecessor_dialog_new (MrpTask       *task,
        tasks = g_list_remove (tasks, task);
        task_dialog_setup_task_combo (GTK_COMBO_BOX (w), tasks);
 
-       w = GTK_WIDGET (gtk_builder_get_object (builder, "type_optionmenu"));
-       g_object_set_data (G_OBJECT (dialog), "type_optionmenu", w);
+       w = GTK_WIDGET (gtk_builder_get_object (builder, "type_relation"));
+       g_object_set_data (G_OBJECT (dialog), "type_relation", w);
 
-       task_dialog_setup_option_menu (w,
-                                      NULL,
-                                      NULL,
-                                      _("Finish to start (FS)"), MRP_RELATION_FS,
-                                      _("Finish to finish (FF)"), MRP_RELATION_FF,
-                                      _("Start to start (SS)"), MRP_RELATION_SS,
-                                      _("Start to finish (SF)"), MRP_RELATION_SF,
-                                      NULL);
+       task_dialog_setup_relation_combo (GTK_COMBO_BOX_TEXT (w));
 
        w = GTK_WIDGET (gtk_builder_get_object (builder, "lag_entry"));
        g_object_set_data (G_OBJECT (dialog), "lag_entry", w);
@@ -1941,7 +1876,7 @@ task_dialog_new_pred_ok_clicked_cb (GtkWidget *button,
        MrpTask       *new_task_pred = NULL;
        MrpProject    *project;
        gint           lag;
-       gint           pred_type;
+       MrpRelationType pred_type;
        GtkTreeIter    iter;
        const gchar   *str;
 
@@ -1956,8 +1891,8 @@ task_dialog_new_pred_ok_clicked_cb (GtkWidget *button,
        lag = planner_parse_duration_with_day_length (str, 24*60*60);
 
        /* Predecessor type. */
-       w = g_object_get_data (G_OBJECT(dialog), "type_optionmenu");
-       pred_type = task_dialog_option_menu_get_selected (w);
+       w = g_object_get_data (G_OBJECT(dialog), "type_relation");
+       pred_type = task_dialog_relation_get_selected (GTK_COMBO_BOX (w));
 
        /* Predecessor task. */
        w = g_object_get_data (G_OBJECT (dialog), "predecessor_combo");
@@ -2177,6 +2112,26 @@ cell_index_to_relation_type (gint i)
        }
 }
 
+#if 0
+static gint
+relation_type_to_cell_index (MrpRelationType relation)
+{
+       switch (relation) {
+       case MRP_RELATION_FS:
+               return 0;
+       case MRP_RELATION_FF:
+               return 1;
+       case MRP_RELATION_SS:
+               return 2;
+       case MRP_RELATION_SF:
+               return 3;
+       default:
+               g_warning ("Unknown cell index for conversion to relation type");
+               return MRP_RELATION_FS;
+       }
+}
+#endif
+
 static void
 task_dialog_cell_type_show_popup (PlannerCellRendererList *cell,
                                  const gchar        *path_string,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]