]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetListingsParams.cpp
Fix segfault after deleting monitor
[lyx.git] / src / insets / InsetListingsParams.cpp
index a2d2cea3c734b807cff32943a7ae341345264e71..998554c395c7f3f6e33c4798c2fb469b3b6e0c36 100644 (file)
@@ -102,7 +102,7 @@ docstring ListingsParam::validate(string const & par) const
        bool unclosed = false;
        string par2 = par;
        // braces are allowed
-       if (prefixIs(par, "{") && suffixIs(par, "}") && !suffixIs(par, "\\}"))  
+       if (prefixIs(par, "{") && suffixIs(par, "}") && !suffixIs(par, "\\}"))
                par2 = par.substr(1, par.size() - 2);
 
        // check for unmatched braces
@@ -114,7 +114,7 @@ docstring ListingsParam::validate(string const & par) const
                        --braces;
        }
        unclosed = braces != 0;
-       
+
        switch (type_) {
 
        case ALL:
@@ -269,6 +269,31 @@ char const * allowed_languages =
        "[97]VRML\nXML\nXSLT";
 
 
+/// Return language allowed in the GUI without dialect and proper casing
+string const languageonly(string const & lang)
+{
+       string const locase = ascii_lowercase(trim(lang, "{}"));
+       string const all_languages = ascii_lowercase(allowed_languages) + "\n";
+       string language = (lang.at(0) == '[') ? locase + "\n"
+                                             : string("]") + locase + "\n";
+       size_t i = all_languages.find(language);
+       if (i == string::npos && lang.at(0) != '[') {
+               language[0] = '\n';
+               i = all_languages.find(language);
+       }
+       if (i == string::npos)
+               return lang;
+       if (all_languages.at(i) == '[')
+               i = all_languages.find(']', i);
+       if (i == string::npos)
+               return lang;
+       size_t j = all_languages.find('\n', i + 1);
+       if (j == string::npos)
+               return lang;
+       return string(allowed_languages).substr(i + 1, j - i - 1);
+}
+
+
 /// ListingsParam Validator.
 /// This class is aimed to be a singleton which is instantiated in
 /// \c InsetListingsParams::addParam().
@@ -657,12 +682,6 @@ ParValidator::ParValidator()
        // is to signal that this is a floating listing.
        all_params_[1]["float"] =
                ListingsParam("false", true, SUBSETOF, "*tbph", empty_hint);
-       all_params_[1]["chapter"] =
-               ListingsParam("", true, TRUEFALSE, "", _(
-                                       "Number floats by chapter"));
-       all_params_[1]["section"] =
-               ListingsParam("", true, TRUEFALSE, "", _(
-                                       "Number floats by section"));
        all_params_[1]["cache"] =
                ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["cachedir"] =
@@ -685,25 +704,25 @@ ParValidator::ParValidator()
        all_params_[1]["outputdir"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["autogobble"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["baselinestretch"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breakafter"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breakaftergroup"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["breakaftersymbolpre"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breakaftersymbolpost"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breakanywhere"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["breakanywheresymbolpre"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breakanywheresymbolpost"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breakautoindent"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["breakbefore"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breakbeforegroup"] =
@@ -713,13 +732,13 @@ ParValidator::ParValidator()
        all_params_[1]["breakbeforesymbolpost"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breakbytoken"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["breakbytokenanywhere"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["breakindent"] =
                ListingsParam("", false, LENGTH, "", empty_hint);
        all_params_[1]["breaklines"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["breaksymbol"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["breaksymbolleft"] =
@@ -743,7 +762,7 @@ ParValidator::ParValidator()
        all_params_[1]["codetagify"] =
                ListingsParam("", false, ALL, "", empty_hint);
        all_params_[1]["curlyquotes"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["encoding"] =
                ListingsParam("", false, ALL, "", _(
                                "Sets encoding expected by Pygments"));
@@ -753,7 +772,7 @@ ParValidator::ParValidator()
                ListingsParam("", false, INTEGER, "", empty_hint);
        all_params_[1]["firstnumber"] =
                ListingsParam("", false, ALL, "", _(
-                                       "(auto | last | integer)"));
+                                       "auto, last or a number"));
        all_params_[1]["fontfamily"] =
                ListingsParam("", false, ALL, "", _(
                                "A latex family such as tt, sf, rm"));
@@ -777,7 +796,7 @@ ParValidator::ParValidator()
        all_params_[1]["framesep"] =
                ListingsParam("", false, LENGTH, "", empty_hint);
        all_params_[1]["funcnamehighlighting"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["gobble"] =
                ListingsParam("", false, INTEGER, "", empty_hint);
        all_params_[1]["highlightcolor"] =
@@ -800,56 +819,56 @@ ParValidator::ParValidator()
        all_params_[1]["lastline"] =
                ListingsParam("", false, INTEGER, "", empty_hint);
        all_params_[1]["linenos"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["numberfirstline"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["numbers"] =
                ListingsParam("", false, ONEOF,
                                "left\nright\nboth\nnone", empty_hint);
        all_params_[1]["mathescape"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["numberblanklines"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["numbersep"] =
                ListingsParam("", false, LENGTH, "", empty_hint);
        all_params_[1]["obeytabs"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["outencoding"] =
                ListingsParam("", false, ALL, "", _(
                  "File encoding used by Pygments for highlighting"));
        all_params_[1]["python3"] =
-               ListingsParam("", true, TRUEFALSE, "", _(
+               ListingsParam("", false, TRUEFALSE, "", _(
                                        "Apply Python 3 highlighting"));
-       all_params_[1]["resetsmargins"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+       all_params_[1]["resetmargins"] =
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["rulecolor"] =
                ListingsParam("", false, ALL, "", color_hint_mint);
        all_params_[1]["samepage"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["showspaces"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["showtabs"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["space"] =
                ListingsParam("", false, ALL, "", _(
-                               "A macro. Default: \textvisiblespace"));
+                               "A macro. Default: \\textvisiblespace"));
        all_params_[1]["spacecolor"] =
                ListingsParam("", false, ALL, "", color_hint_mint);
        all_params_[1]["startinline"] =
-               ListingsParam("", true, TRUEFALSE, "", _("For PHP only"));
+               ListingsParam("", false, TRUEFALSE, "", _("For PHP only"));
        all_params_[1]["style"] =
                ListingsParam("", false, ALL, "", _(
                                        "The style used by Pygments"));
        all_params_[1]["stepnumber"] =
                ListingsParam("", false, INTEGER, "", empty_hint);
        all_params_[1]["stepnumberfromfirst"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["stepnumberoffsetvalues"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["stripall"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["stripnl"] =
-               ListingsParam("", true, TRUEFALSE, "", empty_hint);
+               ListingsParam("", false, TRUEFALSE, "", empty_hint);
        all_params_[1]["tab"] =
                ListingsParam("", false, ALL, "", _(
                                "A macro to redefine visible tabs"));
@@ -858,10 +877,10 @@ ParValidator::ParValidator()
        all_params_[1]["tabsize"] =
                ListingsParam("", false, INTEGER, "", empty_hint);
        all_params_[1]["texcl"] =
-               ListingsParam("", true, TRUEFALSE, "", _(
+               ListingsParam("", false, TRUEFALSE, "", _(
                                "Enables latex code in comments"));
        all_params_[1]["texcomments"] =
-               ListingsParam("", true, TRUEFALSE, "", _(
+               ListingsParam("", false, TRUEFALSE, "", _(
                                "Enables latex code in comments"));
        all_params_[1]["xleftmargin"] =
                ListingsParam("", false, LENGTH, "", empty_hint);
@@ -895,10 +914,10 @@ docstring ParValidator::validate(string const & name,
                                        _("Available listing parameters are %1$s"), from_ascii(param_names));
                else
                        return bformat(
-                                       _("Available listings parameters containing string \"%1$s\" are %2$s"), 
+                                       _("Available listings parameters containing string \"%1$s\" are %2$s"),
                                                from_utf8(suffix), from_utf8(param_names));
        }
+
        // locate name in parameter table
        ListingsParams::const_iterator it = all_params_[p].find(name);
        if (it != all_params_[p].end()) {
@@ -940,7 +959,7 @@ bool ParValidator::onoff(string const & name) const
                return false;
 }
 
-} // namespace anon.
+} // namespace
 
 // define a global ParValidator
 ParValidator * par_validator = 0;
@@ -950,13 +969,13 @@ ParValidator * par_validator = 0;
 int InsetListingsParams::package_ = 0;
 
 InsetListingsParams::InsetListingsParams()
-       : inline_(false), params_(), status_(InsetCollapsable::Open)
+       : inline_(false), params_(), status_(InsetCollapsible::Open)
 {
 }
 
 
 InsetListingsParams::InsetListingsParams(string const & par, bool in,
-               InsetCollapsable::CollapseStatus s)
+               InsetCollapsible::CollapseStatus s)
        : inline_(in), params_(), status_(s)
 {
        // this will activate parameter validation.
@@ -977,9 +996,9 @@ void InsetListingsParams::write(ostream & os) const
 void InsetListingsParams::read(Lexer & lex)
 {
        lex >> inline_;
-       int s = InsetCollapsable::Collapsed;
+       int s = InsetCollapsible::Collapsed;
        lex >> s;
-       status_ = static_cast<InsetCollapsable::CollapseStatus>(s);
+       status_ = static_cast<InsetCollapsible::CollapseStatus>(s);
        string par;
        lex >> par;
        fromEncodedString(par);
@@ -1025,12 +1044,15 @@ string InsetListingsParams::getValue(string const & key) const
 }
 
 
-void InsetListingsParams::addParam(string const & key, 
-               string const & value, bool replace)
+void InsetListingsParams::addParam(string const & key,
+               string const & val, bool replace)
 {
        if (key.empty())
                return;
 
+       bool const is_minted_language = minted() && key == "language";
+       string const value = (is_minted_language && !val.empty())
+                               ? languageonly(val) : val;
        // duplicate parameters!
        string keyname = key;
        if (!replace && hasParam(key))
@@ -1055,7 +1077,7 @@ void InsetListingsParams::addParam(string const & key,
                                has_special_char = true;
                                break;
                        }
-               if (has_special_char)
+               if (has_special_char && !is_minted_language)
                        params_.push_back(make_pair(keyname, "{" + value + "}"));
                else
                        params_.push_back(make_pair(keyname, value));
@@ -1089,7 +1111,7 @@ void InsetListingsParams::addParams(string const & par)
                } else if (par[i] == '{' && i > 0 && par[i-1] != '\\')
                        // don't count a brace in first position
                        ++braces;
-               else if (par[i] == '}' && i != par.size() - 1 
+               else if (par[i] == '}' && i != par.size() - 1
                         && (i == 0 || (i > 0 && par[i-1] != '\\')))
                        --braces;