Add CopyStyle tag for InsetLayout, per request of Steve Litt.

Update documentation for new tag.



git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@25933 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2008-07-28 15:14:37 +00:00
parent 0b86ea9f71
commit 5d95df6e39
6 changed files with 72 additions and 8 deletions

View File

@ -1,5 +1,5 @@
#LyX 1.6.0svn created this file. For more info see http://www.lyx.org/ #LyX 1.6.0svn created this file. For more info see http://www.lyx.org/
\lyxformat 338 \lyxformat 339
\begin_document \begin_document
\begin_header \begin_header
\textclass scrbook \textclass scrbook
@ -9518,6 +9518,13 @@ CopyStyle
\end_inset \end_inset
\begin_inset CommandInset label
LatexCommand label
name "des:CopyStyle"
\end_inset
\begin_inset Flex CharStyle:Code \begin_inset Flex CharStyle:Code
status collapsed status collapsed
@ -12922,6 +12929,26 @@ src/ColorCode.h
\begin_inset Flex CharStyle:Code \begin_inset Flex CharStyle:Code
status collapsed status collapsed
\begin_layout Plain Layout
CopyStyle
\end_layout
\end_inset
As with paragraph styles (see page
\begin_inset CommandInset ref
LatexCommand ref
reference "des:CopyStyle"
\end_inset
).
\end_layout
\begin_layout Description
\begin_inset Flex CharStyle:Code
status collapsed
\begin_layout Plain Layout \begin_layout Plain Layout
Decoration Decoration
\end_layout \end_layout

View File

@ -28,6 +28,7 @@ import os, re, string, sys
# Incremented to format 8, 25 July 2008 by rgh # Incremented to format 8, 25 July 2008 by rgh
# UseModule tag added to layout files # UseModule tag added to layout files
# CopyStyle added to InsetLayout
currentFormat = 8 currentFormat = 8
@ -171,6 +172,10 @@ def convert(lines):
i += 1 i += 1
continue continue
if format == 7:
i += 1
continue
if format == 6: if format == 6:
i += 1 i += 1
continue continue

View File

@ -513,7 +513,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
case TC_INSETLAYOUT: case TC_INSETLAYOUT:
if (lexrc.next()) { if (lexrc.next()) {
InsetLayout il; InsetLayout il;
if (il.read(lexrc)) if (il.read(lexrc, *this))
insetlayoutlist_[il.name()] = il; insetlayoutlist_[il.name()] = il;
// else there was an error, so forget it // else there was an error, so forget it
} }

View File

@ -135,6 +135,8 @@ public:
bool hasLayout(docstring const & name) const; bool hasLayout(docstring const & name) const;
/// ///
Layout const & operator[](docstring const & vname) const; Layout const & operator[](docstring const & vname) const;
/// Inset layouts of this doc class
InsetLayouts const & insetLayouts() const { return insetlayoutlist_; };
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
// reading routines // reading routines
@ -330,8 +332,6 @@ public:
bool hasLaTeXLayout(std::string const & lay) const; bool hasLaTeXLayout(std::string const & lay) const;
/// A DocumentClass nevers count as loaded, since it is dynamic /// A DocumentClass nevers count as loaded, since it is dynamic
virtual bool loaded() { return false; } virtual bool loaded() { return false; }
/// Inset layouts of this doc class
InsetLayouts const & insetLayouts() const { return insetlayoutlist_; };
/// \return the layout object of an inset given by name. If the name /// \return the layout object of an inset given by name. If the name
/// is not found as such, the part after the ':' is stripped off, and /// is not found as such, the part after the ':' is stripped off, and
/// searched again. In this way, an error fallback can be provided: /// searched again. In this way, an error fallback can be provided:

View File

@ -17,7 +17,9 @@
#include "Color.h" #include "Color.h"
#include "Font.h" #include "Font.h"
#include "Lexer.h" #include "Lexer.h"
#include "TextClass.h"
#include "support/debug.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include <vector> #include <vector>
@ -55,16 +57,17 @@ InsetLayout::InsetDecoration translateDecoration(std::string const & str)
} }
bool InsetLayout::read(Lexer & lex) bool InsetLayout::read(Lexer & lex, TextClass & tclass)
{ {
name_ = support::subst(lex.getDocString(), '_', ' '); name_ = support::subst(lex.getDocString(), '_', ' ');
enum { enum {
IL_FONT,
IL_BGCOLOR, IL_BGCOLOR,
IL_COPYSTYLE,
IL_DECORATION, IL_DECORATION,
IL_FREESPACING, IL_FONT,
IL_FORCELTR, IL_FORCELTR,
IL_FREESPACING,
IL_LABELFONT, IL_LABELFONT,
IL_LABELSTRING, IL_LABELSTRING,
IL_LATEXNAME, IL_LATEXNAME,
@ -83,6 +86,7 @@ bool InsetLayout::read(Lexer & lex)
LexerKeyword elementTags[] = { LexerKeyword elementTags[] = {
{ "bgcolor", IL_BGCOLOR }, { "bgcolor", IL_BGCOLOR },
{ "copystyle", IL_COPYSTYLE},
{ "decoration", IL_DECORATION }, { "decoration", IL_DECORATION },
{ "end", IL_END }, { "end", IL_END },
{ "font", IL_FONT }, { "font", IL_FONT },
@ -161,6 +165,33 @@ bool InsetLayout::read(Lexer & lex)
case IL_NEEDPROTECT: case IL_NEEDPROTECT:
lex >> needprotect_; lex >> needprotect_;
break; break;
case IL_COPYSTYLE: { // initialize with a known style
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;
} else {
LYXERR0("Cannot copy unknown InsetLayout `"
<< style << "'\n"
<< "All InsetLayouts so far:");
TextClass::InsetLayouts::const_iterator lit =
tclass.insetLayouts().begin();
TextClass::InsetLayouts::const_iterator len =
tclass.insetLayouts().end();
for (; lit != len; ++lit)
lyxerr << lit->second.name() << "\n";
}
break;
}
case IL_FONT: { case IL_FONT: {
font_ = lyxRead(lex, inherit_font); font_ = lyxRead(lex, inherit_font);
// If you want to define labelfont, you need to do so after // If you want to define labelfont, you need to do so after

View File

@ -24,6 +24,7 @@
namespace lyx { namespace lyx {
class Lexer; class Lexer;
class TextClass;
/// ///
class InsetLayout { class InsetLayout {
@ -38,7 +39,7 @@ public:
Default Default
}; };
/// ///
bool read(Lexer & lexrc); bool read(Lexer & lexrc, TextClass & tclass);
/// ///
docstring name() const { return name_; }; docstring name() const { return name_; };
/// ///