Great to see this happening.... Richard
On 01/03/2017 11:28 AM, Juergen Spitzmueller wrote: > The branch, biblatex2, has been updated. > > - Log ----------------------------------------------------------------- > > commit 18d6701a40514764ff08f4a90886f5d073a57c32 > Author: Juergen Spitzmueller <sp...@lyx.org> > Date: Tue Jan 3 17:27:51 2017 +0100 > > No need to hardcode the possible cite commands > > We fall back to a sensible default anyway. > > diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp > index 233243b..94a1592 100644 > --- a/src/insets/InsetCitation.cpp > +++ b/src/insets/InsetCitation.cpp > @@ -61,8 +61,8 @@ InsetCitation::~InsetCitation() > > ParamInfo const & InsetCitation::findInfo(string const & /* cmdName */) > { > - // standard cite does only take one argument if jurabib is > - // not used, but jurabib extends this to two arguments, so > + // standard cite does only take one argument, but biblatex, jurabib > + // and natbib extend this to two arguments, so > // we have to allow both here. InsetCitation takes care that > // LaTeX output is nevertheless correct. > if (param_info_.empty()) { > @@ -74,44 +74,11 @@ ParamInfo const & InsetCitation::findInfo(string const & > /* cmdName */) > } > > > -namespace { > - > -vector<string> const init_possible_cite_commands() > +// We allow any command here, since we fall back to cite > +// anyway if a command is not allowed by a style > +bool InsetCitation::isCompatibleCommand(string const &) > { > - char const * const possible[] = { > - "cite", "nocite", "citet", "citep", "citealt", "citealp", > - "citeauthor", "citeyear", "citeyearpar", > - "citet*", "citep*", "citealt*", "citealp*", "citeauthor*", > - "Citet", "Citep", "Citealt", "Citealp", "Citeauthor", > - "Citet*", "Citep*", "Citealt*", "Citealp*", "Citeauthor*", > - "fullcite", > - "footcite", "footcitet", "footcitep", "footcitealt", > - "footcitealp", "footciteauthor", "footciteyear", > "footciteyearpar", > - "citefield", "citetitle", "cite*" > - }; > - size_t const size_possible = sizeof(possible) / sizeof(possible[0]); > - > - return vector<string>(possible, possible + size_possible); > -} > - > - > -vector<string> const & possibleCiteCommands() > -{ > - static vector<string> const possible = init_possible_cite_commands(); > - return possible; > -} > - > - > -} // anon namespace > - > - > -// FIXME: use the citeCommands provided by the TextClass > -// instead of possibleCiteCommands defined in this file. > -bool InsetCitation::isCompatibleCommand(string const & cmd) > -{ > - vector<string> const & possibles = possibleCiteCommands(); > - vector<string>::const_iterator const end = possibles.end(); > - return find(possibles.begin(), end, cmd) != end; > + return true; > } > > > @@ -214,8 +181,6 @@ CitationStyle asValidLatexCommand(BufferParams const & > bp, string const & input, > { > CitationStyle cs = valid_styles[0]; > cs.forceUpperCase = false; > - if (!InsetCitation::isCompatibleCommand(input)) > - return cs; > cs.hasStarredVersion = false; > > string normalized_input = input; > diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h > index 70022c6..40926b3 100644 > --- a/src/insets/InsetCitation.h > +++ b/src/insets/InsetCitation.h > @@ -80,7 +80,7 @@ public: > /// > static std::string defaultCommand() { return "cite"; } > /// > - static bool isCompatibleCommand(std::string const & cmd); > + static bool isCompatibleCommand(std::string const &); > //@} > > private: > > commit e6666bd62aacafdd7be9cf39a8392c2a2252b288 > Author: Juergen Spitzmueller <sp...@lyx.org> > Date: Tue Jan 3 17:25:41 2017 +0100 > > Generalize starred cite commands > > Not all of them expand the author list. Thus rename the parameter to > hasStarredVersion and provide a means to adjust the GUI accordingly. > > diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp > index dedcd12..9a35328 100644 > --- a/src/BiblioInfo.cpp > +++ b/src/BiblioInfo.cpp > @@ -1197,7 +1197,7 @@ CitationStyle citationStyleFromString(string const & > command, > > size_t const n = command.size() - 1; > if (command[n] == '*') { > - cs.fullAuthorList = true; > + cs.hasStarredVersion = true; > if (suffixIs(cmd, '*')) > cmd = cmd.substr(0, cmd.size() - 1); > } > @@ -1212,7 +1212,7 @@ string citationStyleToString(const CitationStyle & cs, > bool const latex) > string cmd = latex ? cs.cmd : cs.name; > if (cs.forceUpperCase) > cmd[0] = uppercase(cmd[0]); > - if (cs.fullAuthorList) > + if (cs.hasStarredVersion) > cmd += '*'; > return cmd; > } > diff --git a/src/Citation.h b/src/Citation.h > index 42ddfc2..fed47a5 100644 > --- a/src/Citation.h > +++ b/src/Citation.h > @@ -31,16 +31,20 @@ class CitationStyle > public: > /// > CitationStyle() : name("cite"), cmd("cite"), forceUpperCase(false), > - fullAuthorList(false), textAfter(false), textBefore(false) {} > + hasStarredVersion(false), textAfter(false), textBefore(false) {} > > /// the LyX name > std::string name; > /// the LaTeX command (might differ from the LyX name) > std::string cmd; > + /// Optional alternative description what the starred version does (for > the GUI) > + std::string stardesc; > + /// Optional tooltip for the starred version > + std::string startooltip; > /// upper casing author prefixes (van -> Van) > bool forceUpperCase; > - /// expanding the full author list > - bool fullAuthorList; > + /// starred version (full author list by default) > + bool hasStarredVersion; > /// supports text after the citation > bool textAfter; > /// supports text before the citation > diff --git a/src/TextClass.cpp b/src/TextClass.cpp > index 03c6c79..65c5478 100644 > --- a/src/TextClass.cpp > +++ b/src/TextClass.cpp > @@ -1053,19 +1053,24 @@ bool TextClass::readCiteEngine(Lexer & lexrc) > * the given LyX name in the current engine > * 3. The actual LaTeX command that is output > * (2) and (3) are optional. > + * Also, the GUI string for the starred version can > + * be changed > * The syntax is: > - * LyXName|alias,nextalias*[][]=latexcmd > + * > LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd > */ > enum ScanMode { > LyXName, > Alias, > - LaTeXCmd > + LaTeXCmd, > + StarDesc > }; > > ScanMode mode = LyXName; > + ScanMode oldmode = LyXName; > string lyx_cmd; > string alias; > string latex_cmd; > + string stardesc; > size_t const n = def.size(); > for (size_t i = 0; i != n; ++i) { > ichar = def[i]; > @@ -1073,10 +1078,17 @@ bool TextClass::readCiteEngine(Lexer & lexrc) > mode = Alias; > else if (ichar == '=') > mode = LaTeXCmd; > + else if (ichar == '<') { > + oldmode = mode; > + mode = StarDesc; > + } else if (ichar == '>') > + mode = oldmode; > else if (mode == LaTeXCmd) > latex_cmd += ichar; > + else if (mode == StarDesc) > + stardesc += ichar; > else if (ichar == '*') > - cs.fullAuthorList = true; > + cs.hasStarredVersion = true; > else if (ichar == '[' && cs.textAfter) > cs.textBefore = true; > else if (ichar == '[') > @@ -1095,6 +1107,12 @@ bool TextClass::readCiteEngine(Lexer & lexrc) > for (string const &s: aliases) > cite_command_aliases_[s] = lyx_cmd; > } > + vector<string> const stardescs = getVectorFromString(stardesc, > "!"); > + int size = stardesc.size(); > + if (size > 0) > + cs.stardesc = stardescs[0]; > + if (size > 1) > + cs.startooltip = stardescs[1]; > if (type & ENGINE_TYPE_AUTHORYEAR) > cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs); > if (type & ENGINE_TYPE_NUMERICAL) > diff --git a/src/frontends/qt4/GuiCitation.cpp > b/src/frontends/qt4/GuiCitation.cpp > index 459a51e..b2fe9a9 100644 > --- a/src/frontends/qt4/GuiCitation.cpp > +++ b/src/frontends/qt4/GuiCitation.cpp > @@ -25,6 +25,7 @@ > #include "BufferView.h" > #include "BiblioInfo.h" > #include "BufferParams.h" > +#include "TextClass.h" > #include "FuncRequest.h" > > #include "insets/InsetCommand.h" > @@ -123,7 +124,7 @@ GuiCitation::GuiCitation(GuiView & lv) > > connect(citationStyleCO, SIGNAL(activated(int)), > this, SLOT(on_citationStyleCO_currentIndexChanged(int))); > - connect(fulllistCB, SIGNAL(clicked()), > + connect(starredCB, SIGNAL(clicked()), > this, SLOT(changed())); > connect(forceuppercaseCB, SIGNAL(clicked()), > this, SLOT(changed())); > @@ -179,7 +180,7 @@ void GuiCitation::applyView() > { > int const choice = max(0, citationStyleCO->currentIndex()); > style_ = choice; > - bool const full = fulllistCB->isChecked(); > + bool const full = starredCB->isChecked(); > bool const force = forceuppercaseCB->isChecked(); > > QString const before = textBeforeED->text(); > @@ -246,9 +247,10 @@ void GuiCitation::updateControls(BiblioInfo const & bi) > > void GuiCitation::updateFormatting(CitationStyle currentStyle) > { > + BufferParams const bp = documentBuffer().params(); > bool const force = currentStyle.forceUpperCase; > - bool const full = currentStyle.fullAuthorList && > - documentBuffer().params().fullAuthorList(); > + bool const starred = currentStyle.hasStarredVersion; > + bool const full = starred && bp.fullAuthorList(); > bool const textbefore = currentStyle.textBefore; > bool const textafter = currentStyle.textAfter; > > @@ -256,13 +258,38 @@ void GuiCitation::updateFormatting(CitationStyle > currentStyle) > selectedLV->model()->rowCount() > 0; > > forceuppercaseCB->setEnabled(force && haveSelection); > - fulllistCB->setEnabled(full && haveSelection); > + starredCB->setEnabled(full && haveSelection); > textBeforeED->setEnabled(textbefore && haveSelection); > textBeforeLA->setEnabled(textbefore && haveSelection); > textAfterED->setEnabled(textafter && haveSelection); > textAfterLA->setEnabled(textafter && haveSelection); > citationStyleCO->setEnabled(haveSelection); > citationStyleLA->setEnabled(haveSelection); > + > + // Check if we have a custom string/tooltip for the starred version > + if (starred && !currentStyle.stardesc.empty()) { > + string val = > + bp.documentClass().getCiteMacro(bp.citeEngineType(), > currentStyle.stardesc); > + if (!val.empty()) { > + docstring const trans = > + translateIfPossible(from_utf8(val)); > + starredCB->setText(toqstr(trans)); > + starredCB->setEnabled(haveSelection); > + } > + if (!currentStyle.startooltip.empty()) { > + val = > bp.documentClass().getCiteMacro(bp.citeEngineType(), > + > currentStyle.startooltip); > + if (!val.empty()) { > + docstring const trans = > + translateIfPossible(from_utf8(val)); > + starredCB->setToolTip(toqstr(trans)); > + } > + } > + } else { > + // This is the default meaning of the starred commands > + starredCB->setText(qt_("All aut&hors")); > + starredCB->setToolTip(qt_("Always list all authors (rather than > using \"et al.\")")); > + } > } > > > @@ -516,7 +543,7 @@ void GuiCitation::applyParams(int const choice, bool > full, bool force, > after.clear(); > > cs.forceUpperCase &= force; > - cs.fullAuthorList &= full; > + cs.hasStarredVersion &= full; > string const command = citationStyleToString(cs); > > params_.setCmdName(command); > @@ -558,7 +585,7 @@ void GuiCitation::init() > CitationStyle const cs = > citationStyleFromString(cmd, documentBuffer().params()); > forceuppercaseCB->setChecked(cs.forceUpperCase); > - fulllistCB->setChecked(cs.fullAuthorList && > + starredCB->setChecked(cs.hasStarredVersion && > documentBuffer().params().fullAuthorList()); > textBeforeED->setText(toqstr(params_["before"])); > textAfterED->setText(toqstr(params_["after"])); > diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp > index 624becc..546fd0c 100644 > --- a/src/frontends/qt4/Menus.cpp > +++ b/src/frontends/qt4/Menus.cpp > @@ -1548,7 +1548,7 @@ void MenuDefinition::expandCiteStyles(BufferView const > * bv) > > size_t const n = cmd.size(); > bool const force = isUpperCase(cmd[0]); > - bool const full = cmd[n] == '*'; > + bool const star = cmd[n] == '*'; > > vector<docstring> const keys = getVectorFromString(key); > > @@ -1565,7 +1565,7 @@ void MenuDefinition::expandCiteStyles(BufferView const > * bv) > docstring label = *cit; > CitationStyle cs = citeStyleList[ii - 1]; > cs.forceUpperCase &= force; > - cs.fullAuthorList &= full; > + cs.hasStarredVersion &= star; > addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(label), > FuncRequest(LFUN_INSET_MODIFY, > "changetype " + > from_utf8(citationStyleToString(cs))))); > diff --git a/src/frontends/qt4/ui/CitationUi.ui > b/src/frontends/qt4/ui/CitationUi.ui > index 4eb346b..a824212 100644 > --- a/src/frontends/qt4/ui/CitationUi.ui > +++ b/src/frontends/qt4/ui/CitationUi.ui > @@ -387,7 +387,7 @@ > </widget> > </item> > <item> > - <widget class="QCheckBox" name="fulllistCB"> > + <widget class="QCheckBox" name="starredCB"> > <property name="toolTip"> > <string>Always list all authors (rather than using "et > al.")</string> > </property> > @@ -492,7 +492,7 @@ > <tabstop>textBeforeED</tabstop> > <tabstop>textAfterED</tabstop> > <tabstop>forceuppercaseCB</tabstop> > - <tabstop>fulllistCB</tabstop> > + <tabstop>starredCB</tabstop> > <tabstop>restorePB</tabstop> > <tabstop>okPB</tabstop> > <tabstop>applyPB</tabstop> > diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp > index 9327129..233243b 100644 > --- a/src/insets/InsetCitation.cpp > +++ b/src/insets/InsetCitation.cpp > @@ -214,9 +214,9 @@ CitationStyle asValidLatexCommand(BufferParams const & > bp, string const & input, > { > CitationStyle cs = valid_styles[0]; > cs.forceUpperCase = false; > - cs.fullAuthorList = false; > if (!InsetCitation::isCompatibleCommand(input)) > return cs; > + cs.hasStarredVersion = false; > > string normalized_input = input; > string::size_type const n = input.size() - 1; > @@ -240,7 +240,7 @@ CitationStyle asValidLatexCommand(BufferParams const & > bp, string const & input, > } > > cs.forceUpperCase &= input[0] == uppercase(input[0]); > - cs.fullAuthorList &= input[n] == '*'; > + cs.hasStarredVersion &= input[n] == '*'; > > return cs; > } > > ----------------------------------------------------------------------- > > Summary of changes: > src/BiblioInfo.cpp | 4 +- > src/Citation.h | 10 +++++-- > src/TextClass.cpp | 24 +++++++++++++++-- > src/frontends/qt4/GuiCitation.cpp | 41 ++++++++++++++++++++++++----- > src/frontends/qt4/Menus.cpp | 4 +- > src/frontends/qt4/ui/CitationUi.ui | 4 +- > src/insets/InsetCitation.cpp | 51 +++++------------------------------ > src/insets/InsetCitation.h | 2 +- > 8 files changed, 77 insertions(+), 63 deletions(-) > > > hooks/post-receive