]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCounter.cpp
Use LaTeXName of counter in LaTeX output.
[lyx.git] / src / insets / InsetCounter.cpp
index d0aa10877a064daa888d28b3ba82105c76abf837..a43bc60662f435e249484bdc464c8bdf97fba7f5 100644 (file)
@@ -15,9 +15,8 @@
 #include "BufferParams.h"
 #include "Counters.h"
 #include "LaTeXFeatures.h"
-#include "OutputParams.h"
 #include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
 #include "texstream.h"
 #include "TextClass.h"
 
@@ -58,7 +57,7 @@ InsetCounter::InsetCounter(InsetCounter const & ir)
 {}
 
 
-const map<string, string> InsetCounter::counterTable =
+const vector<pair<string, string>> InsetCounter::counterTable =
 {
        {"set", N_("Set counter to ...")},
        {"addto", N_("Increase counter by ...")},
@@ -68,8 +67,13 @@ const map<string, string> InsetCounter::counterTable =
 };
 
 
-bool InsetCounter::isCompatibleCommand(string const & s) {
-       return counterTable.count(s);
+bool InsetCounter::isCompatibleCommand(string const & s)
+{
+       for (auto & i : counterTable) {
+               if (i.first == s)
+                       return true;
+       }
+       return false;
 }
 
 
@@ -92,31 +96,33 @@ void InsetCounter::latex(otexstream & os, OutputParams const &) const
                return;
 
        string const cmd = getCmdName();
-       docstring cntr = getParam("counter");
+       docstring const & cntr = getParam("counter");
        Counters & cnts = buffer().params().documentClass().counters();
+       docstring const & latexname = cnts.latexName(cntr);
+
        if (cmd == "set") {
                docstring const & val = getParam("value");
-               os << "\\setcounter{" << cntr << "}{" << val << "}";
+               os << "\\setcounter{" << latexname << "}{" << val << "}";
        } else if (cmd == "addto") {
                docstring const & val = getParam("value");
-               os << "\\addtocounter{" << cntr << "}{" << val << "}";
+               os << "\\addtocounter{" << latexname << "}{" << val << "}";
        } else if (cmd == "reset") {
-               os << "\\setcounter{" << cntr << "}{0}";
+               os << "\\setcounter{" << latexname << "}{0}";
        } else if (cmd == "save") {
                cnts.saveValue(cntr);
-               os << "\\setcounter{" << lyxSaveCounter() 
-                  << "}{\\value{" << cntr << "}}";
+               os << "\\setcounter{" << lyxSaveCounter()
+                  << "}{\\value{" << latexname << "}}";
        } else if (cmd == "restore") {
                cnts.restoreValue(cntr);
-               os << "\\setcounter{" << cntr
-                  << "{\\value{" << lyxSaveCounter() << "}}";
+               os << "\\setcounter{" << latexname
+                  << "}{\\value{" << lyxSaveCounter() << "}}";
        }
 }
 
 
 void InsetCounter::toString(odocstream & os) const
 {
-       os << "[Counter " << from_utf8(getCmdName()) << ": " 
+       os << "[Counter " << from_utf8(getCmdName()) << ": "
           <<  getParam("counter") << "]";
 }
 
@@ -179,17 +185,16 @@ void InsetCounter::trackCounters(string const & cmd) const
        }
 }
 
-int InsetCounter::docbook(odocstream &, OutputParams const &) const
+void InsetCounter::docbook(XMLStream &, OutputParams const &) const
 {
        // Here, we need to track counter values ourselves,
        // since unlike in the LaTeX case, there is no external
        // mechanism for doing that.
        trackCounters(getCmdName());
-       return 0;
 }
 
 
-docstring InsetCounter::xhtml(XHTMLStream &, OutputParams const &) const
+docstring InsetCounter::xhtml(XMLStream &, OutputParams const &) const
 {
        // Here, we need to track counter values ourselves,
        // since unlike in the LaTeX case, there is no external
@@ -204,32 +209,36 @@ void InsetCounter::updateBuffer(ParIterator const &, UpdateType, bool const)
        string const cmd = getCmdName();
        docstring cntr = getParam("counter");
        Counters & cnts = buffer().params().documentClass().counters();
-       map<string, string>::const_iterator cit = counterTable.find(cmd);
-       LASSERT(cit != counterTable.end(), return);
-       string const label = cit->second;
+       string label;
+       for (auto & i : counterTable) {
+               if (i.first == cmd)
+                       label = i.second;
+       }
+       LASSERT(!label.empty(), return);
        docstring const tlabel = translateIfPossible(from_ascii(label));
 
+       docstring guiname = translateIfPossible(cnts.guiName(cntr));
        if (cmd == "set") {
                docstring const & val = getParam("value");
                cnts.set(cntr, convert<int>(val));
-               screen_label_ = bformat(_("Counter: Set %1$s"), cntr);
+               screen_label_ = bformat(_("Counter: Set %1$s"), guiname);
                tooltip_ = bformat(_("Set value of counter %1$s to %2$s"), cntr, val);
        } else if (cmd == "addto") {
                docstring const & val = getParam("value");
                cnts.addto(cntr, convert<int>(val));
-               screen_label_ = bformat(_("Counter: Add to %1$s"), cntr);
+               screen_label_ = bformat(_("Counter: Add to %1$s"), guiname);
                tooltip_ = bformat(_("Add %1$s to value of counter %2$s"), val, cntr);
        } else if (cmd == "reset") {
-               cnts.reset(cntr);               
-               screen_label_ = bformat(_("Counter: Reset %1$s"), cntr);
+               cnts.reset(cntr);
+               screen_label_ = bformat(_("Counter: Reset %1$s"), guiname);
                tooltip_ = bformat(_("Reset value of counter %1$s"), cntr);
        } else if (cmd == "save") {
                cnts.saveValue(cntr);
-               screen_label_ = bformat(_("Counter: Save %1$s"), cntr);
+               screen_label_ = bformat(_("Counter: Save %1$s"), guiname);
                tooltip_ = bformat(_("Save value of counter %1$s"), cntr);
        } else if (cmd == "restore") {
                cnts.restoreValue(cntr);
-               screen_label_ = bformat(_("Counter: Restore %1$s"), cntr);
+               screen_label_ = bformat(_("Counter: Restore %1$s"), guiname);
                tooltip_ = bformat(_("Restore value of counter %1$s"), cntr);
        }
 }
@@ -254,8 +263,8 @@ void InsetCounter::validate(LaTeXFeatures & features) const
 }
 
 
-string InsetCounter::contextMenuName() const 
-{ 
-       return "context-counter"; 
+string InsetCounter::contextMenuName() const
+{
+    return "context-counter";
 }
 } // namespace lyx