From c355edfb6da71b5efc9ed1ce548bd206ad9f57cb Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Sun, 12 Jul 2009 17:30:56 +0000 Subject: [PATCH] revert r30515: too many files there git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30516 a592a061-630c-0410-9148-cb99ea01b6c8 --- configure.ac | 2 +- src/Buffer.cpp | 6 ++-- src/Counters.cpp | 55 +++++++++++++++++-------------- src/Counters.h | 55 +++++++++++++------------------ src/Paragraph.cpp | 21 ++++++++---- src/frontends/qt4/GuiGraphics.cpp | 8 +++++ src/frontends/qt4/Validator.cpp | 2 +- src/insets/InsetBibitem.cpp | 10 ++---- src/insets/InsetCaption.cpp | 4 +-- src/insets/InsetCollapsable.cpp | 7 ++-- src/insets/InsetFoot.cpp | 14 ++++---- 11 files changed, 93 insertions(+), 91 deletions(-) diff --git a/configure.ac b/configure.ac index f233132e12..f81818aa40 100644 --- a/configure.ac +++ b/configure.ac @@ -26,7 +26,7 @@ fi AM_MAINTAINER_MODE save_PACKAGE=$PACKAGE -AM_INIT_AUTOMAKE([foreign dist-bzip2 no-define 1.5 silent-rules]) +AM_INIT_AUTOMAKE([foreign dist-bzip2 no-define 1.5]) PACKAGE=$save_PACKAGE ### Set the execute permissions of the various scripts correctly diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 2d44472d4f..369dff14f8 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -3389,8 +3389,7 @@ static void setLabel(Buffer const & buf, ParIterator & it) counters.reset(enumcounter); counters.step(enumcounter); - string const & lang = par.getParLanguage(bp)->code(); - par.params().labelString(counters.theCounter(enumcounter, lang)); + par.params().labelString(counters.theCounter(enumcounter)); break; } @@ -3403,11 +3402,10 @@ static void setLabel(Buffer const & buf, ParIterator & it) else { docstring name = buf.B_(textclass.floats().getType(type).name()); if (counters.hasCounter(from_utf8(type))) { - string const & lang = par.getParLanguage(bp)->code(); counters.step(from_utf8(type)); full_label = bformat(from_ascii("%1$s %2$s:"), name, - counters.theCounter(from_utf8(type), lang)); + counters.theCounter(from_utf8(type))); } else full_label = bformat(from_ascii("%1$s #:"), name); } diff --git a/src/Counters.cpp b/src/Counters.cpp index a79bc6b36d..3921cf2890 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -18,7 +18,6 @@ #include "support/convert.h" #include "support/debug.h" -#include "support/gettext.h" #include "support/lassert.h" #include "support/lstrings.h" @@ -144,12 +143,19 @@ docstring const & Counter::labelString(bool in_appendix) const } -Counter::StringMap & Counter::flatLabelStrings(bool in_appendix) const +docstring const & Counter::flatLabelString(bool in_appendix) const { return in_appendix ? flatlabelstringappendix_ : flatlabelstring_; } +void Counter::setFlatLabelStrings(docstring const & fls, docstring const & flsa) +{ + flatlabelstring_ = fls; + flatlabelstringappendix_ = flsa; +} + + void Counters::newCounter(docstring const & newc, docstring const & masterc, docstring const & ls, @@ -249,6 +255,20 @@ void Counters::reset() appendix_ = false; subfloat_ = false; current_float_.erase(); + CounterList::iterator it = counterList_.begin(); + CounterList::iterator const end = counterList_.end(); + std::vector callers; + for (; it != end; ++it) { + it->second.reset(); + // Compute the explicit counter labels without any + // \thexxx strings, in order to avoid recursion. + // It only needs to be done when the textclass is + // updated, but in practice the extra work is probably + // not noticeable (JMarc) + docstring const fls = flattenLabelString(it->first, false, callers); + docstring const flsa = flattenLabelString(it->first, true, callers); + it->second.setFlatLabelStrings(fls, flsa); + } } @@ -410,29 +430,18 @@ docstring Counters::labelItem(docstring const & ctr, } -docstring Counters::theCounter(docstring const & counter, - string const & lang) const +docstring Counters::theCounter(docstring const & counter) const { CounterList::const_iterator it = counterList_.find(counter); if (it == counterList_.end()) return from_ascii("??"); - Counter const & ctr = it->second; - Counter::StringMap sm = ctr.flatLabelStrings(appendix()); - Counter::StringMap::iterator smit = sm.find(lang); - if (smit != sm.end()) - return counterLabel(smit->second, lang); - - vector callers; - docstring const & fls = flattenLabelString(counter, appendix(), - lang, callers); - sm[lang] = fls; - return counterLabel(fls, lang); + // FIXME: this should get translated. + return counterLabel(it->second.flatLabelString(appendix())); } docstring Counters::flattenLabelString(docstring const & counter, - bool in_appendix, - string const & lang, + bool in_appendix, vector & callers) const { docstring label; @@ -450,12 +459,12 @@ docstring Counters::flattenLabelString(docstring const & counter, return from_ascii("??"); Counter const & c = it->second; - docstring ls = translateIfPossible(c.labelString(in_appendix), lang); + docstring ls = c.labelString(in_appendix); callers.push_back(counter); if (ls.empty()) { if (!c.master().empty()) - ls = flattenLabelString(c.master(), in_appendix, lang, callers) + ls = flattenLabelString(c.master(), in_appendix, callers) + from_ascii("."); callers.pop_back(); return ls + from_ascii("\\arabic{") + counter + "}"; @@ -472,8 +481,7 @@ docstring Counters::flattenLabelString(docstring const & counter, && lowercase(ls[k]) <= 'z') ++k; docstring const newc = ls.substr(j, k - j); - docstring const repl = flattenLabelString(newc, in_appendix, - lang, callers); + docstring const repl = flattenLabelString(newc, in_appendix, callers); ls.replace(i, k - j + 4, repl); } callers.pop_back(); @@ -482,8 +490,7 @@ docstring Counters::flattenLabelString(docstring const & counter, } -docstring Counters::counterLabel(docstring const & format, - string const & lang) const +docstring Counters::counterLabel(docstring const & format) const { docstring label = format; @@ -500,7 +507,7 @@ docstring Counters::counterLabel(docstring const & format, && lowercase(label[k]) <= 'z') ++k; docstring const newc = label.substr(j, k - j); - docstring const repl = theCounter(newc, lang); + docstring const repl = theCounter(newc); label.replace(i, k - j + 4, repl); } while (true) { diff --git a/src/Counters.h b/src/Counters.h index fdae212a26..a83c5226e2 100644 --- a/src/Counters.h +++ b/src/Counters.h @@ -49,19 +49,19 @@ public: docstring const & master() const; /// Returns a LaTeX-like string to format the counter. /** This is similar to what one gets in LaTeX when using - * "\the". The \c in_appendix bool tells whether we - * want the version shown in an appendix. + * "\the". The \c in_appendix bool tells whether + * we want the version shown in an appendix. */ docstring const & labelString(bool in_appendix) const; - /// Returns a map of LaTeX-like strings to format the counter. - /** For each language, the string is similar to what one gets - * in LaTeX when using "\the". The \c in_appendix - * bool tells whether we want the version shown in an - * appendix. This version does not contain any \\the - * expression. + /// Returns a LaTeX-like string to format the counter. + /** This is similar to what one gets in LaTeX when using + * "\the". The \c in_appendix bool tells whether + * we want the version shown in an appendix. This version does + * not contain any \\the expression. */ - typedef std::map StringMap; - StringMap & flatLabelStrings(bool in_appendix) const; + docstring const & flatLabelString(bool in_appendix) const; + /// set the \c flatLabelString values. + void setFlatLabelStrings(docstring const & fls, docstring const & flsa); private: /// int value_; @@ -75,12 +75,10 @@ private: docstring labelstring_; /// The same as labelstring_, but in appendices. docstring labelstringappendix_; - /// Cache of the labelstring with \\the expressions expanded, - /// indexed by language - mutable StringMap flatlabelstring_; - /// Cache of the appendix labelstring with \\the expressions expanded, - /// indexed by language - mutable StringMap flatlabelstringappendix_; + /// A version of the labelstring with \\the expressions expanded + docstring flatlabelstring_; + /// A version of the appendix labelstring with \\the expressions expanded + docstring flatlabelstringappendix_; }; @@ -121,17 +119,11 @@ public: /// the &to array of counters. Empty string matches all. void copy(Counters & from, Counters & to, docstring const & match = docstring()); - /** returns the expanded string representation of counter \c - * c. The \c lang code is used to translate the string. - */ - docstring theCounter(docstring const & c, - std::string const & lang) const; - /** Replace in \c format all the LaTeX-like macros that depend - * on counters. The \c lang code is used to translate the - * string. - */ - docstring counterLabel(docstring const & format, - std::string const & lang) const; + /// returns the expanded string representation of the counter. + docstring theCounter(docstring const & c) const; + /// Replace in \c format all the LaTeX-like macros that depend on + /// counters. + docstring counterLabel(docstring const & format) const; /// Are we in appendix? bool appendix() const { return appendix_; }; /// Set the state variable indicating whether we are in appendix. @@ -145,12 +137,9 @@ public: /// Set the state variable indicating whether we are in a subfloat. void isSubfloat(bool s) { subfloat_ = s; }; private: - /** expands recusrsively any \\the macro in the - * labelstring of \c counter. The \c lang code is used to - * translate the string. - */ - docstring flattenLabelString(docstring const & counter, bool in_appendix, - std::string const &lang, + /// expands recusrsively any \\the macro in the + /// labelstring of \c counter. + docstring flattenLabelString(docstring const & counter, bool in_appendix, std::vector & callers) const; /// Returns the value of the counter according to the /// numbering scheme numbertype. diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 9dc6f4fafa..19997fa51b 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -58,6 +58,7 @@ #include "support/gettext.h" #include "support/lassert.h" #include "support/lstrings.h" +#include "support/Messages.h" #include "support/textutils.h" #include @@ -1608,7 +1609,14 @@ void Paragraph::setLabelWidthString(docstring const & s) docstring const Paragraph::translateIfPossible(docstring const & s, BufferParams const & bparams) const { - return lyx::translateIfPossible(s, getParLanguage(bparams)->code()); + if (!isAscii(s) || s.empty()) { + // This must be a user defined layout. We cannot translate + // this, since gettext accepts only ascii keys. + return s; + } + // Probably standard layout, try to translate + Messages & m = getMessages(getParLanguage(bparams)->code()); + return m.get(to_ascii(s)); } @@ -1616,18 +1624,17 @@ docstring Paragraph::expandLabel(Layout const & layout, BufferParams const & bparams, bool process_appendix) const { DocumentClass const & tclass = bparams.documentClass(); - string const & lang = getParLanguage(bparams)->code(); docstring fmt; if (process_appendix && d->params_.appendix()) - fmt = lyx::translateIfPossible(layout.labelstring_appendix(), - lang); + fmt = translateIfPossible(layout.labelstring_appendix(), + bparams); else - fmt = lyx::translateIfPossible(layout.labelstring(), lang); + fmt = translateIfPossible(layout.labelstring(), bparams); if (fmt.empty() && layout.labeltype == LABEL_COUNTER && !layout.counter.empty()) - return tclass.counters().theCounter(layout.counter, lang); + return tclass.counters().theCounter(layout.counter); // handle 'inherited level parts' in 'fmt', // i.e. the stuff between '@' in '@Section@.\arabic{subsection}' @@ -1645,7 +1652,7 @@ docstring Paragraph::expandLabel(Layout const & layout, } } - return tclass.counters().counterLabel(fmt, lang); + return tclass.counters().counterLabel(fmt); } diff --git a/src/frontends/qt4/GuiGraphics.cpp b/src/frontends/qt4/GuiGraphics.cpp index 2fcb798671..953f8e1247 100644 --- a/src/frontends/qt4/GuiGraphics.cpp +++ b/src/frontends/qt4/GuiGraphics.cpp @@ -469,6 +469,14 @@ void GuiGraphics::on_angle_textChanged(const QString & filename) (filename != "0")); } +// returns the number of the string s in the vector v +static int itemNumber(const vector & v, string const & s) +{ + vector::const_iterator cit = + find(v.begin(), v.end(), s); + return (cit != v.end()) ? int(cit - v.begin()) : 0; +} + void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) { diff --git a/src/frontends/qt4/Validator.cpp b/src/frontends/qt4/Validator.cpp index 59655eb004..d27f6b301f 100644 --- a/src/frontends/qt4/Validator.cpp +++ b/src/frontends/qt4/Validator.cpp @@ -41,7 +41,7 @@ LengthValidator::LengthValidator(QWidget * parent) QValidator::State LengthValidator::validate(QString & qtext, int &) const { bool ok; - qtext.trimmed().toDouble(&ok); + double d = qtext.trimmed().toDouble(&ok); if (qtext.isEmpty() || ok) return QValidator::Acceptable; diff --git a/src/insets/InsetBibitem.cpp b/src/insets/InsetBibitem.cpp index 008bf9aebe..a679dd6dbd 100644 --- a/src/insets/InsetBibitem.cpp +++ b/src/insets/InsetBibitem.cpp @@ -23,12 +23,10 @@ #include "FuncRequest.h" #include "InsetIterator.h" #include "InsetList.h" -#include "Language.h" #include "Lexer.h" #include "output_xhtml.h" #include "Paragraph.h" #include "ParagraphList.h" -#include "ParIterator.h" #include "TextClass.h" #include "frontends/alert.h" @@ -255,15 +253,13 @@ void InsetBibitem::fillWithBibKeys(BiblioInfo & keys, InsetIterator const & it) // Update the counters of this inset and of its contents -void InsetBibitem::updateLabels(ParIterator const & it) +void InsetBibitem::updateLabels(ParIterator const &) { - BufferParams const & bp = buffer().masterBuffer()->params(); - Counters & counters = bp.documentClass().counters(); + Counters & counters = buffer().masterBuffer()->params().documentClass().counters(); docstring const bibitem = from_ascii("bibitem"); if (counters.hasCounter(bibitem) && getParam("label").empty()) { counters.step(bibitem); - string const & lang = it.paragraph().getParLanguage(bp)->code(); - autolabel_ = counters.theCounter(bibitem, lang); + autolabel_ = counters.theCounter(bibitem); } else { autolabel_ = from_ascii("??"); } diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp index f3dbc5808a..09254d133f 100644 --- a/src/insets/InsetCaption.cpp +++ b/src/insets/InsetCaption.cpp @@ -25,7 +25,6 @@ #include "FuncRequest.h" #include "FuncStatus.h" #include "InsetList.h" -#include "Language.h" #include "MetricsInfo.h" #include "output_latex.h" #include "OutputParams.h" @@ -302,7 +301,6 @@ void InsetCaption::updateLabels(ParIterator const & it) { Buffer const & master = *buffer().masterBuffer(); DocumentClass const & tclass = master.params().documentClass(); - string const & lang = it.paragraph().getParLanguage(master.params())->code(); Counters & cnts = tclass.counters(); string const & type = cnts.current_float(); // Memorize type for addToToc(). @@ -327,7 +325,7 @@ void InsetCaption::updateLabels(ParIterator const & it) cnts.step(counter); full_label_ = bformat(from_ascii("%1$s %2$s:"), name, - cnts.theCounter(counter, lang)); + cnts.theCounter(counter)); } else full_label_ = bformat(from_ascii("%1$s #:"), name); } diff --git a/src/insets/InsetCollapsable.cpp b/src/insets/InsetCollapsable.cpp index 2abe8a7f75..8590cc5c7b 100644 --- a/src/insets/InsetCollapsable.cpp +++ b/src/insets/InsetCollapsable.cpp @@ -970,12 +970,11 @@ docstring InsetCollapsable::xhtml(odocstream & os, OutputParams const & runparam bool const opened = html::openTag(os, il.htmltag(), il.htmlattr()); if (!il.counter().empty()) { - BufferParams const & bp = buffer().masterBuffer()->params(); - Counters & cntrs = bp.documentClass().counters(); + // FIXME Master buffer? + Counters & cntrs = buffer().params().documentClass().counters(); cntrs.step(il.counter()); - // FIXME: translate to paragraph language if (!il.htmllabel().empty()) - os << cntrs.counterLabel(from_utf8(il.htmllabel()), bp.language->code()); + os << cntrs.counterLabel(translateIfPossible(from_ascii(il.htmllabel()))); } bool innertag_opened = false; if (!il.htmlinnertag().empty()) diff --git a/src/insets/InsetFoot.cpp b/src/insets/InsetFoot.cpp index 6c0d9b7924..2b64cc3640 100644 --- a/src/insets/InsetFoot.cpp +++ b/src/insets/InsetFoot.cpp @@ -16,8 +16,9 @@ #include "Buffer.h" #include "BufferParams.h" #include "Counters.h" -#include "Language.h" #include "Layout.h" +// FIXME: the following is needed just to get the layout of the enclosing +// paragraph. This seems a bit too much to me (JMarc) #include "OutputParams.h" #include "ParIterator.h" #include "TextClass.h" @@ -32,7 +33,6 @@ using namespace std; namespace lyx { -using support::bformat; InsetFoot::InsetFoot(Buffer const & buf) : InsetFootlike(buf) @@ -47,16 +47,16 @@ docstring InsetFoot::editMessage() const void InsetFoot::updateLabels(ParIterator const & it) { - BufferParams const & bp = buffer().masterBuffer()->params(); - Counters & cnts = bp.documentClass().counters(); + DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass(); + Counters & cnts = tclass.counters(); docstring const foot = from_ascii("footnote"); Paragraph const & outer = it.paragraph(); if (!outer.layout().intitle && cnts.hasCounter(foot)) { cnts.step(foot); // FIXME: the counter should format itself. - custom_label_= bformat(from_utf8("%1$s %2$s"), - translateIfPossible(getLayout(bp).labelstring()), - cnts.theCounter(foot, outer.getParLanguage(bp)->code())); + custom_label_= support::bformat(from_utf8("%1$s %2$s"), + translateIfPossible(getLayout(buffer().params()).labelstring()), + cnts.theCounter(foot)); setLabel(custom_label_); }