* Licence details can be found in the file COPYING.
*
* \author John Levon
+ * \¸author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include "GuiBibitem.h"
+#include "Buffer.h"
+#include "BufferParams.h"
+
#include "qt_helpers.h"
#include "insets/InsetCommand.h"
this, SIGNAL(changed()));
connect(labelED, SIGNAL(textChanged(QString)),
this, SIGNAL(changed()));
+ connect(yearED, SIGNAL(textChanged(QString)),
+ this, SIGNAL(changed()));
connect(literalCB, SIGNAL(clicked()),
this, SIGNAL(changed()));
}
InsetCommand const * ic = static_cast<InsetCommand const *>(inset);
InsetCommandParams const & params = ic->params();
keyED->setText(toqstr(params["key"]));
- labelED->setText(toqstr(params["label"]));
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
{
InsetCommandParams params(insetCode());
+ QString label = labelED->text();
+ if (!yearED->isHidden())
+ label += "(" + yearED->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()
? from_ascii("true") : from_ascii("false");
return from_utf8(InsetCommand::params2string(params));
labelED->setReadOnly(readonly);
if (!InsetParamsWidget::checkWidgets())
return false;
- return !keyED->text().isEmpty();
+ return !keyED->text().isEmpty()
+ && (yearED->isHidden() || !yearED->text().isEmpty());
}
} // namespace frontend
<rect>
<x>0</x>
<y>0</y>
- <width>218</width>
- <height>121</height>
+ <width>400</width>
+ <height>123</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
- <layout class="QGridLayout" name="gridLayout">
+ <layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
+ <widget class="QLabel" name="label">
+ <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">
<property name="toolTip">
<string>The bibliography key</string>
</property>
</widget>
</item>
- <item>
- <widget class="QLabel" name="labelLA">
- <property name="toolTip">
- <string>The label as it appears in the document</string>
- </property>
- <property name="text">
- <string>&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>
+ <item row="0" column="1">
<widget class="QLineEdit" name="keyED">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
</property>
</widget>
</item>
- <item>
- <widget class="QLineEdit" name="labelED">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
+ <item row="1" column="0">
+ <widget class="QLabel" name="labelLA">
<property name="toolTip">
<string>The label as it appears in the document</string>
</property>
- </widget>
- </item>
- <item>
- <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&teral</string>
+ <string>&Label:</string>
+ </property>
+ <property name="buddy">
+ <cstring>labelED</cstring>
</property>
</widget>
</item>
+ <item row="1" column="1">
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="spacing">
+ <number>0</number>
+ </property>
+ <item>
+ <widget class="QLineEdit" name="labelED">
+ <property name="sizePolicy">
+ <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>&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 "Author (Year)" citations (without parentheses).</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
</layout>
</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&teral</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<includes>
BufferParams const & bp = buffer().masterBuffer()->params();
if (bp.citeEngineType() == ENGINE_TYPE_NUMERICAL)
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;
}