This allows to restrict the use of flex insets to specific contexts.
Note that this is currently very basis. It only considers immediately
containing insets/layouts and can be surpassed via cut and paste.
The use case that made me finally implement this are macros in covington
that make sense only in specific environments (but also consider \inst
in some article classes)
#LyX 2.4 created this file. For more info see https://www.lyx.org/
-\lyxformat 616
+\lyxformat 617
\begin_document
\begin_header
\save_transient_properties true
This is only implemented for Flex insets.
Default:
disabled.
+\change_inserted -712698321 1690284265
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted -712698321 1690284544
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690284277
+AllowedInInsets
+\end_layout
+
+\end_inset
+
+ Includes a comma-separated list of insets to which this inset can be inserted.
+ Must be ended by
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690284318
+EndAllowedInInsets
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+.
+ If you you also want the insertion to be allowed in specific arguments of the target insets,
+ append the argument name after @ (e.
+\begin_inset space \thinspace{}
+\end_inset
+
+g.,
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690284445
+My_Inset@post:1
+\change_unchanged
+
+\end_layout
+
+\end_inset
+
+).
+ Note that this currently only supports immediately containing insets (no deeper nesting).
+ See also
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690284329
+AllowedInLayouts
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Description
+
+\change_inserted -712698321 1690284561
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690284338
+AllowedInLayouts
+\end_layout
+
+\end_inset
+
+ Includes a comma-separated list of layouts within which this inset can be inserted.
+ Must be ended by
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690284353
+EndAllowedInLayouts
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+.
+ Note that this currently only supports immediately containing layouts (no deeper nesting).
+ See also
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1690284358
+AllowedInInsets
+\end_layout
+
+\end_inset
+
+.
+\change_unchanged
+
\end_layout
\begin_layout Description
\change_inserted 47243155 1689528630
InheritFont
+\change_unchanged
+
\end_layout
\end_inset
\change_inserted 47243155 1689528607
0
+\change_unchanged
+
\end_layout
\end_inset
\emph on
1
+\change_unchanged
+
\end_layout
\end_inset
#LyX 2.4 created this file. For more info see https://www.lyx.org/
-\lyxformat 615
+\lyxformat 617
\begin_document
\begin_header
\save_transient_properties true
\begin_inset Flex Code
status collapsed
+\begin_layout Plain Layout
+AllowedInInsets
+\end_layout
+
+\end_inset
+
+ enthält eine kommaseparierte Liste von Einfügungen,
+ in die diese Einfügung platziert werden kann.
+ Muss mittels
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+EndAllowedInInsets
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+ beendet werden.
+ Falls Sie die Einfügung (auch) in bestimmten Argumenten der entsprechenden Einfügung erlauben möchten,
+ hängen Sie den Namen des Arguments nach @ an (bspw.
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+Meine_Einfuegung@post:1
+\end_layout
+
+\end_inset
+
+).
+ Beachten Sie,
+ dass im Moment nur Einfügungen berücksichtigt werden,
+ die eine Hierarchiestufe höher stehen (keine tiefere Verschachtelung).
+ Siehe auch
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+AllowedInLayouts
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Description
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+AllowedInLayouts
+\end_layout
+
+\end_inset
+
+ enthält eine kommaseparierte Liste von Stilen,
+ in die diese Einfügung platziert werden kann.
+ Muss mittels
+\begin_inset Quotes eld
+\end_inset
+
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+EndAllowedInLayouts
+\end_layout
+
+\end_inset
+
+
+\begin_inset Quotes erd
+\end_inset
+
+ beendet werden.
+ Beachten Sie,
+ dass im Moment nur Stile berücksichtigt werden,
+ die die Einfügung unmittelbar enthalten (keine tiefere Verschachtelung).
+ Siehe auch
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+AllowedInInsets
+\end_layout
+
+\end_inset
+
+.
+\end_layout
+
+\begin_layout Description
+\begin_inset Flex Code
+status collapsed
+
\begin_layout Plain Layout
Argument
\end_layout
# This script will update a .layout file to current format
# The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 101
+currentFormat = 102
# Incremented to format 4, 6 April 2007, lasgouttes
# Incremented to format 101, 22 July 2023 by lasgouttes
# add InsetLayout tag InheritFont
+# Incremented to format 102, 25 July 2023 by spitz
+# add InsetLayout tags AllowedInInsets, EndAllowedInInsets,
+# AllowedInLayouts, EndAllowedInLayouts
+
# Do not forget to document format change in Customization
# Manual (section "Declaring a new text class").
i += 1
continue
+ if format == 101:
+ # nothing to do.
+ i += 1
+ continue
+
if format == 100:
# InheritFont has been introduced and defaults to true. Some insets had
# an hardcoded inheritFont') method returning true. We removed them, so
#include "BufferEncodings.h"
#include "Changes.h"
#include "Counters.h"
+#include "Cursor.h"
#include "InsetList.h"
#include "Language.h"
#include "LaTeXFeatures.h"
}
+bool Paragraph::allowedInContext(Cursor const & cur, InsetLayout const & il) const
+{
+ set<docstring> const & allowed_insets = il.allowedInInsets();
+ set<docstring> const & allowed_layouts = il.allowedInLayouts();
+
+ if (allowed_insets.find(inInset().getLayout().name()) != allowed_insets.end())
+ return true;
+
+ if (allowed_layouts.find(d->layout_->name()) != allowed_layouts.end())
+ return true;
+
+ 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;
+ }
+ }
+
+ return (allowed_insets.empty() && allowed_layouts.empty());
+}
+
+
bool Paragraph::isPartOfTextSequence() const
{
for (pos_type i = 0; i < size(); ++i) {
#include "support/strfwd.h"
#include "support/types.h"
+#include "insets/InsetLayout.h"
+
#include <set>
#include <vector>
class Buffer;
class BufferParams;
class Change;
+class Cursor;
class DocIterator;
class docstring_list;
class DocumentClass;
///
bool parbreakIsNewline() const;
///
+ bool allowedInContext(Cursor const & cur, InsetLayout const & il) const;
+ ///
bool isPartOfTextSequence() const;
///
pos_type size() const;
s = from_ascii("Flex:") + s;
if (!cur.buffer()->params().documentClass().hasInsetLayout(s))
enable = false;
+ else if (!cur.paragraph().allowedInContext(cur, cur.buffer()->params().documentClass().insetLayout(s)))
+ enable = false;
else {
InsetLyXType ilt =
cur.buffer()->params().documentClass().insetLayout(s).lyxtype();
// You should also run the development/tools/updatelayouts.py script,
// to update the format of all of our layout files.
//
-int const LAYOUT_FORMAT = 101; // lasgouttes: add InheritFont tag
+int const LAYOUT_FORMAT = 102; // spitz: add AllowedInInsets and AllowedInLayouts tag
// Layout format for the current lyx file format. Controls which format is
{
enum {
IL_ADDTOTOC,
+ IL_ALLOWED_IN_INSET,
+ IL_ALLOWED_IN_LAYOUT,
IL_ARGUMENT,
IL_BABELPREAMBLE,
IL_BGCOLOR,
LexerKeyword elementTags[] = {
{ "addtotoc", IL_ADDTOTOC },
+ { "allowedininsets", IL_ALLOWED_IN_INSET },
+ { "allowedinlayouts", IL_ALLOWED_IN_LAYOUT },
{ "argument", IL_ARGUMENT },
{ "babelpreamble", IL_BABELPREAMBLE },
{ "bgcolor", IL_BGCOLOR },
case IL_EDITEXTERNAL:
lex >> edit_external_;
break;
+ case IL_ALLOWED_IN_INSET: {
+ docstring allowed = lex.getLongString(from_ascii("EndAllowedInInsets"));
+ allowed = subst(allowed, from_ascii("\n"), docstring());
+ allowed = subst(allowed, from_ascii("\t"), docstring());
+ allowed = subst(allowed, from_ascii("\""), docstring());
+ allowed = subst(allowed, '_', ' ');
+ vector<docstring> const allowances =
+ getVectorFromString(allowed, from_ascii(","), false, true);
+ allowed_in_insets_.clear();
+ allowed_in_insets_.insert(allowances.begin(), allowances.end());
+ break;
+ }
+
+ case IL_ALLOWED_IN_LAYOUT: {
+ docstring allowed = lex.getLongString(from_ascii("EndAllowedInLayouts"));
+ allowed = subst(allowed, from_ascii("\n"), docstring());
+ allowed = subst(allowed, from_ascii("\t"), docstring());
+ allowed = subst(allowed, from_ascii("\""), docstring());
+ allowed = subst(allowed, '_', ' ');
+ vector<docstring> const allowances =
+ getVectorFromString(allowed, from_ascii(","), false, true);
+ allowed_in_layouts_.clear();
+ allowed_in_layouts_.insert(allowances.begin(), allowances.end());
+ break;
+ }
case IL_END:
getout = true;
break;
bool isTocCaption() const { return is_toc_caption_; }
///
bool editExternally () const { return edit_external_; }
+ ///
+ std::set<docstring> const & allowedInInsets() const { return allowed_in_insets_; }
+ ///
+ std::set<docstring> const & allowedInLayouts() const { return allowed_in_layouts_; }
private:
///
void makeDefaultCSS() const;
bool is_toc_caption_ = false;
///
bool edit_external_ = false;
+ /// Insets that can hold insets with this InsetLayout
+ std::set<docstring> allowed_in_insets_;
+ /// Layouts that can hold insets with this InsetLayout
+ std::set<docstring> allowed_in_layouts_;
};
///