+
+ // 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)
+{
+ vector<docstring> selList;
+
+ CutStack::const_iterator cit = theCuts.begin();
+ CutStack::const_iterator end = theCuts.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;
+ docstring 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, docstring::npos,
+ from_ascii("..."));
+ break;
+ }
+ }
+
+ selList.push_back(asciiSel);
+ }
+
+ return selList;
+}
+
+
+size_type numberOfSelections()
+{
+ return theCuts.size();
+}
+
+
+void cutSelection(LCursor & cur, bool doclear, bool realcut)
+{
+ // This doesn't make sense, if there is no selection
+ if (!cur.selection())
+ return;
+
+ // OK, we have a selection. This is always between cur.selBegin()
+ // and cur.selEnd()
+
+ if (cur.inTexted()) {
+ LyXText * text = cur.text();
+ BOOST_ASSERT(text);
+ // Stuff what we got on the clipboard. Even if there is no selection.
+
+ // There is a problem with having the stuffing here in that the
+ // larger the selection the slower LyX will get. This can be
+ // solved by running the line below only when the selection has
+ // finished. The solution used currently just works, to make it
+ // faster we need to be more clever and probably also have more
+ // calls to theSelection().put. (Lgb)
+// theSelection().put(cur.selectionAsString(true));
+
+
+ // make sure that the depth behind the selection are restored, too
+ recordUndoSelection(cur);
+ pit_type begpit = cur.selBegin().pit();
+ pit_type endpit = cur.selEnd().pit();
+
+ int endpos = cur.selEnd().pos();
+
+ BufferParams const & bp = cur.buffer().params();
+ if (realcut) {
+ copySelectionHelper(cur.buffer(),
+ text->paragraphs(),
+ begpit, endpit,
+ cur.selBegin().pos(), endpos,
+ bp.textclass);
+ }
+
+ boost::tie(endpit, endpos) =
+ eraseSelectionHelper(bp,
+ text->paragraphs(),
+ begpit, endpit,
+ cur.selBegin().pos(), endpos,
+ doclear);
+
+ // sometimes necessary
+ if (doclear)
+ text->paragraphs()[begpit].stripLeadingSpaces();
+
+ // cutSelection can invalidate the cursor so we need to set
+ // it anew. (Lgb)
+ // we prefer the end for when tracking changes
+ cur.pos() = endpos;
+ cur.pit() = endpit;
+
+ // need a valid cursor. (Lgb)
+ cur.clearSelection();
+ updateLabels(cur.buffer());
+
+ // tell tabular that a recent copy happened
+ dirtyTabularStack(false);
+ }
+
+ if (cur.inMathed()) {
+ if (cur.selBegin().idx() != cur.selEnd().idx()) {
+ // The current selection spans more than one cell.
+ // Record all cells
+ recordUndoInset(cur);
+ } else {
+ // Record only the current cell to avoid a jumping
+ // cursor after undo
+ recordUndo(cur);
+ }
+ if (realcut)
+ copySelection(cur);
+ eraseSelection(cur);
+ }
+}
+
+
+void copySelection(LCursor & cur)
+{
+ // stuff the selection onto the X clipboard, from an explicit copy request
+ theClipboard().put(cur.selectionAsString(true));
+
+ // this doesn't make sense, if there is no selection
+ if (!cur.selection())
+ return;
+
+ if (cur.inTexted()) {
+ LyXText * text = cur.text();
+ BOOST_ASSERT(text);
+ // ok we have a selection. This is always between cur.selBegin()
+ // and sel_end cursor
+
+ // copy behind a space if there is one
+ ParagraphList & pars = text->paragraphs();
+ pos_type pos = cur.selBegin().pos();
+ pit_type par = cur.selBegin().pit();
+ while (pos < pars[par].size()
+ && pars[par].isLineSeparator(pos)
+ && (par != cur.selEnd().pit() || pos < cur.selEnd().pos()))
+ ++pos;
+
+ copySelectionHelper(cur.buffer(), pars, par, cur.selEnd().pit(),
+ pos, cur.selEnd().pos(), cur.buffer().params().textclass);
+ }
+
+ if (cur.inMathed()) {
+ //lyxerr << "copySelection in mathed" << endl;
+ ParagraphList pars;
+ Paragraph par;
+ BufferParams const & bp = cur.buffer().params();
+ par.layout(bp.getLyXTextClass().defaultLayout());
+ par.insert(0, grabSelection(cur), LyXFont(), Change(Change::UNCHANGED));
+ pars.push_back(par);
+ theCuts.push(make_pair(pars, bp.textclass));
+ }
+ // tell tabular that a recent copy happened
+ dirtyTabularStack(false);