- Translator_group * current = report_to_l ();
- Translator_group * last = 0;
-
- Change_translator const * t = dynamic_cast<Change_translator const*> (music_l_);
- String to_type = t->change_to_type_str_;
- String to_id = t->change_to_id_str_;
-
- /* find the type of translator that we're changing.
-
- If \translator Staff = bass, then look for Staff = *
- */
- while (current && current->type_str_ != to_type)
+ string result; // error message
+
+ // Find the context that should have its parent changed.
+ Context *last = find_context_above_by_parent_type (it.get_outlet (), to_type);
+ if (last)
+ {
+ // Find the new parent.
+ Context *dest = find_context_near (it.get_outlet (), to_type, to_id);
+ if (dest)
+ {
+ send_stream_event (last, "ChangeParent", it.get_music ()->origin (),
+ ly_symbol2scm ("context"), dest->self_scm ());
+ }
+ else
+ /* FIXME: constant error message. */
+ it.get_music ()->origin ()->warning (_ ("cannot find context to switch to"));
+ }
+ else if (it.get_outlet ()->is_alias (to_type))