Allow Input of local includes from local layout files

When including files, LyX always searches the user and the system
directory, in that order. This means that when using local layout
files broken down into multiple includes, the various includes should
be specified with a path relative to the user layouts directory
(typically ~/.lyx/layouts), making this very impractical.
This commit allows including local files by specifying their path
as explicitly relative to the main layout file position, i.e., by
specifying their path with either "./" or "../". If the main layout
is not loaded from a local file, the usual search order is used,
even if the path are explicitly relative. So, for system layouts,
both "Input ./name.inc" and "Input name.inc" are equivalent.
This commit is contained in:
Enrico Forestieri 2017-03-01 09:19:18 +01:00
parent 34d2f3cf06
commit 17ab47b3e6
3 changed files with 14 additions and 3 deletions

View File

@ -43,7 +43,8 @@ LayoutFile::LayoutFile(string const & fn, string const & cln,
string const & desc, string const & prereq, string const & desc, string const & prereq,
string const & category, bool texclassavail) string const & category, bool texclassavail)
{ {
name_ = fn; name_ = onlyFileName(fn);
path_ = fn.rfind('/') == string::npos ? string() : onlyPath(fn);
latexname_ = cln; latexname_ = cln;
description_ = desc; description_ = desc;
prerequisites_ = prereq; prerequisites_ = prereq;
@ -331,7 +332,8 @@ LayoutFileIndex LayoutFileList::addLocalLayout(
return string(); return string();
LayoutFile * tmpl = LayoutFile * tmpl =
new LayoutFile(textclass, class_name, textclass, class_prereq, category, true); new LayoutFile(addName(moved ? oldpath : path, textclass),
class_name, textclass, class_prereq, category, true);
//FIXME: The prerequisites are available from the layout file and //FIXME: The prerequisites are available from the layout file and
// can be extracted from the above regex, but for now this // can be extracted from the above regex, but for now this
// field is simply set to class_name + ".cls" // field is simply set to class_name + ".cls"

View File

@ -463,8 +463,13 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
case TC_INPUT: // Include file case TC_INPUT: // Include file
if (lexrc.next()) { if (lexrc.next()) {
FileName tmp;
string const inc = lexrc.getString(); string const inc = lexrc.getString();
FileName tmp = libFileSearch("layouts", inc, if (!path().empty() && (prefixIs(inc, "./") ||
prefixIs(inc, "../")))
tmp = fileSearch(path(), inc, "layout");
else
tmp = libFileSearch("layouts", inc,
"layout"); "layout");
if (tmp.empty()) { if (tmp.empty()) {

View File

@ -194,6 +194,8 @@ public:
/// ///
std::string const & name() const { return name_; } std::string const & name() const { return name_; }
/// ///
std::string const & path() const { return path_; }
///
std::string const & category() const { return category_; } std::string const & category() const { return category_; }
/// ///
std::string const & description() const { return description_; } std::string const & description() const { return description_; }
@ -242,6 +244,8 @@ protected:
mutable LayoutList layoutlist_; mutable LayoutList layoutlist_;
/// Layout file name /// Layout file name
std::string name_; std::string name_;
/// Layout file path (empty for system layout files)
std::string path_;
/// Class category /// Class category
std::string category_; std::string category_;
/// document class name /// document class name