From: Juergen Spitzmueller Date: Sat, 7 Jan 2017 16:37:35 +0000 (+0100) Subject: Add items to toggle "Force uppercase" and "Full author list" to the context menu X-Git-Tag: 2.3.0alpha1~511 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=db889bc6a74d801102f2303952dc658a09c90b61;p=features.git Add items to toggle "Force uppercase" and "Full author list" to the context menu --- diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp index fd2d0f39e7..e38441a8ce 100644 --- a/src/frontends/qt4/Menus.cpp +++ b/src/frontends/qt4/Menus.cpp @@ -1529,10 +1529,11 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv) FuncRequest(LFUN_NOACTION))); return; } - InsetCommand const * citinset = - static_cast(inset); + InsetCitation const * citinset = + static_cast(inset); Buffer const * buf = &bv->buffer(); + BufferParams const & bp = buf->params(); string const cmd = citinset->params().getCmdName(); docstring const & key = citinset->getParam("key"); @@ -1572,6 +1573,45 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv) FuncRequest(LFUN_INSET_MODIFY, "changetype " + from_utf8(citationStyleToString(cs))))); } + + // Extra features of the citation styles + CitationStyle cs = citinset->getCitationStyle(bp, cmd, citeStyleList); + + if (cs.hasStarredVersion) { + docstring starred = _("All authors|h"); + // Check if we have a custom string/tooltip for the starred version + if (!cs.stardesc.empty()) { + string val = + bp.documentClass().getCiteMacro(buf->params().citeEngineType(), cs.stardesc); + if (!val.empty()) + starred = translateIfPossible(from_utf8(val)); + // Transform qt-style accelerators to menu-style + int const amps = count_char(starred, '&'); + if (amps > 0) { + if (amps > 1) + starred = subst(starred, from_ascii("&&"), from_ascii("<:amp:>")); + size_t n = starred.find('&'); + char_type accel = char_type(); + if (n != docstring::npos && n < starred.size() - 1) + accel = starred[n + 1]; + starred = subst(starred, from_ascii("&"), from_ascii("")); + if (amps > 1) + starred = subst(starred, from_ascii("<:amp:>"), from_ascii("&&")); + if (accel != char_type()) + starred = starred + '|' + accel; + } + } + add(MenuItem(MenuItem::Separator)); + addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(starred), + FuncRequest(LFUN_INSET_MODIFY, "toggleparam star"))); + } + + if (cs.forceUpperCase) { + if (!cs.hasStarredVersion) + add(MenuItem(MenuItem::Separator)); + addWithStatusCheck(MenuItem(MenuItem::Command, toqstr(_("Force upper case|u")), + FuncRequest(LFUN_INSET_MODIFY, "toggleparam casing"))); + } } diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp index e47f31189f..3972394ce2 100644 --- a/src/insets/InsetCitation.cpp +++ b/src/insets/InsetCitation.cpp @@ -82,13 +82,69 @@ bool InsetCitation::isCompatibleCommand(string const &) } +CitationStyle InsetCitation::getCitationStyle(BufferParams const & bp, string const & input, + vector const & valid_styles) const +{ + CitationStyle cs = valid_styles[0]; + cs.forceUpperCase = false; + cs.hasStarredVersion = false; + + string normalized_input = input; + string::size_type const n = input.size() - 1; + if (isUpperCase(input[0])) + normalized_input[0] = lowercase(input[0]); + if (input[n] == '*') + normalized_input = normalized_input.substr(0, n); + + string const alias = bp.getCiteAlias(normalized_input); + if (!alias.empty()) + normalized_input = alias; + + vector::const_iterator it = valid_styles.begin(); + vector::const_iterator end = valid_styles.end(); + for (; it != end; ++it) { + CitationStyle this_cs = *it; + if (this_cs.name == normalized_input) { + cs = *it; + break; + } + } + + return cs; +} + + void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd) { - if (cmd.action() == LFUN_INSET_MODIFY) { + switch (cmd.action()) { + case LFUN_INSET_MODIFY: { buffer().removeBiblioTempFiles(); cache.recalculate = true; + if (cmd.getArg(0) == "toggleparam") { + string cmdname = getCmdName(); + string const alias = + buffer().params().getCiteAlias(cmdname); + if (!alias.empty()) + cmdname = alias; + string const par = cmd.getArg(1); + string newcmdname = cmdname; + if (par == "star") { + if (suffixIs(cmdname, "*")) + newcmdname = rtrim(cmdname, "*"); + else + newcmdname = cmdname + "*"; + } else if (par == "casing") { + if (isUpperCase(cmdname[0])) + newcmdname[0] = lowercase(cmdname[0]); + else + newcmdname[0] = uppercase(newcmdname[0]); + } + cmd = FuncRequest(LFUN_INSET_MODIFY, "changetype " + newcmdname); + } + } + default: + InsetCommand::doDispatch(cur, cmd); } - InsetCommand::doDispatch(cur, cmd); } @@ -100,14 +156,35 @@ bool InsetCitation::getStatus(Cursor & cur, FuncRequest const & cmd, case LFUN_INSET_MODIFY: if (cmd.getArg(0) == "changetype") { string cmdname = getCmdName(); - string const alias = buffer().params().getCiteAlias(cmdname); + string const alias = + buffer().params().getCiteAlias(cmdname); if (!alias.empty()) cmdname = alias; + if (suffixIs(cmdname, "*")) + cmdname = rtrim(cmdname, "*"); string const newtype = cmd.getArg(1); status.setEnabled(isCompatibleCommand(newtype)); status.setOnOff(newtype == cmdname); } - status.setEnabled(true); + if (cmd.getArg(0) == "toggleparam") { + string cmdname = getCmdName(); + string const alias = + buffer().params().getCiteAlias(cmdname); + if (!alias.empty()) + cmdname = alias; + vector citation_styles = + buffer().params().citeStyles(); + CitationStyle cs = getCitationStyle(buffer().params(), + cmdname, citation_styles); + if (cmd.getArg(1) == "star") { + status.setEnabled(cs.hasStarredVersion); + status.setOnOff(suffixIs(cmdname, "*")); + } + else if (cmd.getArg(1) == "casing") { + status.setEnabled(cs.forceUpperCase); + status.setOnOff(isUpperCase(cmdname[0])); + } + } return true; default: return InsetCommand::getStatus(cur, cmd, status); diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index 40926b310a..cde7bd126c 100644 --- a/src/insets/InsetCitation.h +++ b/src/insets/InsetCitation.h @@ -14,6 +14,7 @@ #define INSET_CITATION_H #include "InsetCommand.h" +#include "Citation.h" namespace lyx { @@ -82,6 +83,9 @@ public: /// static bool isCompatibleCommand(std::string const &); //@} + /// + CitationStyle getCitationStyle(BufferParams const & bp, std::string const & input, + std::vector const & valid_styles) const; private: /// tries to make a pretty label and makes a basic one if not