From 2ad57dcb6b9b54b6d0aa43b4729c3ea480f6d51c Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Sat, 29 Jul 2023 14:07:28 -0400 Subject: [PATCH] Preview formatted references in the work area. Patch from Daniel Ramoeller , fixed up by RKH. --- lib/lyx2lyx/lyx_2_4.py | 15 +- src/Buffer.cpp | 4 + src/BufferParams.cpp | 4 + src/BufferParams.h | 2 + src/frontends/qt/GuiDocument.cpp | 4 + src/frontends/qt/ui/LaTeXUi.ui | 227 +++++++++++++++---------------- src/insets/InsetRef.cpp | 36 +++-- src/insets/InsetRef.h | 4 + 8 files changed, 166 insertions(+), 130 deletions(-) diff --git a/lib/lyx2lyx/lyx_2_4.py b/lib/lyx2lyx/lyx_2_4.py index ede6e4fae6..4cc5fe5bdf 100644 --- a/lib/lyx2lyx/lyx_2_4.py +++ b/lib/lyx2lyx/lyx_2_4.py @@ -5548,6 +5548,12 @@ def revert_hequotes(document): document.body[i] = "\\begin_inset Quotes pld" +def revert_formatted_refs(document): + i = find_token(document.header, "\\use_formatted_ref", 0) + if i != -1: + del document.header[i] + + ## # Conversion hub # @@ -5627,11 +5633,14 @@ convert = [ [615, [convert_acknowledgment,convert_ack_theorems]], [616, [convert_empty_macro]], [617, [convert_cov_options]], - [618, []] + [618, []], + [619, []] ] -revert = [[617, [revert_hequotes]], - [616, [revert_expreambles,revert_exarg2,revert_linggloss2,revert_cov_options]], + +revert = [[618, [revert_formatted_refs]], + [617, [revert_hequotes]], + [616, [revert_expreambles,revert_exarg2,revert_linggloss2,revert_cov_options]], [615, [revert_empty_macro]], [614, [revert_ack_theorems,revert_acknowledgment]], [613, [revert_hyper_other]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index e028fa958d..732ca7e323 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -5342,6 +5342,10 @@ void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const void Buffer::updateBuffer(ParIterator & parit, UpdateType utype, bool const deleted) const { + // if fomatted references are shown in workarea update buffer accordingly + if (params().use_formatted_ref) + utype = OutputUpdate; + pushIncludedBuffer(this); // LASSERT: Is it safe to continue here, or should we just return? LASSERT(parit.pit() == 0, /**/); diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 3dad8c6913..4c2b615776 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -488,6 +488,7 @@ BufferParams::BufferParams() shell_escape = false; output_sync = false; use_refstyle = true; + use_formatted_ref = false; use_minted = false; use_lineno = false; @@ -1205,6 +1206,8 @@ string BufferParams::readToken(Lexer & lex, string const & token, lex >> output_sync_macro; } else if (token == "\\use_refstyle") { lex >> use_refstyle; + } else if (token == "\\use_formatted_ref") { + lex >> use_formatted_ref; } else if (token == "\\use_minted") { lex >> use_minted; } else if (token == "\\use_lineno") { @@ -1433,6 +1436,7 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const << "\n\\suppress_date " << convert(suppress_date) << "\n\\justification " << convert(justification) << "\n\\use_refstyle " << use_refstyle + << "\n\\use_formatted_ref " << use_formatted_ref << "\n\\use_minted " << use_minted << "\n\\use_lineno " << use_lineno << '\n'; diff --git a/src/BufferParams.h b/src/BufferParams.h index 2a2e0f3087..34b44474af 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -606,6 +606,8 @@ public: std::string output_sync_macro; /// use refstyle? or prettyref? bool use_refstyle; + /// use formatted references in the workarea? + bool use_formatted_ref; /// use minted? or listings? bool use_minted; //output line numbering diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp index f9fb19b331..4d873bda69 100644 --- a/src/frontends/qt/GuiDocument.cpp +++ b/src/frontends/qt/GuiDocument.cpp @@ -1626,6 +1626,8 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(latexModule->refstyleCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(latexModule->refFormattedCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); latexModule->optionsLE->setValidator(new NoNewLineValidator( latexModule->optionsLE)); @@ -3563,6 +3565,7 @@ void GuiDocument::applyView() // date bp_.suppress_date = latexModule->suppressDateCB->isChecked(); bp_.use_refstyle = latexModule->refstyleCB->isChecked(); + bp_.use_formatted_ref = latexModule->refFormattedCB->isChecked(); // biblio string const engine = @@ -4067,6 +4070,7 @@ void GuiDocument::paramsToDialog() // date latexModule->suppressDateCB->setChecked(bp_.suppress_date); latexModule->refstyleCB->setChecked(bp_.use_refstyle); + latexModule->refFormattedCB->setChecked(bp_.use_formatted_ref); // biblio string const cite_engine = bp_.citeEngine(); diff --git a/src/frontends/qt/ui/LaTeXUi.ui b/src/frontends/qt/ui/LaTeXUi.ui index e6f579a7e1..61d376fa1d 100644 --- a/src/frontends/qt/ui/LaTeXUi.ui +++ b/src/frontends/qt/ui/LaTeXUi.ui @@ -6,7 +6,7 @@ 0 0 - 341 + 332 442 @@ -14,6 +14,72 @@ + + + + &Graphics driver: + + + psdriverCO + + + + + + + false + + + + + + + &Use refstyle (not prettyref) for cross-references + + + + + + + Qt::Vertical + + + + 20 + 2 + + + + + + + + true + + + + 0 + 0 + + + + &Suppress default date on front page + + + + + + + Qt::Horizontal + + + + 261 + 22 + + + + @@ -23,12 +89,6 @@ true - - 9 - - - 6 - @@ -55,81 +115,6 @@ - - - - Class Options - - - true - - - - - - Enable to use the options that are predefined in the layout file - - - &Predefined: - - - - - - - The options that are predefined in the layout file. Click to the left to select/deselect. - - - true - - - - - - - Cus&tom: - - - optionsLE - - - - - - - - - - - - - &Graphics driver: - - - psdriverCO - - - - - - - false - - - - - - - Qt::Horizontal - - - - 261 - 22 - - - - @@ -148,12 +133,6 @@ true - - 9 - - - 6 - @@ -181,39 +160,55 @@ - - - - true - - - - 0 - 0 - + + + + Class Options - - &Suppress default date on front page + + true + + + + + Enable to use the options that are predefined in the layout file + + + &Predefined: + + + + + + + The options that are predefined in the layout file. Click to the left to select/deselect. + + + true + + + + + + + Cus&tom: + + + optionsLE + + + + + + + - - - - Qt::Vertical - - - - 20 - 2 - - - - - - + + - &Use refstyle (not prettyref) for cross-references + Indicate cross-reference output in the work area diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index 277f8e5155..fcd28d2346 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -382,11 +382,11 @@ void InsetRef::docbook(XMLStream & xs, OutputParams const &) const } -docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const +docstring InsetRef::displayString(docstring const & ref, string const & cmd, + string const & language) const + { - docstring const & ref = getParam("reference"); InsetLabel const * il = buffer().insetLabel(ref, true); - string const & cmd = params().getCmdName(); docstring display_string; if (il && !il->counterValue().empty()) { @@ -397,11 +397,11 @@ docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const else if (cmd == "vref") // normally, would be "ref on page #", but we have no pages display_string = value; - else if (cmd == "pageref" || cmd == "vpageref") + else if (cmd == "pageref" || cmd == "vpageref") { // normally would be "on page #", but we have no pages. - display_string = translateIfPossible(from_ascii("elsewhere"), - op.local_font->language()->lang()); - else if (cmd == "eqref") + display_string = + translateIfPossible(from_ascii("elsewhere"), language); + } else if (cmd == "eqref") display_string = '(' + value + ')'; else if (cmd == "formatted") { display_string = il->formattedCounter(); @@ -418,14 +418,21 @@ docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const // in that section. So this is not trivial. display_string = il->prettyCounter(); } else - display_string = ref; + display_string = ref; + return display_string; +} + +docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const + { + docstring const & ref = getParam("reference"); + string const & cmd = params().getCmdName(); // FIXME What we'd really like to do is to be able to output some // appropriate sort of text here. But to do that, we need to associate // some sort of counter with the label, and we don't have that yet. docstring const attr = "href=\"#" + xml::cleanAttr(ref) + '"'; xs << xml::StartTag("a", to_utf8(attr)); - xs << display_string; + xs << displayString(ref, cmd, op.local_font->language()->lang());; xs << xml::EndTag("a"); return docstring(); } @@ -520,14 +527,21 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType, bool const /*del label += getParam("name"); } + bool const use_formatted_ref = buffer().params().use_formatted_ref; unsigned int const maxLabelChars = 24; - if (label.size() > maxLabelChars) { + // Show label in tooltip when formatted references are shown in the work + // area or it is too long + if (use_formatted_ref || label.size() > maxLabelChars) { tooltip_ = label; support::truncateWithEllipsis(label, maxLabelChars); } else tooltip_ = from_ascii(""); - screen_label_ = label; + if (use_formatted_ref && cmd != "pageref" && cmd != "vpageref" + && cmd != "vref" && cmd != "labelonly") + screen_label_ = displayString(ref, cmd); + else + screen_label_ = label; broken_ = false; setBroken(broken_); } diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index 6286652f4d..09d5e18e34 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -117,6 +117,10 @@ private: docstring screenLabel() const override; //@} + /// + docstring displayString(docstring const & ref, std::string const & cmd, + std::string const & language = std::string()) const; + /// \return the label with things that need to be escaped escaped docstring getEscapedLabel(OutputParams const &) const; -- 2.39.5