commit 7bf6d2b9ce8530eae9330a40057cdc5f2bc59ae2
Author: Juergen Spitzmueller <[email protected]>
Date: Fri Dec 16 11:23:22 2016 +0100
Extend quote-insert
Two more optional arguments to specify side and quote style.
GUI support follows.
---
lib/RELEASE-NOTES | 5 +++++
src/LyXAction.cpp | 11 ++++++++++-
src/Text3.cpp | 5 ++---
src/insets/InsetQuotes.cpp | 34 ++++++++++++++++++++++++++++++----
src/insets/InsetQuotes.h | 6 +++++-
5 files changed, 52 insertions(+), 9 deletions(-)
diff --git a/lib/RELEASE-NOTES b/lib/RELEASE-NOTES
index 07f73e2..385f171 100644
--- a/lib/RELEASE-NOTES
+++ b/lib/RELEASE-NOTES
@@ -40,6 +40,11 @@
!!!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:
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 9fe5917..642d774 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -403,8 +403,17 @@ void LyXAction::init()
* \li Action: Inserts quotes according to the type and quote-language
preference.
* \li Notion: Currently English, Swedish, German, Polish, French, Danish
quotes
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.
+ * <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
*/
{ LFUN_QUOTE_INSERT, "quote-insert", Noop, Edit },
diff --git a/src/Text3.cpp b/src/Text3.cpp
index a7c3cd0..ac17439 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1548,13 +1548,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
while (pos > 0 && par.isDeleted(pos - 1))
--pos;
- string const arg = to_utf8(cmd.argument());
char_type c = ' ';
if (pos > 0 && (!cur.prevInset() ||
!cur.prevInset()->isSpace()))
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;
- 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.posForward();
break;
diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp
index 49bb00b..b445936 100644
--- a/src/insets/InsetQuotes.cpp
+++ b/src/insets/InsetQuotes.cpp
@@ -111,19 +111,25 @@ InsetQuotes::InsetQuotes(Buffer * buf, string const &
str) : Inset(buf)
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)
{
if (buf) {
- language_ = buf->params().quotes_language;
+ language_ = l.empty() ? buf->params().quotes_language :
getLanguage(l);
fontenc_ = (buf->params().fontenc == "global")
? lyxrc.fontenc : buf->params().fontenc;
} else {
- language_ = EnglishQuotes;
+ language_ = l.empty() ? EnglishQuotes : getLanguage(l);
fontenc_ = lyxrc.fontenc;
}
- setSide(c);
+ if (s == "left")
+ side_ = LeftQuote;
+ else if (s == "right")
+ side_ = RightQuote;
+ else
+ 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
{
diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h
index b26c5d3..024304b 100644
--- a/src/insets/InsetQuotes.h
+++ b/src/insets/InsetQuotes.h
@@ -64,7 +64,9 @@ public:
*/
explicit InsetQuotes(Buffer * buf, std::string const & str = "eld");
/// 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;
///
@@ -112,6 +114,8 @@ private:
docstring displayString() const;
///
docstring getQuoteEntity() const;
+ ///
+ QuoteLanguage getLanguage(std::string const &);
///
QuoteLanguage language_;