]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/newtraindialog.cpp
Convert Catalogue to a Collection
[r2c2.git] / source / engineer / newtraindialog.cpp
index 11fd5c04d6f1331c607926c8d84256216d9e44df..e0b4e1a279a4c51d7e3c396ad9ad392783cd3682 100644 (file)
@@ -42,10 +42,17 @@ NewTrainDialog::NewTrainDialog(Engineer &e):
 
        drp_protocol->set_selected_index(0);
 
-       const Catalogue::VehicleMap &cat_vtypes = engineer.get_layout().get_catalogue().get_vehicles();
-       for(Catalogue::VehicleMap::const_iterator i=cat_vtypes.begin(); i!=cat_vtypes.end(); ++i)
-               if(i->second->is_locomotive())
-                       loco_types.append(i->second);
+       list<VehicleType *> veh_types = engineer.get_layout().get_catalogue().get_list<VehicleType>();
+       for(list<VehicleType *>::iterator i=veh_types.begin(); i!=veh_types.end(); ++i)
+               if((*i)->is_locomotive())
+                       loco_types.append(*i);
+}
+
+void NewTrainDialog::prefill(const Driver::DetectedLocomotive &loco)
+{
+       drp_protocol->set_selected_index(protocols.find(loco.protocol));
+       ent_address->set_text(lexical_cast<string>(loco.address));
+       ent_name->set_text(loco.name);
 }
 
 void NewTrainDialog::on_response(int code)
@@ -67,12 +74,8 @@ void NewTrainDialog::on_response(int code)
                Train *train = new Train(engineer.get_layout(), type, address, protocol);
                train->set_name(ent_name->get_text());
 
-               GLtk::Container *root = parent;
-               while(root->get_parent())
-                       root = root->get_parent();
-
                TrainDialog *dlg = new TrainDialog(engineer, *train);
-               root->add(*dlg);
+               find_ancestor<GLtk::Root>()->add(*dlg);
                dlg->autosize();
        }
 }