commit 666f90cdbb15b33d2f3f0b643e3bd66512f7b852
Author: Richard Kimberly Heck <rikih...@lyx.org>
Date:   Sat May 2 23:00:17 2020 -0400

    Use GuiNames for counters.
---
 src/Counters.cpp                |   24 +++++++++++++++++++++++-
 src/Counters.h                  |    6 ++++++
 src/frontends/qt/GuiCounter.cpp |   15 +++++++++------
 3 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/src/Counters.cpp b/src/Counters.cpp
index 830c7e0..42e10e8 100644
--- a/src/Counters.cpp
+++ b/src/Counters.cpp
@@ -56,12 +56,14 @@ bool Counter::read(Lexer & lex)
                CT_LABELSTRING_APPENDIX,
                CT_PRETTYFORMAT,
                CT_INITIALVALUE,
+               CT_GUINAME,
                CT_END
        };
 
        LexerKeyword counterTags[] = {
                { "end", CT_END },
-         { "initialvalue", CT_INITIALVALUE},
+               { "guiname", CT_GUINAME },
+               { "initialvalue", CT_INITIALVALUE},
                { "labelstring", CT_LABELSTRING },
                { "labelstringappendix", CT_LABELSTRING_APPENDIX },
                { "prettyformat", CT_PRETTYFORMAT },
@@ -112,6 +114,10 @@ bool Counter::read(Lexer & lex)
                                lex.next();
                                labelstringappendix_ = lex.getDocString();
                                break;
+                       case CT_GUINAME:
+                               lex.next();
+                               guiname_ = lex.getDocString();
+                               break;
                        case CT_END:
                                getout = true;
                                break;
@@ -349,6 +355,22 @@ void Counters::step(docstring const & ctr, UpdateType 
utype)
 }
 
 
+docstring const & Counters::guiName(docstring const & cntr) const
+{
+       CounterList::const_iterator it = counterList_.find(cntr);
+       if (it == counterList_.end()) {
+               lyxerr << "step: Counter does not exist: "
+                          << to_utf8(cntr) << endl;
+               return empty_docstring();
+       }
+
+       docstring const & guiname = it->second.guiName();
+       if (guiname.empty())
+               return cntr;
+       return guiname;
+}
+
+
 void Counters::reset()
 {
        appendix_ = false;
diff --git a/src/Counters.h b/src/Counters.h
index 77e1f11..92643c1 100644
--- a/src/Counters.h
+++ b/src/Counters.h
@@ -67,6 +67,8 @@ public:
        /// Similar, but used for formatted references in XHTML output.
        /// E.g., for a section counter it might be "section \thesection"
        docstring const & prettyFormat() const { return prettyformat_; }
+       ///
+       docstring const & guiName() const { return guiname_; }
 
        /// Returns a map of LaTeX-like strings to format the counter.
        /** For each language, the string is similar to what one gets
@@ -97,6 +99,8 @@ private:
        docstring labelstringappendix_;
        /// Similar, but used for formatted references in XHTML output
        docstring prettyformat_;
+       ///
+       docstring guiname_;
        /// Cache of the labelstring with \\the<counter> expressions expanded,
        /// indexed by language
        mutable StringMap flatlabelstring_;
@@ -174,6 +178,8 @@ public:
        /// format given by Counter::prettyFormat().
        docstring prettyCounter(docstring const & cntr,
                               std::string const & lang) const;
+       ///
+       docstring const & guiName(docstring const & cntr) const;
        /// Are we in appendix?
        bool appendix() const { return appendix_; }
        /// Set the state variable indicating whether we are in appendix.
diff --git a/src/frontends/qt/GuiCounter.cpp b/src/frontends/qt/GuiCounter.cpp
index c3e3265..9b8fbb6 100644
--- a/src/frontends/qt/GuiCounter.cpp
+++ b/src/frontends/qt/GuiCounter.cpp
@@ -59,7 +59,7 @@ GuiCounter::GuiCounter(GuiView & lv, QWidget * parent) :
 void GuiCounter::processParams(InsetCommandParams const & params)
 {
        QString const & counter = toqstr(params["counter"]);
-       int c = counterCB->findText(counter);
+       int c = counterCB->findData(counter);
        counterCB->setCurrentIndex(c);
 
        QString cmd = toqstr(params.getCmdName());
@@ -85,10 +85,13 @@ void GuiCounter::fillCombos()
        if (!bv)
                return;
        
-       std::vector<docstring> counts = 
-               
bv->buffer().params().documentClass().counters().listOfCounters();
-       for (auto const & c : counts)
-               counterCB->addItem(toqstr(c));
+       Counters const & cntrs =
+               bv->buffer().params().documentClass().counters();
+       std::vector<docstring> counts = cntrs.listOfCounters();
+       for (auto const & c : counts) {
+               docstring const & guiname = cntrs.guiName(c);
+               counterCB->addItem(toqstr(guiname), toqstr(c));
+       }
 }
 
 
@@ -118,7 +121,7 @@ docstring GuiCounter::dialogToParams() const
 {
        InsetCommandParams params(insetCode());
 
-       params["counter"] = qstring_to_ucs4(counterCB->currentText());
+       params["counter"] = 
qstring_to_ucs4(counterCB->itemData(counterCB->currentIndex()).toString());
        params["value"] = convert<docstring>(valueSB->value());
        
params.setCmdName(fromqstr(actionCB->itemData(actionCB->currentIndex()).toString()));
        params["lyxonly"] = from_ascii(lyxonlyXB->isChecked() ? "true" : 
"false");
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to