2002-09-25 14:26:13 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetInclude.cpp
|
2002-09-25 14:26:13 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2007-10-23 18:51:04 +00:00
|
|
|
* \author Richard Heck (conversion to InsetCommand)
|
2002-09-25 14:26:13 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
#include <config.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetInclude.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "BufferList.h"
|
|
|
|
#include "BufferParams.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "BufferView.h"
|
2011-03-24 15:47:40 +00:00
|
|
|
#include "Converter.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
2010-11-28 14:20:45 +00:00
|
|
|
#include "Encoding.h"
|
2008-03-06 18:13:04 +00:00
|
|
|
#include "ErrorList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Exporter.h"
|
2008-04-27 18:03:21 +00:00
|
|
|
#include "Format.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
#include "FuncStatus.h"
|
2003-03-05 14:59:37 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "LayoutFile.h"
|
2009-02-12 15:07:22 +00:00
|
|
|
#include "LayoutModuleList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "LyX.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2012-03-19 21:33:47 +00:00
|
|
|
#include "output_plaintext.h"
|
2009-11-30 17:34:01 +00:00
|
|
|
#include "output_xhtml.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2008-02-15 14:30:08 +00:00
|
|
|
#include "TocBackend.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2007-04-28 20:44:46 +00:00
|
|
|
#include "frontends/alert.h"
|
2002-08-01 17:28:59 +00:00
|
|
|
#include "frontends/Painter.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2004-04-19 13:05:36 +00:00
|
|
|
#include "graphics/PreviewImage.h"
|
2003-10-10 21:08:55 +00:00
|
|
|
#include "graphics/PreviewLoader.h"
|
|
|
|
|
2008-03-07 13:33:33 +00:00
|
|
|
#include "insets/InsetLabel.h"
|
Add support for listings package. Two listings command \lstinline, \lstinputlisting and an environment \lstlisting are supported, along with preamble \lstset. \lstinputlisting is implemented through Include dialog, and the other two are implemented with a new inset listings, along with its dialog.
* src/LyXAction.cpp: listing-insert action
* src/insets/Inset.h,cpp: LISTINGS_CODE
* src/insets/InsetInclude.cpp: handle \lstinputlisting
* src/insets/InsetListings.h,cpp: new listings inset
* src/insets/InsetListingsParams.h,cpp: parameters from listings package
* src/insets/InsetCommandParams.h,cpp: handle lstinputlisting option
* src/Bidi.cpp: handle LISTINGS_CODE
* src/frontends/qt4/ui/TextLayoutUi.ui: update UI
* src/frontends/qt4/ui/ListingsUi.ui: new dialog
* src/frontends/qt4/ui/IncludeUi.ui: update UI
* src/frontends/qt4/QInclude.h,cpp: add lstinputlisting
* src/frontends/qt4/QDocument.h,cpp: add textedit for preamble listings_params
* src/frontends/qt4/QListings.h,cpp: new listings inset
* src/frontends/qt4/Dialogs.cpp: new listings dialog
* src/frontends/controllers/ControlInclude.h,cpp: add lstinputlisting
* src/frontends/controllers/ControlListings.h,cpp: new listings inset
* src/LyXFunc.cpp: handle LISTING_CODE
* src/Paragraph.cpp: handle LISTING_CODE
* src/factory.cpp: new listings inset
* src/CutAndPaste.cpp: handle LISTINGS_CODE
* src/LaTeXFeatures.cpp: require listings
* src/Text3.cpp: Handle LISTINGS_CODE
* src/lfuns.h: add LFUN_LISTING_INSERT
* src/Buffer.cpp: change lyx file format to 269
* src/BufferParams.h,cpp: add listings_params to preamble
* lib/lyx2lyx/LyX.py: lyx2lyx
* lib/lyx2lyx/lyx_1_5.py: lyx2lyx
* lib/ui/stdmenus.inc: new menu item (no shortcut!)
* src/insets/Makefile.am: update autotools
* src/frontends/controllers/Makefile.am
* src/frontends/qt4/Makefile.dialogs
* src/frontends/qt4/Makefile.am
* po/POTFILES.in: a few more translatable files.
* development/scons/scons_manifest.py: scons build system
* development/FORMAT: document format changes
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@18243 a592a061-630c-0410-9148-cb99ea01b6c8
2007-05-09 19:11:42 +00:00
|
|
|
#include "insets/InsetListingsParams.h"
|
2008-03-07 13:33:33 +00:00
|
|
|
#include "insets/RenderPreview.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2010-12-20 18:15:39 +00:00
|
|
|
#include "mathed/MacroTable.h"
|
|
|
|
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/convert.h"
|
2008-02-15 14:30:08 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2019-03-12 08:00:59 +00:00
|
|
|
#include "support/FileName.h"
|
2007-12-05 10:32:49 +00:00
|
|
|
#include "support/FileNameList.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "support/filetools.h"
|
2008-02-15 14:30:08 +00:00
|
|
|
#include "support/gettext.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/lassert.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
#include "support/lstrings.h" // contains
|
2006-10-11 19:40:50 +00:00
|
|
|
#include "support/lyxalgo.h"
|
2014-07-05 10:09:49 +00:00
|
|
|
#include "support/mutex.h"
|
2016-09-02 21:10:41 +00:00
|
|
|
#include "support/ExceptionMessage.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2010-04-22 11:16:58 +00:00
|
|
|
#include "support/bind.h"
|
2002-08-06 14:02:59 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2007-09-16 10:36:57 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace Alert = frontend::Alert;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2006-10-21 19:40:29 +00:00
|
|
|
docstring const uniqueID()
|
2001-03-23 17:09:34 +00:00
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
static unsigned int seed = 1000;
|
2014-07-05 10:09:49 +00:00
|
|
|
static Mutex mutex;
|
|
|
|
Mutex::Locker lock(&mutex);
|
2006-10-21 19:40:29 +00:00
|
|
|
return "file" + convert<docstring>(++seed);
|
2000-07-02 09:52:44 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 14:40:39 +00:00
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
/// the type of inclusion
|
|
|
|
enum Types {
|
2007-10-25 04:13:56 +00:00
|
|
|
INCLUDE, VERB, INPUT, VERBAST, LISTINGS, NONE
|
2007-10-23 15:02:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
Types type(string const & s)
|
2007-11-03 17:37:37 +00:00
|
|
|
{
|
2007-10-25 04:13:56 +00:00
|
|
|
if (s == "input")
|
2007-10-23 15:02:15 +00:00
|
|
|
return INPUT;
|
2007-10-25 04:13:56 +00:00
|
|
|
if (s == "verbatiminput")
|
2007-10-23 15:02:15 +00:00
|
|
|
return VERB;
|
2007-10-25 04:13:56 +00:00
|
|
|
if (s == "verbatiminput*")
|
2007-10-23 15:02:15 +00:00
|
|
|
return VERBAST;
|
2017-06-08 17:33:54 +00:00
|
|
|
if (s == "lstinputlisting" || s == "inputminted")
|
2007-10-23 15:02:15 +00:00
|
|
|
return LISTINGS;
|
2007-10-25 04:13:56 +00:00
|
|
|
if (s == "include")
|
|
|
|
return INCLUDE;
|
|
|
|
return NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Types type(InsetCommandParams const & params)
|
|
|
|
{
|
2007-11-03 17:37:37 +00:00
|
|
|
return type(params.getCmdName());
|
2007-10-23 15:02:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-18 14:40:39 +00:00
|
|
|
bool isListings(InsetCommandParams const & params)
|
|
|
|
{
|
2007-10-23 15:02:15 +00:00
|
|
|
return type(params) == LISTINGS;
|
2007-05-18 14:40:39 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
bool isVerbatim(InsetCommandParams const & params)
|
|
|
|
{
|
|
|
|
Types const t = type(params);
|
2007-10-23 18:51:04 +00:00
|
|
|
return t == VERB || t == VERBAST;
|
2007-10-23 15:02:15 +00:00
|
|
|
}
|
2000-07-02 09:52:44 +00:00
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
|
|
|
|
bool isInputOrInclude(InsetCommandParams const & params)
|
2003-10-09 19:27:07 +00:00
|
|
|
{
|
2007-10-23 15:02:15 +00:00
|
|
|
Types const t = type(params);
|
2015-05-17 15:27:12 +00:00
|
|
|
return t == INPUT || t == INCLUDE;
|
2003-10-09 19:27:07 +00:00
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2008-01-08 16:35:43 +00:00
|
|
|
|
|
|
|
FileName const masterFileName(Buffer const & buffer)
|
|
|
|
{
|
|
|
|
return buffer.masterBuffer()->fileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void add_preview(RenderMonitoredPreview &, InsetInclude const &, Buffer const &);
|
|
|
|
|
|
|
|
|
2010-04-21 01:19:36 +00:00
|
|
|
string const parentFileName(Buffer const & buffer)
|
2008-01-08 16:35:43 +00:00
|
|
|
{
|
|
|
|
return buffer.absFileName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-21 01:19:36 +00:00
|
|
|
FileName const includedFileName(Buffer const & buffer,
|
2008-01-08 16:35:43 +00:00
|
|
|
InsetCommandParams const & params)
|
|
|
|
{
|
2019-03-12 08:00:59 +00:00
|
|
|
return makeAbsPath(ltrim(to_utf8(params["filename"])),
|
2010-04-21 01:19:36 +00:00
|
|
|
onlyPath(parentFileName(buffer)));
|
2008-01-08 16:35:43 +00:00
|
|
|
}
|
|
|
|
|
2008-04-20 03:08:11 +00:00
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetLabel * createLabel(Buffer * buf, docstring const & label_str)
|
2008-03-07 13:33:33 +00:00
|
|
|
{
|
|
|
|
if (label_str.empty())
|
|
|
|
return 0;
|
|
|
|
InsetCommandParams icp(LABEL_CODE);
|
|
|
|
icp["name"] = label_str;
|
2009-11-08 16:10:34 +00:00
|
|
|
return new InsetLabel(buf, icp);
|
2008-03-07 13:33:33 +00:00
|
|
|
}
|
|
|
|
|
2019-02-04 09:49:02 +00:00
|
|
|
|
|
|
|
char_type replaceCommaInBraces(docstring & params)
|
|
|
|
{
|
|
|
|
// Code point from private use area
|
|
|
|
char_type private_char = 0xE000;
|
|
|
|
int count = 0;
|
|
|
|
for (char_type & c : params) {
|
|
|
|
if (c == '{')
|
|
|
|
++count;
|
|
|
|
else if (c == '}')
|
|
|
|
--count;
|
|
|
|
else if (c == ',' && count)
|
|
|
|
c = private_char;
|
|
|
|
}
|
|
|
|
return private_char;
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
|
2009-11-08 16:10:34 +00:00
|
|
|
InsetInclude::InsetInclude(Buffer * buf, InsetCommandParams const & p)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, p), include_label(uniqueID()),
|
2017-03-09 21:44:07 +00:00
|
|
|
preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false),
|
2019-03-12 08:00:59 +00:00
|
|
|
set_label_(false), label_(0), child_buffer_(0), file_exist_(false)
|
2003-10-09 19:27:07 +00:00
|
|
|
{
|
2017-03-09 21:44:07 +00:00
|
|
|
preview_->connect([=](){ fileChanged(); });
|
2008-03-07 13:33:33 +00:00
|
|
|
|
|
|
|
if (isListings(params())) {
|
|
|
|
InsetListingsParams listing_params(to_utf8(p["lstparams"]));
|
2009-11-08 16:10:34 +00:00
|
|
|
label_ = createLabel(buffer_, from_utf8(listing_params.getParamValue("label")));
|
2010-12-20 18:15:39 +00:00
|
|
|
} else if (isInputOrInclude(params()) && buf)
|
|
|
|
loadIfNeeded();
|
2003-10-09 19:27:07 +00:00
|
|
|
}
|
2003-06-12 08:52:36 +00:00
|
|
|
|
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
InsetInclude::InsetInclude(InsetInclude const & other)
|
|
|
|
: InsetCommand(other), include_label(other.include_label),
|
2017-03-09 21:44:07 +00:00
|
|
|
preview_(make_unique<RenderMonitoredPreview>(this)), failedtoload_(false),
|
2019-03-12 08:00:59 +00:00
|
|
|
set_label_(false), label_(0), child_buffer_(0), file_exist_(other.file_exist_)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2017-03-09 21:44:07 +00:00
|
|
|
preview_->connect([=](){ fileChanged(); });
|
2008-03-07 13:33:33 +00:00
|
|
|
|
|
|
|
if (other.label_)
|
|
|
|
label_ = new InsetLabel(*other.label_);
|
2003-03-05 14:59:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 20:58:59 +00:00
|
|
|
InsetInclude::~InsetInclude()
|
|
|
|
{
|
2008-03-07 13:36:39 +00:00
|
|
|
delete label_;
|
2008-03-06 20:58:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-07 13:33:33 +00:00
|
|
|
void InsetInclude::setBuffer(Buffer & buffer)
|
|
|
|
{
|
2008-03-27 04:35:26 +00:00
|
|
|
InsetCommand::setBuffer(buffer);
|
2008-03-07 13:33:33 +00:00
|
|
|
if (label_)
|
|
|
|
label_->setBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-09 14:47:47 +00:00
|
|
|
void InsetInclude::setChildBuffer(Buffer * buffer)
|
|
|
|
{
|
|
|
|
child_buffer_ = buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-23 22:01:02 +00:00
|
|
|
ParamInfo const & InsetInclude::findInfo(string const & /* cmdName */)
|
2007-10-25 04:13:56 +00:00
|
|
|
{
|
2007-11-30 22:16:02 +00:00
|
|
|
// FIXME
|
2007-11-03 17:37:37 +00:00
|
|
|
// This is only correct for the case of listings, but it'll do for now.
|
|
|
|
// In the other cases, this second parameter should just be empty.
|
2008-02-23 22:01:02 +00:00
|
|
|
static ParamInfo param_info_;
|
|
|
|
if (param_info_.empty()) {
|
Per Abdel's suggestion that we focus on bug-fixing at this point, this will be the last patch in this series for a bit. But I wanted to get this done before I forget what it is I was doing, so here it is.
The idea behind this patch is to make real key-value support for InsetCommand parameters possible. This should be particularly useful for the listings version of InsetInclude, though we would need some kind of UI for it before it would really be helpful. (See below for some thoughts.) This doesn't substantially change anything else, though some things do get re-arranged a bit.
Basically, the idea is this. First, we introduce a whole range of parameter types: Normal LaTeX optional and required parameters; ones for LyX's internal use (like embed); and finally, in connection with keyval, ones that represent keys and ones that represent optional and required arguments where the keyval stuff will appear. (I'm assuming here that there will always be exactly one of those, and that it will accept only keyval-type material.) The parameters themselves are stored in a map, so it's really only the output routines that need to care about the different types of parameters.
Regarding the frontend, it seems to me that something like the following would work:
(i) scan the parameter list for LATEX_KEY type parameters
(ii) the dialog will have a series of lines, each of which has a combo box listing the acceptable keys and a QLineEdit for entering its value, as well as a "delete" button of some sort for removing this key and its value
(iii) there should be an "add line" button to add a new line, activated only when all other lines are filled with values
Probably not even too hard.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23235 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-25 22:13:45 +00:00
|
|
|
param_info_.add("filename", ParamInfo::LATEX_REQUIRED);
|
|
|
|
param_info_.add("lstparams", ParamInfo::LATEX_OPTIONAL);
|
2018-02-23 07:58:16 +00:00
|
|
|
param_info_.add("literal", ParamInfo::LYX_INTERNAL);
|
2008-02-23 22:01:02 +00:00
|
|
|
}
|
|
|
|
return param_info_;
|
2007-10-25 04:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
bool InsetInclude::isCompatibleCommand(string const & s)
|
2007-11-03 17:37:37 +00:00
|
|
|
{
|
2007-10-25 04:13:56 +00:00
|
|
|
return type(s) != NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-04 09:56:42 +00:00
|
|
|
bool InsetInclude::needsCProtection(bool const /*maintext*/, bool const fragile) const
|
|
|
|
{
|
|
|
|
// We need to \cprotect all types in fragile context
|
|
|
|
return fragile;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetInclude::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-03-05 14:59:37 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
2008-04-27 18:03:21 +00:00
|
|
|
case LFUN_INSET_EDIT: {
|
2019-03-12 08:00:59 +00:00
|
|
|
editIncluded(ltrim(to_utf8(params()["filename"])));
|
2008-04-27 18:03:21 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
2010-08-09 17:01:51 +00:00
|
|
|
// It should be OK just to invalidate the cache in setParams()
|
2009-03-25 12:23:07 +00:00
|
|
|
// If not....
|
|
|
|
// child_buffer_ = 0;
|
2007-10-19 17:22:55 +00:00
|
|
|
InsetCommandParams p(INCLUDE_CODE);
|
2008-04-27 15:49:15 +00:00
|
|
|
if (cmd.getArg(0) == "changetype") {
|
2010-11-29 09:47:46 +00:00
|
|
|
cur.recordUndo();
|
2008-04-27 15:49:15 +00:00
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
|
|
|
p = params();
|
|
|
|
} else
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(to_utf8(cmd.argument()), p);
|
2006-04-15 11:46:17 +00:00
|
|
|
if (!p.getCmdName().empty()) {
|
2007-05-18 14:40:39 +00:00
|
|
|
if (isListings(p)){
|
2008-03-07 13:33:33 +00:00
|
|
|
InsetListingsParams new_params(to_utf8(p["lstparams"]));
|
2008-09-30 08:41:37 +00:00
|
|
|
docstring const new_label =
|
|
|
|
from_utf8(new_params.getParamValue("label"));
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2009-02-19 20:53:35 +00:00
|
|
|
if (new_label.empty()) {
|
2008-03-07 13:33:33 +00:00
|
|
|
delete label_;
|
2009-02-19 20:53:35 +00:00
|
|
|
label_ = 0;
|
2009-02-19 21:33:07 +00:00
|
|
|
} else {
|
|
|
|
docstring old_label;
|
2017-07-03 17:53:14 +00:00
|
|
|
if (label_)
|
2009-02-19 21:33:07 +00:00
|
|
|
old_label = label_->getParam("name");
|
|
|
|
else {
|
2009-11-08 16:10:34 +00:00
|
|
|
label_ = createLabel(buffer_, new_label);
|
2009-02-19 21:33:07 +00:00
|
|
|
label_->setBuffer(buffer());
|
2017-07-03 17:53:14 +00:00
|
|
|
}
|
2009-02-19 21:33:07 +00:00
|
|
|
|
|
|
|
if (new_label != old_label) {
|
2011-07-06 17:40:51 +00:00
|
|
|
label_->updateLabelAndRefs(new_label, &cur);
|
2009-02-19 21:33:07 +00:00
|
|
|
// the label might have been adapted (duplicate)
|
|
|
|
if (new_label != label_->getParam("name")) {
|
2017-07-03 17:53:14 +00:00
|
|
|
new_params.addParam("label", "{" +
|
2009-02-19 21:33:07 +00:00
|
|
|
to_utf8(label_->getParam("name")) + "}", true);
|
|
|
|
p["lstparams"] = from_utf8(new_params.params());
|
|
|
|
}
|
2008-09-30 08:41:37 +00:00
|
|
|
}
|
2008-03-07 13:33:33 +00:00
|
|
|
}
|
2007-05-18 14:40:39 +00:00
|
|
|
}
|
2010-12-08 09:24:04 +00:00
|
|
|
cur.recordUndo();
|
2008-02-27 20:43:16 +00:00
|
|
|
setParams(p);
|
2010-07-09 14:37:00 +00:00
|
|
|
cur.forceBufferUpdate();
|
2006-04-15 11:46:17 +00:00
|
|
|
} else
|
2010-07-08 20:04:35 +00:00
|
|
|
cur.noScreenUpdate();
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
2019-04-27 01:59:52 +00:00
|
|
|
case LFUN_MOUSE_RELEASE: {
|
|
|
|
if (cmd.modifier() == ControlModifier) {
|
|
|
|
FileName const incfile = includedFileName(buffer(), params());
|
|
|
|
string const & incname = incfile.absFileName();
|
|
|
|
editIncluded(incname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
//pass everything else up the chain
|
2003-03-07 15:58:02 +00:00
|
|
|
default:
|
2007-10-23 15:02:15 +00:00
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-03-07 15:58:02 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
2019-04-27 01:51:48 +00:00
|
|
|
void InsetInclude::editIncluded(string const & f)
|
2008-04-27 18:03:21 +00:00
|
|
|
{
|
2019-04-27 01:51:48 +00:00
|
|
|
if (isLyXFileName(f)) {
|
|
|
|
FuncRequest fr(LFUN_BUFFER_CHILD_OPEN, f);
|
2008-04-27 18:03:21 +00:00
|
|
|
lyx::dispatch(fr);
|
|
|
|
} else
|
|
|
|
// tex file or other text file in verbatim mode
|
2017-03-14 03:33:40 +00:00
|
|
|
theFormats().edit(buffer(),
|
2019-04-27 01:51:48 +00:00
|
|
|
support::makeAbsPath(f, support::onlyPath(buffer().absFileName())),
|
2008-04-27 18:03:21 +00:00
|
|
|
"text");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetInclude::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2008-04-27 18:03:21 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_EDIT:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2008-04-27 18:03:21 +00:00
|
|
|
return true;
|
|
|
|
|
2009-06-29 12:41:43 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (cmd.getArg(0) == "changetype")
|
|
|
|
return InsetCommand::getStatus(cur, cmd, flag);
|
|
|
|
else
|
|
|
|
flag.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
|
2008-04-27 18:03:21 +00:00
|
|
|
default:
|
|
|
|
return InsetCommand::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetInclude::setParams(InsetCommandParams const & p)
|
2001-03-23 17:09:34 +00:00
|
|
|
{
|
2009-03-25 12:23:07 +00:00
|
|
|
// invalidate the cache
|
|
|
|
child_buffer_ = 0;
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCommand::setParams(p);
|
2003-09-19 10:16:33 +00:00
|
|
|
set_label_ = false;
|
2001-03-23 17:09:34 +00:00
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
if (preview_->monitoring())
|
|
|
|
preview_->stopMonitoring();
|
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
if (type(params()) == INPUT)
|
2008-02-27 20:43:16 +00:00
|
|
|
add_preview(*preview_, *this, buffer());
|
2001-03-14 10:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-10 15:10:40 +00:00
|
|
|
bool InsetInclude::isChildIncluded() const
|
|
|
|
{
|
|
|
|
std::list<std::string> includeonlys =
|
|
|
|
buffer().params().getIncludedChildren();
|
|
|
|
if (includeonlys.empty())
|
|
|
|
return true;
|
|
|
|
return (std::find(includeonlys.begin(),
|
|
|
|
includeonlys.end(),
|
2019-03-12 08:00:59 +00:00
|
|
|
ltrim(to_utf8(params()["filename"]))) != includeonlys.end());
|
2010-01-10 15:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetInclude::screenLabel() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2019-03-12 08:00:59 +00:00
|
|
|
docstring pre = file_exist_ ? docstring() : _("FILE MISSING:");
|
|
|
|
|
2006-09-09 15:27:44 +00:00
|
|
|
docstring temp;
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
switch (type(params())) {
|
2006-09-09 15:27:44 +00:00
|
|
|
case INPUT:
|
2008-02-27 20:43:16 +00:00
|
|
|
temp = buffer().B_("Input");
|
2006-09-09 15:27:44 +00:00
|
|
|
break;
|
|
|
|
case VERB:
|
2019-07-11 20:20:03 +00:00
|
|
|
temp = buffer().B_("Verbatim");
|
2006-09-09 15:27:44 +00:00
|
|
|
break;
|
|
|
|
case VERBAST:
|
2019-07-11 20:20:03 +00:00
|
|
|
temp = buffer().B_("Verbatim*");
|
2006-09-09 15:27:44 +00:00
|
|
|
break;
|
|
|
|
case INCLUDE:
|
2010-01-10 15:10:40 +00:00
|
|
|
if (isChildIncluded())
|
|
|
|
temp = buffer().B_("Include");
|
|
|
|
else
|
|
|
|
temp += buffer().B_("Include (excluded)");
|
2006-09-09 15:27:44 +00:00
|
|
|
break;
|
2007-10-25 04:13:56 +00:00
|
|
|
case LISTINGS:
|
2007-08-12 21:43:58 +00:00
|
|
|
temp = listings_label_;
|
2007-11-13 01:06:49 +00:00
|
|
|
break;
|
2007-10-25 04:13:56 +00:00
|
|
|
case NONE:
|
2013-04-25 21:27:10 +00:00
|
|
|
LASSERT(false, temp = buffer().B_("Unknown"));
|
|
|
|
break;
|
2001-03-14 10:57:39 +00:00
|
|
|
}
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
temp += ": ";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2019-03-12 08:00:59 +00:00
|
|
|
if (ltrim(params()["filename"]).empty())
|
2006-10-11 19:40:50 +00:00
|
|
|
temp += "???";
|
2001-03-14 10:57:39 +00:00
|
|
|
else
|
2019-03-12 08:00:59 +00:00
|
|
|
temp += from_utf8(onlyFileName(ltrim(to_utf8(params()["filename"]))));
|
2001-03-14 10:57:39 +00:00
|
|
|
|
2019-03-12 08:00:59 +00:00
|
|
|
return pre.empty() ? temp : pre + from_ascii(" ") + temp;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-26 00:48:32 +00:00
|
|
|
Buffer * InsetInclude::getChildBuffer() const
|
2006-05-19 07:21:43 +00:00
|
|
|
{
|
2017-07-03 17:53:14 +00:00
|
|
|
Buffer * childBuffer = loadIfNeeded();
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2014-02-23 11:33:15 +00:00
|
|
|
// FIXME RECURSIVE INCLUDE
|
|
|
|
// This isn't sufficient, as the inclusion could be downstream.
|
|
|
|
// But it'll have to do for now.
|
2009-03-26 00:48:32 +00:00
|
|
|
return (childBuffer == &buffer()) ? 0 : childBuffer;
|
2006-05-19 07:21:43 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
2009-03-26 00:48:32 +00:00
|
|
|
Buffer * InsetInclude::loadIfNeeded() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2010-03-08 14:25:32 +00:00
|
|
|
// This is for background export and preview. We don't even want to
|
|
|
|
// try to load the cloned child document again.
|
|
|
|
if (buffer().isClone())
|
2010-01-09 14:47:47 +00:00
|
|
|
return child_buffer_;
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2009-03-25 12:23:07 +00:00
|
|
|
// Don't try to load it again if we failed before.
|
2009-06-19 15:11:33 +00:00
|
|
|
if (failedtoload_ || isVerbatim(params()) || isListings(params()))
|
2008-11-24 12:45:18 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-04-21 01:19:36 +00:00
|
|
|
FileName const included_file = includedFileName(buffer(), params());
|
2009-03-25 12:23:07 +00:00
|
|
|
// Use cached Buffer if possible.
|
|
|
|
if (child_buffer_ != 0) {
|
2010-03-08 14:25:32 +00:00
|
|
|
if (theBufferList().isLoaded(child_buffer_)
|
2017-09-27 16:05:58 +00:00
|
|
|
// additional sanity check: make sure the Buffer really is
|
2010-03-08 14:25:32 +00:00
|
|
|
// associated with the file we want.
|
|
|
|
&& child_buffer_ == theBufferList().getBuffer(included_file))
|
2009-03-25 12:23:07 +00:00
|
|
|
return child_buffer_;
|
|
|
|
// Buffer vanished, so invalidate cache and try to reload.
|
|
|
|
child_buffer_ = 0;
|
|
|
|
}
|
|
|
|
|
2010-04-21 01:19:31 +00:00
|
|
|
if (!isLyXFileName(included_file.absFileName()))
|
2007-08-13 19:40:54 +00:00
|
|
|
return 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2008-07-29 08:16:09 +00:00
|
|
|
Buffer * child = theBufferList().getBuffer(included_file);
|
2007-08-21 07:33:46 +00:00
|
|
|
if (!child) {
|
2004-03-25 10:12:44 +00:00
|
|
|
// the readonly flag can/will be wrong, not anymore I think.
|
2007-10-18 19:29:32 +00:00
|
|
|
if (!included_file.exists())
|
2007-08-21 07:33:46 +00:00
|
|
|
return 0;
|
|
|
|
|
2010-04-21 01:19:09 +00:00
|
|
|
child = theBufferList().newBuffer(included_file.absFileName());
|
2007-12-17 18:37:13 +00:00
|
|
|
if (!child)
|
|
|
|
// Buffer creation is not possible.
|
|
|
|
return 0;
|
|
|
|
|
2010-12-20 18:15:39 +00:00
|
|
|
// Set parent before loading, such that macros can be tracked
|
|
|
|
child->setParent(&buffer());
|
|
|
|
|
2010-11-05 21:21:01 +00:00
|
|
|
if (child->loadLyXFile() != Buffer::ReadSuccess) {
|
2008-11-24 12:45:18 +00:00
|
|
|
failedtoload_ = true;
|
2010-12-20 18:15:39 +00:00
|
|
|
child->setParent(0);
|
2007-08-21 07:33:46 +00:00
|
|
|
//close the buffer we just opened
|
2007-12-04 22:21:25 +00:00
|
|
|
theBufferList().release(child);
|
2007-08-21 07:33:46 +00:00
|
|
|
return 0;
|
2007-07-10 15:07:00 +00:00
|
|
|
}
|
2010-12-20 18:15:39 +00:00
|
|
|
|
2008-03-06 18:13:04 +00:00
|
|
|
if (!child->errorList("Parse").empty()) {
|
|
|
|
// FIXME: Do something.
|
|
|
|
}
|
2010-12-20 18:15:39 +00:00
|
|
|
} else {
|
|
|
|
// The file was already loaded, so, simply
|
|
|
|
// inform parent buffer about local macros.
|
2010-12-21 14:52:18 +00:00
|
|
|
Buffer const * parent = &buffer();
|
2010-12-20 18:15:39 +00:00
|
|
|
child->setParent(parent);
|
|
|
|
MacroNameSet macros;
|
|
|
|
child->listMacroNames(macros);
|
|
|
|
MacroNameSet::const_iterator cit = macros.begin();
|
|
|
|
MacroNameSet::const_iterator end = macros.end();
|
|
|
|
for (; cit != end; ++cit)
|
|
|
|
parent->usermacros.insert(*cit);
|
2004-03-25 10:12:44 +00:00
|
|
|
}
|
2010-12-20 18:15:39 +00:00
|
|
|
|
2009-03-25 12:23:07 +00:00
|
|
|
// Cache the child buffer.
|
|
|
|
child_buffer_ = child;
|
2007-08-21 07:33:46 +00:00
|
|
|
return child;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetInclude::latex(otexstream & os, OutputParams const & runparams) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2019-03-12 08:00:59 +00:00
|
|
|
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);
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2019-03-12 08:00:59 +00:00
|
|
|
}
|
|
|
|
// 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;
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2010-04-21 01:19:36 +00:00
|
|
|
FileName const included_file = includedFileName(buffer(), params());
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
// Check we're not trying to include ourselves.
|
|
|
|
// FIXME RECURSIVE INCLUDE
|
|
|
|
// This isn't sufficient, as the inclusion could be downstream.
|
|
|
|
// But it'll have to do for now.
|
2007-10-23 15:02:15 +00:00
|
|
|
if (isInputOrInclude(params()) &&
|
2010-04-21 01:19:09 +00:00
|
|
|
buffer().absFileName() == included_file.absFileName())
|
2007-05-24 17:17:04 +00:00
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
Alert::error(_("Recursive input"),
|
|
|
|
bformat(_("Attempted to include file %1$s in itself! "
|
|
|
|
"Ignoring inclusion."), from_utf8(incfile)));
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2007-05-21 15:34:29 +00:00
|
|
|
}
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
Buffer const * const masterBuffer = buffer().masterBuffer();
|
2004-03-25 10:12:44 +00:00
|
|
|
|
|
|
|
// if incfile is relative, make it relative to the master
|
|
|
|
// buffer directory.
|
2009-05-02 17:12:31 +00:00
|
|
|
if (!FileName::isAbsolute(incfile)) {
|
2007-03-27 07:24:16 +00:00
|
|
|
// FIXME UNICODE
|
2010-04-21 01:19:09 +00:00
|
|
|
incfile = to_utf8(makeRelPath(from_utf8(included_file.absFileName()),
|
2007-10-20 10:03:45 +00:00
|
|
|
from_utf8(masterBuffer->filePath())));
|
2004-03-25 10:12:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-15 01:07:49 +00:00
|
|
|
string exppath = incfile;
|
|
|
|
if (!runparams.export_folder.empty()) {
|
|
|
|
exppath = makeAbsPath(exppath, runparams.export_folder).realPath();
|
|
|
|
FileName(exppath).onlyPath().createPath();
|
|
|
|
}
|
|
|
|
|
2004-03-25 10:12:44 +00:00
|
|
|
// write it to a file (so far the complete file)
|
2009-01-11 21:38:04 +00:00
|
|
|
string exportfile;
|
|
|
|
string mangled;
|
2009-01-11 22:55:16 +00:00
|
|
|
// bug 5681
|
2009-01-11 21:38:04 +00:00
|
|
|
if (type(params()) == LISTINGS) {
|
2011-09-15 01:07:49 +00:00
|
|
|
exportfile = exppath;
|
2010-04-21 01:19:22 +00:00
|
|
|
mangled = DocFileName(included_file).mangledFileName();
|
2009-01-11 21:38:04 +00:00
|
|
|
} else {
|
2011-09-15 01:07:49 +00:00
|
|
|
exportfile = changeExtension(exppath, ".tex");
|
2010-04-21 01:19:09 +00:00
|
|
|
mangled = DocFileName(changeExtension(included_file.absFileName(), ".tex")).
|
2010-04-21 01:19:22 +00:00
|
|
|
mangledFileName();
|
2009-01-11 21:38:04 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 23:07:48 +00:00
|
|
|
if (!runparams.nice)
|
2013-03-04 23:12:11 +00:00
|
|
|
incfile = mangled;
|
2013-11-12 19:52:35 +00:00
|
|
|
else if (!runparams.silent)
|
|
|
|
; // no warning wanted
|
2013-03-04 23:07:48 +00:00
|
|
|
else if (!isValidLaTeXFileName(incfile)) {
|
|
|
|
frontend::Alert::warning(_("Invalid filename"),
|
|
|
|
_("The following filename will cause troubles "
|
|
|
|
"when running the exported file through LaTeX: ") +
|
|
|
|
from_utf8(incfile));
|
2013-03-04 23:12:11 +00:00
|
|
|
} else if (!isValidDVIFileName(incfile)) {
|
2013-03-04 23:07:48 +00:00
|
|
|
frontend::Alert::warning(_("Problematic filename for DVI"),
|
|
|
|
_("The following filename can cause troubles "
|
|
|
|
"when running the exported file through LaTeX "
|
|
|
|
"and opening the resulting DVI: ") +
|
|
|
|
from_utf8(incfile), true);
|
|
|
|
}
|
|
|
|
|
2015-06-02 15:23:52 +00:00
|
|
|
FileName const writefile(makeAbsPath(mangled, runparams.for_preview ?
|
|
|
|
buffer().temppath() : masterBuffer->temppath()));
|
2004-03-25 10:12:44 +00:00
|
|
|
|
2013-03-04 23:07:48 +00:00
|
|
|
LYXERR(Debug::LATEX, "incfile:" << incfile);
|
|
|
|
LYXERR(Debug::LATEX, "exportfile:" << exportfile);
|
|
|
|
LYXERR(Debug::LATEX, "writefile:" << writefile);
|
|
|
|
|
2013-02-21 16:38:36 +00:00
|
|
|
string const tex_format = flavor2format(runparams.flavor);
|
|
|
|
|
|
|
|
switch (type(params())) {
|
|
|
|
case VERB:
|
|
|
|
case VERBAST: {
|
|
|
|
incfile = latex_path(incfile);
|
|
|
|
// FIXME UNICODE
|
|
|
|
os << '\\' << from_ascii(params().getCmdName()) << '{'
|
|
|
|
<< from_utf8(incfile) << '}';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case INPUT: {
|
|
|
|
runparams.exportdata->addExternalFile(tex_format, writefile,
|
|
|
|
exportfile);
|
|
|
|
|
|
|
|
// \input wants file with extension (default is .tex)
|
|
|
|
if (!isLyXFileName(included_file.absFileName())) {
|
|
|
|
incfile = latex_path(incfile);
|
|
|
|
// FIXME UNICODE
|
|
|
|
os << '\\' << from_ascii(params().getCmdName())
|
|
|
|
<< '{' << from_utf8(incfile) << '}';
|
|
|
|
} else {
|
|
|
|
incfile = changeExtension(incfile, ".tex");
|
|
|
|
incfile = latex_path(incfile);
|
|
|
|
// FIXME UNICODE
|
|
|
|
os << '\\' << from_ascii(params().getCmdName())
|
|
|
|
<< '{' << from_utf8(incfile) << '}';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LISTINGS: {
|
2017-06-08 17:33:54 +00:00
|
|
|
// Here, listings and minted have sligthly different behaviors.
|
|
|
|
// Using listings, it is always possible to have a caption,
|
|
|
|
// even for non-floats. Using minted, only floats can have a
|
|
|
|
// caption. So, with minted we use the following strategy.
|
2017-06-10 16:43:23 +00:00
|
|
|
// If a caption was specified but the float parameter was not,
|
|
|
|
// we ourselves add a caption above the listing (because the
|
|
|
|
// listing comes from a file and might span several pages).
|
|
|
|
// Otherwise, if float was specified, the floating listing
|
|
|
|
// environment provided by minted is used. In either case, the
|
2017-06-08 17:33:54 +00:00
|
|
|
// label parameter is taken as the label by which the float
|
|
|
|
// can be referenced, otherwise it will have the meaning
|
|
|
|
// intended by minted. In this last case, the label will
|
|
|
|
// serve as a sort of caption that, however, will be shown
|
|
|
|
// by minted only if the frame parameter is also specified.
|
|
|
|
bool const use_minted = buffer().params().use_minted;
|
2013-02-21 16:38:36 +00:00
|
|
|
runparams.exportdata->addExternalFile(tex_format, writefile,
|
|
|
|
exportfile);
|
|
|
|
string const opt = to_utf8(params()["lstparams"]);
|
|
|
|
// opt is set in QInclude dialog and should have passed validation.
|
2017-06-08 17:33:54 +00:00
|
|
|
InsetListingsParams lstparams(opt);
|
2018-02-19 16:15:31 +00:00
|
|
|
docstring parameters = from_utf8(lstparams.params());
|
|
|
|
docstring language;
|
|
|
|
docstring caption;
|
|
|
|
docstring label;
|
|
|
|
docstring placement;
|
2017-06-10 16:43:23 +00:00
|
|
|
bool isfloat = lstparams.isFloat();
|
2019-02-04 09:49:02 +00:00
|
|
|
// We are going to split parameters at commas, so
|
|
|
|
// replace commas that are not parameter separators
|
|
|
|
// with a code point from the private use area
|
|
|
|
char_type comma = replaceCommaInBraces(parameters);
|
2018-02-19 16:15:31 +00:00
|
|
|
// Get float placement, language, caption, and
|
|
|
|
// label, then remove the relative options if minted.
|
|
|
|
vector<docstring> opts =
|
|
|
|
getVectorFromString(parameters, from_ascii(","), false);
|
|
|
|
vector<docstring> latexed_opts;
|
|
|
|
for (size_t i = 0; i < opts.size(); ++i) {
|
2019-02-04 09:49:02 +00:00
|
|
|
// Restore replaced commas
|
|
|
|
opts[i] = subst(opts[i], comma, ',');
|
2018-02-19 16:15:31 +00:00
|
|
|
if (use_minted && prefixIs(opts[i], from_ascii("float"))) {
|
|
|
|
if (prefixIs(opts[i], from_ascii("float=")))
|
|
|
|
placement = opts[i].substr(6);
|
|
|
|
opts.erase(opts.begin() + i--);
|
|
|
|
} else if (use_minted && prefixIs(opts[i], from_ascii("language="))) {
|
|
|
|
language = opts[i].substr(9);
|
|
|
|
opts.erase(opts.begin() + i--);
|
|
|
|
} else if (prefixIs(opts[i], from_ascii("caption="))) {
|
2018-03-17 17:28:54 +00:00
|
|
|
caption = params().prepareCommand(runparams, trim(opts[i].substr(8), "{}"),
|
2018-02-23 07:58:16 +00:00
|
|
|
ParamInfo::HANDLING_LATEXIFY);
|
2018-02-19 16:15:31 +00:00
|
|
|
opts.erase(opts.begin() + i--);
|
|
|
|
if (!use_minted)
|
2019-02-05 18:04:12 +00:00
|
|
|
latexed_opts.push_back(from_ascii("caption={") + caption + "}");
|
2018-02-19 16:15:31 +00:00
|
|
|
} else if (prefixIs(opts[i], from_ascii("label="))) {
|
|
|
|
label = params().prepareCommand(runparams, trim(opts[i].substr(6), "{}"),
|
|
|
|
ParamInfo::HANDLING_ESCAPE);
|
|
|
|
opts.erase(opts.begin() + i--);
|
|
|
|
if (!use_minted)
|
|
|
|
latexed_opts.push_back(from_ascii("label={") + label + "}");
|
2017-06-08 17:33:54 +00:00
|
|
|
}
|
2018-02-19 16:15:31 +00:00
|
|
|
if (use_minted && !label.empty()) {
|
2017-06-10 16:43:23 +00:00
|
|
|
if (isfloat || !caption.empty())
|
2017-06-08 17:33:54 +00:00
|
|
|
label = trim(label, "{}");
|
|
|
|
else
|
2018-02-19 16:15:31 +00:00
|
|
|
opts.push_back(from_ascii("label=") + label);
|
2017-06-08 17:33:54 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-19 16:15:31 +00:00
|
|
|
if (!latexed_opts.empty())
|
|
|
|
opts.insert(opts.end(), latexed_opts.begin(), latexed_opts.end());
|
|
|
|
parameters = getStringFromVector(opts, from_ascii(","));
|
2017-06-08 17:33:54 +00:00
|
|
|
if (language.empty())
|
2018-02-19 16:15:31 +00:00
|
|
|
language = from_ascii("TeX");
|
2017-06-08 17:33:54 +00:00
|
|
|
if (use_minted && isfloat) {
|
|
|
|
os << breakln << "\\begin{listing}";
|
|
|
|
if (!placement.empty())
|
|
|
|
os << '[' << placement << "]";
|
|
|
|
os << breakln;
|
2017-06-10 16:43:23 +00:00
|
|
|
} else if (use_minted && !caption.empty()) {
|
|
|
|
os << breakln << "\\lyxmintcaption[t]{" << caption;
|
|
|
|
if (!label.empty())
|
|
|
|
os << "\\label{" << label << "}";
|
|
|
|
os << "}\n";
|
2017-06-08 17:33:54 +00:00
|
|
|
}
|
|
|
|
os << (use_minted ? "\\inputminted" : "\\lstinputlisting");
|
|
|
|
if (!parameters.empty())
|
|
|
|
os << "[" << parameters << "]";
|
|
|
|
if (use_minted)
|
2017-06-26 21:23:23 +00:00
|
|
|
os << '{' << ascii_lowercase(language) << '}';
|
2017-06-08 17:33:54 +00:00
|
|
|
os << '{' << incfile << '}';
|
|
|
|
if (use_minted && isfloat) {
|
|
|
|
if (!caption.empty())
|
|
|
|
os << breakln << "\\caption{" << caption << "}";
|
|
|
|
if (!label.empty())
|
|
|
|
os << breakln << "\\label{" << label << "}";
|
|
|
|
os << breakln << "\\end{listing}\n";
|
|
|
|
}
|
2013-02-21 16:38:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case INCLUDE: {
|
|
|
|
runparams.exportdata->addExternalFile(tex_format, writefile,
|
|
|
|
exportfile);
|
|
|
|
|
|
|
|
// \include don't want extension and demands that the
|
|
|
|
// file really have .tex
|
|
|
|
incfile = changeExtension(incfile, string());
|
|
|
|
incfile = latex_path(incfile);
|
|
|
|
// FIXME UNICODE
|
|
|
|
os << '\\' << from_ascii(params().getCmdName()) << '{'
|
|
|
|
<< from_utf8(incfile) << '}';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case NONE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (runparams.inComment || runparams.dryrun)
|
|
|
|
// Don't try to load or copy the file if we're
|
|
|
|
// in a comment or doing a dryrun
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isInputOrInclude(params()) &&
|
2010-04-21 01:19:31 +00:00
|
|
|
isLyXFileName(included_file.absFileName())) {
|
2010-08-10 14:39:12 +00:00
|
|
|
// if it's a LyX file and we're inputting or including,
|
|
|
|
// try to load it so we can write the associated latex
|
2011-03-29 08:35:37 +00:00
|
|
|
|
2010-08-10 14:39:12 +00:00
|
|
|
Buffer * tmp = loadIfNeeded();
|
2011-03-07 14:36:22 +00:00
|
|
|
if (!tmp) {
|
2013-11-12 19:52:35 +00:00
|
|
|
if (!runparams.silent) {
|
|
|
|
docstring text = bformat(_("Could not load included "
|
|
|
|
"file\n`%1$s'\n"
|
|
|
|
"Please, check whether it actually exists."),
|
|
|
|
included_file.displayName());
|
2017-03-10 20:38:27 +00:00
|
|
|
throw ExceptionMessage(ErrorException, _("Error: "),
|
|
|
|
text);
|
2013-11-12 19:52:35 +00:00
|
|
|
}
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2011-03-07 14:36:22 +00:00
|
|
|
}
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2013-11-12 19:52:35 +00:00
|
|
|
if (!runparams.silent) {
|
|
|
|
if (tmp->params().baseClass() != masterBuffer->params().baseClass()) {
|
|
|
|
// FIXME UNICODE
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This patch adds the backend. The ModuleList class holds a list of the available modules, which are retrieved from lyxmodules.lst, itself generated by configure.py. There are two LFUNs available: modules-clear and module-add, which do the obvious thing; you can test by typing these into the minibuffer, along with the name of one of the available modules: URL (a CharStyle), Endnote (a Custom Inset), and---with the spaces---End To Foot (View>LaTeX and look at the user preamble), which are themselves in lib/layouts. There are some others, too, that allow theorems to be added to classes like article and book.
The GUI will come next.
Issues: (i) The configure.py script could be improved. It'd be nice, for example, if it tested for the presence of the LaTeX packages a particular module needs. But this would mean re-working the LaTeX script, and I don't know how to do that. Note that at present, the packages are ignored. This will change shortly. (ii) I've used std::string in LyXModule, following what seemed to be a precedent in TextClass. If some of these should be docstrings, please let me know, and I'll change them. (iii) There is at present no distinction between LaTeX and DocBook modules. Should there be? That is: Should there be modules that are available when the document class is a LaTeX class and others that are available only when it is DocBook? Or should there just be one set of modules? Each module can of course indicate for what it is suitable in its description.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19893 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-29 17:59:49 +00:00
|
|
|
docstring text = bformat(_("Included file `%1$s'\n"
|
2013-11-12 19:52:35 +00:00
|
|
|
"has textclass `%2$s'\n"
|
|
|
|
"while parent file has textclass `%3$s'."),
|
|
|
|
included_file.displayName(),
|
|
|
|
from_utf8(tmp->params().documentClass().name()),
|
|
|
|
from_utf8(masterBuffer->params().documentClass().name()));
|
|
|
|
Alert::warning(_("Different textclasses"), text, true);
|
|
|
|
}
|
|
|
|
|
2016-11-25 02:47:45 +00:00
|
|
|
string const child_tf = tmp->params().useNonTeXFonts ? "true" : "false";
|
|
|
|
string const master_tf = masterBuffer->params().useNonTeXFonts ? "true" : "false";
|
|
|
|
if (tmp->params().useNonTeXFonts != masterBuffer->params().useNonTeXFonts) {
|
|
|
|
docstring text = bformat(_("Included file `%1$s'\n"
|
|
|
|
"has use-non-TeX-fonts set to `%2$s'\n"
|
|
|
|
"while parent file has use-non-TeX-fonts set to `%3$s'."),
|
|
|
|
included_file.displayName(),
|
|
|
|
from_utf8(child_tf),
|
|
|
|
from_utf8(master_tf));
|
|
|
|
Alert::warning(_("Different use-non-TeX-fonts settings"), text, true);
|
2019-03-18 11:49:10 +00:00
|
|
|
}
|
|
|
|
else if (tmp->params().inputenc != masterBuffer->params().inputenc) {
|
|
|
|
docstring text = bformat(_("Included file `%1$s'\n"
|
|
|
|
"uses input encoding \"%2$s\" [%3$s]\n"
|
|
|
|
"while parent file uses input encoding \"%4$s\" [%5$s]."),
|
|
|
|
included_file.displayName(),
|
|
|
|
_(tmp->params().inputenc),
|
|
|
|
from_utf8(tmp->params().encoding().guiName()),
|
|
|
|
_(masterBuffer->params().inputenc),
|
|
|
|
from_utf8(masterBuffer->params().encoding().guiName()));
|
|
|
|
Alert::warning(_("Different LaTeX input encodings"), text, true);
|
2016-11-25 02:47:45 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 19:52:35 +00:00
|
|
|
// Make sure modules used in child are all included in master
|
|
|
|
// FIXME It might be worth loading the children's modules into the master
|
|
|
|
// over in BufferParams rather than doing this check.
|
|
|
|
LayoutModuleList const masterModules = masterBuffer->params().getModules();
|
|
|
|
LayoutModuleList const childModules = tmp->params().getModules();
|
|
|
|
LayoutModuleList::const_iterator it = childModules.begin();
|
|
|
|
LayoutModuleList::const_iterator end = childModules.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
string const module = *it;
|
|
|
|
LayoutModuleList::const_iterator found =
|
|
|
|
find(masterModules.begin(), masterModules.end(), module);
|
|
|
|
if (found == masterModules.end()) {
|
|
|
|
docstring text = bformat(_("Included file `%1$s'\n"
|
|
|
|
"uses module `%2$s'\n"
|
|
|
|
"which is not used in parent file."),
|
|
|
|
included_file.displayName(), from_utf8(module));
|
2018-09-28 01:56:29 +00:00
|
|
|
Alert::warning(_("Module not found"), text, true);
|
2013-11-12 19:52:35 +00:00
|
|
|
}
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This patch adds the backend. The ModuleList class holds a list of the available modules, which are retrieved from lyxmodules.lst, itself generated by configure.py. There are two LFUNs available: modules-clear and module-add, which do the obvious thing; you can test by typing these into the minibuffer, along with the name of one of the available modules: URL (a CharStyle), Endnote (a Custom Inset), and---with the spaces---End To Foot (View>LaTeX and look at the user preamble), which are themselves in lib/layouts. There are some others, too, that allow theorems to be added to classes like article and book.
The GUI will come next.
Issues: (i) The configure.py script could be improved. It'd be nice, for example, if it tested for the presence of the LaTeX packages a particular module needs. But this would mean re-working the LaTeX script, and I don't know how to do that. Note that at present, the packages are ignored. This will change shortly. (ii) I've used std::string in LyXModule, following what seemed to be a precedent in TextClass. If some of these should be docstrings, please let me know, and I'll change them. (iii) There is at present no distinction between LaTeX and DocBook modules. Should there be? That is: Should there be modules that are available when the document class is a LaTeX class and others that are available only when it is DocBook? Or should there just be one set of modules? Each module can of course indicate for what it is suitable in its description.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19893 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-29 17:59:49 +00:00
|
|
|
}
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2007-10-20 10:03:45 +00:00
|
|
|
tmp->markDepClean(masterBuffer->temppath());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2011-03-24 15:47:40 +00:00
|
|
|
// Don't assume the child's format is latex
|
2011-05-13 19:39:56 +00:00
|
|
|
string const inc_format = tmp->params().bufferFormat();
|
2011-03-24 15:47:40 +00:00
|
|
|
FileName const tmpwritefile(changeExtension(writefile.absFileName(),
|
2017-03-14 03:33:40 +00:00
|
|
|
theFormats().extension(inc_format)));
|
2011-03-24 15:47:40 +00:00
|
|
|
|
2009-06-19 14:10:41 +00:00
|
|
|
// FIXME: handle non existing files
|
2007-03-25 16:31:16 +00:00
|
|
|
// The included file might be written in a different encoding
|
2009-10-18 21:48:13 +00:00
|
|
|
// and language.
|
2007-03-25 16:31:16 +00:00
|
|
|
Encoding const * const oldEnc = runparams.encoding;
|
2009-10-18 21:48:13 +00:00
|
|
|
Language const * const oldLang = runparams.master_language;
|
2015-11-05 09:52:22 +00:00
|
|
|
// If the master uses non-TeX fonts (XeTeX, LuaTeX),
|
2010-11-28 14:20:45 +00:00
|
|
|
// the children must be encoded in plain utf8!
|
2015-11-05 09:52:22 +00:00
|
|
|
runparams.encoding = masterBuffer->params().useNonTeXFonts ?
|
2019-03-18 17:16:40 +00:00
|
|
|
encodings.fromLyXName("utf8-plain") : oldEnc;
|
2009-10-19 10:29:15 +00:00
|
|
|
runparams.master_language = buffer().params().language;
|
2010-12-18 13:49:39 +00:00
|
|
|
runparams.par_begin = 0;
|
|
|
|
runparams.par_end = tmp->paragraphs().size();
|
2012-10-03 08:41:07 +00:00
|
|
|
runparams.is_child = true;
|
Fix some problems with background cancellation.
The problem was that, if we killed export when some graphic was
being converted, or some external template was being handled, it
would only cancel that process, and then it would just continue.
To deal with that, we need to do a few things:
1. Modify the return values for some of the Converters routines,
and similarly the routines for external templates, so we can
tell when something has been canceled.
2. Throw an exception from InsetGraphics or InsetExternal when this
has happened during export, but ONLY when the Buffer is a clone.
We shouldn't be able to 'cancel' export when we're, say, generating
code for the preview pane, but this keeps us on the safe side..
The exception then has to be caught, obviously, back in the export
routines in Buffer.
Probably Coverity will be unhappy about something here, but I'll
deal with that problem as it arises.
2018-02-20 03:43:44 +00:00
|
|
|
Buffer::ExportStatus retval =
|
|
|
|
tmp->makeLaTeXFile(tmpwritefile, masterFileName(buffer()).
|
|
|
|
onlyPath().absFileName(), runparams, Buffer::OnlyBody);
|
|
|
|
if (retval == Buffer::ExportKilled && buffer().isClone() &&
|
|
|
|
buffer().isExporting()) {
|
|
|
|
// We really shouldn't get here, I don't think.
|
|
|
|
LYXERR0("No conversion exception?");
|
|
|
|
throw ConversionException();
|
|
|
|
}
|
|
|
|
else if (retval != Buffer::ExportSuccess) {
|
2013-11-12 19:52:35 +00:00
|
|
|
if (!runparams.silent) {
|
|
|
|
docstring msg = bformat(_("Included file `%1$s' "
|
2016-09-02 21:10:41 +00:00
|
|
|
"was not exported correctly.\n "
|
2011-02-28 01:14:19 +00:00
|
|
|
"LaTeX export is probably incomplete."),
|
|
|
|
included_file.displayName());
|
2013-11-12 19:52:35 +00:00
|
|
|
ErrorList const & el = tmp->errorList("Export");
|
|
|
|
if (!el.empty())
|
|
|
|
msg = bformat(from_ascii("%1$s\n\n%2$s\n\n%3$s"),
|
2018-04-15 02:45:11 +00:00
|
|
|
msg, el.begin()->error, el.begin()->description);
|
|
|
|
throw ExceptionMessage(ErrorException, _("Error: "), msg);
|
2013-11-12 19:52:35 +00:00
|
|
|
}
|
2011-02-28 01:14:19 +00:00
|
|
|
}
|
2007-03-25 16:31:16 +00:00
|
|
|
runparams.encoding = oldEnc;
|
2009-10-18 21:48:13 +00:00
|
|
|
runparams.master_language = oldLang;
|
2012-10-03 08:41:07 +00:00
|
|
|
runparams.is_child = false;
|
2011-03-24 15:47:40 +00:00
|
|
|
|
2011-03-30 00:23:32 +00:00
|
|
|
// If needed, use converters to produce a latex file from the child
|
|
|
|
if (tmpwritefile != writefile) {
|
2011-03-29 08:35:37 +00:00
|
|
|
ErrorList el;
|
Fix some problems with background cancellation.
The problem was that, if we killed export when some graphic was
being converted, or some external template was being handled, it
would only cancel that process, and then it would just continue.
To deal with that, we need to do a few things:
1. Modify the return values for some of the Converters routines,
and similarly the routines for external templates, so we can
tell when something has been canceled.
2. Throw an exception from InsetGraphics or InsetExternal when this
has happened during export, but ONLY when the Buffer is a clone.
We shouldn't be able to 'cancel' export when we're, say, generating
code for the preview pane, but this keeps us on the safe side..
The exception then has to be caught, obviously, back in the export
routines in Buffer.
Probably Coverity will be unhappy about something here, but I'll
deal with that problem as it arises.
2018-02-20 03:43:44 +00:00
|
|
|
Converters::RetVal const retval =
|
2011-03-29 08:35:37 +00:00
|
|
|
theConverters().convert(tmp, tmpwritefile, writefile,
|
Fix some problems with background cancellation.
The problem was that, if we killed export when some graphic was
being converted, or some external template was being handled, it
would only cancel that process, and then it would just continue.
To deal with that, we need to do a few things:
1. Modify the return values for some of the Converters routines,
and similarly the routines for external templates, so we can
tell when something has been canceled.
2. Throw an exception from InsetGraphics or InsetExternal when this
has happened during export, but ONLY when the Buffer is a clone.
We shouldn't be able to 'cancel' export when we're, say, generating
code for the preview pane, but this keeps us on the safe side..
The exception then has to be caught, obviously, back in the export
routines in Buffer.
Probably Coverity will be unhappy about something here, but I'll
deal with that problem as it arises.
2018-02-20 03:43:44 +00:00
|
|
|
included_file, inc_format, tex_format, el);
|
|
|
|
if (retval == Converters::KILLED && buffer().isClone() &&
|
|
|
|
buffer().isExporting()) {
|
|
|
|
// We really shouldn't get here, I don't think.
|
|
|
|
LYXERR0("No conversion exception?");
|
|
|
|
throw ConversionException();
|
|
|
|
} else if (retval != Converters::SUCCESS && !runparams.silent) {
|
2011-03-29 08:35:37 +00:00
|
|
|
docstring msg = bformat(_("Included file `%1$s' "
|
2016-09-02 21:10:41 +00:00
|
|
|
"was not exported correctly.\n "
|
2011-03-29 08:35:37 +00:00
|
|
|
"LaTeX export is probably incomplete."),
|
|
|
|
included_file.displayName());
|
|
|
|
if (!el.empty())
|
|
|
|
msg = bformat(from_ascii("%1$s\n\n%2$s\n\n%3$s"),
|
2018-04-15 02:45:11 +00:00
|
|
|
msg, el.begin()->error, el.begin()->description);
|
|
|
|
throw ExceptionMessage(ErrorException, _("Error: "), msg);
|
2011-03-29 08:35:37 +00:00
|
|
|
}
|
2011-03-24 15:47:40 +00:00
|
|
|
}
|
2004-06-01 13:39:33 +00:00
|
|
|
} else {
|
2007-05-26 17:26:58 +00:00
|
|
|
// In this case, it's not a LyX file, so we copy the file
|
2007-05-28 22:27:45 +00:00
|
|
|
// to the temp dir, so that .aux files etc. are not created
|
|
|
|
// in the original dir. Files included by this file will be
|
2011-10-22 15:10:43 +00:00
|
|
|
// found via either the environment variable TEXINPUTS, or
|
|
|
|
// input@path, see ../Buffer.cpp.
|
2007-11-30 09:23:44 +00:00
|
|
|
unsigned long const checksum_in = included_file.checksum();
|
|
|
|
unsigned long const checksum_out = writefile.checksum();
|
2004-03-25 10:12:44 +00:00
|
|
|
|
|
|
|
if (checksum_in != checksum_out) {
|
2007-12-15 08:25:53 +00:00
|
|
|
if (!included_file.copyTo(writefile)) {
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LATEX,
|
|
|
|
to_utf8(bformat(_("Could not copy the file\n%1$s\n"
|
2013-02-21 16:38:36 +00:00
|
|
|
"into the temporary directory."),
|
|
|
|
from_utf8(included_file.absFileName()))));
|
2011-02-10 20:02:48 +00:00
|
|
|
return;
|
2004-03-25 10:12:44 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-03 20:59:03 +00:00
|
|
|
docstring InsetInclude::xhtml(XHTMLStream & xs, OutputParams const & rp) const
|
2009-06-19 15:11:33 +00:00
|
|
|
{
|
|
|
|
if (rp.inComment)
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
// For verbatim and listings, we just include the contents of the file as-is.
|
|
|
|
// In the case of listings, we wrap it in <pre>.
|
2009-06-19 17:51:17 +00:00
|
|
|
bool const listing = isListings(params());
|
2009-06-19 15:11:33 +00:00
|
|
|
if (listing || isVerbatim(params())) {
|
|
|
|
if (listing)
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::StartTag("pre");
|
2009-06-19 15:11:33 +00:00
|
|
|
// FIXME: We don't know the encoding of the file, default to UTF-8.
|
2010-04-21 01:19:36 +00:00
|
|
|
xs << includedFileName(buffer(), params()).fileContents("UTF-8");
|
2009-06-19 15:11:33 +00:00
|
|
|
if (listing)
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::EndTag("pre");
|
2009-06-19 15:11:33 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't (yet) know how to Input or Include non-LyX files.
|
|
|
|
// (If we wanted to get really arcane, we could run some tex2html
|
|
|
|
// converter on the included file. But that's just masochistic.)
|
2010-04-21 01:19:36 +00:00
|
|
|
FileName const included_file = includedFileName(buffer(), params());
|
2010-04-21 01:19:31 +00:00
|
|
|
if (!isLyXFileName(included_file.absFileName())) {
|
2013-11-12 19:52:35 +00:00
|
|
|
if (!rp.silent)
|
|
|
|
frontend::Alert::warning(_("Unsupported Inclusion"),
|
2009-10-11 09:34:13 +00:00
|
|
|
bformat(_("LyX does not know how to include non-LyX files when "
|
|
|
|
"generating HTML output. Offending file:\n%1$s"),
|
2019-03-12 08:00:59 +00:00
|
|
|
ltrim(params()["filename"])));
|
2009-06-19 15:11:33 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
// In the other cases, we will generate the HTML and include it.
|
|
|
|
|
|
|
|
// Check we're not trying to include ourselves.
|
|
|
|
// FIXME RECURSIVE INCLUDE
|
2010-04-21 01:19:09 +00:00
|
|
|
if (buffer().absFileName() == included_file.absFileName()) {
|
2009-06-19 15:11:33 +00:00
|
|
|
Alert::error(_("Recursive input"),
|
|
|
|
bformat(_("Attempted to include file %1$s in itself! "
|
2019-03-12 08:00:59 +00:00
|
|
|
"Ignoring inclusion."), ltrim(params()["filename"])));
|
2009-06-19 15:11:33 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
Buffer const * const ibuf = loadIfNeeded();
|
|
|
|
if (!ibuf)
|
|
|
|
return docstring();
|
2011-07-03 20:59:03 +00:00
|
|
|
|
|
|
|
// are we generating only some paragraphs, or all of them?
|
2017-07-03 17:53:14 +00:00
|
|
|
bool const all_pars = !rp.dryrun ||
|
|
|
|
(rp.par_begin == 0 &&
|
2011-07-03 20:59:03 +00:00
|
|
|
rp.par_end == (int)buffer().text().paragraphs().size());
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2011-07-03 20:59:03 +00:00
|
|
|
OutputParams op = rp;
|
|
|
|
if (all_pars) {
|
|
|
|
op.par_begin = 0;
|
|
|
|
op.par_end = 0;
|
2012-04-23 17:55:13 +00:00
|
|
|
ibuf->writeLyXHTMLSource(xs.os(), op, Buffer::IncludedFile);
|
2011-07-03 20:59:03 +00:00
|
|
|
} else
|
2017-07-03 17:53:14 +00:00
|
|
|
xs << XHTMLStream::ESCAPE_NONE
|
|
|
|
<< "<!-- Included file: "
|
|
|
|
<< from_utf8(included_file.absFileName())
|
|
|
|
<< XHTMLStream::ESCAPE_NONE
|
2011-07-03 20:59:03 +00:00
|
|
|
<< " -->";
|
2009-06-19 15:11:33 +00:00
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetInclude::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const & op, size_t) const
|
2000-12-28 16:22:28 +00:00
|
|
|
{
|
2013-03-12 16:45:15 +00:00
|
|
|
// just write the filename if we're making a tooltip or toc entry,
|
|
|
|
// or are generating this for advanced search
|
|
|
|
if (op.for_tooltip || op.for_toc || op.for_search) {
|
2013-03-09 17:42:56 +00:00
|
|
|
os << '[' << screenLabel() << '\n'
|
2019-03-12 08:00:59 +00:00
|
|
|
<< ltrim(getParam("filename")) << "\n]";
|
2013-03-09 17:42:56 +00:00
|
|
|
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVerbatim(params()) || isListings(params())) {
|
2019-02-27 09:17:56 +00:00
|
|
|
if (op.for_search) {
|
|
|
|
os << '[' << screenLabel() << ']';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
os << '[' << screenLabel() << '\n'
|
|
|
|
// FIXME: We don't know the encoding of the file, default to UTF-8.
|
|
|
|
<< includedFileName(buffer(), params()).fileContents("UTF-8")
|
|
|
|
<< "\n]";
|
|
|
|
}
|
2007-02-20 19:14:55 +00:00
|
|
|
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
2012-03-19 21:33:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Buffer const * const ibuf = loadIfNeeded();
|
|
|
|
if (!ibuf) {
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring const str = '[' + screenLabel() + ']';
|
2007-02-20 19:14:55 +00:00
|
|
|
os << str;
|
|
|
|
return str.size();
|
2006-09-10 09:28:00 +00:00
|
|
|
}
|
2012-03-19 21:33:47 +00:00
|
|
|
writePlaintextFile(*ibuf, os, op);
|
2012-05-03 13:09:47 +00:00
|
|
|
return 0;
|
2000-12-28 16:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetInclude::docbook(odocstream & os, OutputParams const & runparams) const
|
2000-07-01 12:54:45 +00:00
|
|
|
{
|
2019-03-12 08:00:59 +00:00
|
|
|
string incfile = ltrim(to_utf8(params()["filename"]));
|
2000-09-26 13:54:57 +00:00
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
// Do nothing if no file name has been specified
|
2000-09-26 13:54:57 +00:00
|
|
|
if (incfile.empty())
|
2000-07-01 12:54:45 +00:00
|
|
|
return 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2010-04-21 01:19:36 +00:00
|
|
|
string const included_file = includedFileName(buffer(), params()).absFileName();
|
2003-09-19 10:16:33 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
// Check we're not trying to include ourselves.
|
|
|
|
// FIXME RECURSIVE INCLUDE
|
|
|
|
// This isn't sufficient, as the inclusion could be downstream.
|
|
|
|
// But it'll have to do for now.
|
|
|
|
if (buffer().absFileName() == included_file) {
|
2007-05-28 22:27:45 +00:00
|
|
|
Alert::error(_("Recursive input"),
|
|
|
|
bformat(_("Attempted to include file %1$s in itself! "
|
|
|
|
"Ignoring inclusion."), from_utf8(incfile)));
|
2007-05-21 15:34:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-09-15 01:07:49 +00:00
|
|
|
string exppath = incfile;
|
|
|
|
if (!runparams.export_folder.empty()) {
|
|
|
|
exppath = makeAbsPath(exppath, runparams.export_folder).realPath();
|
|
|
|
FileName(exppath).onlyPath().createPath();
|
|
|
|
}
|
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
// write it to a file (so far the complete file)
|
2011-09-15 01:07:49 +00:00
|
|
|
string const exportfile = changeExtension(exppath, ".sgml");
|
2006-11-26 21:30:39 +00:00
|
|
|
DocFileName writefile(changeExtension(included_file, ".sgml"));
|
2004-06-01 13:39:33 +00:00
|
|
|
|
2010-08-10 14:39:12 +00:00
|
|
|
Buffer * tmp = loadIfNeeded();
|
|
|
|
if (tmp) {
|
2010-04-21 01:19:22 +00:00
|
|
|
string const mangled = writefile.mangledFileName();
|
2006-04-08 22:31:11 +00:00
|
|
|
writefile = makeAbsPath(mangled,
|
2008-02-27 20:43:16 +00:00
|
|
|
buffer().masterBuffer()->temppath());
|
2004-06-01 13:39:33 +00:00
|
|
|
if (!runparams.nice)
|
|
|
|
incfile = mangled;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::LATEX, "incfile:" << incfile);
|
|
|
|
LYXERR(Debug::LATEX, "exportfile:" << exportfile);
|
|
|
|
LYXERR(Debug::LATEX, "writefile:" << writefile);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2011-10-29 20:14:48 +00:00
|
|
|
tmp->makeDocBookFile(writefile, runparams, Buffer::OnlyBody);
|
2001-03-14 10:57:39 +00:00
|
|
|
}
|
2000-07-01 12:54:45 +00:00
|
|
|
|
2004-06-01 13:39:33 +00:00
|
|
|
runparams.exportdata->addExternalFile("docbook", writefile,
|
2006-04-05 23:56:29 +00:00
|
|
|
exportfile);
|
2004-06-01 13:39:33 +00:00
|
|
|
runparams.exportdata->addExternalFile("docbook-xml", writefile,
|
2006-04-05 23:56:29 +00:00
|
|
|
exportfile);
|
2004-06-01 13:39:33 +00:00
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
if (isVerbatim(params()) || isListings(params())) {
|
2002-01-16 12:04:16 +00:00
|
|
|
os << "<inlinegraphic fileref=\""
|
2006-10-21 19:40:29 +00:00
|
|
|
<< '&' << include_label << ';'
|
2002-01-16 12:54:52 +00:00
|
|
|
<< "\" format=\"linespecific\">";
|
2001-03-14 10:57:39 +00:00
|
|
|
} else
|
2007-05-28 22:27:45 +00:00
|
|
|
os << '&' << include_label << ';';
|
2002-03-21 17:09:55 +00:00
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
void InsetInclude::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(&buffer() == &features.buffer());
|
2003-09-19 10:16:33 +00:00
|
|
|
|
2019-03-12 08:00:59 +00:00
|
|
|
string incfile = ltrim(to_utf8(params()["filename"]));
|
2008-02-27 20:43:16 +00:00
|
|
|
string const included_file =
|
2010-04-21 01:19:36 +00:00
|
|
|
includedFileName(buffer(), params()).absFileName();
|
2000-11-13 15:43:36 +00:00
|
|
|
|
2013-04-25 21:27:10 +00:00
|
|
|
string writefile;
|
2010-04-21 01:19:31 +00:00
|
|
|
if (isLyXFileName(included_file))
|
2006-04-08 22:31:11 +00:00
|
|
|
writefile = changeExtension(included_file, ".sgml");
|
2004-02-25 12:00:53 +00:00
|
|
|
else
|
2003-09-19 10:16:33 +00:00
|
|
|
writefile = included_file;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
2007-10-23 15:02:15 +00:00
|
|
|
if (!features.runparams().nice && !isVerbatim(params()) && !isListings(params())) {
|
2010-04-21 01:19:22 +00:00
|
|
|
incfile = DocFileName(writefile).mangledFileName();
|
2006-04-08 22:31:11 +00:00
|
|
|
writefile = makeAbsPath(incfile,
|
2010-04-21 01:19:09 +00:00
|
|
|
buffer().masterBuffer()->temppath()).absFileName();
|
2004-02-25 12:00:53 +00:00
|
|
|
}
|
|
|
|
|
2001-11-19 15:34:11 +00:00
|
|
|
features.includeFile(include_label, writefile);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
2012-04-10 18:21:01 +00:00
|
|
|
features.useInsetLayout(getLayout());
|
2007-10-23 15:02:15 +00:00
|
|
|
if (isVerbatim(params()))
|
2001-11-19 15:34:11 +00:00
|
|
|
features.require("verbatim");
|
2017-06-06 22:55:23 +00:00
|
|
|
else if (isListings(params())) {
|
2017-06-10 16:43:23 +00:00
|
|
|
if (buffer().params().use_minted) {
|
2017-06-06 22:55:23 +00:00
|
|
|
features.require("minted");
|
2017-06-10 16:43:23 +00:00
|
|
|
string const opts = to_utf8(params()["lstparams"]);
|
|
|
|
InsetListingsParams lstpars(opts);
|
|
|
|
if (!lstpars.isFloat() && contains(opts, "caption="))
|
|
|
|
features.require("lyxmintcaption");
|
|
|
|
} else
|
2017-06-06 22:55:23 +00:00
|
|
|
features.require("listings");
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// Here we must do the fun stuff...
|
|
|
|
// Load the file in the include if it needs
|
|
|
|
// to be loaded:
|
2010-08-10 14:39:12 +00:00
|
|
|
Buffer * const tmp = loadIfNeeded();
|
|
|
|
if (tmp) {
|
|
|
|
// the file is loaded
|
2007-05-21 15:34:29 +00:00
|
|
|
// make sure the buffer isn't us
|
|
|
|
// FIXME RECURSIVE INCLUDES
|
|
|
|
// This is not sufficient, as recursive includes could be
|
|
|
|
// more than a file away. But it will do for now.
|
2008-02-27 20:43:16 +00:00
|
|
|
if (tmp && tmp != &buffer()) {
|
2004-04-08 10:09:09 +00:00
|
|
|
// We must temporarily change features.buffer,
|
|
|
|
// otherwise it would always be the master buffer,
|
|
|
|
// and nested includes would not work.
|
|
|
|
features.setBuffer(*tmp);
|
2013-07-21 19:33:34 +00:00
|
|
|
// Maybe this is already a child
|
|
|
|
bool const is_child =
|
|
|
|
features.runparams().is_child;
|
2012-10-05 07:59:44 +00:00
|
|
|
features.runparams().is_child = true;
|
2001-03-23 17:09:34 +00:00
|
|
|
tmp->validate(features);
|
2013-07-21 19:33:34 +00:00
|
|
|
features.runparams().is_child = is_child;
|
2008-02-27 20:43:16 +00:00
|
|
|
features.setBuffer(buffer());
|
2004-04-08 10:09:09 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-18 07:20:31 +00:00
|
|
|
void InsetInclude::collectBibKeys(InsetIterator const & /*di*/, FileNameList & checkedFiles) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2010-08-10 14:12:48 +00:00
|
|
|
Buffer * child = loadIfNeeded();
|
|
|
|
if (!child)
|
|
|
|
return;
|
2014-02-23 11:33:15 +00:00
|
|
|
// FIXME RECURSIVE INCLUDE
|
|
|
|
// This isn't sufficient, as the inclusion could be downstream.
|
|
|
|
// But it'll have to do for now.
|
|
|
|
if (child == &buffer())
|
|
|
|
return;
|
2017-10-18 07:20:31 +00:00
|
|
|
child->collectBibKeys(checkedFiles);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-08-01 17:28:59 +00:00
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(mi.base.bv);
|
2004-04-19 13:05:36 +00:00
|
|
|
|
|
|
|
bool use_preview = false;
|
2014-05-20 10:19:26 +00:00
|
|
|
if (RenderPreview::previewText()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
graphics::PreviewImage const * pimage =
|
2007-08-21 13:03:55 +00:00
|
|
|
preview_->getPreviewImage(mi.base.bv->buffer());
|
2004-04-19 13:05:36 +00:00
|
|
|
use_preview = pimage && pimage->image();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (use_preview) {
|
2003-10-10 21:24:06 +00:00
|
|
|
preview_->metrics(mi, dim);
|
2003-06-02 10:03:27 +00:00
|
|
|
} else {
|
2003-06-12 08:52:36 +00:00
|
|
|
if (!set_label_) {
|
|
|
|
set_label_ = true;
|
2017-05-24 09:28:08 +00:00
|
|
|
button_.update(screenLabel(), true, false);
|
2003-06-12 08:52:36 +00:00
|
|
|
}
|
|
|
|
button_.metrics(mi, dim);
|
2003-06-02 10:03:27 +00:00
|
|
|
}
|
2004-08-14 19:20:42 +00:00
|
|
|
|
|
|
|
Box b(0, dim.wid, -dim.asc, dim.des);
|
2003-09-04 14:02:05 +00:00
|
|
|
button_.setBox(b);
|
2002-08-01 17:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
void InsetInclude::draw(PainterInfo & pi, int x, int y) const
|
2002-08-01 17:28:59 +00:00
|
|
|
{
|
2013-04-27 21:52:55 +00:00
|
|
|
LBUFERR(pi.base.bv);
|
2004-04-19 13:05:36 +00:00
|
|
|
|
|
|
|
bool use_preview = false;
|
2014-05-20 10:19:26 +00:00
|
|
|
if (RenderPreview::previewText()) {
|
2006-10-21 00:16:43 +00:00
|
|
|
graphics::PreviewImage const * pimage =
|
2007-08-21 13:03:55 +00:00
|
|
|
preview_->getPreviewImage(pi.base.bv->buffer());
|
2004-04-19 13:05:36 +00:00
|
|
|
use_preview = pimage && pimage->image();
|
2002-08-01 17:28:59 +00:00
|
|
|
}
|
|
|
|
|
2004-04-19 13:05:36 +00:00
|
|
|
if (use_preview)
|
2004-08-14 19:20:42 +00:00
|
|
|
preview_->draw(pi, x, y);
|
2004-04-19 13:05:36 +00:00
|
|
|
else
|
2004-08-14 19:20:42 +00:00
|
|
|
button_.draw(pi, x, y);
|
2002-08-01 17:28:59 +00:00
|
|
|
}
|
|
|
|
|
2007-05-18 14:32:29 +00:00
|
|
|
|
2015-05-03 21:55:19 +00:00
|
|
|
void InsetInclude::write(ostream & os) const
|
|
|
|
{
|
|
|
|
params().Write(os, &buffer());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetInclude::contextMenuName() const
|
2008-04-27 15:49:15 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-include";
|
2008-04-27 15:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-18 14:32:29 +00:00
|
|
|
Inset::DisplayType InsetInclude::display() const
|
2004-10-05 10:11:42 +00:00
|
|
|
{
|
2018-09-12 13:26:15 +00:00
|
|
|
return type(params()) == INPUT ? Inline : AlignCenter;
|
2004-08-14 19:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-10 18:21:01 +00:00
|
|
|
docstring InsetInclude::layoutName() const
|
|
|
|
{
|
|
|
|
if (isListings(params()))
|
|
|
|
return from_ascii("IncludeListings");
|
|
|
|
return InsetCommand::layoutName();
|
|
|
|
}
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// preview stuff
|
|
|
|
//
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
void InsetInclude::fileChanged() const
|
2002-08-01 17:28:59 +00:00
|
|
|
{
|
2007-11-17 15:32:12 +00:00
|
|
|
Buffer const * const buffer = updateFrontend();
|
|
|
|
if (!buffer)
|
2003-10-10 21:08:55 +00:00
|
|
|
return;
|
|
|
|
|
2007-11-17 15:32:12 +00:00
|
|
|
preview_->removePreview(*buffer);
|
2016-06-02 22:49:36 +00:00
|
|
|
add_preview(*preview_, *this, *buffer);
|
2007-11-17 15:32:12 +00:00
|
|
|
preview_->startLoading(*buffer);
|
2002-08-01 17:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool preview_wanted(InsetCommandParams const & params, Buffer const & buffer)
|
2002-08-01 17:28:59 +00:00
|
|
|
{
|
2010-04-21 01:19:36 +00:00
|
|
|
FileName const included_file = includedFileName(buffer, params);
|
2003-09-19 10:16:33 +00:00
|
|
|
|
2003-10-10 21:08:55 +00:00
|
|
|
return type(params) == INPUT && params.preview() &&
|
2007-11-25 11:18:16 +00:00
|
|
|
included_file.isReadableFile();
|
2002-08-01 17:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring latexString(InsetInclude const & inset)
|
2002-08-01 17:28:59 +00:00
|
|
|
{
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
odocstringstream ods;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexstream os(ods);
|
2007-03-25 16:45:51 +00:00
|
|
|
// We don't need to set runparams.encoding since this will be done
|
|
|
|
// by latex() anyway.
|
2007-03-18 10:59:16 +00:00
|
|
|
OutputParams runparams(0);
|
2003-11-05 12:06:20 +00:00
|
|
|
runparams.flavor = OutputParams::LATEX;
|
2015-06-02 15:23:52 +00:00
|
|
|
runparams.for_preview = true;
|
2008-02-27 20:43:16 +00:00
|
|
|
inset.latex(os, runparams);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
return ods.str();
|
2002-08-01 17:28:59 +00:00
|
|
|
}
|
2002-08-06 14:02:59 +00:00
|
|
|
|
|
|
|
|
2003-10-22 22:26:47 +00:00
|
|
|
void add_preview(RenderMonitoredPreview & renderer, InsetInclude const & inset,
|
|
|
|
Buffer const & buffer)
|
2002-08-06 14:02:59 +00:00
|
|
|
{
|
2003-10-10 21:08:55 +00:00
|
|
|
InsetCommandParams const & params = inset.params();
|
2014-05-20 10:19:26 +00:00
|
|
|
if (RenderPreview::previewText() && preview_wanted(params, buffer)) {
|
2010-04-21 01:19:36 +00:00
|
|
|
renderer.setAbsFile(includedFileName(buffer, params));
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring const snippet = latexString(inset);
|
2003-10-22 22:26:47 +00:00
|
|
|
renderer.addPreview(snippet, buffer);
|
2003-10-10 21:08:55 +00:00
|
|
|
}
|
2002-08-06 14:02:59 +00:00
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2003-10-10 21:08:55 +00:00
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
2009-11-22 20:50:35 +00:00
|
|
|
void InsetInclude::addPreview(DocIterator const & /*inset_pos*/,
|
|
|
|
graphics::PreviewLoader & ploader) const
|
2002-08-06 14:02:59 +00:00
|
|
|
{
|
2003-10-22 22:26:47 +00:00
|
|
|
Buffer const & buffer = ploader.buffer();
|
2008-02-15 14:30:08 +00:00
|
|
|
if (!preview_wanted(params(), buffer))
|
|
|
|
return;
|
2010-04-21 01:19:36 +00:00
|
|
|
preview_->setAbsFile(includedFileName(buffer, params()));
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring const snippet = latexString(*this);
|
2008-02-15 14:30:08 +00:00
|
|
|
preview_->addPreview(snippet, ploader);
|
2002-08-06 14:02:59 +00:00
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
|
|
|
2015-09-27 06:05:00 +00:00
|
|
|
void InsetInclude::addToToc(DocIterator const & cpit, bool output_active,
|
2017-01-13 10:06:48 +00:00
|
|
|
UpdateType utype, TocBackend & backend) const
|
2006-11-13 16:53:49 +00:00
|
|
|
{
|
2007-10-23 15:02:15 +00:00
|
|
|
if (isListings(params())) {
|
2008-03-07 13:33:33 +00:00
|
|
|
if (label_)
|
2017-01-13 10:06:48 +00:00
|
|
|
label_->addToToc(cpit, output_active, utype, backend);
|
2017-01-14 17:40:58 +00:00
|
|
|
TocBuilder & b = backend.builder("listing");
|
2017-01-09 16:37:50 +00:00
|
|
|
b.pushItem(cpit, screenLabel(), output_active);
|
2007-10-23 18:51:04 +00:00
|
|
|
InsetListingsParams p(to_utf8(params()["lstparams"]));
|
2017-01-09 16:37:50 +00:00
|
|
|
b.argumentItem(from_utf8(p.getParamValue("caption")));
|
|
|
|
b.pop();
|
2015-09-01 16:08:35 +00:00
|
|
|
} else {
|
|
|
|
Buffer const * const childbuffer = getChildBuffer();
|
2017-01-09 16:37:50 +00:00
|
|
|
|
2017-01-14 17:40:58 +00:00
|
|
|
TocBuilder & b = backend.builder("child");
|
2017-01-09 16:37:50 +00:00
|
|
|
docstring str = childbuffer ? childbuffer->fileName().displayName()
|
|
|
|
: from_ascii("?");
|
|
|
|
b.pushItem(cpit, str, output_active);
|
|
|
|
b.pop();
|
|
|
|
|
2015-09-01 16:08:35 +00:00
|
|
|
if (!childbuffer)
|
|
|
|
return;
|
2006-11-13 16:53:49 +00:00
|
|
|
|
2017-05-16 10:14:25 +00:00
|
|
|
// Update the child's tocBackend. The outliner uses the master's, but
|
|
|
|
// the navigation menu uses the child's.
|
|
|
|
childbuffer->tocBackend().update(output_active, utype);
|
2017-01-09 16:37:50 +00:00
|
|
|
// Include Tocs from children
|
2017-01-26 23:39:45 +00:00
|
|
|
childbuffer->inset().addToToc(DocIterator(), output_active, utype,
|
|
|
|
backend);
|
2017-01-14 17:40:58 +00:00
|
|
|
//Copy missing outliner names (though the user has been warned against
|
|
|
|
//having different document class and module selection between master
|
|
|
|
//and child).
|
|
|
|
for (pair<string, docstring> const & name
|
|
|
|
: childbuffer->params().documentClass().outlinerNames())
|
|
|
|
backend.addName(name.first, translateIfPossible(name.second));
|
2015-09-01 16:08:35 +00:00
|
|
|
}
|
2006-11-13 16:53:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-19 04:50:25 +00:00
|
|
|
void InsetInclude::updateCommand()
|
|
|
|
{
|
|
|
|
if (!label_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
docstring old_label = label_->getParam("name");
|
2011-07-06 17:40:51 +00:00
|
|
|
label_->updateLabel(old_label);
|
2009-02-19 04:50:25 +00:00
|
|
|
// the label might have been adapted (duplicate)
|
|
|
|
docstring new_label = label_->getParam("name");
|
|
|
|
if (old_label == new_label)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// update listings parameters...
|
|
|
|
InsetCommandParams p(INCLUDE_CODE);
|
|
|
|
p = params();
|
|
|
|
InsetListingsParams par(to_utf8(params()["lstparams"]));
|
|
|
|
par.addParam("label", "{" + to_utf8(new_label) + "}", true);
|
|
|
|
p["lstparams"] = from_utf8(par.params());
|
2017-07-03 17:53:14 +00:00
|
|
|
setParams(p);
|
2009-02-19 04:50:25 +00:00
|
|
|
}
|
|
|
|
|
2011-07-06 17:40:51 +00:00
|
|
|
|
2010-03-03 22:13:45 +00:00
|
|
|
void InsetInclude::updateBuffer(ParIterator const & it, UpdateType utype)
|
2006-11-13 16:53:49 +00:00
|
|
|
{
|
2019-03-12 08:00:59 +00:00
|
|
|
file_exist_ = includedFileExist();
|
|
|
|
|
2017-05-24 09:28:08 +00:00
|
|
|
button_.update(screenLabel(), true, false);
|
2012-06-26 18:41:25 +00:00
|
|
|
|
2009-03-26 00:48:32 +00:00
|
|
|
Buffer const * const childbuffer = getChildBuffer();
|
2008-02-15 14:30:08 +00:00
|
|
|
if (childbuffer) {
|
2010-03-03 22:13:45 +00:00
|
|
|
childbuffer->updateBuffer(Buffer::UpdateChildOnly, utype);
|
2008-02-15 14:30:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!isListings(params()))
|
|
|
|
return;
|
|
|
|
|
2008-03-07 13:33:33 +00:00
|
|
|
if (label_)
|
2010-03-03 22:13:45 +00:00
|
|
|
label_->updateBuffer(it, utype);
|
2008-03-07 13:33:33 +00:00
|
|
|
|
2008-02-15 14:30:08 +00:00
|
|
|
InsetListingsParams const par(to_utf8(params()["lstparams"]));
|
|
|
|
if (par.getParamValue("caption").empty()) {
|
2008-06-01 18:23:22 +00:00
|
|
|
listings_label_ = buffer().B_("Program Listing");
|
2008-02-15 14:30:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-05-20 13:09:35 +00:00
|
|
|
Buffer const & master = *buffer().masterBuffer();
|
|
|
|
Counters & counters = master.params().documentClass().counters();
|
2008-02-15 14:30:08 +00:00
|
|
|
docstring const cnt = from_ascii("listing");
|
2008-05-20 13:09:35 +00:00
|
|
|
listings_label_ = master.B_("Program Listing");
|
2008-02-15 14:30:08 +00:00
|
|
|
if (counters.hasCounter(cnt)) {
|
2010-01-20 19:42:12 +00:00
|
|
|
counters.step(cnt, utype);
|
2008-02-15 14:30:08 +00:00
|
|
|
listings_label_ += " " + convert<docstring>(counters.value(cnt));
|
2007-05-24 14:10:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-12 08:00:59 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|