Index: src/cmenu.c =================================================================== --- src/cmenu.c (revision 21) +++ src/cmenu.c (revision 22) @@ -283,7 +283,7 @@ else poi.label = g_strdup(""); poi.desc = g_strdup(""); - poi.clabel = NULL; + poi.clabel = get_category_label(poi_cat); poi_dialog(_window, &poi, TRUE); poi_cat = poi.cat_id; Index: src/poi.c =================================================================== --- src/poi.c (revision 21) +++ src/poi.c (revision 22) @@ -104,6 +104,7 @@ GtkWidget *cmb_category; gint cat_id; GtkWidget *tree_view; + gboolean populated; }; /** Data used during action: add or edit category/poi **/ @@ -1177,6 +1178,23 @@ return has_active; } +static void +poi_populate_categories_cb(GtkComboBox *combo, gpointer data) +{ + PoiCategoryEditInfo *cat = data; + GtkTreeIter iter; + + if (cat->populated) + return; + + poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model( + GTK_COMBO_BOX(cat->cmb_category))), + cat->cat_id, &iter); + gtk_combo_box_set_active_iter(combo, &iter); + + cat->populated = TRUE; +} + static gboolean poi_edit_cat(GtkWidget *widget, PoiCategoryEditInfo *data) { @@ -1197,10 +1215,11 @@ } static GtkWidget* -poi_create_cat_combo() +poi_create_cat_combo(gboolean populate) { GtkWidget *cmb_category; GtkTreeModel *model; + GtkCellRenderer *renderer; printf("%s()\n", __PRETTY_FUNCTION__); model = GTK_TREE_MODEL(gtk_list_store_new(2, @@ -1210,18 +1229,18 @@ g_object_unref(model); /* Set up the view for the combo box. */ + renderer = gtk_cell_renderer_text_new(); + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cmb_category), renderer, TRUE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cmb_category), + renderer, "text", 1, NULL); + + if (populate) { - GtkCellRenderer *renderer; GtkTreeIter active; - renderer = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start( - GTK_CELL_LAYOUT(cmb_category), renderer, TRUE); - gtk_cell_layout_set_attributes( - GTK_CELL_LAYOUT(cmb_category), renderer, "text", 1, NULL); - poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model( GTK_COMBO_BOX(cmb_category))), -1, &active); } + vprintf("%s(): return\n", __PRETTY_FUNCTION__); return cmb_category; } @@ -1236,10 +1255,12 @@ static GtkWidget *txt_lon, *txt_lat; static GtkTextBuffer *desc_txt; static GtkWidget *cmb_category; + GtkListStore *store; GtkTreeIter iter; DeletePOI dpoi; PoiCategoryEditInfo pcedit; + gint cols = (DEG_FORMAT_ENUM_TEXT[_degformat].field_2_in_use) ? 6 : 4; gchar tmp1[LL_FMT_LEN], tmp2[LL_FMT_LEN]; gint fallback_deg_format = _degformat; @@ -1331,8 +1352,10 @@ cols - 2, cols - 1, 0, 1, GTK_FILL, 0, 2, 0); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); gtk_table_attach(GTK_TABLE(table), - cmb_category = poi_create_cat_combo(), + cmb_category = poi_create_cat_combo(FALSE), cols - 1, cols - 0, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 0); + g_signal_connect(G_OBJECT(cmb_category), "popup", + G_CALLBACK(poi_populate_categories_cb), &pcedit); gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Label")), @@ -1395,11 +1418,27 @@ gtk_text_buffer_set_text(desc_txt, poi->desc, -1); /* Category. */ - gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model( - GTK_COMBO_BOX(cmb_category)))); - if(poi_populate_categories(GTK_LIST_STORE(gtk_combo_box_get_model( - GTK_COMBO_BOX(cmb_category))), poi->cat_id, &iter)) + /* Write current category in the list. */ + store = GTK_LIST_STORE(gtk_combo_box_get_model( + GTK_COMBO_BOX(cmb_category))); + if (poi->cat_id != -1) + { + gtk_list_store_clear(store); + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, poi->cat_id, 1, poi->clabel, -1); gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &iter); + pcedit.populated = FALSE; + } + else + { + /* + * It's a bit silly to populate entire list here -- we could just fetch + * category of the latest POI and use it like cat_id was set. + */ + if(poi_populate_categories(store, poi->cat_id, &iter)) + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &iter); + pcedit.populated = TRUE; + } pcedit.dialog = dialog; pcedit.cmb_category = cmb_category; @@ -1409,7 +1448,6 @@ while(GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - GtkTreeIter iter; const gchar *lat, *lon = NULL; GtkTextIter begin, end; @@ -1697,7 +1735,7 @@ FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), - cmb_category = poi_create_cat_combo(), + cmb_category = poi_create_cat_combo(TRUE), FALSE, FALSE, 4); gtk_box_pack_start(GTK_BOX(hbox), @@ -2301,7 +2339,7 @@ FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), - cmb_category = poi_create_cat_combo(), + cmb_category = poi_create_cat_combo(TRUE), FALSE, FALSE, 4); gtk_box_pack_start(GTK_BOX(hbox), @@ -2481,7 +2519,7 @@ 2, 3, 1, 2, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); gtk_table_attach(GTK_TABLE(table), - cmb_category = poi_create_cat_combo(), + cmb_category = poi_create_cat_combo(TRUE), 3, 4, 1, 2, GTK_FILL, 0, 2, 4); /* Page. */ @@ -2802,7 +2840,7 @@ 2, 3, 0, 1, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); gtk_table_attach(GTK_TABLE(table), - cmb_category = poi_create_cat_combo(), + cmb_category = poi_create_cat_combo(TRUE), 3, 4, 0, 1, GTK_FILL, 0, 2, 4); /* Add an extra, "" category. */ {