]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCommandParams.cpp
requires is a keyword in C++2a
[lyx.git] / src / insets / InsetCommandParams.cpp
index cae982782c6d50fc4038e4f89dfb79aa7bca68b5..1f7d32110810fe3e18ed6aee8680e75c4dac11d0 100644 (file)
@@ -20,6 +20,7 @@
 #include "InsetBibitem.h"
 #include "InsetBibtex.h"
 #include "InsetCitation.h"
+#include "InsetCounter.h"
 #include "InsetFloatList.h"
 #include "InsetHyperlink.h"
 #include "InsetInclude.h"
@@ -63,6 +64,8 @@ static ParamInfo const & findInfo(InsetCode code, string const & cmdName)
                return InsetBibtex::findInfo(cmdName);
        case CITE_CODE:
                return InsetCitation::findInfo(cmdName);
+       case COUNTER_CODE:
+               return InsetCounter::findInfo(cmdName);
        case FLOAT_LIST_CODE:
                return InsetFloatList::findInfo(cmdName);
        case HYPERLINK_CODE:
@@ -132,10 +135,10 @@ bool ParamInfo::hasParam(std::string const & name) const
 
 
 void ParamInfo::add(std::string const & name, ParamType type,
-                    ParamHandling handling, bool ignore,
+                    ParamHandling handling, bool ignoreval,
                     docstring default_value)
 {
-       info_.push_back(ParamData(name, type, handling, ignore, default_value));
+       info_.push_back(ParamData(name, type, handling, ignoreval, default_value));
 }
 
 
@@ -201,6 +204,8 @@ string InsetCommandParams::getDefaultCmd(InsetCode code)
                        return InsetBibtex::defaultCommand();
                case CITE_CODE:
                        return InsetCitation::defaultCommand();
+               case COUNTER_CODE:
+                       return InsetCounter::defaultCommand();
                case FLOAT_LIST_CODE:
                        return InsetFloatList::defaultCommand();
                case HYPERLINK_CODE:
@@ -238,6 +243,8 @@ bool InsetCommandParams::isCompatibleCommand(InsetCode code, string const & s)
                        return InsetBibtex::isCompatibleCommand(s);
                case CITE_CODE:
                        return InsetCitation::isCompatibleCommand(s);
+               case COUNTER_CODE:
+                       return InsetCounter::isCompatibleCommand(s);
                case FLOAT_LIST_CODE:
                        return InsetFloatList::isCompatibleCommand(s);
                case HYPERLINK_CODE:
@@ -282,7 +289,7 @@ void InsetCommandParams::setCmdName(string const & name)
 
 void InsetCommandParams::read(Lexer & lex)
 {
-       Read(lex, 0);
+       Read(lex, nullptr);
 }
 
 
@@ -356,7 +363,7 @@ void InsetCommandParams::Read(Lexer & lex, Buffer const * buffer)
 
 void InsetCommandParams::write(ostream & os) const
 {
-       Write(os, 0);
+       Write(os, nullptr);
 }
 
 
@@ -464,14 +471,15 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
                }
                // Now escape special commands
                static docstring const backslash = from_ascii("\\");
-               static char_type const chars_escape[6] = {
-                       '&', '_', '$', '%', '#', '^'};
+               int const nchars_escape = 8;
+               static char_type const chars_escape[nchars_escape] = {
+                       '&', '_', '$', '%', '#', '^', '{', '}'};
 
                if (!result.empty()) {
                        int previous;
                        // The characters in chars_name[] need to be changed to a command when
                        // they are LaTeXified.
-                       for (int k = 0; k < 6; k++)
+                       for (int k = 0; k < nchars_escape; k++)
                                for (size_t i = 0, pos;
                                        (pos = result.find(chars_escape[k], i)) != string::npos;
                                        i = pos + 2) {
@@ -489,18 +497,53 @@ docstring InsetCommandParams::prepareCommand(OutputParams const & runparams,
        }
        else if (handling & ParamInfo::HANDLING_ESCAPE)
                result = escape(command);
-       else if (handling & ParamInfo::HANDLING_NONE)
-               result = command;
+       else if (handling & ParamInfo::HANDLING_NONE) {
+               // we can only output characters covered by the current
+               // encoding!
+               docstring uncodable;
+               for (size_type i = 0 ; i < command.size() ; ++i) {
+                       char_type c = command[i];
+                       try {
+                               if (runparams.encoding->encodable(c))
+                                       result += c;
+                               else if (runparams.dryrun) {
+                                       result += "<" + _("LyX Warning: ")
+                                          + _("uncodable character") + " '";
+                                       result += docstring(1, c);
+                                       result += "'>";
+                               } else
+                                       uncodable += c;
+                       } catch (EncodingException & /* e */) {
+                               if (runparams.dryrun) {
+                                       result += "<" + _("LyX Warning: ")
+                                          + _("uncodable character") + " '";
+                                       result += docstring(1, c);
+                                       result += "'>";
+                               } else
+                                       uncodable += c;
+                       }
+               }
+               if (!uncodable.empty() && !runparams.silent) {
+                       // issue a warning about omitted characters
+                       // FIXME: should be passed to the error dialog
+                       frontend::Alert::warning(_("Uncodable characters in inset"),
+                               bformat(_("The following characters in one of the insets are\n"
+                                         "not representable in the current encoding and have been omitted: %1$s.\n"
+                                         "Unchecking 'Literal' in the respective inset dialog might help."),
+                               uncodable));
+               }
+       }
        // INDEX_ESCAPE is independent of the others
        if (handling & ParamInfo::HANDLING_INDEX_ESCAPE) {
                // Now escape special commands
                static docstring const quote = from_ascii("\"");
-               static char_type const chars_escape[4] = { '"', '@', '|', '!' };
+               int const nchars_escape = 4;
+               static char_type const chars_escape[nchars_escape] = { '"', '@', '|', '!' };
 
                if (!result.empty()) {
                        // The characters in chars_name[] need to be changed to a command when
                        // they are LaTeXified.
-                       for (int k = 0; k < 4; k++)
+                       for (int k = 0; k < nchars_escape; k++)
                                for (size_t i = 0, pos;
                                        (pos = result.find(chars_escape[k], i)) != string::npos;
                                        i = pos + 2)
@@ -591,6 +634,7 @@ docstring & InsetCommandParams::operator[](string const & name)
 void InsetCommandParams::clear()
 {
        params_.clear();
+       preview(false);
 }