3 This file is part of R²C²
4 Copyright © 2010-2011 Mikkosoft Productions, Mikko Rasa
5 Distributed under the GPL
8 #include <msp/strings/formatter.h>
9 #include "libr2c2/route.h"
17 Routebar::Routebar(Designer &d):
18 Toolbar("Route", 370),
21 pnl_content->add(*(drp_routes = new GLtk::Dropdown));
22 drp_routes->set_geometry(GLtk::Geometry(0, 10, 250, 20));
23 drp_routes->set_tooltip("Select route to edit");
24 drp_routes->append("(new route)");
25 drp_routes->signal_item_selected.connect(sigc::mem_fun(this, &Routebar::route_selected));
29 pnl_content->add(*(btn = new GLtk::Button("Del")));
30 btn->set_geometry(GLtk::Geometry(250, 10, 40, 24));
31 btn->set_style("red");
32 btn->set_tooltip("Delete the current route");
33 btn->signal_clicked.connect(sigc::mem_fun(this, &Routebar::delete_route_clicked));
35 pnl_content->add(*(btn = new GLtk::Button("Name")));
36 btn->set_geometry(GLtk::Geometry(290, 10, 40, 24));
37 btn->set_tooltip("Rename the current route");
38 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::rename_route));
40 pnl_content->add(*(btn = new GLtk::Button("Add")));
41 btn->set_geometry(GLtk::Geometry(330, 10, 40, 24));
42 btn->set_tooltip("Add selected tracks to current route (A)");
43 btn->signal_clicked.connect(sigc::mem_fun(&designer, &Designer::add_selection_to_route));
45 designer.get_layout().signal_route_added.connect(sigc::mem_fun(this, &Routebar::route_added));
46 designer.get_layout().signal_route_removed.connect(sigc::hide(sigc::mem_fun(this, &Routebar::update_routes)));
48 const set<Route *> &routes = designer.get_layout().get_routes();
49 for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i)
50 (*i)->signal_name_changed.connect(sigc::hide(sigc::mem_fun(this, &Routebar::update_routes)));
55 void Routebar::route_selected(unsigned index, const string &)
57 if(index==drp_routes->get_n_items()-1)
59 Layout &rlayout = designer.get_layout();
60 const set<Route *> &routes = rlayout.get_routes();
61 Route *route = new Route(rlayout);
62 route->set_name(format("Route %d", routes.size()));
63 designer.edit_route(route);
67 for(set<Route *>::const_iterator i=routes.begin(); (selected<0 && i!=routes.end()); ++i, ++n)
70 drp_routes->set_selected_index(selected);
74 const set<Route *> &routes = designer.get_layout().get_routes();
75 set<Route *>::const_iterator i = routes.begin();
77 designer.edit_route(*i);
81 void Routebar::delete_route_clicked()
83 Route *route = designer.get_current_route();
84 designer.edit_route(0);
88 void Routebar::route_added(Route &r)
90 r.signal_name_changed.connect(sigc::hide(sigc::mem_fun(this, &Routebar::update_routes)));
94 void Routebar::update_routes()
97 const set<Route *> &routes = designer.get_layout().get_routes();
100 for(set<Route *>::const_iterator i=routes.begin(); i!=routes.end(); ++i, ++n)
102 drp_routes->append((*i)->get_name());
103 if(*i==designer.get_current_route())
106 drp_routes->append("(new route)");
107 drp_routes->set_selected_index(selected);