2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetinclude.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS
|
|
|
|
|
*/
|
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
|
|
|
|
|
|
|
|
|
#include "insetinclude.h"
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferlist.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "BufferView.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
2003-03-05 14:59:37 +00:00
|
|
|
|
#include "funcrequest.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "gettext.h"
|
2003-03-05 14:59:37 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "lyxrc.h"
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include "Lsstream.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
#include "frontends/Dialogs.h"
|
2002-08-02 16:30:58 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2002-08-01 17:28:59 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
#include "support/filetools.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/FileInfo.h"
|
2002-08-06 14:02:59 +00:00
|
|
|
|
#include "support/FileMonitor.h"
|
2001-07-29 17:39:01 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
#include "graphics/PreviewedInset.h"
|
|
|
|
|
#include "graphics/PreviewImage.h"
|
|
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
using std::vector;
|
2000-06-07 08:53:40 +00:00
|
|
|
|
using std::pair;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
extern BufferList bufferlist;
|
2002-08-02 16:30:58 +00:00
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
|
|
class InsetInclude::PreviewImpl : public grfx::PreviewedInset {
|
|
|
|
|
public:
|
|
|
|
|
///
|
|
|
|
|
PreviewImpl(InsetInclude & p) : PreviewedInset(p) {}
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
bool previewWanted() const;
|
|
|
|
|
///
|
|
|
|
|
string const latexString() const;
|
|
|
|
|
///
|
|
|
|
|
InsetInclude & parent() const {
|
|
|
|
|
return *static_cast<InsetInclude*>(inset());
|
|
|
|
|
}
|
2002-08-06 14:02:59 +00:00
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
bool monitoring() const { return monitor_.get(); }
|
|
|
|
|
///
|
|
|
|
|
void startMonitoring();
|
|
|
|
|
///
|
|
|
|
|
void stopMonitoring() { monitor_.reset(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/// Invoked by monitor_ should the parent file change.
|
|
|
|
|
void restartLoading();
|
|
|
|
|
///
|
|
|
|
|
boost::scoped_ptr<FileMonitor> monitor_;
|
2002-08-01 17:28:59 +00:00
|
|
|
|
};
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-06-05 15:07:44 +00:00
|
|
|
|
string const uniqueID()
|
2001-03-23 17:09:34 +00:00
|
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
|
static unsigned int seed = 1000;
|
2000-07-02 09:52:44 +00:00
|
|
|
|
|
2001-07-13 14:03:48 +00:00
|
|
|
|
ostringstream ost;
|
2000-07-02 09:52:44 +00:00
|
|
|
|
ost << "file" << ++seed;
|
2000-07-25 16:15:35 +00:00
|
|
|
|
|
|
|
|
|
// Needed if we use lyxstring.
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(ost.str());
|
2000-07-02 09:52:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2000-07-02 09:52:44 +00:00
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
InsetInclude::InsetInclude(Params const & p)
|
2002-08-01 17:28:59 +00:00
|
|
|
|
: params_(p), include_label(uniqueID()),
|
|
|
|
|
preview_(new PreviewImpl(*this))
|
2001-03-23 17:09:34 +00:00
|
|
|
|
{}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b)
|
2002-08-01 17:28:59 +00:00
|
|
|
|
: include_label(uniqueID()),
|
|
|
|
|
preview_(new PreviewImpl(*this))
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-23 17:09:34 +00:00
|
|
|
|
params_.cparams = p;
|
|
|
|
|
params_.masterFilename_ = b.fileName();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetInclude::~InsetInclude()
|
|
|
|
|
{
|
2003-03-05 14:59:37 +00:00
|
|
|
|
InsetIncludeMailer mailer(*this);
|
|
|
|
|
mailer.hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
|
|
|
|
|
{
|
2003-03-07 15:58:02 +00:00
|
|
|
|
dispatch_result result = UNDISPATCHED;
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetInclude::Params p;
|
|
|
|
|
InsetIncludeMailer::string2params(cmd.argument, p);
|
|
|
|
|
if (p.cparams.getCmdName().empty())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
set(p);
|
|
|
|
|
params_.masterFilename_ = cmd.view()->buffer()->fileName();
|
|
|
|
|
|
2003-03-19 14:45:22 +00:00
|
|
|
|
cmd.view()->updateInset(this);
|
2003-03-07 15:58:02 +00:00
|
|
|
|
result = DISPATCHED;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
|
|
|
|
InsetIncludeMailer mailer(*this);
|
2003-03-10 22:12:07 +00:00
|
|
|
|
mailer.updateDialog(cmd.view());
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2003-03-09 09:38:47 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
|
|
|
|
edit(cmd.view(), cmd.x, cmd.y, cmd.button());
|
|
|
|
|
break;
|
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
return result;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
InsetInclude::Params const & InsetInclude::params() const
|
2001-03-14 10:57:39 +00:00
|
|
|
|
{
|
|
|
|
|
return params_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
bool InsetInclude::Params::operator==(Params const & o) const
|
2001-03-14 10:57:39 +00:00
|
|
|
|
{
|
2001-03-23 17:09:34 +00:00
|
|
|
|
if (cparams == o.cparams && flag == o.flag &&
|
2002-09-09 17:32:53 +00:00
|
|
|
|
masterFilename_ == o.masterFilename_)
|
2001-03-23 17:09:34 +00:00
|
|
|
|
return true;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
bool InsetInclude::Params::operator!=(Params const & o) const
|
|
|
|
|
{
|
|
|
|
|
return !(*this == o);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
void InsetInclude::set(Params const & p)
|
|
|
|
|
{
|
|
|
|
|
params_ = p;
|
|
|
|
|
|
2002-12-04 12:07:48 +00:00
|
|
|
|
string command;
|
2003-04-24 20:02:49 +00:00
|
|
|
|
|
2002-12-04 12:07:48 +00:00
|
|
|
|
switch (params_.flag) {
|
|
|
|
|
case INCLUDE:
|
|
|
|
|
command="include";
|
|
|
|
|
break;
|
|
|
|
|
case VERB:
|
|
|
|
|
command="verbatiminput";
|
|
|
|
|
break;
|
|
|
|
|
case INPUT:
|
|
|
|
|
command="input";
|
|
|
|
|
break;
|
|
|
|
|
case VERBAST:
|
|
|
|
|
command="verbatiminput*";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-04-24 20:02:49 +00:00
|
|
|
|
|
|
|
|
|
params_.cparams.setCmdName(command);
|
|
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
if (preview_->monitoring())
|
|
|
|
|
preview_->stopMonitoring();
|
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
if (grfx::PreviewedInset::activated() && params_.flag == INPUT)
|
|
|
|
|
preview_->generatePreview();
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
Inset * InsetInclude::clone(Buffer const & buffer, bool) const
|
2001-03-14 10:57:39 +00:00
|
|
|
|
{
|
2001-03-23 17:09:34 +00:00
|
|
|
|
Params p(params_);
|
|
|
|
|
p.masterFilename_ = buffer.fileName();
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
return new InsetInclude(p);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
2003-03-10 22:12:07 +00:00
|
|
|
|
void InsetInclude::edit(BufferView * bv, int, int, mouse_button::state)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2003-03-05 14:59:37 +00:00
|
|
|
|
InsetIncludeMailer mailer(*this);
|
2003-03-10 22:12:07 +00:00
|
|
|
|
mailer.showDialog(bv);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-20 14:18:48 +00:00
|
|
|
|
void InsetInclude::edit(BufferView * bv, bool)
|
|
|
|
|
{
|
2002-05-26 17:33:14 +00:00
|
|
|
|
edit(bv, 0, 0, mouse_button::none);
|
2001-07-20 14:18:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetInclude::write(Buffer const *, ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2002-08-02 18:25:25 +00:00
|
|
|
|
os << "Include " << params_.cparams.getCommand() << '\n'
|
|
|
|
|
<< "preview " << tostr(params_.cparams.preview()) << '\n';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetInclude::read(Buffer const *, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-28 10:25:20 +00:00
|
|
|
|
params_.cparams.read(lex);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (params_.cparams.getCmdName() == "include")
|
|
|
|
|
params_.flag = INCLUDE;
|
|
|
|
|
else if (params_.cparams.getCmdName() == "input")
|
|
|
|
|
params_.flag = INPUT;
|
|
|
|
|
/* FIXME: is this logic necessary now ? */
|
|
|
|
|
else if (contains(params_.cparams.getCmdName(), "verbatim")) {
|
|
|
|
|
params_.flag = VERB;
|
|
|
|
|
if (params_.cparams.getCmdName() == "verbatiminput*")
|
|
|
|
|
params_.flag = VERBAST;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
bool InsetInclude::display() const
|
2000-04-04 00:19:15 +00:00
|
|
|
|
{
|
2001-03-14 10:57:39 +00:00
|
|
|
|
return !(params_.flag == INPUT);
|
2000-04-04 00:19:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-28 12:24:16 +00:00
|
|
|
|
string const InsetInclude::getScreenLabel(Buffer const *) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string temp;
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
|
|
|
|
switch (params_.flag) {
|
|
|
|
|
case INPUT: temp += _("Input"); break;
|
|
|
|
|
case VERB: temp += _("Verbatim Input"); break;
|
|
|
|
|
case VERBAST: temp += _("Verbatim Input*"); break;
|
|
|
|
|
case INCLUDE: temp += _("Include"); break;
|
|
|
|
|
}
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
temp += ": ";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (params_.cparams.getContents().empty())
|
|
|
|
|
temp += "???";
|
|
|
|
|
else
|
|
|
|
|
temp += params_.cparams.getContents();
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const InsetInclude::getFileName() const
|
2000-07-27 08:55:59 +00:00
|
|
|
|
{
|
2001-03-14 10:57:39 +00:00
|
|
|
|
return MakeAbsPath(params_.cparams.getContents(),
|
2000-07-27 08:55:59 +00:00
|
|
|
|
OnlyPath(getMasterFilename()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const InsetInclude::getMasterFilename() const
|
2000-04-04 00:19:15 +00:00
|
|
|
|
{
|
2001-03-23 17:09:34 +00:00
|
|
|
|
return params_.masterFilename_;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool InsetInclude::loadIfNeeded() const
|
|
|
|
|
{
|
2002-09-09 17:32:53 +00:00
|
|
|
|
if (isVerbatim())
|
2001-03-14 10:57:39 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (!IsLyXFilename(getFileName()))
|
|
|
|
|
return false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (bufferlist.exists(getFileName()))
|
|
|
|
|
return true;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// the readonly flag can/will be wrong, not anymore I think.
|
|
|
|
|
FileInfo finfo(getFileName());
|
2002-01-13 21:35:50 +00:00
|
|
|
|
if (!finfo.isOK())
|
|
|
|
|
return false;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-04-24 20:02:49 +00:00
|
|
|
|
return bufferlist.loadLyXFile(getFileName(), false) != 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetInclude::latex(Buffer const * buffer, ostream & os,
|
2000-04-19 01:42:55 +00:00
|
|
|
|
bool /*fragile*/, bool /*fs*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-14 10:57:39 +00:00
|
|
|
|
string incfile(params_.cparams.getContents());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
// Do nothing if no file name has been specified
|
2000-09-26 13:54:57 +00:00
|
|
|
|
if (incfile.empty())
|
2000-03-02 02:19:43 +00:00
|
|
|
|
return 0;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
if (loadIfNeeded()) {
|
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(getFileName());
|
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
// FIXME: this should be a GUI warning
|
2000-10-03 09:13:34 +00:00
|
|
|
|
if (tmp->params.textclass != buffer->params.textclass) {
|
2001-03-13 13:40:08 +00:00
|
|
|
|
lyxerr << "WARNING: Included file `"
|
2000-03-02 02:19:43 +00:00
|
|
|
|
<< MakeDisplayPath(getFileName())
|
2001-03-13 13:40:08 +00:00
|
|
|
|
<< "' has textclass `"
|
2002-07-21 21:21:06 +00:00
|
|
|
|
<< tmp->params.getLyXTextClass().name()
|
2001-03-13 13:40:08 +00:00
|
|
|
|
<< "' while parent file has textclass `"
|
2002-07-21 21:21:06 +00:00
|
|
|
|
<< buffer->params.getLyXTextClass().name()
|
2000-03-02 02:19:43 +00:00
|
|
|
|
<< "'." << endl;
|
2001-03-13 13:40:08 +00:00
|
|
|
|
//return 0;
|
2000-03-02 02:19:43 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
// write it to a file (so far the complete file)
|
2000-05-11 16:12:46 +00:00
|
|
|
|
string writefile = ChangeExtension(getFileName(), ".tex");
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2000-10-03 09:13:34 +00:00
|
|
|
|
if (!buffer->tmppath.empty()
|
|
|
|
|
&& !buffer->niceFile) {
|
2000-03-02 02:19:43 +00:00
|
|
|
|
incfile = subst(incfile, '/','@');
|
|
|
|
|
#ifdef __EMX__
|
|
|
|
|
incfile = subst(incfile, ':', '$');
|
|
|
|
|
#endif
|
2000-10-03 09:13:34 +00:00
|
|
|
|
writefile = AddName(buffer->tmppath, incfile);
|
2000-03-02 02:19:43 +00:00
|
|
|
|
} else
|
|
|
|
|
writefile = getFileName();
|
2000-05-11 16:12:46 +00:00
|
|
|
|
writefile = ChangeExtension(writefile, ".tex");
|
2000-03-02 02:19:43 +00:00
|
|
|
|
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
|
|
|
|
|
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-10-03 09:13:34 +00:00
|
|
|
|
tmp->markDepClean(buffer->tmppath);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-03-02 02:19:43 +00:00
|
|
|
|
tmp->makeLaTeXFile(writefile,
|
2001-03-14 10:57:39 +00:00
|
|
|
|
OnlyPath(getMasterFilename()),
|
2000-10-03 09:13:34 +00:00
|
|
|
|
buffer->niceFile, true);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
2000-03-02 02:19:43 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (isVerbatim()) {
|
|
|
|
|
os << '\\' << params_.cparams.getCmdName() << '{' << incfile << '}';
|
|
|
|
|
} else if (params_.flag == INPUT) {
|
2000-03-02 02:19:43 +00:00
|
|
|
|
// \input wants file with extension (default is .tex)
|
|
|
|
|
if (!IsLyXFilename(getFileName())) {
|
2001-03-14 10:57:39 +00:00
|
|
|
|
os << '\\' << params_.cparams.getCmdName() << '{' << incfile << '}';
|
2000-03-02 02:19:43 +00:00
|
|
|
|
} else {
|
2001-03-14 10:57:39 +00:00
|
|
|
|
os << '\\' << params_.cparams.getCmdName() << '{'
|
2000-05-11 16:12:46 +00:00
|
|
|
|
<< ChangeExtension(incfile, ".tex")
|
2000-03-02 02:19:43 +00:00
|
|
|
|
<< '}';
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// \include don't want extension and demands that the
|
|
|
|
|
// file really have .tex
|
2001-03-14 10:57:39 +00:00
|
|
|
|
os << '\\' << params_.cparams.getCmdName() << '{'
|
2000-05-11 16:12:46 +00:00
|
|
|
|
<< ChangeExtension(incfile, string())
|
2000-03-02 02:19:43 +00:00
|
|
|
|
<< '}';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
int InsetInclude::ascii(Buffer const *, ostream & os, int) const
|
2000-12-28 16:22:28 +00:00
|
|
|
|
{
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (isVerbatim())
|
2000-12-28 16:22:28 +00:00
|
|
|
|
os << GetFileContents(getFileName());
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetInclude::linuxdoc(Buffer const * buffer, ostream & os) const
|
2000-07-01 12:54:45 +00:00
|
|
|
|
{
|
2001-03-14 10:57:39 +00:00
|
|
|
|
string incfile(params_.cparams.getContents());
|
2002-03-21 17:09:55 +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
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (loadIfNeeded()) {
|
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(getFileName());
|
|
|
|
|
|
|
|
|
|
// write it to a file (so far the complete file)
|
|
|
|
|
string writefile = ChangeExtension(getFileName(), ".sgml");
|
2002-03-04 10:04:29 +00:00
|
|
|
|
if (!buffer->tmppath.empty() && !buffer->niceFile) {
|
2000-07-01 12:54:45 +00:00
|
|
|
|
incfile = subst(incfile, '/','@');
|
2000-10-03 09:13:34 +00:00
|
|
|
|
writefile = AddName(buffer->tmppath, incfile);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
} else
|
|
|
|
|
writefile = getFileName();
|
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (IsLyXFilename(getFileName()))
|
2000-07-01 12:54:45 +00:00
|
|
|
|
writefile = ChangeExtension(writefile, ".sgml");
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
|
|
|
|
|
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-10-03 09:13:34 +00:00
|
|
|
|
tmp->makeLinuxDocFile(writefile, buffer->niceFile, true);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (isVerbatim()) {
|
2002-01-16 12:04:16 +00:00
|
|
|
|
os << "<![CDATA["
|
|
|
|
|
<< GetFileContents(getFileName())
|
|
|
|
|
<< "]]>";
|
2001-03-14 10:57:39 +00:00
|
|
|
|
} else
|
2000-07-01 12:54:45 +00:00
|
|
|
|
os << '&' << include_label << ';';
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
int InsetInclude::docbook(Buffer const * buffer, ostream & os,
|
|
|
|
|
bool /*mixcont*/) const
|
2000-07-01 12:54:45 +00:00
|
|
|
|
{
|
2001-03-14 10:57:39 +00:00
|
|
|
|
string incfile(params_.cparams.getContents());
|
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
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (loadIfNeeded()) {
|
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(getFileName());
|
|
|
|
|
|
|
|
|
|
// write it to a file (so far the complete file)
|
|
|
|
|
string writefile = ChangeExtension(getFileName(), ".sgml");
|
2002-03-04 10:04:29 +00:00
|
|
|
|
if (!buffer->tmppath.empty() && !buffer->niceFile) {
|
2000-07-01 12:54:45 +00:00
|
|
|
|
incfile = subst(incfile, '/','@');
|
2000-10-03 09:13:34 +00:00
|
|
|
|
writefile = AddName(buffer->tmppath, incfile);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
} else
|
|
|
|
|
writefile = getFileName();
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (IsLyXFilename(getFileName()))
|
2000-07-01 12:54:45 +00:00
|
|
|
|
writefile = ChangeExtension(writefile, ".sgml");
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
|
|
|
|
|
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2000-10-03 09:13:34 +00:00
|
|
|
|
tmp->makeDocBookFile(writefile, buffer->niceFile, true);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (isVerbatim()) {
|
2002-01-16 12:04:16 +00:00
|
|
|
|
os << "<inlinegraphic fileref=\""
|
|
|
|
|
<< '&' << include_label << ';'
|
2002-01-16 12:54:52 +00:00
|
|
|
|
<< "\" format=\"linespecific\">";
|
2001-03-14 10:57:39 +00:00
|
|
|
|
} else
|
2000-07-01 12:54: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
|
|
|
|
{
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
string incfile(params_.cparams.getContents());
|
|
|
|
|
string writefile;
|
|
|
|
|
|
2001-03-23 17:09:34 +00:00
|
|
|
|
Buffer const * const b = bufferlist.getBuffer(getMasterFilename());
|
2000-11-13 15:43:36 +00:00
|
|
|
|
|
2002-03-04 10:04:29 +00:00
|
|
|
|
if (b && !b->tmppath.empty() && !b->niceFile && !isVerbatim()) {
|
2002-02-20 09:04:56 +00:00
|
|
|
|
incfile = subst(incfile, '/','@');
|
|
|
|
|
writefile = AddName(b->tmppath, incfile);
|
|
|
|
|
} else
|
2000-11-13 15:43:36 +00:00
|
|
|
|
writefile = getFileName();
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2002-02-20 09:04:56 +00:00
|
|
|
|
if (IsLyXFilename(getFileName()))
|
|
|
|
|
writefile = ChangeExtension(writefile, ".sgml");
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.includeFile(include_label, writefile);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (isVerbatim())
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("verbatim");
|
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:
|
|
|
|
|
if (loadIfNeeded()) {
|
|
|
|
|
// a file got loaded
|
2002-03-05 13:38:40 +00:00
|
|
|
|
Buffer * const tmp = bufferlist.getBuffer(getFileName());
|
|
|
|
|
if (tmp) {
|
|
|
|
|
if (b)
|
|
|
|
|
tmp->niceFile = b->niceFile;
|
2001-03-23 17:09:34 +00:00
|
|
|
|
tmp->validate(features);
|
2002-03-05 13:38:40 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
vector<string> const InsetInclude::getLabelList() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
|
vector<string> l;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
if (loadIfNeeded()) {
|
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(getFileName());
|
2001-03-14 10:57:39 +00:00
|
|
|
|
tmp->setParentName("");
|
2000-09-26 13:54:57 +00:00
|
|
|
|
l = tmp->getLabelList();
|
|
|
|
|
tmp->setParentName(getMasterFilename());
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
return l;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-18 13:25:18 +00:00
|
|
|
|
void InsetInclude::fillWithBibKeys(vector<pair<string,string> > & keys) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (loadIfNeeded()) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(getFileName());
|
2001-03-14 10:57:39 +00:00
|
|
|
|
tmp->setParentName("");
|
2003-02-18 13:25:18 +00:00
|
|
|
|
tmp->fillWithBibKeys(keys);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmp->setParentName(getMasterFilename());
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetInclude::ascent(BufferView * bv, LyXFont const & font) const
|
|
|
|
|
{
|
|
|
|
|
return preview_->previewReady() ?
|
|
|
|
|
preview_->pimage()->ascent() : InsetButton::ascent(bv, font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetInclude::descent(BufferView * bv, LyXFont const & font) const
|
|
|
|
|
{
|
|
|
|
|
return preview_->previewReady() ?
|
|
|
|
|
preview_->pimage()->descent() : InsetButton::descent(bv, font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetInclude::width(BufferView * bv, LyXFont const & font) const
|
|
|
|
|
{
|
|
|
|
|
return preview_->previewReady() ?
|
|
|
|
|
preview_->pimage()->width() : InsetButton::width(bv, font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetInclude::draw(BufferView * bv, LyXFont const & font, int y,
|
2003-03-17 01:34:36 +00:00
|
|
|
|
float & xx) const
|
2002-08-01 17:28:59 +00:00
|
|
|
|
{
|
2003-02-26 13:10:16 +00:00
|
|
|
|
cache(bv);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
if (!preview_->previewReady()) {
|
2003-03-17 01:34:36 +00:00
|
|
|
|
InsetButton::draw(bv, font, y, xx);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
if (!preview_->monitoring())
|
|
|
|
|
preview_->startMonitoring();
|
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
int const x = int(xx);
|
|
|
|
|
int const w = width(bv, font);
|
|
|
|
|
int const d = descent(bv, font);
|
|
|
|
|
int const a = ascent(bv, font);
|
|
|
|
|
int const h = a + d;
|
|
|
|
|
|
|
|
|
|
bv->painter().image(x, y - a, w, h,
|
2003-02-26 11:41:23 +00:00
|
|
|
|
*(preview_->pimage()->image()));
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
|
|
|
|
xx += w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// preview stuff
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
void InsetInclude::addPreview(grfx::PreviewLoader & ploader) const
|
|
|
|
|
{
|
|
|
|
|
preview_->addPreview(ploader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetInclude::PreviewImpl::previewWanted() const
|
|
|
|
|
{
|
2002-08-02 18:25:25 +00:00
|
|
|
|
return parent().params_.flag == InsetInclude::INPUT &&
|
2002-08-06 14:02:59 +00:00
|
|
|
|
parent().params_.cparams.preview() &&
|
|
|
|
|
IsFileReadable(parent().getFileName());
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetInclude::PreviewImpl::latexString() const
|
|
|
|
|
{
|
|
|
|
|
if (!view() || !view()->buffer())
|
|
|
|
|
return string();
|
|
|
|
|
|
|
|
|
|
ostringstream os;
|
|
|
|
|
parent().latex(view()->buffer(), os, false, false);
|
|
|
|
|
|
2002-11-04 02:12:42 +00:00
|
|
|
|
return STRCONV(os.str());
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
2002-08-06 14:02:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetInclude::PreviewImpl::startMonitoring()
|
|
|
|
|
{
|
|
|
|
|
monitor_.reset(new FileMonitor(parent().getFileName(), 2000));
|
|
|
|
|
monitor_->connect(boost::bind(&PreviewImpl::restartLoading, this));
|
|
|
|
|
monitor_->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetInclude::PreviewImpl::restartLoading()
|
|
|
|
|
{
|
|
|
|
|
lyxerr << "restartLoading()" << std::endl;
|
|
|
|
|
removePreview();
|
|
|
|
|
if (view())
|
2003-03-19 14:45:22 +00:00
|
|
|
|
view()->updateInset(&parent());
|
2002-08-06 14:02:59 +00:00
|
|
|
|
generatePreview();
|
|
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
string const InsetIncludeMailer::name_("include");
|
|
|
|
|
|
2003-03-05 14:59:37 +00:00
|
|
|
|
InsetIncludeMailer::InsetIncludeMailer(InsetInclude & inset)
|
2003-03-07 14:08:10 +00:00
|
|
|
|
: inset_(inset)
|
2003-03-05 14:59:37 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetIncludeMailer::inset2string() const
|
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
return params2string(inset_.params());
|
2003-03-05 14:59:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetIncludeMailer::string2params(string const & in,
|
|
|
|
|
InsetInclude::Params & params)
|
|
|
|
|
{
|
|
|
|
|
params = InsetInclude::Params();
|
|
|
|
|
|
2003-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
istringstream data(in);
|
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
|
lex.setStream(data);
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
if (token != name_)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
|
// by Buffer::readInset
|
2003-03-07 14:08:10 +00:00
|
|
|
|
if (lex.isOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
if (token != "Include")
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-03-10 03:11:54 +00:00
|
|
|
|
if (lex.isOK()) {
|
2003-04-24 20:02:49 +00:00
|
|
|
|
InsetInclude inset(params);
|
2003-03-10 03:11:54 +00:00
|
|
|
|
inset.read(0, lex);
|
|
|
|
|
params = inset.params();
|
|
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const
|
2003-03-07 14:08:10 +00:00
|
|
|
|
InsetIncludeMailer::params2string(InsetInclude::Params const & params)
|
2003-03-05 14:59:37 +00:00
|
|
|
|
{
|
|
|
|
|
InsetInclude inset(params);
|
|
|
|
|
inset.set(params);
|
|
|
|
|
ostringstream data;
|
2003-03-07 14:08:10 +00:00
|
|
|
|
data << name_ << ' ';
|
2003-03-05 14:59:37 +00:00
|
|
|
|
inset.write(0, data);
|
|
|
|
|
data << "\\end_inset\n";
|
|
|
|
|
|
|
|
|
|
return data.str();
|
|
|
|
|
}
|