mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-12 22:14:35 +00:00
Add items to toggle "Force uppercase" and "Full author list" to the context menu
This commit is contained in:
parent
eba2f0479e
commit
db889bc6a7
@ -1529,10 +1529,11 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
|
|||||||
FuncRequest(LFUN_NOACTION)));
|
FuncRequest(LFUN_NOACTION)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
InsetCommand const * citinset =
|
InsetCitation const * citinset =
|
||||||
static_cast<InsetCommand const *>(inset);
|
static_cast<InsetCitation const *>(inset);
|
||||||
|
|
||||||
Buffer const * buf = &bv->buffer();
|
Buffer const * buf = &bv->buffer();
|
||||||
|
BufferParams const & bp = buf->params();
|
||||||
string const cmd = citinset->params().getCmdName();
|
string const cmd = citinset->params().getCmdName();
|
||||||
|
|
||||||
docstring const & key = citinset->getParam("key");
|
docstring const & key = citinset->getParam("key");
|
||||||
@ -1572,6 +1573,45 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
|
|||||||
FuncRequest(LFUN_INSET_MODIFY,
|
FuncRequest(LFUN_INSET_MODIFY,
|
||||||
"changetype " + from_utf8(citationStyleToString(cs)))));
|
"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")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,13 +82,69 @@ bool InsetCitation::isCompatibleCommand(string const &)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
CitationStyle InsetCitation::getCitationStyle(BufferParams const & bp, string const & input,
|
||||||
|
vector<CitationStyle> 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<CitationStyle>::const_iterator it = valid_styles.begin();
|
||||||
|
vector<CitationStyle>::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)
|
void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
|
||||||
{
|
{
|
||||||
if (cmd.action() == LFUN_INSET_MODIFY) {
|
switch (cmd.action()) {
|
||||||
|
case LFUN_INSET_MODIFY: {
|
||||||
buffer().removeBiblioTempFiles();
|
buffer().removeBiblioTempFiles();
|
||||||
cache.recalculate = true;
|
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:
|
case LFUN_INSET_MODIFY:
|
||||||
if (cmd.getArg(0) == "changetype") {
|
if (cmd.getArg(0) == "changetype") {
|
||||||
string cmdname = getCmdName();
|
string cmdname = getCmdName();
|
||||||
string const alias = buffer().params().getCiteAlias(cmdname);
|
string const alias =
|
||||||
|
buffer().params().getCiteAlias(cmdname);
|
||||||
if (!alias.empty())
|
if (!alias.empty())
|
||||||
cmdname = alias;
|
cmdname = alias;
|
||||||
|
if (suffixIs(cmdname, "*"))
|
||||||
|
cmdname = rtrim(cmdname, "*");
|
||||||
string const newtype = cmd.getArg(1);
|
string const newtype = cmd.getArg(1);
|
||||||
status.setEnabled(isCompatibleCommand(newtype));
|
status.setEnabled(isCompatibleCommand(newtype));
|
||||||
status.setOnOff(newtype == cmdname);
|
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<CitationStyle> 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;
|
return true;
|
||||||
default:
|
default:
|
||||||
return InsetCommand::getStatus(cur, cmd, status);
|
return InsetCommand::getStatus(cur, cmd, status);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#define INSET_CITATION_H
|
#define INSET_CITATION_H
|
||||||
|
|
||||||
#include "InsetCommand.h"
|
#include "InsetCommand.h"
|
||||||
|
#include "Citation.h"
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
@ -82,6 +83,9 @@ public:
|
|||||||
///
|
///
|
||||||
static bool isCompatibleCommand(std::string const &);
|
static bool isCompatibleCommand(std::string const &);
|
||||||
//@}
|
//@}
|
||||||
|
///
|
||||||
|
CitationStyle getCitationStyle(BufferParams const & bp, std::string const & input,
|
||||||
|
std::vector<CitationStyle> const & valid_styles) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// tries to make a pretty label and makes a basic one if not
|
/// tries to make a pretty label and makes a basic one if not
|
||||||
|
Loading…
Reference in New Issue
Block a user