mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
To finish up #6854, also add AllowedOccurrences
Again very basic for now (this only considers the current paragraph, not the whole inset or a serious of grouped layouts
This commit is contained in:
parent
19975d07dd
commit
729ab602ca
@ -20957,6 +20957,8 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690284277
|
||||
AllowedInInsets
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
@ -20974,6 +20976,8 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690284318
|
||||
EndAllowedInInsets
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
@ -21013,6 +21017,8 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690284329
|
||||
AllowedInLayouts
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
@ -21022,7 +21028,7 @@ AllowedInLayouts
|
||||
|
||||
\begin_layout Description
|
||||
|
||||
\change_inserted -712698321 1690284561
|
||||
\change_inserted -712698321 1690292495
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
@ -21030,6 +21036,8 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690284338
|
||||
AllowedInLayouts
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
@ -21047,6 +21055,8 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690284353
|
||||
EndAllowedInLayouts
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
@ -21065,11 +21075,67 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690284358
|
||||
AllowedInInsets
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Description
|
||||
|
||||
\change_inserted -712698321 1690292676
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690292501
|
||||
AllowedOccurrences
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
[
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690292507
|
||||
int
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
] If
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690292530
|
||||
AllowedInInsets
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
or
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690292536
|
||||
AllowedInLayouts
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
has been defined,
|
||||
this can be used to determine how many times the inset can be inserted to a given paragraph.
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
@ -17395,6 +17395,50 @@ AllowedInInsets
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
AllowedOccurrences
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
[
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
int
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
] Falls
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
AllowedInInsets
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
oder
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
AllowedInLayouts
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
definiert wurde,
|
||||
kann hiermit eine maximale Anzahl von Einfügungen pro Absatz festgelegt werden.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Description
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Argument
|
||||
\end_layout
|
||||
|
@ -250,6 +250,7 @@ InsetLayout Flex:Department
|
||||
AllowedInLayouts
|
||||
Affiliation
|
||||
EndAllowedInLayouts
|
||||
AllowedOccurrences 1
|
||||
End
|
||||
|
||||
InsetLayout Flex:Street_Address
|
||||
@ -261,6 +262,7 @@ InsetLayout Flex:Street_Address
|
||||
AllowedInLayouts
|
||||
Affiliation
|
||||
EndAllowedInLayouts
|
||||
AllowedOccurrences 1
|
||||
End
|
||||
|
||||
InsetLayout Flex:City
|
||||
@ -272,6 +274,7 @@ InsetLayout Flex:City
|
||||
AllowedInLayouts
|
||||
Affiliation
|
||||
EndAllowedInLayouts
|
||||
AllowedOccurrences 1
|
||||
End
|
||||
|
||||
InsetLayout Flex:Country
|
||||
@ -283,6 +286,7 @@ InsetLayout Flex:Country
|
||||
AllowedInLayouts
|
||||
Affiliation
|
||||
EndAllowedInLayouts
|
||||
AllowedOccurrences 1
|
||||
End
|
||||
|
||||
InsetLayout Flex:State
|
||||
@ -294,6 +298,7 @@ InsetLayout Flex:State
|
||||
AllowedInLayouts
|
||||
Affiliation
|
||||
EndAllowedInLayouts
|
||||
AllowedOccurrences 1
|
||||
End
|
||||
|
||||
InsetLayout Flex:Postal_Code
|
||||
@ -305,6 +310,7 @@ InsetLayout Flex:Postal_Code
|
||||
AllowedInLayouts
|
||||
Affiliation
|
||||
EndAllowedInLayouts
|
||||
AllowedOccurrences 1
|
||||
End
|
||||
|
||||
Style TitleNote
|
||||
|
@ -157,6 +157,7 @@ InsetLayout Flex:Example_Preamble
|
||||
AllowedInLayouts
|
||||
Numbered_Example_(multiline), Numbered_Examples_(consecutive)
|
||||
EndAllowedInLayouts
|
||||
AllowedOccurrences 1
|
||||
End
|
||||
|
||||
InsetLayout Flex:Subexample_Preamble
|
||||
|
@ -342,7 +342,7 @@ currentFormat = 102
|
||||
|
||||
# Incremented to format 102, 25 July 2023 by spitz
|
||||
# add InsetLayout tags AllowedInInsets, EndAllowedInInsets,
|
||||
# AllowedInLayouts, EndAllowedInLayouts
|
||||
# AllowedInLayouts, EndAllowedInLayouts, AllowedOccurrences
|
||||
|
||||
# Do not forget to document format change in Customization
|
||||
# Manual (section "Declaring a new text class").
|
||||
|
@ -2344,21 +2344,34 @@ bool Paragraph::allowedInContext(Cursor const & cur, InsetLayout const & il) con
|
||||
set<docstring> const & allowed_insets = il.allowedInInsets();
|
||||
set<docstring> const & allowed_layouts = il.allowedInLayouts();
|
||||
|
||||
bool result = false;
|
||||
if (allowed_insets.find(inInset().getLayout().name()) != allowed_insets.end())
|
||||
return true;
|
||||
result = true;
|
||||
|
||||
if (allowed_layouts.find(d->layout_->name()) != allowed_layouts.end())
|
||||
return true;
|
||||
else if (allowed_layouts.find(d->layout_->name()) != allowed_layouts.end())
|
||||
result = true;
|
||||
|
||||
if (inInset().asInsetArgument()) {
|
||||
else if (inInset().asInsetArgument()) {
|
||||
// check if the argument allows the inset in question
|
||||
if (cur.depth() > 1) {
|
||||
docstring parlayout = cur[cur.depth() - 2].inset().getLayout().name()
|
||||
+ from_ascii("@") + from_ascii(inInset().asInsetArgument()->name());
|
||||
if (allowed_insets.find(parlayout) != allowed_insets.end())
|
||||
return true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (result && il.allowedOccurrences() != -1) {
|
||||
int have_ins = 0;
|
||||
for (auto const & table : insetList())
|
||||
if (table.inset->getLayout().name() == il.name())
|
||||
++have_ins;
|
||||
if (have_ins >= il.allowedOccurrences())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result)
|
||||
return true;
|
||||
|
||||
return (allowed_insets.empty() && allowed_layouts.empty());
|
||||
}
|
||||
|
@ -59,7 +59,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 = 102; // spitz: add AllowedInInsets and AllowedInLayouts tag
|
||||
int const LAYOUT_FORMAT = 102; // spitz: add tags AllowedInInsets, AllowedInLayouts, AllowedOccurrences
|
||||
|
||||
|
||||
// Layout format for the current lyx file format. Controls which format is
|
||||
|
@ -66,6 +66,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
|
||||
IL_ADDTOTOC,
|
||||
IL_ALLOWED_IN_INSET,
|
||||
IL_ALLOWED_IN_LAYOUT,
|
||||
IL_ALLOWED_OCCURRENCES,
|
||||
IL_ARGUMENT,
|
||||
IL_BABELPREAMBLE,
|
||||
IL_BGCOLOR,
|
||||
@ -153,6 +154,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
|
||||
{ "addtotoc", IL_ADDTOTOC },
|
||||
{ "allowedininsets", IL_ALLOWED_IN_INSET },
|
||||
{ "allowedinlayouts", IL_ALLOWED_IN_LAYOUT },
|
||||
{ "allowedoccurrences", IL_ALLOWED_OCCURRENCES },
|
||||
{ "argument", IL_ARGUMENT },
|
||||
{ "babelpreamble", IL_BABELPREAMBLE },
|
||||
{ "bgcolor", IL_BGCOLOR },
|
||||
@ -651,6 +653,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
|
||||
allowed_in_layouts_.insert(allowances.begin(), allowances.end());
|
||||
break;
|
||||
}
|
||||
case IL_ALLOWED_OCCURRENCES:
|
||||
lex >> allowed_occurrences_;
|
||||
break;
|
||||
case IL_END:
|
||||
getout = true;
|
||||
break;
|
||||
|
@ -256,6 +256,8 @@ public:
|
||||
std::set<docstring> const & allowedInInsets() const { return allowed_in_insets_; }
|
||||
///
|
||||
std::set<docstring> const & allowedInLayouts() const { return allowed_in_layouts_; }
|
||||
///
|
||||
int allowedOccurrences() const { return allowed_occurrences_; }
|
||||
private:
|
||||
///
|
||||
void makeDefaultCSS() const;
|
||||
@ -443,6 +445,8 @@ private:
|
||||
std::set<docstring> allowed_in_insets_;
|
||||
/// Layouts that can hold insets with this InsetLayout
|
||||
std::set<docstring> allowed_in_layouts_;
|
||||
///
|
||||
int allowed_occurrences_ = -1;
|
||||
};
|
||||
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user