]> git.lyx.org Git - features.git/commitdiff
To finish up #6854, also add AllowedOccurrences
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 25 Jul 2023 13:49:53 +0000 (15:49 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 25 Jul 2023 13:49:53 +0000 (15:49 +0200)
Again very basic for now (this only considers the current paragraph,
not the whole inset or a serious of grouped layouts

lib/doc/Customization.lyx
lib/doc/de/Customization.lyx
lib/layouts/acmart.layout
lib/layouts/linguistics.module
lib/scripts/layout2layout.py
src/Paragraph.cpp
src/TextClass.cpp
src/insets/InsetLayout.cpp
src/insets/InsetLayout.h

index 3ac10a39689e4e765cfdf20a9edb792715bb02e1..04d9033ae6fffa33dbc743fe58818e5c0b83cea6 100644 (file)
@@ -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
index 748e29e62a3cf843fc5cae7fd03644c26db05bd5..aa5aad8f9460894cd131eacc998b58de674cb639 100644 (file)
@@ -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
index 547fdf9df075c4da8d8512143fa2066d54ada122..5b6c76ea1f10e14346986a1b9c97e59ebf57dbae 100644 (file)
@@ -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
index eafea9659500d8ed2293b6b81aebd40e39018f67..43ec54fff04d45cb2e78e84ad6872fdcc5af7e04 100644 (file)
@@ -157,6 +157,7 @@ InsetLayout Flex:Example_Preamble
        AllowedInLayouts
            Numbered_Example_(multiline), Numbered_Examples_(consecutive)
        EndAllowedInLayouts
+       AllowedOccurrences   1
 End
 
 InsetLayout Flex:Subexample_Preamble
index 5f4a50470644f2cca289cec97bbb73f146658536..cb6023c96fcb4e0b88a694c1861a942e3201a3ca 100644 (file)
@@ -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").
index 9e7fe3016328544f0ab1d8b837d864b9a08acfe9..22e18435d655c4da60f3d685fae8e5d0faafb249 100644 (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_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());
 }
index 5854bcdc278fc799dcf40c211c18f7c45f674f34..d99004f7aab28507272405a32bcd69cfb1c28cc9 100644 (file)
@@ -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
index 91287f41aeaba51ebe164056b4694bf0199ad00f..de217a07cc074fa977756822af1e61762b262e89 100644 (file)
@@ -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;
index 4325ff82ac93b301d8943e6c7d6627dae4a45e19..bf5a01688338175c9370e1ef8b4ac5afd7022464 100644 (file)
@@ -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;
 };
 
 ///