revert r30515: too many files there

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30516 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2009-07-12 17:30:56 +00:00
parent 834bfe5e21
commit c355edfb6d
11 changed files with 93 additions and 91 deletions

View File

@ -26,7 +26,7 @@ fi
AM_MAINTAINER_MODE AM_MAINTAINER_MODE
save_PACKAGE=$PACKAGE 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 PACKAGE=$save_PACKAGE
### Set the execute permissions of the various scripts correctly ### Set the execute permissions of the various scripts correctly

View File

@ -3389,8 +3389,7 @@ static void setLabel(Buffer const & buf, ParIterator & it)
counters.reset(enumcounter); counters.reset(enumcounter);
counters.step(enumcounter); counters.step(enumcounter);
string const & lang = par.getParLanguage(bp)->code(); par.params().labelString(counters.theCounter(enumcounter));
par.params().labelString(counters.theCounter(enumcounter, lang));
break; break;
} }
@ -3403,11 +3402,10 @@ static void setLabel(Buffer const & buf, ParIterator & it)
else { else {
docstring name = buf.B_(textclass.floats().getType(type).name()); docstring name = buf.B_(textclass.floats().getType(type).name());
if (counters.hasCounter(from_utf8(type))) { if (counters.hasCounter(from_utf8(type))) {
string const & lang = par.getParLanguage(bp)->code();
counters.step(from_utf8(type)); counters.step(from_utf8(type));
full_label = bformat(from_ascii("%1$s %2$s:"), full_label = bformat(from_ascii("%1$s %2$s:"),
name, name,
counters.theCounter(from_utf8(type), lang)); counters.theCounter(from_utf8(type)));
} else } else
full_label = bformat(from_ascii("%1$s #:"), name); full_label = bformat(from_ascii("%1$s #:"), name);
} }

View File

@ -18,7 +18,6 @@
#include "support/convert.h" #include "support/convert.h"
#include "support/debug.h" #include "support/debug.h"
#include "support/gettext.h"
#include "support/lassert.h" #include "support/lassert.h"
#include "support/lstrings.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_; return in_appendix ? flatlabelstringappendix_ : flatlabelstring_;
} }
void Counter::setFlatLabelStrings(docstring const & fls, docstring const & flsa)
{
flatlabelstring_ = fls;
flatlabelstringappendix_ = flsa;
}
void Counters::newCounter(docstring const & newc, void Counters::newCounter(docstring const & newc,
docstring const & masterc, docstring const & masterc,
docstring const & ls, docstring const & ls,
@ -249,6 +255,20 @@ void Counters::reset()
appendix_ = false; appendix_ = false;
subfloat_ = false; subfloat_ = false;
current_float_.erase(); current_float_.erase();
CounterList::iterator it = counterList_.begin();
CounterList::iterator const end = counterList_.end();
std::vector<docstring> 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, docstring Counters::theCounter(docstring const & counter) const
string const & lang) const
{ {
CounterList::const_iterator it = counterList_.find(counter); CounterList::const_iterator it = counterList_.find(counter);
if (it == counterList_.end()) if (it == counterList_.end())
return from_ascii("??"); return from_ascii("??");
Counter const & ctr = it->second; // FIXME: this should get translated.
Counter::StringMap sm = ctr.flatLabelStrings(appendix()); return counterLabel(it->second.flatLabelString(appendix()));
Counter::StringMap::iterator smit = sm.find(lang);
if (smit != sm.end())
return counterLabel(smit->second, lang);
vector<docstring> callers;
docstring const & fls = flattenLabelString(counter, appendix(),
lang, callers);
sm[lang] = fls;
return counterLabel(fls, lang);
} }
docstring Counters::flattenLabelString(docstring const & counter, docstring Counters::flattenLabelString(docstring const & counter,
bool in_appendix, bool in_appendix,
string const & lang,
vector<docstring> & callers) const vector<docstring> & callers) const
{ {
docstring label; docstring label;
@ -450,12 +459,12 @@ docstring Counters::flattenLabelString(docstring const & counter,
return from_ascii("??"); return from_ascii("??");
Counter const & c = it->second; Counter const & c = it->second;
docstring ls = translateIfPossible(c.labelString(in_appendix), lang); docstring ls = c.labelString(in_appendix);
callers.push_back(counter); callers.push_back(counter);
if (ls.empty()) { if (ls.empty()) {
if (!c.master().empty()) if (!c.master().empty())
ls = flattenLabelString(c.master(), in_appendix, lang, callers) ls = flattenLabelString(c.master(), in_appendix, callers)
+ from_ascii("."); + from_ascii(".");
callers.pop_back(); callers.pop_back();
return ls + from_ascii("\\arabic{") + counter + "}"; return ls + from_ascii("\\arabic{") + counter + "}";
@ -472,8 +481,7 @@ docstring Counters::flattenLabelString(docstring const & counter,
&& lowercase(ls[k]) <= 'z') && lowercase(ls[k]) <= 'z')
++k; ++k;
docstring const newc = ls.substr(j, k - j); docstring const newc = ls.substr(j, k - j);
docstring const repl = flattenLabelString(newc, in_appendix, docstring const repl = flattenLabelString(newc, in_appendix, callers);
lang, callers);
ls.replace(i, k - j + 4, repl); ls.replace(i, k - j + 4, repl);
} }
callers.pop_back(); callers.pop_back();
@ -482,8 +490,7 @@ docstring Counters::flattenLabelString(docstring const & counter,
} }
docstring Counters::counterLabel(docstring const & format, docstring Counters::counterLabel(docstring const & format) const
string const & lang) const
{ {
docstring label = format; docstring label = format;
@ -500,7 +507,7 @@ docstring Counters::counterLabel(docstring const & format,
&& lowercase(label[k]) <= 'z') && lowercase(label[k]) <= 'z')
++k; ++k;
docstring const newc = label.substr(j, k - j); 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); label.replace(i, k - j + 4, repl);
} }
while (true) { while (true) {

View File

@ -49,19 +49,19 @@ public:
docstring const & master() const; docstring const & master() const;
/// Returns a LaTeX-like string to format the counter. /// Returns a LaTeX-like string to format the counter.
/** This is similar to what one gets in LaTeX when using /** This is similar to what one gets in LaTeX when using
* "\the<counter>". The \c in_appendix bool tells whether we * "\the<counter>". The \c in_appendix bool tells whether
* want the version shown in an appendix. * we want the version shown in an appendix.
*/ */
docstring const & labelString(bool in_appendix) const; docstring const & labelString(bool in_appendix) const;
/// Returns a map of LaTeX-like strings to format the counter. /// Returns a LaTeX-like string to format the counter.
/** For each language, the string is similar to what one gets /** This is similar to what one gets in LaTeX when using
* in LaTeX when using "\the<counter>". The \c in_appendix * "\the<counter>". The \c in_appendix bool tells whether
* bool tells whether we want the version shown in an * we want the version shown in an appendix. This version does
* appendix. This version does not contain any \\the<counter> * not contain any \\the<counter> expression.
* expression.
*/ */
typedef std::map<std::string, docstring> StringMap; docstring const & flatLabelString(bool in_appendix) const;
StringMap & flatLabelStrings(bool in_appendix) const; /// set the \c flatLabelString values.
void setFlatLabelStrings(docstring const & fls, docstring const & flsa);
private: private:
/// ///
int value_; int value_;
@ -75,12 +75,10 @@ private:
docstring labelstring_; docstring labelstring_;
/// The same as labelstring_, but in appendices. /// The same as labelstring_, but in appendices.
docstring labelstringappendix_; docstring labelstringappendix_;
/// Cache of the labelstring with \\the<counter> expressions expanded, /// A version of the labelstring with \\the<counter> expressions expanded
/// indexed by language docstring flatlabelstring_;
mutable StringMap flatlabelstring_; /// A version of the appendix labelstring with \\the<counter> expressions expanded
/// Cache of the appendix labelstring with \\the<counter> expressions expanded, docstring flatlabelstringappendix_;
/// indexed by language
mutable StringMap flatlabelstringappendix_;
}; };
@ -121,17 +119,11 @@ public:
/// the &to array of counters. Empty string matches all. /// the &to array of counters. Empty string matches all.
void copy(Counters & from, Counters & to, void copy(Counters & from, Counters & to,
docstring const & match = docstring()); docstring const & match = docstring());
/** returns the expanded string representation of counter \c /// returns the expanded string representation of the counter.
* c. The \c lang code is used to translate the string. docstring theCounter(docstring const & c) const;
*/ /// Replace in \c format all the LaTeX-like macros that depend on
docstring theCounter(docstring const & c, /// counters.
std::string const & lang) const; docstring counterLabel(docstring const & format) 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;
/// Are we in appendix? /// Are we in appendix?
bool appendix() const { return appendix_; }; bool appendix() const { return appendix_; };
/// Set the state variable indicating whether we are in 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. /// Set the state variable indicating whether we are in a subfloat.
void isSubfloat(bool s) { subfloat_ = s; }; void isSubfloat(bool s) { subfloat_ = s; };
private: private:
/** expands recusrsively any \\the<counter> macro in the /// expands recusrsively any \\the<counter> macro in the
* labelstring of \c counter. The \c lang code is used to /// labelstring of \c counter.
* translate the string.
*/
docstring flattenLabelString(docstring const & counter, bool in_appendix, docstring flattenLabelString(docstring const & counter, bool in_appendix,
std::string const &lang,
std::vector<docstring> & callers) const; std::vector<docstring> & callers) const;
/// Returns the value of the counter according to the /// Returns the value of the counter according to the
/// numbering scheme numbertype. /// numbering scheme numbertype.

View File

@ -58,6 +58,7 @@
#include "support/gettext.h" #include "support/gettext.h"
#include "support/lassert.h" #include "support/lassert.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/Messages.h"
#include "support/textutils.h" #include "support/textutils.h"
#include <sstream> #include <sstream>
@ -1608,7 +1609,14 @@ void Paragraph::setLabelWidthString(docstring const & s)
docstring const Paragraph::translateIfPossible(docstring const & s, docstring const Paragraph::translateIfPossible(docstring const & s,
BufferParams const & bparams) const 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 BufferParams const & bparams, bool process_appendix) const
{ {
DocumentClass const & tclass = bparams.documentClass(); DocumentClass const & tclass = bparams.documentClass();
string const & lang = getParLanguage(bparams)->code();
docstring fmt; docstring fmt;
if (process_appendix && d->params_.appendix()) if (process_appendix && d->params_.appendix())
fmt = lyx::translateIfPossible(layout.labelstring_appendix(), fmt = translateIfPossible(layout.labelstring_appendix(),
lang); bparams);
else else
fmt = lyx::translateIfPossible(layout.labelstring(), lang); fmt = translateIfPossible(layout.labelstring(), bparams);
if (fmt.empty() && layout.labeltype == LABEL_COUNTER if (fmt.empty() && layout.labeltype == LABEL_COUNTER
&& !layout.counter.empty()) && !layout.counter.empty())
return tclass.counters().theCounter(layout.counter, lang); return tclass.counters().theCounter(layout.counter);
// handle 'inherited level parts' in 'fmt', // handle 'inherited level parts' in 'fmt',
// i.e. the stuff between '@' in '@Section@.\arabic{subsection}' // 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);
} }

View File

@ -469,6 +469,14 @@ void GuiGraphics::on_angle_textChanged(const QString & filename)
(filename != "0")); (filename != "0"));
} }
// returns the number of the string s in the vector v
static int itemNumber(const vector<string> & v, string const & s)
{
vector<string>::const_iterator cit =
find(v.begin(), v.end(), s);
return (cit != v.end()) ? int(cit - v.begin()) : 0;
}
void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp) void GuiGraphics::paramsToDialog(InsetGraphicsParams const & igp)
{ {

View File

@ -41,7 +41,7 @@ LengthValidator::LengthValidator(QWidget * parent)
QValidator::State LengthValidator::validate(QString & qtext, int &) const QValidator::State LengthValidator::validate(QString & qtext, int &) const
{ {
bool ok; bool ok;
qtext.trimmed().toDouble(&ok); double d = qtext.trimmed().toDouble(&ok);
if (qtext.isEmpty() || ok) if (qtext.isEmpty() || ok)
return QValidator::Acceptable; return QValidator::Acceptable;

View File

@ -23,12 +23,10 @@
#include "FuncRequest.h" #include "FuncRequest.h"
#include "InsetIterator.h" #include "InsetIterator.h"
#include "InsetList.h" #include "InsetList.h"
#include "Language.h"
#include "Lexer.h" #include "Lexer.h"
#include "output_xhtml.h" #include "output_xhtml.h"
#include "Paragraph.h" #include "Paragraph.h"
#include "ParagraphList.h" #include "ParagraphList.h"
#include "ParIterator.h"
#include "TextClass.h" #include "TextClass.h"
#include "frontends/alert.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 // 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 = buffer().masterBuffer()->params().documentClass().counters();
Counters & counters = bp.documentClass().counters();
docstring const bibitem = from_ascii("bibitem"); docstring const bibitem = from_ascii("bibitem");
if (counters.hasCounter(bibitem) && getParam("label").empty()) { if (counters.hasCounter(bibitem) && getParam("label").empty()) {
counters.step(bibitem); counters.step(bibitem);
string const & lang = it.paragraph().getParLanguage(bp)->code(); autolabel_ = counters.theCounter(bibitem);
autolabel_ = counters.theCounter(bibitem, lang);
} else { } else {
autolabel_ = from_ascii("??"); autolabel_ = from_ascii("??");
} }

View File

@ -25,7 +25,6 @@
#include "FuncRequest.h" #include "FuncRequest.h"
#include "FuncStatus.h" #include "FuncStatus.h"
#include "InsetList.h" #include "InsetList.h"
#include "Language.h"
#include "MetricsInfo.h" #include "MetricsInfo.h"
#include "output_latex.h" #include "output_latex.h"
#include "OutputParams.h" #include "OutputParams.h"
@ -302,7 +301,6 @@ void InsetCaption::updateLabels(ParIterator const & it)
{ {
Buffer const & master = *buffer().masterBuffer(); Buffer const & master = *buffer().masterBuffer();
DocumentClass const & tclass = master.params().documentClass(); DocumentClass const & tclass = master.params().documentClass();
string const & lang = it.paragraph().getParLanguage(master.params())->code();
Counters & cnts = tclass.counters(); Counters & cnts = tclass.counters();
string const & type = cnts.current_float(); string const & type = cnts.current_float();
// Memorize type for addToToc(). // Memorize type for addToToc().
@ -327,7 +325,7 @@ void InsetCaption::updateLabels(ParIterator const & it)
cnts.step(counter); cnts.step(counter);
full_label_ = bformat(from_ascii("%1$s %2$s:"), full_label_ = bformat(from_ascii("%1$s %2$s:"),
name, name,
cnts.theCounter(counter, lang)); cnts.theCounter(counter));
} else } else
full_label_ = bformat(from_ascii("%1$s #:"), name); full_label_ = bformat(from_ascii("%1$s #:"), name);
} }

View File

@ -970,12 +970,11 @@ docstring InsetCollapsable::xhtml(odocstream & os, OutputParams const & runparam
bool const opened = html::openTag(os, il.htmltag(), il.htmlattr()); bool const opened = html::openTag(os, il.htmltag(), il.htmlattr());
if (!il.counter().empty()) { if (!il.counter().empty()) {
BufferParams const & bp = buffer().masterBuffer()->params(); // FIXME Master buffer?
Counters & cntrs = bp.documentClass().counters(); Counters & cntrs = buffer().params().documentClass().counters();
cntrs.step(il.counter()); cntrs.step(il.counter());
// FIXME: translate to paragraph language
if (!il.htmllabel().empty()) 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; bool innertag_opened = false;
if (!il.htmlinnertag().empty()) if (!il.htmlinnertag().empty())

View File

@ -16,8 +16,9 @@
#include "Buffer.h" #include "Buffer.h"
#include "BufferParams.h" #include "BufferParams.h"
#include "Counters.h" #include "Counters.h"
#include "Language.h"
#include "Layout.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 "OutputParams.h"
#include "ParIterator.h" #include "ParIterator.h"
#include "TextClass.h" #include "TextClass.h"
@ -32,7 +33,6 @@ using namespace std;
namespace lyx { namespace lyx {
using support::bformat;
InsetFoot::InsetFoot(Buffer const & buf) InsetFoot::InsetFoot(Buffer const & buf)
: InsetFootlike(buf) : InsetFootlike(buf)
@ -47,16 +47,16 @@ docstring InsetFoot::editMessage() const
void InsetFoot::updateLabels(ParIterator const & it) void InsetFoot::updateLabels(ParIterator const & it)
{ {
BufferParams const & bp = buffer().masterBuffer()->params(); DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
Counters & cnts = bp.documentClass().counters(); Counters & cnts = tclass.counters();
docstring const foot = from_ascii("footnote"); docstring const foot = from_ascii("footnote");
Paragraph const & outer = it.paragraph(); Paragraph const & outer = it.paragraph();
if (!outer.layout().intitle && cnts.hasCounter(foot)) { if (!outer.layout().intitle && cnts.hasCounter(foot)) {
cnts.step(foot); cnts.step(foot);
// FIXME: the counter should format itself. // FIXME: the counter should format itself.
custom_label_= bformat(from_utf8("%1$s %2$s"), custom_label_= support::bformat(from_utf8("%1$s %2$s"),
translateIfPossible(getLayout(bp).labelstring()), translateIfPossible(getLayout(buffer().params()).labelstring()),
cnts.theCounter(foot, outer.getParLanguage(bp)->code())); cnts.theCounter(foot));
setLabel(custom_label_); setLabel(custom_label_);
} }