From cfeddb9293bb1e3b45fe2f118a6ce35e37bbebf3 Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Mon, 8 Dec 2014 09:06:41 +0100 Subject: [PATCH] Add ObsoletedBy tag to InsetLayout Fixes: #9000. --- lib/doc/Customization.lyx | 70 ++++++++++++++++++++++++++++++++++++ lib/scripts/layout2layout.py | 7 ++-- src/TextClass.cpp | 13 +++++-- src/insets/InsetFlex.cpp | 17 +++++++-- src/insets/InsetLayout.cpp | 23 ++++++++++++ src/insets/InsetLayout.h | 7 ++++ 6 files changed, 130 insertions(+), 7 deletions(-) diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx index 96f47300de..073ef9ad81 100644 --- a/lib/doc/Customization.lyx +++ b/lib/doc/Customization.lyx @@ -17951,6 +17951,76 @@ InsetLayout \end_inset . +\change_inserted -712698321 1417953494 + +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1417953559 +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1417953494 +ObsoletedBy +\end_layout + +\end_inset + + [ +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1417953574 + +\end_layout + +\end_inset + +] Name of an +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1417953533 +InsetLayout +\end_layout + +\end_inset + + that has replaced this +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1417953551 +InsetLayout +\end_layout + +\end_inset + +. + This is used to rename an +\begin_inset Flex Code +status collapsed + +\begin_layout Plain Layout + +\change_inserted -712698321 1417953559 +InsetLayout +\end_layout + +\end_inset + +, while keeping backward compatibility. +\change_unchanged + \end_layout \begin_layout Description diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 10811e73b4..cf1374463b 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -174,6 +174,9 @@ import os, re, string, sys # Incremented to format 52, 1 December 2014 by spitz # New InsetLayout tag "ForceOwnlines" +# Incremented to format 53, 7 December 2014 by spitz +# New InsetLayout tag "ObsoletedBy" + # Do not forget to document format change in Customization # Manual (section "Declaring a new text class"). @@ -181,7 +184,7 @@ import os, re, string, sys # development/tools/updatelayouts.py script to update all # layout files to the new format. -currentFormat = 52 +currentFormat = 53 def usage(prog_name): @@ -405,7 +408,7 @@ def convert(lines): i += 1 continue - if format == 50 or format == 51: + if format >= 50 and format <= 52: # nothing to do. i += 1 continue diff --git a/src/TextClass.cpp b/src/TextClass.cpp index 113cddb7fd..cc8fb993bb 100644 --- a/src/TextClass.cpp +++ b/src/TextClass.cpp @@ -61,7 +61,7 @@ namespace lyx { // You should also run the development/tools/updatelayouts.py script, // to update the format of all of our layout files. // -int const LAYOUT_FORMAT = 52; //spitz: add ForceOwnlines tag +int const LAYOUT_FORMAT = 53; //spitz: add ObsoletedBy tag for InsetLayouts namespace { @@ -1422,13 +1422,20 @@ InsetLayout const & DocumentClass::insetLayout(docstring const & name) const InsetLayouts::const_iterator cen = insetlayoutlist_.end(); while (!n.empty()) { InsetLayouts::const_iterator cit = insetlayoutlist_.lower_bound(n); - if (cit != cen && cit->first == n) - return cit->second; + if (cit != cen && cit->first == n) { + if (cit->second.obsoleted_by().empty()) + return cit->second; + n = cit->second.obsoleted_by(); + return insetLayout(n); + } + // If we have a generic prefix (e.g., "Note:"), + // try if this one alone is found. size_t i = n.find(':'); if (i == string::npos) break; n = n.substr(0, i); } + // Layout "name" not found. return plain_insetlayout_; } diff --git a/src/insets/InsetFlex.cpp b/src/insets/InsetFlex.cpp index 70de9fd2eb..44b9b03436 100644 --- a/src/insets/InsetFlex.cpp +++ b/src/insets/InsetFlex.cpp @@ -25,6 +25,7 @@ #include "TextClass.h" #include "support/gettext.h" +#include "support/lstrings.h" #include @@ -66,8 +67,20 @@ InsetLayout::InsetDecoration InsetFlex::decoration() const void InsetFlex::write(ostream & os) const { - os << "Flex " << - (name_.empty() ? "undefined" : name_) << "\n"; + os << "Flex "; + InsetLayout const & il = getLayout(); + if (name_.empty()) + os << "undefined"; + else { + // use il.name(), since this resolves obsoleted + // InsetLayout names + string name = to_utf8(il.name()); + // Remove the "Flex:" prefix, if it is present + if (support::prefixIs(name, "Flex:")) + name = support::token(name, ':', 1); + os << name; + } + os << "\n"; InsetCollapsable::write(os); } diff --git a/src/insets/InsetLayout.cpp b/src/insets/InsetLayout.cpp index 4a6d0a8225..ee415b1b9b 100644 --- a/src/insets/InsetLayout.cpp +++ b/src/insets/InsetLayout.cpp @@ -110,6 +110,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) IL_LATEXTYPE, IL_LEFTDELIM, IL_LYXTYPE, + IL_OBSOLETEDBY, IL_KEEPEMPTY, IL_MULTIPAR, IL_NEEDPROTECT, @@ -164,6 +165,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) { "lyxtype", IL_LYXTYPE }, { "multipar", IL_MULTIPAR }, { "needprotect", IL_NEEDPROTECT }, + { "obsoletedby", IL_OBSOLETEDBY }, { "parbreakisnewline", IL_PARBREAKISNEWLINE }, { "passthru", IL_PASSTHRU }, { "preamble", IL_PREAMBLE }, @@ -330,6 +332,27 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass) } break; } + case IL_OBSOLETEDBY: { + docstring style; + lex >> style; + style = support::subst(style, '_', ' '); + + // We don't want to apply the algorithm in DocumentClass::insetLayout() + // here. So we do it the long way. + TextClass::InsetLayouts::const_iterator it = + tclass.insetLayouts().find(style); + if (it != tclass.insetLayouts().end()) { + docstring const tmpname = name_; + this->operator=(it->second); + name_ = tmpname; + if (obsoleted_by().empty()) + obsoleted_by_ = style; + } else { + LYXERR0("Cannot replace with unknown InsetLayout `" + << style << '\''); + } + break; + } case IL_FONT: { font_ = lyxRead(lex, inherit_font); diff --git a/src/insets/InsetLayout.h b/src/insets/InsetLayout.h index 2ef6be4fdf..cf5647dbc3 100644 --- a/src/insets/InsetLayout.h +++ b/src/insets/InsetLayout.h @@ -175,6 +175,8 @@ public: bool isDisplay() const { return display_; } /// bool forcelocalfontswitch() const { return forcelocalfontswitch_; } + /// + docstring const & obsoleted_by() const { return obsoleted_by_; } private: /// void makeDefaultCSS() const; @@ -277,6 +279,11 @@ private: bool display_; /// bool forcelocalfontswitch_; + /** Name of an insetlayout that has replaced this insetlayout. + This is used to rename an insetlayout, while keeping backward + compatibility + */ + docstring obsoleted_by_; /// Layout::LaTeXArgMap latexargs_; ///