mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
Implement auto-nesting.
Now layouts can specify other layouts that should be nested in and after the current one (if the layout is switched from the current one and if it follows a paragraph in the current one). This is particularly useful for things such as the beamer frames, where particular layouts are practically always nested.
This commit is contained in:
parent
87a6c75d9d
commit
99ecc6e2c9
@ -124,11 +124,12 @@ logicalmkup
|
|||||||
\papercolumns 1
|
\papercolumns 1
|
||||||
\papersides 2
|
\papersides 2
|
||||||
\paperpagestyle headings
|
\paperpagestyle headings
|
||||||
\tracking_changes false
|
\tracking_changes true
|
||||||
\output_changes false
|
\output_changes false
|
||||||
\html_math_output 0
|
\html_math_output 0
|
||||||
\html_css_as_file 0
|
\html_css_as_file 0
|
||||||
\html_be_strict true
|
\html_be_strict true
|
||||||
|
\author -712698321 "Jürgen Spitzmüller"
|
||||||
\end_header
|
\end_header
|
||||||
|
|
||||||
\begin_body
|
\begin_body
|
||||||
@ -14616,6 +14617,49 @@ protect
|
|||||||
not
|
not
|
||||||
\emph default
|
\emph default
|
||||||
whether this command should itself be protected.)
|
whether this command should itself be protected.)
|
||||||
|
\change_inserted -712698321 1514479340
|
||||||
|
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Description
|
||||||
|
|
||||||
|
\change_inserted -712698321 1514479340
|
||||||
|
\begin_inset Flex Code
|
||||||
|
status collapsed
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
\change_inserted -712698321 1514479340
|
||||||
|
Nests
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
Includes a comma-separated list of layout names that should be nested in
|
||||||
|
and after the current one.
|
||||||
|
Only makes sense for nestable layouts (such as environments)
|
||||||
|
\begin_inset Quotes eld
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Flex Code
|
||||||
|
status collapsed
|
||||||
|
|
||||||
|
\begin_layout Plain Layout
|
||||||
|
|
||||||
|
\change_inserted -712698321 1514479340
|
||||||
|
EndNests
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset Quotes erd
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
.
|
||||||
|
\change_unchanged
|
||||||
|
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Description
|
\begin_layout Description
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# Richard Heck <rgheck@lyx.org>, Martin Vermeer <martin.vermeer@hut.fi> and probably others.
|
# Richard Heck <rgheck@lyx.org>, Martin Vermeer <martin.vermeer@hut.fi> and probably others.
|
||||||
|
|
||||||
|
|
||||||
Format 65
|
Format 66
|
||||||
|
|
||||||
#
|
#
|
||||||
# GLOBAL SETTINGS
|
# GLOBAL SETTINGS
|
||||||
@ -482,6 +482,12 @@ Style Frame
|
|||||||
EndFont
|
EndFont
|
||||||
AutoInsert 1
|
AutoInsert 1
|
||||||
EndArgument
|
EndArgument
|
||||||
|
Nests
|
||||||
|
Standard,Itemize,Enumerate,Description,FrameTitle,FrameSubtitle,Column,
|
||||||
|
Columns,ColumnsCenterAligned,ColumnsTopAligned,Pause,Overprint,OverlayArea,Only,Block,
|
||||||
|
ExampleBlock,AlertBlock,Bibliography,Quotation,Quote,Verse,Corollary,Definition,Definitions,
|
||||||
|
Example,Examples,Fact,Lemma,Proof,Theorem,LyX-Code
|
||||||
|
EndNests
|
||||||
End
|
End
|
||||||
|
|
||||||
Style PlainFrame
|
Style PlainFrame
|
||||||
@ -665,6 +671,11 @@ Style Columns
|
|||||||
Family Roman
|
Family Roman
|
||||||
Color latex
|
Color latex
|
||||||
EndFont
|
EndFont
|
||||||
|
Nests
|
||||||
|
Standard,Itemize,Enumerate,Description,Pause,Overprint,OverlayArea,Only,Block,
|
||||||
|
ExampleBlock,AlertBlock,Bibliography,Quotation,Quote,Verse,Corollary,Definition,Definitions,
|
||||||
|
Example,Examples,Fact,Lemma,Proof,Theorem,LyX-Code
|
||||||
|
EndNests
|
||||||
End
|
End
|
||||||
|
|
||||||
Style ColumnsCenterAligned
|
Style ColumnsCenterAligned
|
||||||
@ -885,6 +896,10 @@ Style Block
|
|||||||
EndFont
|
EndFont
|
||||||
AutoInsert 1
|
AutoInsert 1
|
||||||
EndArgument
|
EndArgument
|
||||||
|
Nests
|
||||||
|
Standard,Itemize,Enumerate,Description,Pause,Overprint,OverlayArea,Only,Quotation,
|
||||||
|
Quote,Verse,Corollary,Definition,Definitions,Example,Examples,Fact,Lemma,Proof,Theorem,LyX-Code
|
||||||
|
EndNests
|
||||||
End
|
End
|
||||||
|
|
||||||
Style ExampleBlock
|
Style ExampleBlock
|
||||||
@ -1228,6 +1243,9 @@ Style Corollary
|
|||||||
LabelString "Additional Theorem Text"
|
LabelString "Additional Theorem Text"
|
||||||
Tooltip "Additional text appended to the theorem header"
|
Tooltip "Additional text appended to the theorem header"
|
||||||
EndArgument
|
EndArgument
|
||||||
|
Nests
|
||||||
|
Standard,Itemize,Enumerate,Description,Pause,Overprint,OverlayArea,Only,LyX-Code
|
||||||
|
EndNests
|
||||||
End
|
End
|
||||||
|
|
||||||
Style Definition
|
Style Definition
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
# This script will update a .layout file to current format
|
# This script will update a .layout file to current format
|
||||||
|
|
||||||
# The latest layout format is also defined in src/TextClass.cpp
|
# The latest layout format is also defined in src/TextClass.cpp
|
||||||
currentFormat = 65
|
currentFormat = 66
|
||||||
|
|
||||||
|
|
||||||
# Incremented to format 4, 6 April 2007, lasgouttes
|
# Incremented to format 4, 6 April 2007, lasgouttes
|
||||||
@ -220,6 +220,9 @@ currentFormat = 65
|
|||||||
# Incremented to format 65, 16 October 2017 by spitz
|
# Incremented to format 65, 16 October 2017 by spitz
|
||||||
# Color collapsable -> collapsible
|
# Color collapsable -> collapsible
|
||||||
|
|
||||||
|
# Incremented to format 66, 28 December 2017 by spitz
|
||||||
|
# New Layout tag "Nests ... EndNests"
|
||||||
|
|
||||||
# Do not forget to document format change in Customization
|
# Do not forget to document format change in Customization
|
||||||
# Manual (section "Declaring a new text class").
|
# Manual (section "Declaring a new text class").
|
||||||
|
|
||||||
@ -469,6 +472,11 @@ def convert(lines, end_format):
|
|||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if format == 65:
|
||||||
|
# nothing to do.
|
||||||
|
i += 1
|
||||||
|
continue
|
||||||
|
|
||||||
if format == 64:
|
if format == 64:
|
||||||
match = re.compile(b'(\\s*Color\\s+)(\\w+)', re.IGNORECASE).match(lines[i])
|
match = re.compile(b'(\\s*Color\\s+)(\\w+)', re.IGNORECASE).match(lines[i])
|
||||||
if not match:
|
if not match:
|
||||||
|
@ -75,6 +75,7 @@ enum LayoutTags {
|
|||||||
LT_NEED_PROTECT,
|
LT_NEED_PROTECT,
|
||||||
LT_NEWLINE,
|
LT_NEWLINE,
|
||||||
LT_NEXTNOINDENT,
|
LT_NEXTNOINDENT,
|
||||||
|
LT_NESTS,
|
||||||
LT_PAR_GROUP,
|
LT_PAR_GROUP,
|
||||||
LT_PARINDENT,
|
LT_PARINDENT,
|
||||||
LT_PARSEP,
|
LT_PARSEP,
|
||||||
@ -239,6 +240,7 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
|
|||||||
{ "leftmargin", LT_LEFTMARGIN },
|
{ "leftmargin", LT_LEFTMARGIN },
|
||||||
{ "margin", LT_MARGIN },
|
{ "margin", LT_MARGIN },
|
||||||
{ "needprotect", LT_NEED_PROTECT },
|
{ "needprotect", LT_NEED_PROTECT },
|
||||||
|
{ "nests", LT_NESTS },
|
||||||
{ "newline", LT_NEWLINE },
|
{ "newline", LT_NEWLINE },
|
||||||
{ "nextnoindent", LT_NEXTNOINDENT },
|
{ "nextnoindent", LT_NEXTNOINDENT },
|
||||||
{ "obsoletedby", LT_OBSOLETEDBY },
|
{ "obsoletedby", LT_OBSOLETEDBY },
|
||||||
@ -592,6 +594,17 @@ bool Layout::readIgnoreForcelocal(Lexer & lex, TextClass const & tclass)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case LT_NESTS: {
|
||||||
|
docstring const nest = subst(subst(subst(lex.getLongString(from_ascii("EndNests")),
|
||||||
|
from_ascii("\n"), docstring()),
|
||||||
|
from_ascii(" "), docstring()),
|
||||||
|
from_ascii("\t"), docstring());
|
||||||
|
vector<docstring> const nests =
|
||||||
|
getVectorFromString(nest);
|
||||||
|
nests_.insert(nests.begin(), nests.end());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case LT_REFPREFIX: {
|
case LT_REFPREFIX: {
|
||||||
docstring arg;
|
docstring arg;
|
||||||
lex >> arg;
|
lex >> arg;
|
||||||
@ -1387,6 +1400,16 @@ void Layout::write(ostream & os) const
|
|||||||
}
|
}
|
||||||
os << '\n';
|
os << '\n';
|
||||||
}
|
}
|
||||||
|
if (!nests_.empty()) {
|
||||||
|
os << "\tNests ";
|
||||||
|
for (set<docstring>::const_iterator it = nests_.begin();
|
||||||
|
it != nests_.end(); ++it) {
|
||||||
|
if (it != nests_.begin())
|
||||||
|
os << ',';
|
||||||
|
os << to_utf8(*it);
|
||||||
|
}
|
||||||
|
os << '\n';
|
||||||
|
}
|
||||||
if (refprefix.empty())
|
if (refprefix.empty())
|
||||||
os << "\tRefPrefix OFF\n";
|
os << "\tRefPrefix OFF\n";
|
||||||
else
|
else
|
||||||
|
@ -149,6 +149,8 @@ public:
|
|||||||
///
|
///
|
||||||
std::set<std::string> const & requires() const { return requires_; }
|
std::set<std::string> const & requires() const { return requires_; }
|
||||||
///
|
///
|
||||||
|
std::set<docstring> const & nests() const { return nests_; }
|
||||||
|
///
|
||||||
std::string const & latexparam() const { return latexparam_; }
|
std::string const & latexparam() const { return latexparam_; }
|
||||||
///
|
///
|
||||||
docstring leftdelim() const { return leftdelim_; }
|
docstring leftdelim() const { return leftdelim_; }
|
||||||
@ -468,6 +470,8 @@ private:
|
|||||||
bool par_group_;
|
bool par_group_;
|
||||||
/// Packages needed for this layout
|
/// Packages needed for this layout
|
||||||
std::set<std::string> requires_;
|
std::set<std::string> requires_;
|
||||||
|
/// Layouts that are by default nested after this one
|
||||||
|
std::set<docstring> nests_;
|
||||||
///
|
///
|
||||||
LaTeXArgMap latexargs_;
|
LaTeXArgMap latexargs_;
|
||||||
///
|
///
|
||||||
|
@ -2313,8 +2313,9 @@ void LyXAction::init()
|
|||||||
/*!
|
/*!
|
||||||
* \var lyx::FuncCode lyx::LFUN_LAYOUT
|
* \var lyx::FuncCode lyx::LFUN_LAYOUT
|
||||||
* \li Action: Sets the layout (that is, environment) for the current paragraph.
|
* \li Action: Sets the layout (that is, environment) for the current paragraph.
|
||||||
* \li Syntax: layout <LAYOUT>
|
* \li Syntax: layout <LAYOUT> [ignorenests]
|
||||||
* \li Params: <LAYOUT>: the layout to use
|
* \li Params: <LAYOUT>: the layout to use
|
||||||
|
ignorenests: If specified, nesting advices will be ignored.
|
||||||
* \endvar
|
* \endvar
|
||||||
*/
|
*/
|
||||||
{ LFUN_LAYOUT, "layout", Noop, Layout },
|
{ LFUN_LAYOUT, "layout", Noop, Layout },
|
||||||
|
@ -1419,11 +1419,13 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case LFUN_LAYOUT: {
|
case LFUN_LAYOUT: {
|
||||||
docstring layout = cmd.argument();
|
bool const ignorenests = cmd.getArg(1) == "ignorenests";
|
||||||
|
docstring layout = ignorenests ? from_utf8(cmd.getArg(0)) : cmd.argument();
|
||||||
LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
|
LYXERR(Debug::INFO, "LFUN_LAYOUT: (arg) " << to_utf8(layout));
|
||||||
|
|
||||||
Paragraph const & para = cur.paragraph();
|
Paragraph const & para = cur.paragraph();
|
||||||
docstring const old_layout = para.layout().name();
|
docstring const old_layout = para.layout().name();
|
||||||
|
set<docstring> nests = para.layout().nests();
|
||||||
DocumentClass const & tclass = bv->buffer().params().documentClass();
|
DocumentClass const & tclass = bv->buffer().params().documentClass();
|
||||||
|
|
||||||
if (layout.empty())
|
if (layout.empty())
|
||||||
@ -1473,8 +1475,14 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (change_layout)
|
if (change_layout) {
|
||||||
setLayout(cur, layout);
|
setLayout(cur, layout);
|
||||||
|
bool do_nest = false;
|
||||||
|
if (cur.pit() > 0 && pars_[cur.pit() - 1].layout().name() == old_layout)
|
||||||
|
do_nest = !ignorenests;
|
||||||
|
if (do_nest && nests.find(layout) != nests.end())
|
||||||
|
lyx::dispatch(FuncRequest(LFUN_DEPTH_INCREMENT));
|
||||||
|
}
|
||||||
|
|
||||||
Layout::LaTeXArgMap args = tclass[layout].args();
|
Layout::LaTeXArgMap args = tclass[layout].args();
|
||||||
Layout::LaTeXArgMap::const_iterator lait = args.begin();
|
Layout::LaTeXArgMap::const_iterator lait = args.begin();
|
||||||
@ -1531,7 +1539,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
|
|||||||
lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
|
lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
|
||||||
}
|
}
|
||||||
DocumentClass const & tc = bv->buffer().params().documentClass();
|
DocumentClass const & tc = bv->buffer().params().documentClass();
|
||||||
lyx::dispatch(FuncRequest(LFUN_LAYOUT, tc.plainLayout().name()));
|
lyx::dispatch(FuncRequest(LFUN_LAYOUT, from_ascii("\"") + tc.plainLayout().name()
|
||||||
|
+ from_ascii("\" ignorenests")));
|
||||||
lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
|
lyx::dispatch(FuncRequest(LFUN_SEPARATOR_INSERT, "plain"));
|
||||||
if (before) {
|
if (before) {
|
||||||
cur.backwardPos();
|
cur.backwardPos();
|
||||||
@ -3173,7 +3182,8 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
|
|
||||||
case LFUN_LAYOUT: {
|
case LFUN_LAYOUT: {
|
||||||
DocumentClass const & tclass = cur.buffer()->params().documentClass();
|
DocumentClass const & tclass = cur.buffer()->params().documentClass();
|
||||||
docstring layout = cmd.argument();
|
bool const ignorenests = cmd.getArg(1) == "ignorenests";
|
||||||
|
docstring layout = ignorenests ? from_utf8(cmd.getArg(0)) : cmd.argument();
|
||||||
if (layout.empty())
|
if (layout.empty())
|
||||||
layout = tclass.defaultLayoutName();
|
layout = tclass.defaultLayoutName();
|
||||||
enable = !owner_->forcePlainLayout() && tclass.hasLayout(layout);
|
enable = !owner_->forcePlainLayout() && tclass.hasLayout(layout);
|
||||||
|
@ -62,7 +62,7 @@ namespace lyx {
|
|||||||
// You should also run the development/tools/updatelayouts.py script,
|
// You should also run the development/tools/updatelayouts.py script,
|
||||||
// to update the format of all of our layout files.
|
// to update the format of all of our layout files.
|
||||||
//
|
//
|
||||||
int const LAYOUT_FORMAT = 65; //spitz: Color collapsable -> collapsible.
|
int const LAYOUT_FORMAT = 66; //spitz: New layout tag Nests
|
||||||
|
|
||||||
|
|
||||||
// Layout format for the current lyx file format. Controls which format is
|
// Layout format for the current lyx file format. Controls which format is
|
||||||
|
Loading…
Reference in New Issue
Block a user