Extend quote-insert

Two more optional arguments to specify side and quote style.
GUI support follows.
This commit is contained in:
Juergen Spitzmueller 2016-12-16 11:23:22 +01:00
parent 14dbaa7608
commit 7bf6d2b9ce
5 changed files with 52 additions and 9 deletions

View File

@ -40,6 +40,11 @@
!!!The following LyX functions have been changed in 2.3: !!!The following LyX functions have been changed in 2.3:
* quote-insert
The function now has a second and third optional argument to specify
the side (left, right, auto) and quotation mark style (english, swedish,
german, polish, french, danish).
!!!The following LyX documents have been moved in 2.3: !!!The following LyX documents have been moved in 2.3:

View File

@ -403,8 +403,17 @@ void LyXAction::init()
* \li Action: Inserts quotes according to the type and quote-language preference. * \li Action: Inserts quotes according to the type and quote-language preference.
* \li Notion: Currently English, Swedish, German, Polish, French, Danish quotes * \li Notion: Currently English, Swedish, German, Polish, French, Danish quotes
are distinguished. are distinguished.
* \li Syntax: quote-insert [<TYPE>] * \li Syntax: quote-insert [<TYPE>] [<SIDE>] [<LANG>]
* \li Params: <TYPE>: 'single' for single quotes, otherwise double quotes will be used. * \li Params: <TYPE>: 'single' for single quotes, otherwise double quotes will be used.
* <SIDE>: 'left' for opening quotes, 'right' for closing quotes, otherwise
* the side will be guessed from the context.
* <STYLE>: 'english' for ``English'' quote style
* 'swedish' for ''Swedish'' quote style
* 'german' for ,,German`` quote style
* 'polish' for ,,Polish'' quote style
* 'french' for <<French>> quote style
* 'danish' for >>Danish<< quote style
* If no quote style is specified, the document-wide will be used.
* \endvar * \endvar
*/ */
{ LFUN_QUOTE_INSERT, "quote-insert", Noop, Edit }, { LFUN_QUOTE_INSERT, "quote-insert", Noop, Edit },

View File

@ -1548,13 +1548,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
while (pos > 0 && par.isDeleted(pos - 1)) while (pos > 0 && par.isDeleted(pos - 1))
--pos; --pos;
string const arg = to_utf8(cmd.argument());
char_type c = ' '; char_type c = ' ';
if (pos > 0 && (!cur.prevInset() || !cur.prevInset()->isSpace())) if (pos > 0 && (!cur.prevInset() || !cur.prevInset()->isSpace()))
c = par.getChar(pos - 1); c = par.getChar(pos - 1);
InsetQuotes::QuoteTimes const quote_type = (arg == "single") InsetQuotes::QuoteTimes const quote_type = (cmd.getArg(0) == "single")
? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes; ? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes;
cur.insert(new InsetQuotes(cur.buffer(), c, quote_type)); cur.insert(new InsetQuotes(cur.buffer(), c, quote_type, cmd.getArg(1), cmd.getArg(2)));
cur.buffer()->updateBuffer(); cur.buffer()->updateBuffer();
cur.posForward(); cur.posForward();
break; break;

View File

@ -111,18 +111,24 @@ InsetQuotes::InsetQuotes(Buffer * buf, string const & str) : Inset(buf)
parseString(str); parseString(str);
} }
InsetQuotes::InsetQuotes(Buffer * buf, char_type c, QuoteTimes t) InsetQuotes::InsetQuotes(Buffer * buf, char_type c, QuoteTimes t,
string const & s, string const & l)
: Inset(buf), times_(t), pass_thru_(false) : Inset(buf), times_(t), pass_thru_(false)
{ {
if (buf) { if (buf) {
language_ = buf->params().quotes_language; language_ = l.empty() ? buf->params().quotes_language : getLanguage(l);
fontenc_ = (buf->params().fontenc == "global") fontenc_ = (buf->params().fontenc == "global")
? lyxrc.fontenc : buf->params().fontenc; ? lyxrc.fontenc : buf->params().fontenc;
} else { } else {
language_ = EnglishQuotes; language_ = l.empty() ? EnglishQuotes : getLanguage(l);
fontenc_ = lyxrc.fontenc; fontenc_ = lyxrc.fontenc;
} }
if (s == "left")
side_ = LeftQuote;
else if (s == "right")
side_ = RightQuote;
else
setSide(c); setSide(c);
} }
@ -196,6 +202,26 @@ void InsetQuotes::parseString(string const & s)
} }
} }
InsetQuotes::QuoteLanguage InsetQuotes::getLanguage(string const & s)
{
QuoteLanguage ql = EnglishQuotes;
if (s == "english")
ql = EnglishQuotes;
else if (s == "swedish")
ql = SwedishQuotes;
else if (s == "german")
ql = GermanQuotes;
else if (s == "polish")
ql = PolishQuotes;
else if (s == "french")
ql = FrenchQuotes;
else if (s == "danish")
ql = DanishQuotes;
return ql;
}
docstring InsetQuotes::displayString() const docstring InsetQuotes::displayString() const
{ {

View File

@ -64,7 +64,9 @@ public:
*/ */
explicit InsetQuotes(Buffer * buf, std::string const & str = "eld"); explicit InsetQuotes(Buffer * buf, std::string const & str = "eld");
/// Direct access to inner/outer quotation marks /// Direct access to inner/outer quotation marks
InsetQuotes(Buffer * buf, char_type c, QuoteTimes t); InsetQuotes(Buffer * buf, char_type c, QuoteTimes t,
std::string const & s = std::string(),
std::string const & l = std::string());
/// ///
docstring layoutName() const; docstring layoutName() const;
/// ///
@ -112,6 +114,8 @@ private:
docstring displayString() const; docstring displayString() const;
/// ///
docstring getQuoteEntity() const; docstring getQuoteEntity() const;
///
QuoteLanguage getLanguage(std::string const &);
/// ///
QuoteLanguage language_; QuoteLanguage language_;