Make usage of natbib without BibTeX more obvious

Fixes: #5549
This commit is contained in:
Juergen Spitzmueller 2019-04-18 14:48:01 +02:00
parent 7b313ec452
commit 3615a6a75b
3 changed files with 109 additions and 50 deletions

View File

@ -4,6 +4,7 @@
* Licence details can be found in the file COPYING. * Licence details can be found in the file COPYING.
* *
* \author John Levon * \author John Levon
* \¸author Jürgen Spitzmüller
* *
* Full author contact details are available in file CREDITS. * Full author contact details are available in file CREDITS.
*/ */
@ -12,6 +13,9 @@
#include "GuiBibitem.h" #include "GuiBibitem.h"
#include "Buffer.h"
#include "BufferParams.h"
#include "qt_helpers.h" #include "qt_helpers.h"
#include "insets/InsetCommand.h" #include "insets/InsetCommand.h"
@ -32,6 +36,8 @@ GuiBibitem::GuiBibitem(QWidget * parent) : InsetParamsWidget(parent)
this, SIGNAL(changed())); this, SIGNAL(changed()));
connect(labelED, SIGNAL(textChanged(QString)), connect(labelED, SIGNAL(textChanged(QString)),
this, SIGNAL(changed())); this, SIGNAL(changed()));
connect(yearED, SIGNAL(textChanged(QString)),
this, SIGNAL(changed()));
connect(literalCB, SIGNAL(clicked()), connect(literalCB, SIGNAL(clicked()),
this, SIGNAL(changed())); this, SIGNAL(changed()));
} }
@ -42,16 +48,42 @@ void GuiBibitem::paramsToDialog(Inset const * inset)
InsetCommand const * ic = static_cast<InsetCommand const *>(inset); InsetCommand const * ic = static_cast<InsetCommand const *>(inset);
InsetCommandParams const & params = ic->params(); InsetCommandParams const & params = ic->params();
keyED->setText(toqstr(params["key"])); keyED->setText(toqstr(params["key"]));
labelED->setText(toqstr(params["label"]));
literalCB->setChecked(params["literal"] == "true"); literalCB->setChecked(params["literal"] == "true");
QString const label = toqstr(params["label"]);
BufferParams const bp = inset->buffer().masterParams();
if (bp.citeEngine() == "natbib" && bp.citeEngineType() == ENGINE_TYPE_AUTHORYEAR) {
yearED->setHidden(false);
yearLA->setHidden(false);
labelLA->setText(qt_("Author &Name:"));
labelED->setToolTip(qt_("Insert the author name(s) here. The year goes to the separate field."));
int const i = label.lastIndexOf("(");
int const j = label.lastIndexOf(")");
if (i != -1 && j != -1 && i < j) {
// Split Author(Year) to Author and Year
QString const year = label.left(j).mid(i + 1);
QString const author = label.left(i);
labelED->setText(author);
yearED->setText(year);
} else
labelED->setText(label);
} else {
yearED->setHidden(true);
yearLA->setHidden(true);
labelLA->setText(qt_("&Label:"));
labelED->setToolTip(qt_("The label as it appears in the document"));
labelED->setText(label);
}
} }
docstring GuiBibitem::dialogToParams() const docstring GuiBibitem::dialogToParams() const
{ {
InsetCommandParams params(insetCode()); InsetCommandParams params(insetCode());
QString label = labelED->text();
if (!yearED->isHidden())
label += "(" + yearED->text() + ")";
params["key"] = qstring_to_ucs4(keyED->text()); params["key"] = qstring_to_ucs4(keyED->text());
params["label"] = qstring_to_ucs4(labelED->text()); params["label"] = qstring_to_ucs4(label);
params["literal"] = literalCB->isChecked() params["literal"] = literalCB->isChecked()
? from_ascii("true") : from_ascii("false"); ? from_ascii("true") : from_ascii("false");
return from_utf8(InsetCommand::params2string(params)); return from_utf8(InsetCommand::params2string(params));
@ -64,7 +96,8 @@ bool GuiBibitem::checkWidgets(bool readonly) const
labelED->setReadOnly(readonly); labelED->setReadOnly(readonly);
if (!InsetParamsWidget::checkWidgets()) if (!InsetParamsWidget::checkWidgets())
return false; return false;
return !keyED->text().isEmpty(); return !keyED->text().isEmpty()
&& (yearED->isHidden() || !yearED->text().isEmpty());
} }
} // namespace frontend } // namespace frontend

View File

@ -6,17 +6,24 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>218</width> <width>400</width>
<height>121</height> <height>123</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string/> <string/>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0"> <item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2"> <widget class="QLabel" name="label">
<item> <property name="text">
<string/>
</property>
</widget>
</item>
<item row="0" column="1">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="keyLA"> <widget class="QLabel" name="keyLA">
<property name="toolTip"> <property name="toolTip">
<string>The bibliography key</string> <string>The bibliography key</string>
@ -29,31 +36,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="0" column="1">
<widget class="QLabel" name="labelLA">
<property name="toolTip">
<string>The label as it appears in the document</string>
</property>
<property name="text">
<string>&amp;Label:</string>
</property>
<property name="buddy">
<cstring>labelED</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLineEdit" name="keyED"> <widget class="QLineEdit" name="keyED">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
@ -66,31 +49,71 @@
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="0">
<widget class="QLineEdit" name="labelED"> <widget class="QLabel" name="labelLA">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip"> <property name="toolTip">
<string>The label as it appears in the document</string> <string>The label as it appears in the document</string>
</property> </property>
<property name="text">
<string>&amp;Label:</string>
</property>
<property name="buddy">
<cstring>labelED</cstring>
</property>
</widget> </widget>
</item> </item>
<item> <item row="1" column="1">
<widget class="QCheckBox" name="literalCB"> <layout class="QHBoxLayout" name="horizontalLayout">
<property name="toolTip"> <property name="spacing">
<string>Pass content of the `Label' field literally to LaTeX. Check this if you want to enter LaTeX code.</string> <number>0</number>
</property> </property>
<property name="text"> <item>
<string>Li&amp;teral</string> <widget class="QLineEdit" name="labelED">
</property> <property name="sizePolicy">
</widget> <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>The label as it appears in the document</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="yearLA">
<property name="text">
<string>&amp;Year:</string>
</property>
<property name="margin">
<number>6</number>
</property>
<property name="buddy">
<cstring>yearED</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="yearED">
<property name="toolTip">
<string>The year with &quot;Author (Year)&quot; citations (without parentheses).</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
<item row="1" column="1">
<widget class="QCheckBox" name="literalCB">
<property name="toolTip">
<string>Pass content of the `Label' field literally to LaTeX. Check this if you want to enter LaTeX code.</string>
</property>
<property name="text">
<string>Li&amp;teral</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<includes> <includes>

View File

@ -187,7 +187,10 @@ docstring InsetBibitem::bibLabel() const
BufferParams const & bp = buffer().masterBuffer()->params(); BufferParams const & bp = buffer().masterBuffer()->params();
if (bp.citeEngineType() == ENGINE_TYPE_NUMERICAL) if (bp.citeEngineType() == ENGINE_TYPE_NUMERICAL)
return autolabel_; return autolabel_;
docstring const & label = getParam("label"); docstring label = getParam("label");
if (!label.empty() && bp.citeEngine() == "natbib")
// Add a space before opening paren
label = subst(label, from_ascii("("), from_ascii(" ("));
return label.empty() ? autolabel_ : label; return label.empty() ? autolabel_ : label;
} }