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:
Juergen Spitzmueller 2023-07-25 15:49:53 +02:00
parent 19975d07dd
commit 729ab602ca
9 changed files with 147 additions and 8 deletions

View File

@ -20957,6 +20957,8 @@ status collapsed
\change_inserted -712698321 1690284277 \change_inserted -712698321 1690284277
AllowedInInsets AllowedInInsets
\change_unchanged
\end_layout \end_layout
\end_inset \end_inset
@ -20974,6 +20976,8 @@ status collapsed
\change_inserted -712698321 1690284318 \change_inserted -712698321 1690284318
EndAllowedInInsets EndAllowedInInsets
\change_unchanged
\end_layout \end_layout
\end_inset \end_inset
@ -21013,6 +21017,8 @@ status collapsed
\change_inserted -712698321 1690284329 \change_inserted -712698321 1690284329
AllowedInLayouts AllowedInLayouts
\change_unchanged
\end_layout \end_layout
\end_inset \end_inset
@ -21022,7 +21028,7 @@ AllowedInLayouts
\begin_layout Description \begin_layout Description
\change_inserted -712698321 1690284561 \change_inserted -712698321 1690292495
\begin_inset Flex Code \begin_inset Flex Code
status collapsed status collapsed
@ -21030,6 +21036,8 @@ status collapsed
\change_inserted -712698321 1690284338 \change_inserted -712698321 1690284338
AllowedInLayouts AllowedInLayouts
\change_unchanged
\end_layout \end_layout
\end_inset \end_inset
@ -21047,6 +21055,8 @@ status collapsed
\change_inserted -712698321 1690284353 \change_inserted -712698321 1690284353
EndAllowedInLayouts EndAllowedInLayouts
\change_unchanged
\end_layout \end_layout
\end_inset \end_inset
@ -21065,11 +21075,67 @@ status collapsed
\change_inserted -712698321 1690284358 \change_inserted -712698321 1690284358
AllowedInInsets AllowedInInsets
\change_unchanged
\end_layout \end_layout
\end_inset \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 \change_unchanged
\end_layout \end_layout

View File

@ -17395,6 +17395,50 @@ AllowedInInsets
\begin_inset Flex Code \begin_inset Flex Code
status collapsed 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 \begin_layout Plain Layout
Argument Argument
\end_layout \end_layout

View File

@ -250,6 +250,7 @@ InsetLayout Flex:Department
AllowedInLayouts AllowedInLayouts
Affiliation Affiliation
EndAllowedInLayouts EndAllowedInLayouts
AllowedOccurrences 1
End End
InsetLayout Flex:Street_Address InsetLayout Flex:Street_Address
@ -261,6 +262,7 @@ InsetLayout Flex:Street_Address
AllowedInLayouts AllowedInLayouts
Affiliation Affiliation
EndAllowedInLayouts EndAllowedInLayouts
AllowedOccurrences 1
End End
InsetLayout Flex:City InsetLayout Flex:City
@ -272,6 +274,7 @@ InsetLayout Flex:City
AllowedInLayouts AllowedInLayouts
Affiliation Affiliation
EndAllowedInLayouts EndAllowedInLayouts
AllowedOccurrences 1
End End
InsetLayout Flex:Country InsetLayout Flex:Country
@ -283,6 +286,7 @@ InsetLayout Flex:Country
AllowedInLayouts AllowedInLayouts
Affiliation Affiliation
EndAllowedInLayouts EndAllowedInLayouts
AllowedOccurrences 1
End End
InsetLayout Flex:State InsetLayout Flex:State
@ -294,6 +298,7 @@ InsetLayout Flex:State
AllowedInLayouts AllowedInLayouts
Affiliation Affiliation
EndAllowedInLayouts EndAllowedInLayouts
AllowedOccurrences 1
End End
InsetLayout Flex:Postal_Code InsetLayout Flex:Postal_Code
@ -305,6 +310,7 @@ InsetLayout Flex:Postal_Code
AllowedInLayouts AllowedInLayouts
Affiliation Affiliation
EndAllowedInLayouts EndAllowedInLayouts
AllowedOccurrences 1
End End
Style TitleNote Style TitleNote

View File

@ -157,6 +157,7 @@ InsetLayout Flex:Example_Preamble
AllowedInLayouts AllowedInLayouts
Numbered_Example_(multiline), Numbered_Examples_(consecutive) Numbered_Example_(multiline), Numbered_Examples_(consecutive)
EndAllowedInLayouts EndAllowedInLayouts
AllowedOccurrences 1
End End
InsetLayout Flex:Subexample_Preamble InsetLayout Flex:Subexample_Preamble

View File

@ -342,7 +342,7 @@ currentFormat = 102
# Incremented to format 102, 25 July 2023 by spitz # Incremented to format 102, 25 July 2023 by spitz
# add InsetLayout tags AllowedInInsets, EndAllowedInInsets, # add InsetLayout tags AllowedInInsets, EndAllowedInInsets,
# AllowedInLayouts, EndAllowedInLayouts # AllowedInLayouts, EndAllowedInLayouts, AllowedOccurrences
# 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").

View File

@ -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_insets = il.allowedInInsets();
set<docstring> const & allowed_layouts = il.allowedInLayouts(); set<docstring> const & allowed_layouts = il.allowedInLayouts();
bool result = false;
if (allowed_insets.find(inInset().getLayout().name()) != allowed_insets.end()) if (allowed_insets.find(inInset().getLayout().name()) != allowed_insets.end())
return true; result = true;
if (allowed_layouts.find(d->layout_->name()) != allowed_layouts.end()) else if (allowed_layouts.find(d->layout_->name()) != allowed_layouts.end())
return true; result = true;
if (inInset().asInsetArgument()) { else if (inInset().asInsetArgument()) {
// check if the argument allows the inset in question // check if the argument allows the inset in question
if (cur.depth() > 1) { if (cur.depth() > 1) {
docstring parlayout = cur[cur.depth() - 2].inset().getLayout().name() docstring parlayout = cur[cur.depth() - 2].inset().getLayout().name()
+ from_ascii("@") + from_ascii(inInset().asInsetArgument()->name()); + from_ascii("@") + from_ascii(inInset().asInsetArgument()->name());
if (allowed_insets.find(parlayout) != allowed_insets.end()) 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()); return (allowed_insets.empty() && allowed_layouts.empty());
} }

View File

@ -59,7 +59,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 = 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 // Layout format for the current lyx file format. Controls which format is

View File

@ -66,6 +66,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
IL_ADDTOTOC, IL_ADDTOTOC,
IL_ALLOWED_IN_INSET, IL_ALLOWED_IN_INSET,
IL_ALLOWED_IN_LAYOUT, IL_ALLOWED_IN_LAYOUT,
IL_ALLOWED_OCCURRENCES,
IL_ARGUMENT, IL_ARGUMENT,
IL_BABELPREAMBLE, IL_BABELPREAMBLE,
IL_BGCOLOR, IL_BGCOLOR,
@ -153,6 +154,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
{ "addtotoc", IL_ADDTOTOC }, { "addtotoc", IL_ADDTOTOC },
{ "allowedininsets", IL_ALLOWED_IN_INSET }, { "allowedininsets", IL_ALLOWED_IN_INSET },
{ "allowedinlayouts", IL_ALLOWED_IN_LAYOUT }, { "allowedinlayouts", IL_ALLOWED_IN_LAYOUT },
{ "allowedoccurrences", IL_ALLOWED_OCCURRENCES },
{ "argument", IL_ARGUMENT }, { "argument", IL_ARGUMENT },
{ "babelpreamble", IL_BABELPREAMBLE }, { "babelpreamble", IL_BABELPREAMBLE },
{ "bgcolor", IL_BGCOLOR }, { "bgcolor", IL_BGCOLOR },
@ -651,6 +653,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
allowed_in_layouts_.insert(allowances.begin(), allowances.end()); allowed_in_layouts_.insert(allowances.begin(), allowances.end());
break; break;
} }
case IL_ALLOWED_OCCURRENCES:
lex >> allowed_occurrences_;
break;
case IL_END: case IL_END:
getout = true; getout = true;
break; break;

View File

@ -256,6 +256,8 @@ public:
std::set<docstring> const & allowedInInsets() const { return allowed_in_insets_; } std::set<docstring> const & allowedInInsets() const { return allowed_in_insets_; }
/// ///
std::set<docstring> const & allowedInLayouts() const { return allowed_in_layouts_; } std::set<docstring> const & allowedInLayouts() const { return allowed_in_layouts_; }
///
int allowedOccurrences() const { return allowed_occurrences_; }
private: private:
/// ///
void makeDefaultCSS() const; void makeDefaultCSS() const;
@ -443,6 +445,8 @@ private:
std::set<docstring> allowed_in_insets_; std::set<docstring> allowed_in_insets_;
/// Layouts that can hold insets with this InsetLayout /// Layouts that can hold insets with this InsetLayout
std::set<docstring> allowed_in_layouts_; std::set<docstring> allowed_in_layouts_;
///
int allowed_occurrences_ = -1;
}; };
/// ///