Preview formatted references in the work area.

Patch from Daniel Ramoeller <d.lyx@web.de>, fixed up by RKH.
This commit is contained in:
Richard Kimberly Heck 2023-07-29 14:07:28 -04:00
parent ca3004fc67
commit 2ad57dcb6b
8 changed files with 170 additions and 134 deletions

View File

@ -5548,6 +5548,12 @@ def revert_hequotes(document):
document.body[i] = "\\begin_inset Quotes pld" 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 # Conversion hub
# #
@ -5627,10 +5633,13 @@ convert = [
[615, [convert_acknowledgment,convert_ack_theorems]], [615, [convert_acknowledgment,convert_ack_theorems]],
[616, [convert_empty_macro]], [616, [convert_empty_macro]],
[617, [convert_cov_options]], [617, [convert_cov_options]],
[618, []] [618, []],
[619, []]
] ]
revert = [[617, [revert_hequotes]],
revert = [[618, [revert_formatted_refs]],
[617, [revert_hequotes]],
[616, [revert_expreambles,revert_exarg2,revert_linggloss2,revert_cov_options]], [616, [revert_expreambles,revert_exarg2,revert_linggloss2,revert_cov_options]],
[615, [revert_empty_macro]], [615, [revert_empty_macro]],
[614, [revert_ack_theorems,revert_acknowledgment]], [614, [revert_ack_theorems,revert_acknowledgment]],

View File

@ -5342,6 +5342,10 @@ void Buffer::Impl::setLabel(ParIterator & it, UpdateType utype) const
void Buffer::updateBuffer(ParIterator & parit, UpdateType utype, bool const deleted) 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); pushIncludedBuffer(this);
// LASSERT: Is it safe to continue here, or should we just return? // LASSERT: Is it safe to continue here, or should we just return?
LASSERT(parit.pit() == 0, /**/); LASSERT(parit.pit() == 0, /**/);

View File

@ -488,6 +488,7 @@ BufferParams::BufferParams()
shell_escape = false; shell_escape = false;
output_sync = false; output_sync = false;
use_refstyle = true; use_refstyle = true;
use_formatted_ref = false;
use_minted = false; use_minted = false;
use_lineno = false; use_lineno = false;
@ -1205,6 +1206,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
lex >> output_sync_macro; lex >> output_sync_macro;
} else if (token == "\\use_refstyle") { } else if (token == "\\use_refstyle") {
lex >> use_refstyle; lex >> use_refstyle;
} else if (token == "\\use_formatted_ref") {
lex >> use_formatted_ref;
} else if (token == "\\use_minted") { } else if (token == "\\use_minted") {
lex >> use_minted; lex >> use_minted;
} else if (token == "\\use_lineno") { } else if (token == "\\use_lineno") {
@ -1433,6 +1436,7 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
<< "\n\\suppress_date " << convert<string>(suppress_date) << "\n\\suppress_date " << convert<string>(suppress_date)
<< "\n\\justification " << convert<string>(justification) << "\n\\justification " << convert<string>(justification)
<< "\n\\use_refstyle " << use_refstyle << "\n\\use_refstyle " << use_refstyle
<< "\n\\use_formatted_ref " << use_formatted_ref
<< "\n\\use_minted " << use_minted << "\n\\use_minted " << use_minted
<< "\n\\use_lineno " << use_lineno << "\n\\use_lineno " << use_lineno
<< '\n'; << '\n';

View File

@ -606,6 +606,8 @@ public:
std::string output_sync_macro; std::string output_sync_macro;
/// use refstyle? or prettyref? /// use refstyle? or prettyref?
bool use_refstyle; bool use_refstyle;
/// use formatted references in the workarea?
bool use_formatted_ref;
/// use minted? or listings? /// use minted? or listings?
bool use_minted; bool use_minted;
//output line numbering //output line numbering

View File

@ -1626,6 +1626,8 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(latexModule->refstyleCB, SIGNAL(clicked()), connect(latexModule->refstyleCB, SIGNAL(clicked()),
this, SLOT(change_adaptor())); this, SLOT(change_adaptor()));
connect(latexModule->refFormattedCB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
latexModule->optionsLE->setValidator(new NoNewLineValidator( latexModule->optionsLE->setValidator(new NoNewLineValidator(
latexModule->optionsLE)); latexModule->optionsLE));
@ -3563,6 +3565,7 @@ void GuiDocument::applyView()
// date // date
bp_.suppress_date = latexModule->suppressDateCB->isChecked(); bp_.suppress_date = latexModule->suppressDateCB->isChecked();
bp_.use_refstyle = latexModule->refstyleCB->isChecked(); bp_.use_refstyle = latexModule->refstyleCB->isChecked();
bp_.use_formatted_ref = latexModule->refFormattedCB->isChecked();
// biblio // biblio
string const engine = string const engine =
@ -4067,6 +4070,7 @@ void GuiDocument::paramsToDialog()
// date // date
latexModule->suppressDateCB->setChecked(bp_.suppress_date); latexModule->suppressDateCB->setChecked(bp_.suppress_date);
latexModule->refstyleCB->setChecked(bp_.use_refstyle); latexModule->refstyleCB->setChecked(bp_.use_refstyle);
latexModule->refFormattedCB->setChecked(bp_.use_formatted_ref);
// biblio // biblio
string const cite_engine = bp_.citeEngine(); string const cite_engine = bp_.citeEngine();

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>341</width> <width>332</width>
<height>442</height> <height>442</height>
</rect> </rect>
</property> </property>
@ -14,6 +14,72 @@
<string/> <string/>
</property> </property>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<item row="2" column="0">
<widget class="QLabel" name="psdriverL">
<property name="text">
<string>&amp;Graphics driver:</string>
</property>
<property name="buddy">
<cstring>psdriverCO</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="psdriverCO">
<property name="duplicatesEnabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="5" column="0" colspan="4">
<widget class="QCheckBox" name="refstyleCB">
<property name="text">
<string>&amp;Use refstyle (not prettyref) for cross-references</string>
</property>
</widget>
</item>
<item row="7" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>2</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" colspan="4">
<widget class="QCheckBox" name="suppressDateCB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Suppress default date on front page</string>
</property>
</widget>
</item>
<item row="2" column="3">
<spacer name="horizontalSpacer_1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>261</width>
<height>22</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="4"> <item row="0" column="0" colspan="4">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
@ -23,12 +89,6 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="lyx::frontend::CategorizedCombo" name="classCO"> <widget class="lyx::frontend::CategorizedCombo" name="classCO">
<property name="maxVisibleItems"> <property name="maxVisibleItems">
@ -55,6 +115,51 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="4">
<widget class="QGroupBox" name="childDocGB">
<property name="toolTip">
<string>Select if the current document is included to a master file</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="title">
<string>Select de&amp;fault master document</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="childDocLA">
<property name="text">
<string>&amp;Master:</string>
</property>
<property name="buddy">
<cstring>childDocLE</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="childDocPB">
<property name="text">
<string>&amp;Browse...</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="childDocLE">
<property name="toolTip">
<string>Enter the name of the default master document</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="4"> <item row="1" column="0" colspan="4">
<widget class="QGroupBox" name="optionsGB"> <widget class="QGroupBox" name="optionsGB">
<property name="title"> <property name="title">
@ -100,120 +205,10 @@
</layout> </layout>
</widget> </widget>
</item> </item>
<item row="2" column="0"> <item row="6" column="0" colspan="4">
<widget class="QLabel" name="psdriverL"> <widget class="QCheckBox" name="refFormattedCB">
<property name="text"> <property name="text">
<string>&amp;Graphics driver:</string> <string>Indicate cross-reference output in the work area</string>
</property>
<property name="buddy">
<cstring>psdriverCO</cstring>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QComboBox" name="psdriverCO">
<property name="duplicatesEnabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="3">
<spacer name="horizontalSpacer_1">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>261</width>
<height>22</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="4">
<widget class="QGroupBox" name="childDocGB">
<property name="toolTip">
<string>Select if the current document is included to a master file</string>
</property>
<property name="statusTip">
<string/>
</property>
<property name="title">
<string>Select de&amp;fault master document</string>
</property>
<property name="flat">
<bool>true</bool>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QGridLayout">
<property name="margin">
<number>9</number>
</property>
<property name="spacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="childDocLA">
<property name="text">
<string>&amp;Master:</string>
</property>
<property name="buddy">
<cstring>childDocLE</cstring>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="childDocPB">
<property name="text">
<string>&amp;Browse...</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="childDocLE">
<property name="toolTip">
<string>Enter the name of the default master document</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="4">
<widget class="QCheckBox" name="suppressDateCB">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>&amp;Suppress default date on front page</string>
</property>
</widget>
</item>
<item row="6" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>2</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="4">
<widget class="QCheckBox" name="refstyleCB">
<property name="text">
<string>&amp;Use refstyle (not prettyref) for cross-references</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -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); InsetLabel const * il = buffer().insetLabel(ref, true);
string const & cmd = params().getCmdName();
docstring display_string; docstring display_string;
if (il && !il->counterValue().empty()) { if (il && !il->counterValue().empty()) {
@ -397,11 +397,11 @@ docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const
else if (cmd == "vref") else if (cmd == "vref")
// normally, would be "ref on page #", but we have no pages // normally, would be "ref on page #", but we have no pages
display_string = value; 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. // normally would be "on page #", but we have no pages.
display_string = translateIfPossible(from_ascii("elsewhere"), display_string =
op.local_font->language()->lang()); translateIfPossible(from_ascii("elsewhere"), language);
else if (cmd == "eqref") } else if (cmd == "eqref")
display_string = '(' + value + ')'; display_string = '(' + value + ')';
else if (cmd == "formatted") { else if (cmd == "formatted") {
display_string = il->formattedCounter(); display_string = il->formattedCounter();
@ -419,13 +419,20 @@ docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const
display_string = il->prettyCounter(); display_string = il->prettyCounter();
} else } 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 // 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 // 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. // some sort of counter with the label, and we don't have that yet.
docstring const attr = "href=\"#" + xml::cleanAttr(ref) + '"'; docstring const attr = "href=\"#" + xml::cleanAttr(ref) + '"';
xs << xml::StartTag("a", to_utf8(attr)); xs << xml::StartTag("a", to_utf8(attr));
xs << display_string; xs << displayString(ref, cmd, op.local_font->language()->lang());;
xs << xml::EndTag("a"); xs << xml::EndTag("a");
return docstring(); return docstring();
} }
@ -520,13 +527,20 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType, bool const /*del
label += getParam("name"); label += getParam("name");
} }
bool const use_formatted_ref = buffer().params().use_formatted_ref;
unsigned int const maxLabelChars = 24; 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; tooltip_ = label;
support::truncateWithEllipsis(label, maxLabelChars); support::truncateWithEllipsis(label, maxLabelChars);
} else } else
tooltip_ = from_ascii(""); tooltip_ = from_ascii("");
if (use_formatted_ref && cmd != "pageref" && cmd != "vpageref"
&& cmd != "vref" && cmd != "labelonly")
screen_label_ = displayString(ref, cmd);
else
screen_label_ = label; screen_label_ = label;
broken_ = false; broken_ = false;
setBroken(broken_); setBroken(broken_);

View File

@ -117,6 +117,10 @@ private:
docstring screenLabel() const override; 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 /// \return the label with things that need to be escaped escaped
docstring getEscapedLabel(OutputParams const &) const; docstring getEscapedLabel(OutputParams const &) const;