From: Richard Heck Date: Wed, 20 Jan 2010 20:33:36 +0000 (+0000) Subject: Introduce a "formatted counter" for use with formatted reference during X-Git-Tag: 2.0.0~4309 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=c2ac70552ccb4e5c05130d0071ba513d2e3b3d94;p=features.git Introduce a "formatted counter" for use with formatted reference during XHTML output. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@33113 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index a6abc7eebf..2ab34031c0 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -77,6 +77,9 @@ import os, re, string, sys # Incremented to format 21, 12 January 2010 by rgh # Added HTMLTocLayout and HTMLTitle tags. + +# Incremented to format 22, 20 January 2010 by rgh +# Added HTMLFormat tag to Counters. # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). @@ -85,7 +88,7 @@ import os, re, string, sys # development/tools/updatelayouts.sh script to update all # layout files to the new format. -currentFormat = 21 +currentFormat = 22 def usage(prog_name): @@ -254,7 +257,7 @@ def convert(lines): continue # This just involved new features, not any changes to old ones - if format >= 14 and format <= 20: + if format >= 14 and format <= 21: i += 1 continue diff --git a/po/lyx_pot.py b/po/lyx_pot.py index 275d4f70b2..a9fa753018 100755 --- a/po/lyx_pot.py +++ b/po/lyx_pot.py @@ -77,7 +77,7 @@ def ui_l10n(input_files, output, base): def layouts_l10n(input_files, output, base): '''Generate pot file from lib/layouts/*.{layout,inc,module}''' out = open(output, 'w') - Style = re.compile(r'^Style\s+(.*)') + Style = re.compile(r'^Style\s+(.*)', re.IGNORECASE) # include ???LabelString???, but exclude comment lines LabelString = re.compile(r'^[^#]*LabelString\S*\s+(.*)') GuiName = re.compile(r'\s*GuiName\s+(.*)') @@ -91,6 +91,7 @@ def layouts_l10n(input_files, output, base): I18nPreamble = re.compile(r'\s*(Lang)|(Babel)Preamble\s*$') EndI18nPreamble = re.compile(r'\s*End(Lang)|(Babel)Preamble\s*$') I18nString = re.compile(r'_\(([^\)]+)\)') + CounterFormat = re.compile(r'\s*PrettyFormat\s+(.*)') for src in input_files: readingDescription = False @@ -173,6 +174,11 @@ def layouts_l10n(input_files, output, base): string = res.group(1) writeString(out, src, base, lineno, string) continue + res = CounterFormat.search(line) + if res != None: + string = res.group(1) + writeString(out, src, base, lineno, string) + continue out.close() diff --git a/src/Counters.cpp b/src/Counters.cpp index 626596a833..c06e9a7f9f 100644 --- a/src/Counters.cpp +++ b/src/Counters.cpp @@ -52,6 +52,7 @@ bool Counter::read(Lexer & lex) CT_WITHIN = 1, CT_LABELSTRING, CT_LABELSTRING_APPENDIX, + CT_PRETTYFORMAT, CT_END }; @@ -59,6 +60,7 @@ bool Counter::read(Lexer & lex) { "end", CT_END }, { "labelstring", CT_LABELSTRING }, { "labelstringappendix", CT_LABELSTRING_APPENDIX }, + { "prettyformat", CT_PRETTYFORMAT }, { "within", CT_WITHIN } }; @@ -81,6 +83,10 @@ bool Counter::read(Lexer & lex) if (master_ == "none") master_.erase(); break; + case CT_PRETTYFORMAT: + lex.next(); + prettyformat_ = lex.getDocString(); + break; case CT_LABELSTRING: lex.next(); labelstring_ = lex.getDocString(); @@ -539,6 +545,22 @@ docstring Counters::counterLabel(docstring const & format, } +docstring Counters::prettyCounter(docstring const & counter, + string const & lang) const +{ + CounterList::const_iterator it = counterList_.find(counter); + if (it == counterList_.end()) + return from_ascii("??"); + Counter const & ctr = it->second; + docstring const & format = ctr.prettyFormat(); + if (format.empty()) { + docstring cntrname = translateIfPossible(counter, lang); + return cntrname + " " + theCounter(counter, lang); + } + return counterLabel(format, lang); +} + + docstring Counters::currentCounter() const { LASSERT(!counter_stack_.empty(), /* */); diff --git a/src/Counters.h b/src/Counters.h index 3384e564c6..d992bbb3c6 100644 --- a/src/Counters.h +++ b/src/Counters.h @@ -57,6 +57,10 @@ public: * want the version shown in an appendix. */ docstring const & labelString(bool in_appendix) const; + /// 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_; } + /// 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 @@ -79,6 +83,8 @@ private: docstring labelstring_; /// The same as labelstring_, but in appendices. docstring labelstringappendix_; + /// Similar, but used for formatted references in XHTML output + docstring prettyformat_; /// Cache of the labelstring with \\the expressions expanded, /// indexed by language mutable StringMap flatlabelstring_; @@ -138,6 +144,10 @@ public: */ docstring counterLabel(docstring const & format, std::string const & lang) const; + /// returns a formatted version of the counter, using the + /// format given by Counter::prettyFormat(). + docstring prettyCounter(docstring const & cntr, + std::string const & lang) const; /// Are we in appendix? bool appendix() const { return appendix_; } /// Set the state variable indicating whether we are in appendix. diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 7f7b694595..981dcd185c 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -66,7 +66,7 @@ private: }; // Keep the changes documented in the Customization manual. -int const FORMAT = 21; +int const FORMAT = 22; bool layout2layout(FileName const & filename, FileName const & tempfile) diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index edcf5ec742..fd196cfd77 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -125,10 +125,13 @@ void InsetLabel::updateLabels(ParIterator const & par, UpdateType utype) buffer().masterBuffer()->params().documentClass().counters(); active_counter_ = cnts.currentCounter(); Language const * lang = par->getParLanguage(buffer().params()); - if (lang && !active_counter_.empty()) + if (lang && !active_counter_.empty()) { counter_value_ = cnts.theCounter(active_counter_, lang->code()); - else - counter_value_ = _("(unknown)"); + pretty_counter_ = cnts.prettyCounter(active_counter_, lang->code()); + } else { + counter_value_ = from_ascii("??"); + pretty_counter_ = from_ascii("??"); + } } } diff --git a/src/insets/InsetLabel.h b/src/insets/InsetLabel.h index 1ad8da9b16..ab78761b96 100644 --- a/src/insets/InsetLabel.h +++ b/src/insets/InsetLabel.h @@ -66,6 +66,8 @@ public: docstring const & activeCounter() const { return active_counter_; } /// docstring const & counterValue() const { return counter_value_; } + /// + docstring const & prettyCounter() const { return pretty_counter_; } protected: /// void doDispatch(Cursor & cur, FuncRequest & cmd); @@ -78,6 +80,8 @@ private: docstring active_counter_; /// docstring counter_value_; + /// + docstring pretty_counter_; }; diff --git a/src/insets/InsetRef.cpp b/src/insets/InsetRef.cpp index f292caf32e..30217df713 100644 --- a/src/insets/InsetRef.cpp +++ b/src/insets/InsetRef.cpp @@ -126,20 +126,19 @@ docstring InsetRef::xhtml(XHTMLStream & xs, OutputParams const &) const if (il && !il->counterValue().empty()) { // Try to construct a label from the InsetLabel we reference. - docstring const & cntr = il->activeCounter(); docstring const & value = il->counterValue(); if (cmd == "ref") display_string = value; else if (cmd == "vref") - display_string = bformat(from_ascii("%1$s on page ##"), value); + // normally, would be "ref on page #", but we have no pages + display_string = value; else if (cmd == "pageref" || cmd == "vpageref") - display_string = _("on page ##"); + // normally would be "on page #", but we have no pages + display_string = _("elsewhere"); else if (cmd == "eqref") display_string = bformat(from_ascii("equation (%1$s)"), value); else { // "prettyref" - docstring cntrname = translateIfPossible(cntr); - // FIXME Use the label string, if we have it. Otherwise, do this. - display_string = bformat(from_ascii("%1$s %2$s"), cntrname, value); + display_string = il->prettyCounter(); } } else display_string = ref;