]> git.tdb.fi Git - r2c2.git/blobdiff - source/engineer/vehiclespanel.cpp
Use Widget::find_ancestor to reduce code duplication
[r2c2.git] / source / engineer / vehiclespanel.cpp
index d906f6cb4218e5976a0b0d468941a12553c1d049..cd3b7cf25fa3be207edaa6c6c1db80f9ab887c34 100644 (file)
@@ -1,5 +1,6 @@
 #include <msp/core/maputils.h>
 #include <msp/gltk/button.h>
+#include <msp/gltk/root.h>
 #include <msp/strings/format.h>
 #include "libr2c2/layout.h"
 #include "libr2c2/vehicle.h"
@@ -40,12 +41,8 @@ VehiclesPanel::VehiclesPanel(Train &t):
 
 void VehiclesPanel::add_clicked()
 {
-       GLtk::Container *root = parent;
-       while(root->get_parent())
-               root = root->get_parent();
-
        NewVehicleDialog *dlg = new NewVehicleDialog(train);
-       root->add(*dlg);
+       find_ancestor<GLtk::Root>()->add(*dlg);
        dlg->autosize();
 }