-} // namespace anon
-
-
-namespace lyx {
-namespace cap {
-
-
-int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
- ParagraphList & pars, ErrorList & errorlist)
-{
- BOOST_ASSERT(!pars.empty());
- int ret = 0;
- if (c1 == c2)
- return ret;
-
- LyXTextClass const & tclass1 = textclasslist[c1];
- LyXTextClass const & tclass2 = textclasslist[c2];
-
- InsetText in;
- std::swap(in.paragraphs(), pars);
-
- 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()) {
- ++ret;
- string 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"),
- name, it->layout()->name(), tclass1.name(), tclass2.name());
- // To warn the user that something had to be done.
- errorlist.push_back(ErrorItem("Changed Layout", s,
- it->id(), 0,
- it->size()));
- }
- }
- std::swap(in.paragraphs(), pars);
- return ret;
-}
-
-
-std::vector<string> const availableSelections(Buffer const & buffer)
-{
- vector<string> selList;
-
- CutStack::const_iterator cit = cuts.begin();
- CutStack::const_iterator end = cuts.end();
- for (; cit != end; ++cit) {
- // we do not use cit-> here because gcc 2.9x does not
- // like it (JMarc)
- ParagraphList const & pars = (*cit).first;
- string asciiSel;
- ParagraphList::const_iterator pit = pars.begin();
- ParagraphList::const_iterator pend = pars.end();
- for (; pit != pend; ++pit) {
- asciiSel += pit->asString(buffer, false);
- if (asciiSel.size() > 25) {
- asciiSel.replace(22, string::npos, "...");
- break;
- }
- }
-
- selList.push_back(asciiSel);
- }
-
- return selList;
-}
-
-
-PitPosPair eraseSelection(BufferParams const & params, ParagraphList & pars,
- par_type startpit, par_type endpit,
- int startpos, int endpos, bool doclear)
-{
- if (startpit == par_type(pars.size()) ||
- (startpos > pars[startpit].size()))
- return PitPosPair(endpit, endpos);
-
- if (endpit == par_type(pars.size()) ||
- startpit == endpit) {
- endpos -= pars[startpit].erase(startpos, endpos);
- return PitPosPair(endpit, endpos);
- }
-
- // clear end/begin fragments of the first/last par in selection
- bool all_erased = true;
-
- pars[startpit].erase(startpos, pars[startpit].size());
- if (pars[startpit].size() != startpos)
- all_erased = false;
-
- endpos -= pars[endpit].erase(0, endpos);
- if (endpos != 0)
- all_erased = false;
-
- // Loop through the deleted pars if any, erasing as needed
- for (par_type pit = startpit + 1; pit != endpit;) {
- // "erase" the contents of the par
- pars[pit].erase(0, pars[pit].size());
- if (!pars[pit].size()) {
- // remove the par if it's now empty
- pars.erase(pars.begin() + pit);
- --endpit;
- } else {
- ++pit;
- all_erased = false;
- }
- }
-
-#if 0 // FIXME: why for cut but not copy ?
- // the cut selection should begin with standard layout
- if (realcut) {
- buf->params().clear();
- buf->bibkey = 0;
- buf->layout(textclasslist[buffer->params.textclass].defaultLayoutName());
- }
-#endif
-
- if (startpit + 1 == par_type(pars.size()))
- return PitPosPair(endpit, endpos);
-
- if (doclear) {
- pars[startpit + 1].stripLeadingSpaces();
- }
-
- // paste the paragraphs again, if possible
- if (all_erased &&
- (pars[startpit].hasSameLayout(pars[startpit + 1]) ||
- pars[startpit + 1].empty())) {
- mergeParagraph(params, pars, startpit);
- // this because endpar gets deleted here!
- endpit = startpit;
- endpos = startpos;
- }