#include "support/convert.h"
#include "support/debug.h"
#include "support/docstream.h"
+#include "support/FileName.h"
#include "support/FileNameList.h"
#include "support/filetools.h"
#include "support/gettext.h"
FileName const includedFileName(Buffer const & buffer,
InsetCommandParams const & params)
{
- return makeAbsPath(to_utf8(params["filename"]),
+ return makeAbsPath(ltrim(to_utf8(params["filename"])),
onlyPath(parentFileName(buffer)));
}
InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p)
: InsetCommand(buf, p), include_label(uniqueID()),
preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false),
- set_label_(false), label_(0), child_buffer_(0)
+ set_label_(false), label_(0), child_buffer_(0), file_exist_(false)
{
preview_->connect([=](){ fileChanged(); });
InsetInclude::InsetInclude(InsetInclude const & other)
: InsetCommand(other), include_label(other.include_label),
preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false),
- set_label_(false), label_(0), child_buffer_(0)
+ set_label_(false), label_(0), child_buffer_(0), file_exist_(other.file_exist_)
{
preview_->connect([=](){ fileChanged(); });
switch (cmd.action()) {
case LFUN_INSET_EDIT: {
- editIncluded(to_utf8(params()["filename"]));
+ editIncluded(ltrim(to_utf8(params()["filename"])));
break;
}
return true;
return (std::find(includeonlys.begin(),
includeonlys.end(),
- to_utf8(params()["filename"])) != includeonlys.end());
+ ltrim(to_utf8(params()["filename"]))) != includeonlys.end());
}
docstring InsetInclude::screenLabel() const
{
+ docstring pre = file_exist_ ? docstring() : _("FILE MISSING:");
+
docstring temp;
switch (type(params())) {
temp += ": ";
- if (params()["filename"].empty())
+ if (ltrim(params()["filename"]).empty())
temp += "???";
else
- temp += from_utf8(onlyFileName(to_utf8(params()["filename"])));
+ temp += from_utf8(onlyFileName(ltrim(to_utf8(params()["filename"]))));
- return temp;
+ return pre.empty() ? temp : pre + from_ascii(" ") + temp;
}
void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
{
- string incfile = to_utf8(params()["filename"]);
-
- // Do nothing if no file name has been specified
- if (incfile.empty())
+ string incfile = ltrim(to_utf8(params()["filename"]));
+
+ // Warn if no file name has been specified
+ if (incfile.empty()) {
+ frontend::Alert::warning(_("No file name specified"),
+ _("An included file name is empty.\n"
+ "Ignoring Inclusion"),
+ true);
return;
+ }
+ // Warn if file doesn't exist
+ if (!includedFileExist()) {
+ frontend::Alert::warning(_("Included file not found"),
+ bformat(_("The included file\n"
+ "'%1$s'\n"
+ "has not been found. LyX will ignore the inclusion."),
+ from_utf8(incfile)),
+ true);
+ return;
+ }
FileName const included_file = includedFileName(buffer(), params());
frontend::Alert::warning(_("Unsupported Inclusion"),
bformat(_("LyX does not know how to include non-LyX files when "
"generating HTML output. Offending file:\n%1$s"),
- params()["filename"]));
+ ltrim(params()["filename"])));
return docstring();
}
if (buffer().absFileName() == included_file.absFileName()) {
Alert::error(_("Recursive input"),
bformat(_("Attempted to include file %1$s in itself! "
- "Ignoring inclusion."), params()["filename"]));
+ "Ignoring inclusion."), ltrim(params()["filename"])));
return docstring();
}
// or are generating this for advanced search
if (op.for_tooltip || op.for_toc || op.for_search) {
os << '[' << screenLabel() << '\n'
- << getParam("filename") << "\n]";
+ << ltrim(getParam("filename")) << "\n]";
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
}
int InsetInclude::docbook(odocstream & os, OutputParams const & runparams) const
{
- string incfile = to_utf8(params()["filename"]);
+ string incfile = ltrim(to_utf8(params()["filename"]));
// Do nothing if no file name has been specified
if (incfile.empty())
{
LATTEST(&buffer() == &features.buffer());
- string incfile = to_utf8(params()["filename"]);
+ string incfile = ltrim(to_utf8(params()["filename"]));
string const included_file =
includedFileName(buffer(), params()).absFileName();
void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype)
{
+ file_exist_ = includedFileExist();
+
button_.update(screenLabel(), true, false);
Buffer const * const childbuffer = getChildBuffer();
}
+bool InsetInclude::includedFileExist() const
+{
+ // check whether the included file exist
+ string incFileName = ltrim(to_utf8(params()["filename"]));
+ FileName fn =
+ support::makeAbsPath(incFileName,
+ support::onlyPath(buffer().absFileName()));
+ return fn.exists();
+}
+
} // namespace lyx