From e6666bd62aacafdd7be9cf39a8392c2a2252b288 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Tue, 3 Jan 2017 17:25:41 +0100 Subject: [PATCH] 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. --- 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 | 4 +-- 7 files changed, 70 insertions(+), 21 deletions(-) diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp index dedcd121d7..9a353280e3 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 42ddfc24e2..fed47a5aef 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 03c6c79343..65c547883c 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*[][]=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 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 459a51ecf2..b2fe9a9239 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 624becc24c..546fd0c2d1 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 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 4eb346bd3e..a824212926 100644 --- a/src/frontends/qt4/ui/CitationUi.ui +++ b/src/frontends/qt4/ui/CitationUi.ui @@ -387,7 +387,7 @@ - + Always list all authors (rather than using "et al.") @@ -492,7 +492,7 @@ textBeforeED textAfterED forceuppercaseCB - fulllistCB + starredCB restorePB okPB applyPB diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index 9327129687..233243bbe4 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; } -- 2.39.5