]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetCounter.cpp
InsetFloat: pass back inset-modify that is addressed to other inset
[lyx.git] / src / insets / InsetCounter.cpp
index 32f7c6428c85dffc4590985279b4d42a06236750..4aa109d3ae77e5a6b69f355e0e20351de204759c 100644 (file)
@@ -17,7 +17,7 @@
 #include "LaTeXFeatures.h"
 #include "OutputParams.h"
 #include "output_xhtml.h"
-#include "sgml.h"
+#include "xml.h"
 #include "texstream.h"
 #include "TextClass.h"
 
@@ -58,19 +58,23 @@ InsetCounter::InsetCounter(InsetCounter const & ir)
 {}
 
 
-const map<string, string> InsetCounter::counterTable =
+const vector<pair<string, string>> InsetCounter::counterTable =
 {
-       {"set", N_("Set Counter")},
-       {"addto", N_("Add To Counter")},
-       {"reset", N_("Reset To 0")},
-       {"save", N_("Save Value of Counter")},
-       {"restore", N_("Restore Value of Counter")},
-       {"value", N_("Display Value of Counter")}
+       {"set", N_("Set counter to ...")},
+       {"addto", N_("Increase counter by ...")},
+       {"reset", N_("Reset counter to 0")},
+       {"save", N_("Save current counter value")},
+       {"restore", N_("Restore saved counter value")},
 };
 
 
-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;
 }
 
 
@@ -80,7 +84,6 @@ ParamInfo const & InsetCounter::findInfo(string const & /* cmdName */)
        if (param_info_.empty()) {
                param_info_.add("counter", ParamInfo::LYX_INTERNAL);
                param_info_.add("value", ParamInfo::LYX_INTERNAL);
-               param_info_.add("vtype", ParamInfo::LYX_INTERNAL);
                param_info_.add("lyxonly", ParamInfo::LYX_INTERNAL);
        }
        return param_info_;
@@ -112,8 +115,6 @@ void InsetCounter::latex(otexstream & os, OutputParams const &) const
                cnts.restoreValue(cntr);
                os << "\\setcounter{" << cntr
                   << "{\\value{" << lyxSaveCounter() << "}}";
-       } else if (cmd == "value") {
-               os << "\\the" << cntr << "{}";
        }
 }
 
@@ -133,26 +134,8 @@ int InsetCounter::plaintext(odocstringstream & os,
 }
 
 
-void InsetCounter::trackCounters(string const & cmd) const
-{
-       Counters & cnts = buffer().params().documentClass().counters();
-       docstring cntr = getParam("counter");
-       if (cmd == "set") {
-               docstring const & val = getParam("value");
-               cnts.set(cntr, convert<int>(val));
-       } else if (cmd == "addto") {
-               docstring const & val = getParam("value");
-               cnts.addto(cntr, convert<int>(val));
-       } else if (cmd == "reset") {
-               cnts.reset(cntr);               
-       } else if (cmd == "save") {
-               cnts.saveValue(cntr);
-       } else if (cmd == "restore") {
-               cnts.restoreValue(cntr);
-       }
-}
-
-
+#if 0
+// save this code until we get it working in InsetInfo
 const map<string, string> InsetCounter::valueTable =
 {
        {"Roman", N_("Roman Uppercase")},
@@ -180,40 +163,42 @@ docstring InsetCounter::value() const {
        LATTEST(false);
        return empty_docstring();
 }
+#endif
 
+void InsetCounter::trackCounters(string const & cmd) const
+{
+       Counters & cnts = buffer().params().documentClass().counters();
+       docstring cntr = getParam("counter");
+       if (cmd == "set") {
+               docstring const & val = getParam("value");
+               cnts.set(cntr, convert<int>(val));
+       } else if (cmd == "addto") {
+               docstring const & val = getParam("value");
+               cnts.addto(cntr, convert<int>(val));
+       } else if (cmd == "reset") {
+               cnts.reset(cntr);
+       } else if (cmd == "save") {
+               cnts.saveValue(cntr);
+       } else if (cmd == "restore") {
+               cnts.restoreValue(cntr);
+       }
+}
 
-int InsetCounter::docbook(odocstream & os, 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.
-       string const cmd = getCmdName();
-       if (cmd == "value") {
-               docstring cntr = getParam("counter");
-               Counters & cnts = buffer().params().documentClass().counters();
-               if (cnts.hasCounter(cntr))
-                       os << cnts.value(cntr);
-       } else
-               trackCounters(cmd);
-
-       return 0;
+       trackCounters(getCmdName());
 }
 
 
-docstring InsetCounter::xhtml(XHTMLStream & xs, 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
        // mechanism for doing that.
-       string const cmd = getCmdName();
-       if (cmd == "value") {
-               docstring cntr = getParam("counter");
-               Counters & cnts = buffer().params().documentClass().counters();
-               if (cnts.hasCounter(cntr))
-                       xs << cnts.value(cntr);
-       } else
-               trackCounters(cmd);
-
+       trackCounters(getCmdName());
        return docstring();
 }
 
@@ -223,38 +208,38 @@ 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);
+               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);
-       } else if (cmd == "value") {
-               screen_label_ = bformat(_("Counter: Value %1$s"), cntr);
-               tooltip_ = bformat(_("Display value of counter %1$s"), cntr);
        }
-       
 }