commit a3bb0db65821bec40a226833968140fbc27ae12e
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sun Dec 18 10:29:35 2016 +0100

    Allow wildcards in inset-modify for quotes
    
    A dot in the <lang><side><times> string means: keep current value.
    
    This expert feature allows to change arbitrary quote features in one step.
    
    E.g.,
    
    inset-forall Quotes inset-modify changetype f..
    
    => change all quote insets to French style, maintaining current side
       and times setting
    
    inset-forall Quotes inset-modify changetype ..s
    
    => change all quote insets to single quotes, keeping style and times
    
    inset-forall Quotes inset-modify changetype g.s
    
    => change all quote insets to German single quotes, keeping left/right
       setting
    
    Any idea where to document this?
---
 src/insets/InsetQuotes.cpp |   67 +++++++++++++++++++++++++-------------------
 src/insets/InsetQuotes.h   |    3 +-
 2 files changed, 40 insertions(+), 30 deletions(-)

diff --git a/src/insets/InsetQuotes.cpp b/src/insets/InsetQuotes.cpp
index 60c6426..ef9629f 100644
--- a/src/insets/InsetQuotes.cpp
+++ b/src/insets/InsetQuotes.cpp
@@ -158,7 +158,7 @@ void InsetQuotes::setSide(char_type c)
 }
 
 
-void InsetQuotes::parseString(string const & s)
+void InsetQuotes::parseString(string const & s, bool const allow_wildcards)
 {
        string str = s;
        if (str.length() != 3) {
@@ -169,40 +169,49 @@ void InsetQuotes::parseString(string const & s)
 
        int i;
 
-       for (i = 0; i < 6; ++i) {
-               if (str[0] == language_char[i]) {
-                       language_ = QuoteLanguage(i);
-                       break;
+       // '.' wildcard means: keep current language
+       if (!allow_wildcards || str[0] != '.') {
+               for (i = 0; i < 6; ++i) {
+                       if (str[0] == language_char[i]) {
+                               language_ = QuoteLanguage(i);
+                               break;
+                       }
+               }
+               if (i >= 6) {
+                       lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
+                               " bad language specification." << endl;
+                       language_ = EnglishQuotes;
                }
-       }
-       if (i >= 6) {
-               lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
-                       " bad language specification." << endl;
-               language_ = EnglishQuotes;
        }
 
-       for (i = 0; i < 2; ++i) {
-               if (str[1] == side_char[i]) {
-                       side_ = QuoteSide(i);
-                       break;
+       // '.' wildcard means: keep current side
+       if (!allow_wildcards || str[1] != '.') {
+               for (i = 0; i < 2; ++i) {
+                       if (str[1] == side_char[i]) {
+                               side_ = QuoteSide(i);
+                               break;
+                       }
+               }
+               if (i >= 2) {
+                       lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
+                               " bad side specification." << endl;
+                       side_ = LeftQuote;
                }
-       }
-       if (i >= 2) {
-               lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
-                       " bad side specification." << endl;
-               side_ = LeftQuote;
        }
 
-       for (i = 0; i < 2; ++i) {
-               if (str[2] == times_char[i]) {
-                       times_ = QuoteTimes(i);
-                       break;
+       // '.' wildcard means: keep current times
+       if (!allow_wildcards || str[2] != '.') {
+               for (i = 0; i < 2; ++i) {
+                       if (str[2] == times_char[i]) {
+                               times_ = QuoteTimes(i);
+                               break;
+                       }
+               }
+               if (i >= 2) {
+                       lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
+                               " bad times specification." << endl;
+                       times_ = DoubleQuotes;
                }
-       }
-       if (i >= 2) {
-               lyxerr << "ERROR (InsetQuotes::InsetQuotes):"
-                       " bad times specification." << endl;
-               times_ = DoubleQuotes;
        }
 }
 
@@ -338,7 +347,7 @@ void InsetQuotes::doDispatch(Cursor & cur, FuncRequest & 
cmd)
                        return;
                }
                cur.recordUndoInset(this);
-               parseString(cmd.getArg(1));
+               parseString(cmd.getArg(1), true);
                cur.buffer()->updateBuffer();
                break;
        }
diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h
index 3054054..9bb2179 100644
--- a/src/insets/InsetQuotes.h
+++ b/src/insets/InsetQuotes.h
@@ -118,7 +118,8 @@ private:
        /// Decide whether we need left or right quotation marks
        void setSide(char_type c);
        ///
-       void parseString(std::string const &);
+       void parseString(std::string const &,
+                        bool const allow_wildcards = false);
        ///
        docstring displayString() const;
        ///

Reply via email to