void InsetText::clear()
{
ParagraphList & pars = paragraphs();
- LASSERT(!pars.empty(), /**/);
+ LBUFERR(!pars.empty());
// This is a gross hack...
Layout const & old_layout = pars.begin()->layout();
{
LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd);
- if (getLayout().isPassThru()) {
+#if 0
+// FIXME: This code does not seem to be necessary anymore
+// Remove for 2.1 if no counter-evidence is found.
+ if (isPassThru() && lyxCode() != ARG_CODE) {
// Force any new text to latex_language FIXME: This
// should only be necessary in constructor, but new
// paragraphs that are created by pressing enter at
cur.current_font.setLanguage(latex_language);
cur.real_current_font.setLanguage(latex_language);
}
+#endif
switch (cmd.action()) {
case LFUN_PASTE:
status.setEnabled(false);
return true;
}
- if (&buffer().inset() == this || !cur.paragraph().layout().latexargs().empty())
+ if (&buffer().inset() == this || !cur.paragraph().layout().args().empty())
return text_.getStatus(cur, cmd, status);
- Layout::LaTeXArgMap args = getLayout().latexargs();
- Layout::LaTeXArgMap::const_iterator const lait =
- args.find(convert<unsigned int>(arg));
+
+ Layout::LaTeXArgMap args = getLayout().args();
+ Layout::LaTeXArgMap::const_iterator const lait = args.find(arg);
if (lait != args.end()) {
status.setEnabled(true);
- InsetList::const_iterator it = cur.paragraph().insetList().begin();
- InsetList::const_iterator end = cur.paragraph().insetList().end();
- for (; it != end; ++it) {
- if (it->inset->lyxCode() == ARG_CODE) {
- InsetArgument const * ins =
- static_cast<InsetArgument const *>(it->inset);
- if (ins->name() == arg) {
- // we have this already
- status.setEnabled(false);
- return true;
+ ParagraphList::const_iterator pit = paragraphs().begin();
+ for (; pit != paragraphs().end(); ++pit) {
+ InsetList::const_iterator it = pit->insetList().begin();
+ InsetList::const_iterator end = pit->insetList().end();
+ for (; it != end; ++it) {
+ if (it->inset->lyxCode() == ARG_CODE) {
+ InsetArgument const * ins =
+ static_cast<InsetArgument const *>(it->inset);
+ if (ins->name() == arg) {
+ // we have this already
+ status.setEnabled(false);
+ return true;
+ }
}
}
}
if (runparams.moving_arg)
os << "\\protect";
os << '\\' << from_utf8(il.latexname());
- getOptArg(os, runparams);
+ if (!il.latexargs().empty())
+ getArgs(os, runparams);
if (!il.latexparam().empty())
os << from_utf8(il.latexparam());
os << '{';
} else if (il.latextype() == InsetLayout::ENVIRONMENT) {
if (il.isDisplay())
- os << breakln;
+ os << breakln;
else
- os << safebreakln;
+ os << safebreakln;
if (runparams.lastid != -1)
os.texrow().start(runparams.lastid,
runparams.lastpos);
- os << "\\begin{" << from_utf8(il.latexname()) << "}\n";
+ os << "\\begin{" << from_utf8(il.latexname()) << "}";
+ if (!il.latexargs().empty())
+ getArgs(os, runparams);
if (!il.latexparam().empty())
os << from_utf8(il.latexparam());
+ os << '\n';
}
+ } else {
+ if (!il.latexargs().empty())
+ getArgs(os, runparams);
+ if (!il.latexparam().empty())
+ os << from_utf8(il.latexparam());
}
+
+ if (!il.leftdelim().empty())
+ os << il.leftdelim();
+
OutputParams rp = runparams;
- if (il.isPassThru())
+ if (isPassThru())
rp.pass_thru = true;
if (il.isNeedProtect())
rp.moving_arg = true;
latexParagraphs(buffer(), text_, os, rp);
runparams.encoding = rp.encoding;
+ if (!il.rightdelim().empty())
+ os << il.rightdelim();
+
if (!il.latexname().empty()) {
if (il.latextype() == InsetLayout::COMMAND) {
os << "}";
+ if (!il.postcommandargs().empty())
+ getArgs(os, runparams, true);
} else if (il.latextype() == InsetLayout::ENVIRONMENT) {
// A comment environment doesn't need a % before \n\end
if (il.isDisplay() || runparams.inComment)
- os << breakln;
+ os << breakln;
else
- os << safebreakln;
+ os << safebreakln;
os << "\\end{" << from_utf8(il.latexname()) << "}\n";
if (!il.isDisplay())
os.protectSpace(true);
}
-int InsetText::plaintext(odocstream & os, OutputParams const & runparams) const
+int InsetText::plaintext(odocstringstream & os,
+ OutputParams const & runparams, size_t max_length) const
{
ParagraphList::const_iterator beg = paragraphs().begin();
ParagraphList::const_iterator end = paragraphs().end();
os << '\n';
}
odocstringstream oss;
- writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed);
+ writePlaintextParagraph(buffer(), *it, oss, runparams, ref_printed, max_length);
docstring const str = oss.str();
os << str;
// FIXME: len is not computed fully correctly; in principle,
// we have to count the characters after the last '\n'
len = str.size();
+ if (os.str().size() >= max_length)
+ break;
}
return len;
InsetLayout const & il = getLayout();
if (opts & WriteOuterTag)
xs << html::StartTag(il.htmltag(), il.htmlattr());
+
if ((opts & WriteLabel) && !il.counter().empty()) {
BufferParams const & bp = buffer().masterBuffer()->params();
Counters & cntrs = bp.documentClass().counters();
if (opts & WriteInnerTag)
xs << html::StartTag(il.htmlinnertag(), il.htmlinnerattr());
- OutputParams ours = runparams;
+
+ // we will eventually lose information about the containing inset
if (!il.isMultiPar() || opts == JustText)
- ours.html_make_pars = false;
- xhtmlParagraphs(text_, buffer(), xs, ours);
+ runparams.html_make_pars = false;
+ if (il.isPassThru())
+ runparams.pass_thru = true;
+
+ xhtmlParagraphs(text_, buffer(), xs, runparams);
+
if (opts & WriteInnerTag)
xs << html::EndTag(il.htmlinnertag());
+
if (opts & WriteOuterTag)
xs << html::EndTag(il.htmltag());
+
return docstring();
}
-void InsetText::getOptArg(otexstream & os,
- OutputParams const & runparams) const
+void InsetText::getArgs(otexstream & os, OutputParams const & runparams_in,
+ bool const post) const
{
- latexArgInsets(paragraphs()[0], os, runparams, getLayout().latexargs());
+ OutputParams runparams = runparams_in;
+ runparams.local_font =
+ ¶graphs()[0].getFirstFontSettings(buffer().masterBuffer()->params());
+ if (isPassThru())
+ runparams.pass_thru = true;
+ if (post)
+ latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().postcommandargs(), "post:");
+ else
+ latexArgInsets(paragraphs(), paragraphs().begin(), os, runparams, getLayout().latexargs());
}
}
+bool InsetText::insetAllowed(InsetCode code) const
+{
+ switch (code) {
+ // Arguments are also allowed in PassThru insets
+ case ARG_CODE:
+ return true;
+ default:
+ return !isPassThru();
+ }
+}
+
+
void InsetText::updateBuffer(ParIterator const & it, UpdateType utype)
{
ParIterator it2 = it;
}
-void InsetText::addToToc(DocIterator const & cdit) const
+void InsetText::addToToc(DocIterator const & cdit, bool output_active) const
{
DocIterator dit = cdit;
dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
BufferParams const & bufparams = buffer_->params();
int const min_toclevel = bufparams.documentClass().min_toclevel();
+ // we really should have done this before we got here, but it
+ // can't hurt too much to do it again
+ bool const doing_output = output_active && producesOutput();
// For each paragraph, traverse its insets and let them add
// their toc items
Inset & inset = *it->inset;
dit.pos() = it->pos;
//lyxerr << (void*)&inset << " code: " << inset.lyxCode() << std::endl;
- inset.addToToc(dit);
+ inset.addToToc(dit, doing_output);
if (inset.lyxCode() == ARG_CODE)
arginset = inset.asInsetText();
}
// now the toc entry for the paragraph
- int const toclevel = par.layout().toclevel;
+ int const toclevel = text().getTocLevel(pit);
if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
// insert this into the table of contents
docstring tocstring;
+ int const length = doing_output ? INT_MAX : TOC_ENTRY_LENGTH;
if (arginset) {
tocstring = par.labelString();
if (!tocstring.empty())
tocstring += ' ';
- arginset->text().forToc(tocstring, TOC_ENTRY_LENGTH);
+ arginset->text().forToc(tocstring, length);
} else
- par.forToc(tocstring, TOC_ENTRY_LENGTH);
+ par.forToc(tocstring, length);
dit.pos() = 0;
toc.push_back(TocItem(dit, toclevel - min_toclevel,
- tocstring, tocstring));
+ tocstring, doing_output, tocstring));
}
// And now the list of changes.
- par.addChangesToToc(dit, buffer());
+ par.addChangesToToc(dit, buffer(), doing_output);
}
}
// find text inset in old cursor
Cursor insetCur = old;
int scriptSlice = insetCur.find(this);
- LASSERT(scriptSlice != -1, /**/);
+ // we can try to continue here. returning true means
+ // the cursor is "now" invalid. which it was.
+ LASSERT(scriptSlice != -1, return true);
insetCur.cutOff(scriptSlice);
- LASSERT(&insetCur.inset() == this, /**/);
+ LASSERT(&insetCur.inset() == this, return true);
// update the old paragraph's words
insetCur.paragraph().updateWords();
bool InsetText::completionSupported(Cursor const & cur) const
{
- //LASSERT(&cur.bv().cursor().inset() != this, return false);
+ //LASSERT(&cur.bv().cursor().inset() == this, return false);
return text_.completionSupported(cur);
}
{
size_t const max_length = numlines * len;
OutputParams rp(&buffer().params().encoding());
+ rp.for_tooltip = true;
odocstringstream oss;
oss << prefix;
for (; it != end; ++it) {
if (it != beg)
oss << '\n';
- writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed);
+ writePlaintextParagraph(buffer(), *it, oss, rp, ref_printed, max_length);
str = oss.str();
- if (str.length() > max_length)
+ if (str.length() >= max_length)
break;
}
return support::wrapParas(str, 4, len, numlines);