mirror of
https://github.com/Ardour/ardour.git
synced 2026-01-22 05:07:07 +01:00
Disallow empty names for Groups, automatically enumerate them
This commit is contained in:
parent
26ba90815b
commit
bae86a2d90
3 changed files with 20 additions and 9 deletions
|
|
@ -88,6 +88,15 @@ RouteGroupDialog::RouteGroupDialog (RouteGroup* g, bool creating_new)
|
||||||
|
|
||||||
main_vbox->pack_start (*top_vbox, false, false);
|
main_vbox->pack_start (*top_vbox, false, false);
|
||||||
|
|
||||||
|
if (_group->name ().empty()) {
|
||||||
|
_initial_name = "1";
|
||||||
|
while (!unique_name (_initial_name)) {
|
||||||
|
_initial_name = bump_name_number (_initial_name);
|
||||||
|
}
|
||||||
|
_name.set_text (_initial_name);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
_name.set_text (_group->name ());
|
_name.set_text (_group->name ());
|
||||||
_active.set_active (_group->is_active ());
|
_active.set_active (_group->is_active ());
|
||||||
|
|
||||||
|
|
@ -181,14 +190,14 @@ RouteGroupDialog::do_run ()
|
||||||
return Gtk::RESPONSE_CANCEL;
|
return Gtk::RESPONSE_CANCEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unique_name ()) {
|
if (unique_name (_name.get_text())) {
|
||||||
/* not cancelled and the name is ok, so all is well */
|
/* not cancelled and the name is ok, so all is well */
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_group->set_name (_initial_name);
|
_group->set_name (_initial_name);
|
||||||
MessageDialog msg (
|
MessageDialog msg (
|
||||||
_("A route group of this name already exists. Please use a different name."),
|
_("The group name is not unique. Please use a different name."),
|
||||||
false,
|
false,
|
||||||
Gtk::MESSAGE_ERROR,
|
Gtk::MESSAGE_ERROR,
|
||||||
Gtk::BUTTONS_OK,
|
Gtk::BUTTONS_OK,
|
||||||
|
|
@ -232,11 +241,12 @@ RouteGroupDialog::gain_toggled ()
|
||||||
|
|
||||||
/** @return true if the current group's name is unique accross the session */
|
/** @return true if the current group's name is unique accross the session */
|
||||||
bool
|
bool
|
||||||
RouteGroupDialog::unique_name () const
|
RouteGroupDialog::unique_name (std::string const name) const
|
||||||
{
|
{
|
||||||
|
if (name.empty()) return false; // do not allow empty name, empty means unset.
|
||||||
list<RouteGroup*> route_groups = _group->session().route_groups ();
|
list<RouteGroup*> route_groups = _group->session().route_groups ();
|
||||||
list<RouteGroup*>::iterator i = route_groups.begin ();
|
list<RouteGroup*>::iterator i = route_groups.begin ();
|
||||||
while (i != route_groups.end() && ((*i)->name() != _name.get_text() || *i == _group)) {
|
while (i != route_groups.end() && ((*i)->name() != name || *i == _group)) {
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ private:
|
||||||
|
|
||||||
void gain_toggled ();
|
void gain_toggled ();
|
||||||
void update ();
|
void update ();
|
||||||
bool unique_name () const;
|
bool unique_name (std::string const name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -200,18 +200,19 @@ string
|
||||||
ARDOUR::bump_name_number (const std::string& name)
|
ARDOUR::bump_name_number (const std::string& name)
|
||||||
{
|
{
|
||||||
size_t pos = name.length();
|
size_t pos = name.length();
|
||||||
|
size_t num = 0;
|
||||||
bool have_number = false;
|
bool have_number = false;
|
||||||
while (pos > 0 && isdigit(name.at(--pos))) {
|
while (pos > 0 && isdigit(name.at(--pos))) {
|
||||||
have_number = true;
|
have_number = true;
|
||||||
|
num = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
string newname;
|
string newname;
|
||||||
if (have_number) {
|
if (have_number) {
|
||||||
++pos;
|
int32_t seq = strtol (name.c_str() + num, (char **)NULL, 10);
|
||||||
int32_t num = strtol (name.c_str() + pos, (char **)NULL, 10);
|
|
||||||
char buf[32];
|
char buf[32];
|
||||||
snprintf (buf, sizeof(buf), "%d", num + 1);
|
snprintf (buf, sizeof(buf), "%d", seq + 1);
|
||||||
newname = name.substr (0, pos);
|
newname = name.substr (0, num);
|
||||||
newname += buf;
|
newname += buf;
|
||||||
} else {
|
} else {
|
||||||
newname = name;
|
newname = name;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue