+ LASSERT(&it2.inset() == this && it2.pit() == 0, /**/);
+ if (producesOutput())
+ lyx::updateLabels(buffer(), it2);
+ else {
+ DocumentClass const & tclass = buffer().params().documentClass();
+ Counters const savecnt = tclass.counters();
+ lyx::updateLabels(buffer(), it2);
+ tclass.counters() = savecnt;
+ }
+}
+
+
+void InsetText::addToToc(DocIterator const & cdit)
+{
+ DocIterator dit = cdit;
+ dit.push_back(CursorSlice(*this));
+ Toc & toc = buffer().tocBackend().toc("tableofcontents");
+
+ BufferParams const & bufparams = buffer_->params();
+ const int min_toclevel = bufparams.documentClass().min_toclevel();
+
+ // For each paragraph, traverse its insets and let them add
+ // their toc items
+ ParagraphList & pars = paragraphs();
+ pit_type pend = paragraphs().size();
+ for (pit_type pit = 0; pit != pend; ++pit) {
+ Paragraph const & par = pars[pit];
+ dit.pit() = pit;
+ // the string that goes to the toc (could be the optarg)
+ docstring tocstring;
+ InsetList::const_iterator it = par.insetList().begin();
+ InsetList::const_iterator end = par.insetList().end();
+ for (; it != end; ++it) {
+ Inset & inset = *it->inset;
+ dit.pos() = it->pos;
+ //lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
+ inset.addToToc(dit);
+ switch (inset.lyxCode()) {
+ case OPTARG_CODE: {
+ if (!tocstring.empty())
+ break;
+ dit.pos() = 0;
+ Paragraph const & insetpar =
+ *static_cast<InsetOptArg&>(inset).paragraphs().begin();
+ if (!par.labelString().empty())
+ tocstring = par.labelString() + ' ';
+ tocstring += insetpar.asString();
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ /// now the toc entry for the paragraph
+ int const toclevel = par.layout().toclevel;
+ if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
+ dit.pos() = 0;
+ // insert this into the table of contents
+ if (tocstring.empty())
+ tocstring = par.asString(AS_STR_LABEL);
+ toc.push_back(TocItem(dit, toclevel - min_toclevel, tocstring));
+ }
+ }
+}
+
+
+bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
+{
+ if (cur.buffer().isClean())
+ return Inset::notifyCursorLeaves(old, cur);
+
+ // find text inset in old cursor
+ Cursor insetCur = old;
+ int scriptSlice = insetCur.find(this);
+ LASSERT(scriptSlice != -1, /**/);
+ insetCur.cutOff(scriptSlice);
+ LASSERT(&insetCur.inset() == this, /**/);
+
+ // update the old paragraph's words
+ insetCur.paragraph().updateWords(insetCur.top());
+
+ return Inset::notifyCursorLeaves(old, cur);
+}
+
+
+bool InsetText::completionSupported(Cursor const & cur) const
+{
+ Cursor const & bvCur = cur.bv().cursor();
+ if (&bvCur.inset() != this)
+ return false;
+ return text_.completionSupported(cur);
+}
+
+
+bool InsetText::inlineCompletionSupported(Cursor const & cur) const
+{
+ return completionSupported(cur);
+}
+
+
+bool InsetText::automaticInlineCompletion() const
+{
+ return lyxrc.completion_inline_text;
+}
+
+
+bool InsetText::automaticPopupCompletion() const
+{
+ return lyxrc.completion_popup_text;
+}
+
+
+bool InsetText::showCompletionCursor() const
+{
+ return lyxrc.completion_cursor_text;
+}
+
+
+CompletionList const * InsetText::createCompletionList(Cursor const & cur) const
+{
+ return completionSupported(cur) ? text_.createCompletionList(cur) : 0;
+}
+
+
+docstring InsetText::completionPrefix(Cursor const & cur) const
+{
+ if (!completionSupported(cur))
+ return docstring();
+ return text_.completionPrefix(cur);
+}
+
+
+bool InsetText::insertCompletion(Cursor & cur, docstring const & s,
+ bool finished)
+{
+ if (!completionSupported(cur))
+ return false;
+
+ return text_.insertCompletion(cur, s, finished);
+}
+
+
+void InsetText::completionPosAndDim(Cursor const & cur, int & x, int & y,
+ Dimension & dim) const
+{
+ TextMetrics const & tm = cur.bv().textMetrics(&text_);
+ tm.completionPosAndDim(cur, x, y, dim);
+}
+
+
+docstring InsetText::contextMenu(BufferView const &, int, int) const
+{
+ return from_ascii("context-edit");