[planner] Switch from GtkComboEntry to GtkCombo
- From: Alexandre Franke <afranke src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [planner] Switch from GtkComboEntry to GtkCombo
- Date: Mon, 13 May 2013 16:13:16 +0000 (UTC)
commit 7b003e5afa0dfd33c5bc902fe74b2a843ae23ad6
Author: Caolan McNamara <caolanm redhat com>
Date: Mon May 13 17:59:08 2013 +0200
Switch from GtkComboEntry to GtkCombo
https://bugzilla.gnome.org/show_bug.cgi?id=604169
data/glade/add-predecessor.glade | 58 ++++++++-------------------
src/planner-gantt-model.c | 47 ++++++++++++----------
src/planner-task-dialog.c | 81 ++++++++++++++++++++------------------
3 files changed, 87 insertions(+), 99 deletions(-)
---
diff --git a/data/glade/add-predecessor.glade b/data/glade/add-predecessor.glade
index 2595484..62f8cb3 100644
--- a/data/glade/add-predecessor.glade
+++ b/data/glade/add-predecessor.glade
@@ -88,7 +88,6 @@
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
- <property name="mnemonic_widget">combo-entry1</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
@@ -162,6 +161,7 @@
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
+ <property name="mnemonic_widget">lag_entry</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
@@ -178,45 +178,6 @@
</child>
<child>
- <widget class="GtkCombo" id="predecessor_combo">
- <property name="visible">True</property>
- <property name="value_in_list">False</property>
- <property name="allow_empty">True</property>
- <property name="case_sensitive">False</property>
- <property name="enable_arrow_keys">True</property>
- <property name="enable_arrows_always">False</property>
-
- <child internal-child="entry">
- <widget class="GtkEntry" id="combo-entry1">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="editable">True</property>
- <property name="visibility">True</property>
- <property name="max_length">0</property>
- <property name="text" translatable="yes"></property>
- <property name="has_frame">True</property>
- <property name="invisible_char">*</property>
- <property name="activates_default">True</property>
- </widget>
- </child>
-
- <child internal-child="list">
- <widget class="GtkList" id="combo-list1">
- <property name="visible">True</property>
- <property name="selection_mode">GTK_SELECTION_BROWSE</property>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="left_attach">1</property>
- <property name="right_attach">2</property>
- <property name="top_attach">0</property>
- <property name="bottom_attach">1</property>
- <property name="y_options"></property>
- </packing>
- </child>
-
- <child>
<widget class="GtkEntry" id="lag_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -236,6 +197,23 @@
<property name="y_options"></property>
</packing>
</child>
+
+ <child>
+ <widget class="GtkComboBoxEntry" id="predecessor_combo">
+ <property name="visible">True</property>
+ <property name="add_tearoffs">False</property>
+ <property name="has_frame">True</property>
+ <property name="focus_on_click">True</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ <property name="x_options">fill</property>
+ <property name="y_options">fill</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="padding">0</property>
diff --git a/src/planner-gantt-model.c b/src/planner-gantt-model.c
index 1e7b7e0..c1d328c 100644
--- a/src/planner-gantt-model.c
+++ b/src/planner-gantt-model.c
@@ -72,6 +72,7 @@ static void gantt_model_task_prop_changed_cb (MrpTask *ta
PlannerGanttModel *model);
static GtkTreePath *gantt_model_get_path_from_node (PlannerGanttModel *model,
GNode *node);
+gchar * get_wbs_from_task (MrpTask *task);
static const gchar *value_cache_get_wbs (PlannerGanttModel *model,
MrpTask *task);
static ValueCache * value_cache_get (PlannerGanttModel *model,
@@ -1125,28 +1126,13 @@ planner_gantt_model_get_indent_task_target (PlannerGanttModel *model,
return sibling->data;
}
-static const gchar *
-value_cache_get_wbs (PlannerGanttModel *model,
- MrpTask *task)
+gchar *
+get_wbs_from_task(MrpTask *task)
{
- ValueCache *cache;
- MrpTask *tmp_task;
+ gint pos;
gchar *str;
+ MrpTask *tmp_task;
GString *string;
- gint pos;
-
- cache = value_cache_get (model, task);
- if (!cache->wbs) {
- goto update_cache;
- }
-
- if (cache->wbs_stamp != model->priv->wbs_stamp) {
- goto update_cache;
- }
-
- return cache->wbs;
-
- update_cache:
string = g_string_sized_new (24);
pos = -1;
@@ -1168,10 +1154,29 @@ value_cache_get_wbs (PlannerGanttModel *model,
if (mrp_task_get_parent (tmp_task) == NULL)
break;
}
+ return g_string_free (string, FALSE);
+}
- g_free (cache->wbs);
+static const gchar *
+value_cache_get_wbs (PlannerGanttModel *model,
+ MrpTask *task)
+{
+ ValueCache *cache;
+
+ cache = value_cache_get (model, task);
+ if (!cache->wbs) {
+ goto update_cache;
+ }
+
+ if (cache->wbs_stamp != model->priv->wbs_stamp) {
+ goto update_cache;
+ }
+
+ return cache->wbs;
- cache->wbs = g_string_free (string, FALSE);
+ update_cache:
+ g_free (cache->wbs);
+ cache->wbs = get_wbs_from_task(task);
cache->wbs_stamp = model->priv->wbs_stamp;
return cache->wbs;
diff --git a/src/planner-task-dialog.c b/src/planner-task-dialog.c
index 63bb1da..813cd67 100644
--- a/src/planner-task-dialog.c
+++ b/src/planner-task-dialog.c
@@ -183,6 +183,7 @@ static void task_dialog_new_pred_cancel_clicked_cb (GtkWidget
GtkWidget *dialog);
static void task_dialog_update_sensitivity (DialogData *data);
static void task_dialog_update_title (DialogData *data);
+extern gchar * get_wbs_from_task (MrpTask *task);
@@ -350,56 +351,55 @@ task_dialog_option_menu_set_selected (GtkWidget *option_menu, gint data)
#endif
static void
-task_dialog_task_combo_select_child_cb (GtkList *list,
- GtkWidget *item,
- GtkCombo *combo)
-{
- MrpTask *task;
-
- task = g_object_get_data (G_OBJECT (item), "task");
- g_object_set_data (G_OBJECT (combo), "selected_task", task);
-}
-
-static void
-task_dialog_setup_task_combo (GtkCombo *combo,
+task_dialog_setup_task_combo (GtkComboBoxEntry *combo,
GList *tasks)
{
- GList *strings;
- GList *children;
- GList *l;
- const gchar *name;
+ GtkListStore *store;
+ GtkTreeIter iter;
+ GList *l;
+ const gchar *name;
if (tasks == NULL) {
return;
}
- strings = NULL;
+ store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
for (l = tasks; l; l = l->next) {
+ GString *task_label;
+ gchar *wbs;
+
+ gtk_list_store_append (store, &iter);
+ task_label = g_string_new( NULL);
+
+ wbs = get_wbs_from_task (l->data);
+ if (wbs != NULL && wbs[0] != 0)
+ g_string_append_printf (task_label, "%s ", wbs);
+ g_free(wbs);
+
name = mrp_task_get_name (l->data);
- if (name == NULL || name[0] == 0) {
- strings = g_list_prepend (strings,
- _("(No name)"));
+ if (name != NULL && name[0] != 0)
+ g_string_append (task_label, name);
+
+ if (task_label->len == 0) {
+ gtk_list_store_set (store, &iter,
+ 0, _("(No name)"),
+ 1, l->data,
+ -1);
} else {
- strings = g_list_prepend (strings, (gchar*) name);
+ gtk_list_store_set (store, &iter,
+ 0, task_label->str,
+ 1, l->data,
+ -1);
}
+ g_string_free(task_label, TRUE);
}
- strings = g_list_reverse (strings);
- gtk_combo_set_popdown_strings (combo, strings);
- g_list_free (strings);
+ gtk_combo_box_set_model (GTK_COMBO_BOX (combo),
+ GTK_TREE_MODEL (store));
- g_object_set_data (G_OBJECT (combo), "selected_task", tasks->data);
-
- children = GTK_LIST (combo->list)->children;
- for (l = children; l; l = l->next) {
- g_object_set_data (G_OBJECT (l->data), "task", tasks->data);
- tasks = tasks->next;
- }
+ gtk_combo_box_entry_set_text_column (combo, 0);
- g_signal_connect (combo->list,
- "select-child",
- G_CALLBACK (task_dialog_task_combo_select_child_cb),
- combo);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
}
static gboolean
@@ -1898,7 +1898,7 @@ task_dialog_predecessor_dialog_new (MrpTask *task,
tasks = mrp_project_get_all_tasks (project);
tasks = g_list_remove (tasks, task);
- task_dialog_setup_task_combo (GTK_COMBO (w), tasks);
+ task_dialog_setup_task_combo (GTK_COMBO_BOX_ENTRY (w), tasks);
w = glade_xml_get_widget (glade, "type_optionmenu");
g_object_set_data (G_OBJECT (dialog), "type_optionmenu", w);
@@ -1939,10 +1939,11 @@ task_dialog_new_pred_ok_clicked_cb (GtkWidget *button,
GtkWidget *w;
GError *error = NULL;
MrpTask *task_main;
- MrpTask *new_task_pred;
+ MrpTask *new_task_pred = NULL;
MrpProject *project;
gint lag;
gint pred_type;
+ GtkTreeIter iter;
const gchar *str;
main_window = g_object_get_data (G_OBJECT (dialog), "main_window");
@@ -1962,7 +1963,11 @@ task_dialog_new_pred_ok_clicked_cb (GtkWidget *button,
/* Predecessor task. */
w = g_object_get_data (G_OBJECT (dialog), "predecessor_combo");
- new_task_pred = g_object_get_data (G_OBJECT (w), "selected_task");
+ if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &iter)) {
+ gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (w)),
+ &iter, 1, &new_task_pred, -1);
+ }
+
if (new_task_pred == NULL) {
g_warning (_("Can't add new predecessor. No task selected!"));
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]