X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetText.cpp;h=3ec6f40492288ea6c56736bfa6336c8db74c141b;hb=90f7007a2e6c78ffd031e4636ff909ab1bc2ddec;hp=e209e5021505b2cb20b9443c25e2300a4bc235e8;hpb=2e69c66195544ee06e2b286f84fdfb6a2515a36d;p=lyx.git diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index e209e50215..3ec6f40492 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -266,7 +266,10 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd) { 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 @@ -276,6 +279,7 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd) cur.current_font.setLanguage(latex_language); cur.real_current_font.setLanguage(latex_language); } +#endif switch (cmd.action()) { case LFUN_PASTE: @@ -338,26 +342,29 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd, 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(arg)); + + Layout::LaTeXArgMap args = getLayout().args(); + Layout::LaTeXArgMap::const_iterator const lait = args.find(arg); if (lait != args.end()) { - 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(it->inset); - if (ins->name() == arg) { - // we have this already - status.setEnabled(false); - return true; + status.setEnabled(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(it->inset); + if (ins->name() == arg) { + // we have this already + status.setEnabled(false); + return true; + } } } } - status.setEnabled(true); } else status.setEnabled(false); return true; @@ -436,24 +443,38 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const if (runparams.moving_arg) os << "\\protect"; os << '\\' << from_utf8(il.latexname()); + 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; @@ -464,15 +485,20 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const 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); @@ -560,6 +586,7 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp, 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(); @@ -579,17 +606,38 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp, 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::getArgs(otexstream & os, OutputParams const & runparams_in, + bool const post) const +{ + 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()); +} + void InsetText::cursorPos(BufferView const & bv, CursorSlice const & sl, bool boundary, int & x, int & y) const @@ -701,6 +749,18 @@ ParagraphList & InsetText::paragraphs() } +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; @@ -777,7 +837,7 @@ void InsetText::addToToc(DocIterator const & cdit) const 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;