Introduce InputGlobal (#12087)

This is a variant of Input for layout files that only searches build
and system directories and thus allows "InputGlobal name.inc" in a user
file name.inc that attempts to modify its global counterpart.
This commit is contained in:
Juergen Spitzmueller 2021-01-26 08:42:39 +01:00
parent 10c7954ffb
commit 76eae4572e
6 changed files with 231 additions and 16 deletions

View File

@ -1,5 +1,5 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/ #LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 601 \lyxformat 605
\begin_document \begin_document
\begin_header \begin_header
\save_transient_properties true \save_transient_properties true
@ -109,7 +109,7 @@ logicalmkup
\branch OutDated \branch OutDated
\selected 0 \selected 0
\filename_suffix 0 \filename_suffix 0
\color #f5fae7 \color #f5fae7 #0a0518
\end_branch \end_branch
\index Index \index Index
\shortcut idx \shortcut idx
@ -10375,6 +10375,115 @@ stdclass.inc
\end_inset \end_inset
, which contains most of the basic layouts. , which contains most of the basic layouts.
\change_inserted -712698321 1611646803
\end_layout
\begin_layout Description
\change_inserted -712698321 1611646804
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1611646837
InputGlobal
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1611646804
<filename>
\end_layout
\end_inset
] is a variant of the
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1611646804
Input
\end_layout
\end_inset
command which does not look for files in the user directory.
This allows to create a file
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1611646804
name.layout
\end_layout
\end_inset
or
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1611646804
name.inc
\end_layout
\end_inset
in the user directory which includes a global file with the same name via
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1611646853
InputGlobal name
\end_layout
\end_inset
or
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1611646855
InputGlobal name.inc
\end_layout
\end_inset
, respectively (with
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -712698321 1611646804
Input
\end_layout
\end_inset
, the file would recursively include itself).
This way, you can modify global files without having to completely copy
them.
\change_unchanged
\end_layout \end_layout
\begin_layout Description \begin_layout Description

View File

@ -1,5 +1,5 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/ #LyX 2.4 created this file. For more info see https://www.lyx.org/
\lyxformat 600 \lyxformat 605
\begin_document \begin_document
\begin_header \begin_header
\save_transient_properties true \save_transient_properties true
@ -117,7 +117,7 @@ logicalmkup
\branch OutDated \branch OutDated
\selected 0 \selected 0
\filename_suffix 0 \filename_suffix 0
\color #faf0e6 \color background background
\end_branch \end_branch
\index Stichwortverzeichnis \index Stichwortverzeichnis
\shortcut idx \shortcut idx
@ -8266,6 +8266,93 @@ stdclass.inc
\begin_inset Flex Code \begin_inset Flex Code
status collapsed status collapsed
\begin_layout Plain Layout
InputGlobal
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
<Dateiname>
\end_layout
\end_inset
] ist eine Variante des Befehls
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
Input
\end_layout
\end_inset
, die nicht nach Dateien im Benutzerverzeichnis sucht.
Das erlaubt es Ihnen, im Benutzerverzeichnis eine Datei
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
name.layout
\end_layout
\end_inset
oder
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
name.inc
\end_layout
\end_inset
anzulegen, die mit
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
InputGlobal name
\end_layout
\end_inset
bzw.
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
InputGlobal name.inc
\end_layout
\end_inset
eine globale Datei desselben Namens einbindet (mit
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
Input
\end_layout
\end_inset
würde die Datei sich selbst einbinden).
Damit können Sie globale Dateien modifizieren, ohne sie komplett kopieren
zu müssen.
\end_layout
\begin_layout Description
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout \begin_layout Plain Layout
InsetLayout InsetLayout
\end_layout \end_layout

View File

@ -11,7 +11,7 @@
# This script will update a .layout file to current format # This script will update a .layout file to current format
# The latest layout format is also defined in src/TextClass.cpp # The latest layout format is also defined in src/TextClass.cpp
currentFormat = 90 currentFormat = 91
# Incremented to format 4, 6 April 2007, lasgouttes # Incremented to format 4, 6 April 2007, lasgouttes
@ -307,6 +307,9 @@ currentFormat = 90
# Incremented to format 90, 11 December 2020 by spitz # Incremented to format 90, 11 December 2020 by spitz
# Use semantic label colors # Use semantic label colors
# Incremented to format 91, 25 January 2021 by spitz
# InputGlobal tag
# 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").
@ -557,7 +560,7 @@ def convert(lines, end_format):
i += 1 i += 1
continue continue
if 87 <= format <= 90: if 87 <= format <= 91:
# nothing to do. # nothing to do.
i += 1 i += 1
continue continue

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 = 90; // spitz: semantic label colors int const LAYOUT_FORMAT = 91; // spitz: InputGlobal method
// Layout format for the current lyx file format. Controls which format is // Layout format for the current lyx file format. Controls which format is
@ -165,6 +165,7 @@ enum TextClassTags {
TC_OUTPUTTYPE = 1, TC_OUTPUTTYPE = 1,
TC_OUTPUTFORMAT, TC_OUTPUTFORMAT,
TC_INPUT, TC_INPUT,
TC_INPUT_GLOBAL,
TC_STYLE, TC_STYLE,
TC_MODIFYSTYLE, TC_MODIFYSTYLE,
TC_PROVIDESTYLE, TC_PROVIDESTYLE,
@ -249,6 +250,7 @@ LexerKeyword textClassTags[] = {
{ "htmltocsection", TC_HTMLTOCSECTION }, { "htmltocsection", TC_HTMLTOCSECTION },
{ "ifcounter", TC_IFCOUNTER }, { "ifcounter", TC_IFCOUNTER },
{ "input", TC_INPUT }, { "input", TC_INPUT },
{ "inputglobal", TC_INPUT_GLOBAL },
{ "insetlayout", TC_INSETLAYOUT }, { "insetlayout", TC_INSETLAYOUT },
{ "leftmargin", TC_LEFTMARGIN }, { "leftmargin", TC_LEFTMARGIN },
{ "maxcitenames", TC_MAXCITENAMES }, { "maxcitenames", TC_MAXCITENAMES },
@ -432,6 +434,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
bool modifystyle = false; bool modifystyle = false;
bool providestyle = false; bool providestyle = false;
bool ifcounter = false; bool ifcounter = false;
bool only_global = false;
switch (static_cast<TextClassTags>(le)) { switch (static_cast<TextClassTags>(le)) {
@ -459,6 +462,9 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
} }
break; break;
case TC_INPUT_GLOBAL:
only_global = true;
// fall through
case TC_INPUT: // Include file case TC_INPUT: // Include file
if (lexrc.next()) { if (lexrc.next()) {
FileName tmp; FileName tmp;
@ -466,9 +472,13 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
if (!path().empty() && (prefixIs(inc, "./") || if (!path().empty() && (prefixIs(inc, "./") ||
prefixIs(inc, "../"))) prefixIs(inc, "../")))
tmp = fileSearch(path(), inc, "layout"); tmp = fileSearch(path(), inc, "layout");
else else {
// InputGlobal only searches in the system and
// build directories. This allows to reuse and
// modify files in the user directory.
tmp = libFileSearch("layouts", inc, tmp = libFileSearch("layouts", inc,
"layout"); "layout", must_exist, only_global);
}
if (tmp.empty()) { if (tmp.empty()) {
lexrc.printError("Could not find input file: " + inc); lexrc.printError("Could not find input file: " + inc);

View File

@ -335,12 +335,16 @@ FileName const fileSearch(string const & path, string const & name,
// 2) build_lyxdir (if not empty) // 2) build_lyxdir (if not empty)
// 3) system_lyxdir // 3) system_lyxdir
FileName const libFileSearch(string const & dir, string const & name, FileName const libFileSearch(string const & dir, string const & name,
string const & ext, search_mode mode) string const & ext, search_mode mode,
bool const only_global)
{ {
FileName fullname = fileSearch(addPath(package().user_support().absFileName(), dir), FileName fullname;
if (!only_global) {
fullname = fileSearch(addPath(package().user_support().absFileName(), dir),
name, ext, mode); name, ext, mode);
if (!fullname.empty()) if (!fullname.empty())
return fullname; return fullname;
}
if (!package().build_support().empty()) if (!package().build_support().empty())
fullname = fileSearch(addPath(package().build_support().absFileName(), dir), fullname = fileSearch(addPath(package().build_support().absFileName(), dir),

View File

@ -118,12 +118,14 @@ bool isBinaryFile(FileName const & filename);
-# user_lyxdir -# user_lyxdir
-# build_lyxdir (if not empty) -# build_lyxdir (if not empty)
-# system_lyxdir -# system_lyxdir
The third parameter `ext' is optional. \p onlyglobal determines whether user_lyxdir should be included.
ext, search_mode and onlyglobal are optional.
*/ */
FileName const libFileSearch(std::string const & dir, FileName const libFileSearch(std::string const & dir,
std::string const & name, std::string const & name,
std::string const & ext = std::string(), std::string const & ext = std::string(),
search_mode mode = must_exist); search_mode mode = must_exist,
bool const onlyglobal = false);
/** Same as libFileSearch(), but tries first to find an /** Same as libFileSearch(), but tries first to find an
internationalized version of the file by prepending $LANG_ to the internationalized version of the file by prepending $LANG_ to the