mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
Improve AllowedOccurrences
This does now apply to the whole inset or paragraph group (not to the
current paragraph only) unless the new boolean AllowedOccurrencesPerItem
is set and we are in a list-type environment.
Amends 729ab602ca
This commit is contained in:
parent
f072bbeb38
commit
7f4c4cd548
@ -21086,7 +21086,7 @@ AllowedInInsets
|
||||
|
||||
\begin_layout Description
|
||||
|
||||
\change_inserted -712698321 1690292676
|
||||
\change_inserted -712698321 1690357747
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
@ -21094,6 +21094,8 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690292501
|
||||
AllowedOccurrences
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
@ -21106,6 +21108,8 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690292507
|
||||
int
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
@ -21118,6 +21122,8 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690292530
|
||||
AllowedInInsets
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
@ -21130,12 +21136,90 @@ status collapsed
|
||||
|
||||
\change_inserted -712698321 1690292536
|
||||
AllowedInLayouts
|
||||
\change_unchanged
|
||||
|
||||
\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.
|
||||
this can be used to determine how many times the inset can be inserted to a given inset or the paragraph (group).
|
||||
\end_layout
|
||||
|
||||
\begin_layout Description
|
||||
|
||||
\change_inserted -712698321 1690357828
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690357753
|
||||
AllowedOccurrencesPerItem
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
[
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690357747
|
||||
|
||||
\emph on
|
||||
0
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
,
|
||||
\begin_inset space \thinspace{}
|
||||
\end_inset
|
||||
|
||||
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690357747
|
||||
1
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
] If this is set to true,
|
||||
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690357774
|
||||
AllowedOccurrences
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
applies to single paragraphs if we are in a list-type environment (with
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\change_inserted -712698321 1690357825
|
||||
|
||||
\backslash
|
||||
item
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
s).
|
||||
\change_unchanged
|
||||
|
||||
\end_layout
|
||||
|
@ -17439,6 +17439,79 @@ AllowedInLayouts
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
AllowedOccurrencesPerItem
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
[
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\emph on
|
||||
0
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
,
|
||||
\begin_inset space \thinspace{}
|
||||
\end_inset
|
||||
|
||||
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
1
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
] Wenn dies auf
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
true
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
gesetzt wird,
|
||||
zählen die
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
AllowedOccurrences
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
je Absatz,
|
||||
sofern wir uns in einer listenartigen Umgebung (mit
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
|
||||
\backslash
|
||||
item
|
||||
\end_layout
|
||||
|
||||
\end_inset
|
||||
|
||||
s) befinden.
|
||||
\end_layout
|
||||
|
||||
\begin_layout Description
|
||||
\begin_inset Flex Code
|
||||
status collapsed
|
||||
|
||||
\begin_layout Plain Layout
|
||||
Argument
|
||||
\end_layout
|
||||
|
@ -158,6 +158,7 @@ InsetLayout Flex:Example_Preamble
|
||||
Numbered_Example_(multiline), Numbered_Examples_(consecutive)
|
||||
EndAllowedInLayouts
|
||||
AllowedOccurrences 1
|
||||
AllowedOccurrencesPerItem true
|
||||
End
|
||||
|
||||
InsetLayout Flex:Subexample_Preamble
|
||||
|
@ -342,7 +342,8 @@ currentFormat = 102
|
||||
|
||||
# Incremented to format 102, 25 July 2023 by spitz
|
||||
# add InsetLayout tags AllowedInInsets, EndAllowedInInsets,
|
||||
# AllowedInLayouts, EndAllowedInLayouts, AllowedOccurrences
|
||||
# AllowedInLayouts, EndAllowedInLayouts, AllowedOccurrences,
|
||||
# AllowedOccurrencesPerItem
|
||||
|
||||
# Do not forget to document format change in Customization
|
||||
# Manual (section "Declaring a new text class").
|
||||
|
@ -2344,33 +2344,73 @@ 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())
|
||||
result = true;
|
||||
bool in_allowed_inset =
|
||||
allowed_insets.find(inInset().getLayout().name()) != allowed_insets.end();
|
||||
|
||||
else if (allowed_layouts.find(d->layout_->name()) != allowed_layouts.end())
|
||||
result = true;
|
||||
bool in_allowed_layout =
|
||||
allowed_layouts.find(d->layout_->name()) != allowed_layouts.end();
|
||||
|
||||
else if (inInset().asInsetArgument()) {
|
||||
if (!in_allowed_inset && 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())
|
||||
result = true;
|
||||
in_allowed_inset = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (result && il.allowedOccurrences() != -1) {
|
||||
int have_ins = 0;
|
||||
for (auto const & table : insetList())
|
||||
if (table.inset->getLayout().name() == il.name())
|
||||
++have_ins;
|
||||
int have_ins = 0;
|
||||
// check if we exceed the number of allowed insets in this inset
|
||||
if (in_allowed_inset && inInset().asInsetText() && il.allowedOccurrences() != -1) {
|
||||
ParagraphList & pars = cur.text()->paragraphs();
|
||||
for (Paragraph const & par : pars) {
|
||||
for (auto const & table : par.insetList())
|
||||
if (table.inset->getLayout().name() == il.name())
|
||||
++have_ins;
|
||||
}
|
||||
if (have_ins >= il.allowedOccurrences())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (result)
|
||||
have_ins = 0;
|
||||
// check if we exceed the number of allowed insets in the layout group
|
||||
if (in_allowed_layout && il.allowedOccurrences() != -1) {
|
||||
pit_type pit = cur.pit();
|
||||
pit_type lastpit = cur.pit();
|
||||
ParagraphList & pars = cur.text()->paragraphs();
|
||||
// If we are not on a list-type environment or AllowedOccurrencesPerItem
|
||||
// is false, we check the whole paragraph group
|
||||
if (d->layout_->isEnvironment()
|
||||
&& !(il.allowedOccurrencesPerItem()
|
||||
&& (d->layout_->latextype == LATEX_LIST_ENVIRONMENT
|
||||
|| d->layout_->latextype == LATEX_ITEM_ENVIRONMENT))) {
|
||||
lastpit = cur.lastpit();
|
||||
// get the first paragraph in sequence with this layout
|
||||
depth_type const current_depth = params().depth();
|
||||
while (true) {
|
||||
if (pit == 0)
|
||||
break;
|
||||
Paragraph cpar = pars[pit - 1];
|
||||
if (&cpar.layout() == d->layout_
|
||||
&& cpar.params().depth() == current_depth)
|
||||
--pit;
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (; pit <= lastpit; ++pit) {
|
||||
if (&pars[pit].layout() != d->layout_)
|
||||
break;
|
||||
for (auto const & table : pars[pit].insetList())
|
||||
if (table.inset->getLayout().name() == il.name())
|
||||
++have_ins;
|
||||
}
|
||||
if (have_ins >= il.allowedOccurrences())
|
||||
return false;
|
||||
}
|
||||
|
||||
if (in_allowed_layout || in_allowed_inset)
|
||||
return true;
|
||||
|
||||
return (allowed_insets.empty() && allowed_layouts.empty());
|
||||
|
@ -67,6 +67,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
|
||||
IL_ALLOWED_IN_INSET,
|
||||
IL_ALLOWED_IN_LAYOUT,
|
||||
IL_ALLOWED_OCCURRENCES,
|
||||
IL_ALLOWED_OCCURRENCES_PER_ITEM,
|
||||
IL_ARGUMENT,
|
||||
IL_BABELPREAMBLE,
|
||||
IL_BGCOLOR,
|
||||
@ -155,6 +156,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
|
||||
{ "allowedininsets", IL_ALLOWED_IN_INSET },
|
||||
{ "allowedinlayouts", IL_ALLOWED_IN_LAYOUT },
|
||||
{ "allowedoccurrences", IL_ALLOWED_OCCURRENCES },
|
||||
{ "allowedoccurrencesperitem", IL_ALLOWED_OCCURRENCES_PER_ITEM },
|
||||
{ "argument", IL_ARGUMENT },
|
||||
{ "babelpreamble", IL_BABELPREAMBLE },
|
||||
{ "bgcolor", IL_BGCOLOR },
|
||||
@ -656,6 +658,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass,
|
||||
case IL_ALLOWED_OCCURRENCES:
|
||||
lex >> allowed_occurrences_;
|
||||
break;
|
||||
case IL_ALLOWED_OCCURRENCES_PER_ITEM:
|
||||
lex >> allowed_occurrences_per_item_;
|
||||
break;
|
||||
case IL_END:
|
||||
getout = true;
|
||||
break;
|
||||
|
@ -258,6 +258,8 @@ public:
|
||||
std::set<docstring> const & allowedInLayouts() const { return allowed_in_layouts_; }
|
||||
///
|
||||
int allowedOccurrences() const { return allowed_occurrences_; }
|
||||
///
|
||||
bool allowedOccurrencesPerItem() const { return allowed_occurrences_per_item_; }
|
||||
private:
|
||||
///
|
||||
void makeDefaultCSS() const;
|
||||
@ -447,6 +449,8 @@ private:
|
||||
std::set<docstring> allowed_in_layouts_;
|
||||
///
|
||||
int allowed_occurrences_ = -1;
|
||||
///
|
||||
bool allowed_occurrences_per_item_ = false;
|
||||
};
|
||||
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user