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
|
|
|
|
|
*
|
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
|
|
|
|
|
|
|
|
|
#include "insetinclude.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "buffer.h"
|
2003-06-20 12:46:28 +00:00
|
|
|
|
#include "buffer_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#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"
|
2003-05-22 18:59:10 +00:00
|
|
|
|
#include "latexrunparams.h"
|
2003-03-05 14:59:37 +00:00
|
|
|
|
#include "lyxlex.h"
|
2003-05-30 06:48:24 +00:00
|
|
|
|
#include "metricsinfo.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "graphics/PreviewedInset.h"
|
|
|
|
|
#include "graphics/PreviewImage.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"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "support/filetools.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/lstrings.h" // contains
|
|
|
|
|
#include "support/tostr.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
|
using namespace lyx::support;
|
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2003-09-08 00:33:41 +00:00
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
|
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
|
|
|
|
|
2003-07-21 21:30:57 +00:00
|
|
|
|
class InsetInclude::PreviewImpl : public lyx::graphics::PreviewedInset {
|
2002-08-01 17:28:59 +00:00
|
|
|
|
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;
|
2003-05-13 16:24:49 +00:00
|
|
|
|
return "file" + tostr(++seed);
|
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()),
|
2003-06-12 08:52:36 +00:00
|
|
|
|
preview_(new PreviewImpl(*this)),
|
|
|
|
|
set_label_(false)
|
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()),
|
2003-06-12 08:52:36 +00:00
|
|
|
|
preview_(new PreviewImpl(*this)),
|
|
|
|
|
set_label_(false)
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-12 08:52:36 +00:00
|
|
|
|
InsetInclude::InsetInclude(InsetInclude const & other)
|
2003-07-25 21:20:24 +00:00
|
|
|
|
: InsetOld(other),
|
2003-06-12 08:52:36 +00:00
|
|
|
|
params_(other.params_),
|
|
|
|
|
include_label(other.include_label),
|
|
|
|
|
preview_(new PreviewImpl(*this)),
|
|
|
|
|
set_label_(other.set_label_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
switch (cmd.action) {
|
2003-05-16 07:44:00 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetInclude::Params p;
|
|
|
|
|
InsetIncludeMailer::string2params(cmd.argument, p);
|
2003-05-16 07:44:00 +00:00
|
|
|
|
if (!p.cparams.getCmdName().empty()) {
|
|
|
|
|
set(p);
|
|
|
|
|
params_.masterFilename_ = cmd.view()->buffer()->fileName();
|
2003-08-27 13:51:18 +00:00
|
|
|
|
cmd.view()->updateInset(this);
|
2003-05-16 07:44:00 +00:00
|
|
|
|
}
|
|
|
|
|
return DISPATCHED;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
2003-03-05 14:59:37 +00:00
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2003-05-16 07:44:00 +00:00
|
|
|
|
InsetIncludeMailer(*this).updateDialog(cmd.view());
|
|
|
|
|
return DISPATCHED;
|
2003-03-07 15:58:02 +00:00
|
|
|
|
|
2003-03-09 09:38:47 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE:
|
2003-09-04 14:02:05 +00:00
|
|
|
|
if (button_.box().contains(cmd.x, cmd.y))
|
|
|
|
|
InsetIncludeMailer(*this).showDialog(cmd.view());
|
|
|
|
|
return DISPATCHED;
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_DIALOG_SHOW:
|
2003-05-16 07:44:00 +00:00
|
|
|
|
InsetIncludeMailer(*this).showDialog(cmd.view());
|
|
|
|
|
return DISPATCHED;
|
2003-03-09 09:38:47 +00:00
|
|
|
|
|
2003-03-07 15:58:02 +00:00
|
|
|
|
default:
|
2003-07-25 21:20:24 +00:00
|
|
|
|
return InsetOld::localDispatch(cmd);
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
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
|
|
|
|
{
|
2003-05-16 07:44:00 +00:00
|
|
|
|
return cparams == o.cparams && flag == o.flag &&
|
|
|
|
|
masterFilename_ == o.masterFilename_;
|
2001-03-23 17:09:34 +00:00
|
|
|
|
}
|
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();
|
|
|
|
|
|
2003-07-21 21:30:57 +00:00
|
|
|
|
if (lyx::graphics::PreviewedInset::activated() && params_.flag == INPUT)
|
2002-08-01 17:28:59 +00:00
|
|
|
|
preview_->generatePreview();
|
2001-03-14 10:57:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetInclude::clone() const
|
2001-03-14 10:57:39 +00:00
|
|
|
|
{
|
2003-06-03 15:10:14 +00:00
|
|
|
|
//Params p(params_);
|
|
|
|
|
//p.masterFilename_ = buffer.fileName();
|
|
|
|
|
#warning FIXME: broken cross-doc copy/paste - must fix
|
2001-03-14 10:57:39 +00:00
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetInclude(params_));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetInclude::write(Buffer const &, ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
write(os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetInclude::write(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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetInclude::read(Buffer const &, LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
read(lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetInclude::read(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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +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;
|
2003-06-20 12:46:28 +00:00
|
|
|
|
return loadLyXFile(bufferlist.newBuffer(getFileName()),
|
|
|
|
|
getFileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetInclude::latex(Buffer const & buffer, ostream & os,
|
2003-05-23 08:59:47 +00:00
|
|
|
|
LatexRunParams const & runparams) 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
|
2003-09-09 09:47:59 +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 `"
|
2003-09-09 09:47:59 +00:00
|
|
|
|
<< tmp->params().getLyXTextClass().name()
|
2001-03-13 13:40:08 +00:00
|
|
|
|
<< "' while parent file has textclass `"
|
2003-09-09 09:47:59 +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
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!buffer.temppath().empty() && !runparams.nice) {
|
2000-03-02 02:19:43 +00:00
|
|
|
|
incfile = subst(incfile, '/','@');
|
|
|
|
|
#ifdef __EMX__
|
|
|
|
|
incfile = subst(incfile, ':', '$');
|
|
|
|
|
#endif
|
2003-09-09 09:47:59 +00:00
|
|
|
|
writefile = AddName(buffer.temppath(), 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
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
tmp->markDepClean(buffer.temppath());
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-05-22 21:10:22 +00:00
|
|
|
|
tmp->makeLaTeXFile(writefile, OnlyPath(getMasterFilename()),
|
2003-07-26 21:37:10 +00:00
|
|
|
|
runparams, false);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +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");
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!buffer.temppath().empty() && !buffer.niceFile()) {
|
2000-07-01 12:54:45 +00:00
|
|
|
|
incfile = subst(incfile, '/','@');
|
2003-09-09 09:47:59 +00:00
|
|
|
|
writefile = AddName(buffer.temppath(), 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
|
|
|
|
|
2003-09-09 09:47:59 +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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetInclude::docbook(Buffer const & buffer, ostream & os,
|
2002-06-24 20:28:12 +00:00
|
|
|
|
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");
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!buffer.temppath().empty() && !buffer.niceFile()) {
|
2000-07-01 12:54:45 +00:00
|
|
|
|
incfile = subst(incfile, '/','@');
|
2003-09-09 09:47:59 +00:00
|
|
|
|
writefile = AddName(buffer.temppath(), 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
|
|
|
|
|
2003-09-09 09:47:59 +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;
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
Buffer const & b = *bufferlist.getBuffer(getMasterFilename());
|
2000-11-13 15:43:36 +00:00
|
|
|
|
|
2003-09-09 09:47:59 +00:00
|
|
|
|
if (!b.temppath().empty() && !b.niceFile() && !isVerbatim()) {
|
2002-02-20 09:04:56 +00:00
|
|
|
|
incfile = subst(incfile, '/','@');
|
2003-09-09 09:47:59 +00:00
|
|
|
|
writefile = AddName(b.temppath(), incfile);
|
2002-02-20 09:04:56 +00:00
|
|
|
|
} 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) {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-16 11:49:38 +00:00
|
|
|
|
void InsetInclude::getLabelList(std::vector<string> & list) const
|
1999-09-27 18:44:28 +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("");
|
2003-06-16 11:49:38 +00:00
|
|
|
|
tmp->getLabelList(list);
|
2000-09-26 13:54:57 +00:00
|
|
|
|
tmp->setParentName(getMasterFilename());
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-28 01:23:11 +00:00
|
|
|
|
void InsetInclude::fillWithBibKeys(std::vector<std::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
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-08-01 17:28:59 +00:00
|
|
|
|
{
|
2003-06-02 10:03:27 +00:00
|
|
|
|
if (preview_->previewReady()) {
|
|
|
|
|
dim.asc = preview_->pimage()->ascent();
|
|
|
|
|
dim.des = preview_->pimage()->descent();
|
|
|
|
|
dim.wid = preview_->pimage()->width();
|
|
|
|
|
} else {
|
2003-06-12 08:52:36 +00:00
|
|
|
|
if (!set_label_) {
|
|
|
|
|
set_label_ = true;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
button_.update(getScreenLabel(*mi.base.bv->buffer()),
|
2003-06-12 08:52:36 +00:00
|
|
|
|
editable() != NOT_EDITABLE);
|
|
|
|
|
}
|
|
|
|
|
button_.metrics(mi, dim);
|
2003-06-02 10:03:27 +00:00
|
|
|
|
}
|
2003-09-04 14:02:05 +00:00
|
|
|
|
int center_indent = (params_.flag == INPUT ? 0 :
|
|
|
|
|
(mi.base.textwidth - dim.wid) / 2);
|
|
|
|
|
Box b(center_indent, center_indent + dim.wid, -dim.asc, dim.des);
|
|
|
|
|
button_.setBox(b);
|
|
|
|
|
|
2003-08-26 10:33:59 +00:00
|
|
|
|
dim.wid = mi.base.textwidth;
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim_ = dim;
|
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
|
|
|
|
{
|
2003-05-30 06:48:24 +00:00
|
|
|
|
cache(pi.base.bv);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
if (!preview_->previewReady()) {
|
2003-09-04 14:02:05 +00:00
|
|
|
|
button_.draw(pi, x + button_.box().x1, y);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-06 14:02:59 +00:00
|
|
|
|
if (!preview_->monitoring())
|
|
|
|
|
preview_->startMonitoring();
|
|
|
|
|
|
2003-09-04 14:02:05 +00:00
|
|
|
|
pi.pain.image(x + button_.box().x1, y - dim_.asc, dim_.wid, dim_.height(),
|
2003-02-26 11:41:23 +00:00
|
|
|
|
*(preview_->pimage()->image()));
|
2002-08-01 17:28:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-12 08:52:36 +00:00
|
|
|
|
BufferView * InsetInclude::view() const
|
|
|
|
|
{
|
|
|
|
|
return button_.view();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-01 17:28:59 +00:00
|
|
|
|
//
|
|
|
|
|
// preview stuff
|
|
|
|
|
//
|
|
|
|
|
|
2003-07-21 21:30:57 +00:00
|
|
|
|
void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
|
2002-08-01 17:28:59 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2003-05-22 18:59:10 +00:00
|
|
|
|
LatexRunParams runparams;
|
|
|
|
|
runparams.flavor = LatexRunParams::LATEX;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
parent().latex(*view()->buffer(), os, runparams);
|
2002-08-01 17:28:59 +00:00
|
|
|
|
|
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-08-27 13:51:18 +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
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetIncludeMailer::inset2string(Buffer const &) const
|
2003-03-05 14:59:37 +00:00
|
|
|
|
{
|
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-05-26 09:13:55 +00:00
|
|
|
|
|
2003-05-13 16:24:49 +00:00
|
|
|
|
istringstream data(STRCONV(in));
|
2003-03-07 14:08:10 +00:00
|
|
|
|
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-08-28 07:41:31 +00:00
|
|
|
|
inset.read(lex);
|
2003-03-10 03:11:54 +00:00
|
|
|
|
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-08-28 07:41:31 +00:00
|
|
|
|
inset.write(data);
|
2003-03-05 14:59:37 +00:00
|
|
|
|
data << "\\end_inset\n";
|
2003-05-13 16:24:49 +00:00
|
|
|
|
return STRCONV(data.str());
|
2003-03-05 14:59:37 +00:00
|
|
|
|
}
|