]> git.lyx.org Git - lyx.git/commitdiff
Add ObsoletedBy tag to InsetLayout
authorJuergen Spitzmueller <spitz@lyx.org>
Mon, 8 Dec 2014 08:06:41 +0000 (09:06 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Mon, 8 Dec 2014 08:08:45 +0000 (09:08 +0100)
Fixes: #9000.
lib/doc/Customization.lyx
lib/scripts/layout2layout.py
src/TextClass.cpp
src/insets/InsetFlex.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h

index 96f47300de8f2684ce3cf3881a45003711cc71cd..073ef9ad812935e9795707c6f69196daa3099a40 100644 (file)
@@ -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
+<layout>
+\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
index 10811e73b4c00b71e60eeb858dc14a9532f0b1a0..cf1374463b3e4b516854842c8e6cd4735e0bb7df 100644 (file)
@@ -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
index 113cddb7fd94e2c763379b90b85e7f60061e347f..cc8fb993bbe9de3d86b76f5355a93a835b5607c7 100644 (file)
@@ -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_;
 }
 
index 70de9fd2ebaeef97cbb5ec8b7ce7fe3721eed0cb..44b9b034360b0174bd5a306785c9e117dd4fb466 100644 (file)
@@ -25,6 +25,7 @@
 #include "TextClass.h"
 
 #include "support/gettext.h"
+#include "support/lstrings.h"
 
 #include <ostream>
 
@@ -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);
 }
 
index 4a6d0a822564b339f09882ed7905dccc5021190a..ee415b1b9b6ebbc3ec67af2d95f51d31d228d231 100644 (file)
@@ -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);
index 2ef6be4fdfb30f4a47dde10ebdcb9c7d6dbdf227..cf5647dbc39b1132e8719acbf9573b7f15197b18 100644 (file)
@@ -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_;
        ///