+void switchBetweenClasses(textclass_type c1, textclass_type c2,
+ InsetText & in, ErrorList & errorlist)
+{
+ BOOST_ASSERT(!in.paragraphs().empty());
+ if (c1 == c2)
+ return;
+
+ LyXTextClass const & tclass1 = textclasslist[c1];
+ LyXTextClass const & tclass2 = textclasslist[c2];
+
+ // layouts
+ ParIterator end = par_iterator_end(in);
+ for (ParIterator it = par_iterator_begin(in); it != end; ++it) {
+ string const name = it->layout()->name();
+ bool hasLayout = tclass2.hasLayout(name);
+
+ if (hasLayout)
+ it->layout(tclass2[name]);
+ else
+ it->layout(tclass2.defaultLayout());
+
+ if (!hasLayout && name != tclass1.defaultLayoutName()) {
+ docstring const s = bformat(
+ _("Layout had to be changed from\n%1$s to %2$s\n"
+ "because of class conversion from\n%3$s to %4$s"),
+ from_utf8(name), from_utf8(it->layout()->name()),
+ from_utf8(tclass1.name()), from_utf8(tclass2.name()));
+ // To warn the user that something had to be done.
+ errorlist.push_back(ErrorItem(_("Changed Layout"), s,
+ it->id(), 0,
+ it->size()));
+ }
+ }
+
+ // character styles
+ InsetIterator const i_end = inset_iterator_end(in);
+ for (InsetIterator it = inset_iterator_begin(in); it != i_end; ++it) {
+ if (it->lyxCode() == InsetBase::CHARSTYLE_CODE) {
+ InsetCharStyle & inset =
+ static_cast<InsetCharStyle &>(*it);
+ string const name = inset.params().type;
+ CharStyles::iterator const found_cs =
+ tclass2.charstyle(name);
+ if (found_cs == tclass2.charstyles().end()) {
+ // The character style is undefined in tclass2
+ inset.setUndefined();
+ docstring const s = bformat(_(
+ "Character style %1$s is "
+ "undefined because of class "
+ "conversion from\n%2$s to %3$s"),
+ from_utf8(name), from_utf8(tclass1.name()),
+ from_utf8(tclass2.name()));
+ // To warn the user that something had to be done.
+ errorlist.push_back(ErrorItem(
+ _("Undefined character style"),
+ s, it.paragraph().id(), it.pos(), it.pos() + 1));
+ } else if (inset.undefined()) {
+ // The character style is undefined in
+ // tclass1 and is defined in tclass2
+ inset.setDefined(found_cs);
+ }
+ }
+ }
+}
+
+
+std::vector<docstring> const availableSelections(Buffer const & buffer)