Fix InsetInclude properly. Data is now stored in an InsetCommandParams

var rather tahn that nasty kludge InsetInclude::Params. Functions
that need info about the Buffer are passed a 'Buffer const &' arg.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7797 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2003-09-19 10:16:33 +00:00
parent e4eb667ea2
commit c319aee7c2
22 changed files with 247 additions and 210 deletions

View File

@ -1,3 +1,10 @@
2003-09-19 Angus Leeming <leeming@lyx.org>
* CutAndPaste.C (pasteSelection): remove fudge used to set the
masterFilename_ parameter in the include inset.
* factory.C (createInset): changes due to the changes to InsetInclude.
2003-09-19 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* paragraph.C: use appropriate alignment tags inside floats (bug 1290)

View File

@ -24,7 +24,6 @@
#include "paragraph_funcs.h"
#include "ParagraphParameters.h"
#include "insets/insetinclude.h"
#include "insets/insettabular.h"
#include "support/lstrings.h"
@ -297,14 +296,6 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
for (; lit != eit; ++lit) {
switch (lit->inset->lyxCode()) {
case InsetOld::INCLUDE_CODE: {
InsetInclude * ii = static_cast<InsetInclude*>(lit->inset);
InsetInclude::Params ip = ii->params();
ip.masterFilename_ = buffer.fileName();
ii->set(ip);
break;
}
case InsetOld::TABULAR_CODE: {
InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
it->buffer(const_cast<Buffer*>(&buffer));

View File

@ -231,7 +231,7 @@ InsetOld * createInset(FuncRequest const & cmd)
return inset;
} else if (name == "include") {
InsetInclude::Params iip;
InsetCommandParams iip;
InsetIncludeMailer::string2params(cmd.argument, iip);
return new InsetInclude(iip);
@ -328,7 +328,7 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
} else if (cmdName == "index") {
inset = new InsetIndex(inscmd);
} else if (cmdName == "include") {
inset = new InsetInclude(inscmd, buf);
inset = new InsetInclude(inscmd);
} else if (cmdName == "label") {
inset = new InsetLabel(inscmd);
} else if (cmdName == "url"
@ -373,7 +373,7 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
inset = new InsetBranch(buf.params(), tmptok);
} else if (tmptok == "Include") {
InsetCommandParams p("Include");
inset = new InsetInclude(p, buf);
inset = new InsetInclude(p);
} else if (tmptok == "Environment") {
lex.next();
inset = new InsetEnvironment(buf.params(), lex.getString());

View File

@ -1,3 +1,10 @@
2003-09-19 Angus Leeming <leeming@lyx.org>
* ControlInclude.[Ch]: Store and access the params as an
InsetCommandParams, rather than access them as a InsetInclude::Params
and store 'em as a boost::scoped_ptr<InsetInclude>.
Other clean-ups due to the changes in InsetInclude.
2003-09-18 Angus Leeming <leeming@lyx.org>
* ControlCommand.C (clearParams): simplify.

View File

@ -14,11 +14,15 @@
#include "ControlInclude.h"
#include "helper_funcs.h"
#include "Kernel.h"
#include "buffer.h"
#include "funcrequest.h"
#include "gettext.h"
#include "lyxrc.h"
#include "insets/insetinclude.h"
#include "support/filetools.h"
#include <utility>
@ -37,32 +41,30 @@ ControlInclude::ControlInclude(Dialog & parent)
bool ControlInclude::initialiseParams(string const & data)
{
InsetInclude::Params params;
InsetIncludeMailer::string2params(data, params);
inset_.reset(new InsetInclude(params));
InsetIncludeMailer::string2params(data, params_);
return true;
}
void ControlInclude::clearParams()
{
inset_.reset();
params_ = InsetCommandParams();
}
void ControlInclude::dispatchParams()
{
InsetInclude::Params p = params();
string const lfun = InsetIncludeMailer::params2string(p);
string const lfun = InsetIncludeMailer::params2string(params_);
kernel().dispatch(FuncRequest(LFUN_INSET_APPLY, lfun));
}
void ControlInclude::setParams(InsetInclude::Params const & params)
void ControlInclude::setParams(InsetCommandParams const & params)
{
inset_->set(params);
params_ = params;
}
string const ControlInclude::Browse(string const & in_name, Type in_type)
{
string const title = _("Select document to include");
@ -86,7 +88,7 @@ string const ControlInclude::Browse(string const & in_name, Type in_type)
pair<string, string> dir1(N_("Documents|#o#O"),
string(lyxrc.document_path));
string const docpath = OnlyPath(params().masterFilename_);
string const docpath = OnlyPath(kernel().buffer().fileName());
return browseRelFile(in_name, docpath, title, pattern, false, dir1);
}
@ -101,7 +103,8 @@ void ControlInclude::load(string const & file)
bool ControlInclude::fileExists(string const & file)
{
string const fileWithAbsPath
= MakeAbsPath(file, OnlyPath(params().masterFilename_));
= MakeAbsPath(file,
OnlyPath(kernel().buffer().fileName()));
if (IsFileReadable(fileWithAbsPath))
return true;

View File

@ -16,7 +16,7 @@
#include "Dialog.h"
#include "insets/insetinclude.h" // InsetIncludeParams
#include "insets/insetcommandparams.h"
/** A controller for the Include file dialog.
@ -45,10 +45,9 @@ public:
virtual bool isBufferDependent() const { return true; }
///
InsetInclude::Params const & params() const
{ return inset_->params(); }
InsetCommandParams const & params() const { return params_; }
///
void setParams(InsetInclude::Params const &);
void setParams(InsetCommandParams const &);
/// Browse for a file
string const Browse(string const &, Type);
@ -60,7 +59,7 @@ public:
bool fileExists(string const & file);
private:
///
boost::scoped_ptr<InsetInclude> inset_;
InsetCommandParams params_;
};
#endif // CONTROLINCLUDE_H

View File

@ -1,3 +1,8 @@
2003-09-19 Angus Leeming <leeming@lyx.org>
* QInclude.C: changes dues to the changed storage in InsetInclude,
from an InsetInclude::params to an InsetCommandParams.
2003-09-18 Angus Leeming <leeming@lyx.org>
* QInclude.C (apply): No need to set InsetInclude::Params::flag;

View File

@ -47,16 +47,16 @@ void QInclude::build_dialog()
void QInclude::update_contents()
{
InsetInclude::Params const & params = controller().params();
InsetCommandParams const & params = controller().params();
dialog_->filenameED->setText(toqstr(params.cparams.getContents()));
dialog_->filenameED->setText(toqstr(params.getContents()));
dialog_->visiblespaceCB->setChecked(false);
dialog_->visiblespaceCB->setEnabled(false);
dialog_->previewCB->setChecked(false);
dialog_->previewCB->setEnabled(false);
string cmdname = controller().params().cparams.getCmdName();
string cmdname = controller().params().getCmdName();
if (cmdname != "include" &&
cmdname != "verbatiminput" &&
cmdname != "verbatiminput*")
@ -65,7 +65,7 @@ void QInclude::update_contents()
if (cmdname == "input") {
dialog_->typeCO->setCurrentItem(0);
dialog_->previewCB->setEnabled(true);
dialog_->previewCB->setChecked(params.cparams.preview());
dialog_->previewCB->setChecked(params.preview());
} else if (cmdname == "include") {
dialog_->typeCO->setCurrentItem(1);
@ -84,21 +84,21 @@ void QInclude::update_contents()
void QInclude::apply()
{
InsetInclude::Params params = controller().params();
InsetCommandParams params = controller().params();
params.cparams.setContents(fromqstr(dialog_->filenameED->text()));
params.cparams.preview(dialog_->previewCB->isChecked());
params.setContents(fromqstr(dialog_->filenameED->text()));
params.preview(dialog_->previewCB->isChecked());
int const item = dialog_->typeCO->currentItem();
if (item == 0)
params.cparams.setCmdName("input");
params.setCmdName("input");
else if (item == 1)
params.cparams.setCmdName("include");
params.setCmdName("include");
else {
if (dialog_->visiblespaceCB->isChecked())
params.cparams.setCmdName("verbatiminput*");
params.setCmdName("verbatiminput*");
else
params.cparams.setCmdName("verbatiminput");
params.setCmdName("verbatiminput");
}
controller().setParams(params);
}

View File

@ -1,3 +1,8 @@
2003-09-19 Angus Leeming <leeming@lyx.org>
* FormInclude.C: changes dues to the changed storage in InsetInclude,
from an InsetInclude::params to an InsetCommandParams.
2003-09-18 Angus Leeming <leeming@lyx.org>
* FormInclude.C (apply): No need to set InsetInclude::Params::flag;

View File

@ -79,9 +79,9 @@ void FormInclude::build()
void FormInclude::update()
{
string const filename = controller().params().cparams.getContents();
string const cmdname = controller().params().cparams.getCmdName();
bool const preview = static_cast<bool>((controller().params().cparams.preview()));
string const filename = controller().params().getContents();
string const cmdname = controller().params().getCmdName();
bool const preview = static_cast<bool>((controller().params().preview()));
fl_set_input(dialog_->input_filename, filename.c_str());
@ -114,21 +114,21 @@ void FormInclude::update()
void FormInclude::apply()
{
InsetInclude::Params params = controller().params();
InsetCommandParams params = controller().params();
params.cparams.preview(fl_get_button(dialog_->check_preview));
params.cparams.setContents(getString(dialog_->input_filename));
params.preview(fl_get_button(dialog_->check_preview));
params.setContents(getString(dialog_->input_filename));
ControlInclude::Type const type = ControlInclude::Type(type_.get());
if (type == ControlInclude::INPUT)
params.cparams.setCmdName("input");
params.setCmdName("input");
else if (type == ControlInclude::INCLUDE)
params.cparams.setCmdName("include");
params.setCmdName("include");
else if (type == ControlInclude::VERBATIM) {
if (fl_get_button(dialog_->check_visiblespace))
params.cparams.setCmdName("verbatiminput*");
params.setCmdName("verbatiminput*");
else
params.cparams.setCmdName("verbatiminput");
params.setCmdName("verbatiminput");
}
controller().setParams(params);

View File

@ -1,3 +1,8 @@
2003-09-19 Angus Leeming <leeming@lyx.org>
* PreviewedInset.[Ch] (generatePreview, previewWanted): now passed
a 'Buffer const &' argument.
2003-09-18 Angus Leeming <leeming@lyx.org>
* PreviewedInset.C (latexString): add a Buffer const & arg.

View File

@ -46,14 +46,13 @@ BufferView * PreviewedInset::view() const
}
void PreviewedInset::generatePreview()
void PreviewedInset::generatePreview(Buffer const & buffer)
{
if (!Previews::activated() || !previewWanted() ||
!view() || !view()->buffer())
if (!Previews::activated() || !previewWanted(buffer))
return;
Previews & previews = Previews::get();
PreviewLoader & loader = previews.loader(*view()->buffer());
PreviewLoader & loader = previews.loader(buffer);
addPreview(loader);
if (!snippet_.empty())
loader.startLoading();
@ -62,7 +61,7 @@ void PreviewedInset::generatePreview()
void PreviewedInset::addPreview(PreviewLoader & ploader)
{
if (!Previews::activated() || !previewWanted())
if (!Previews::activated() || !previewWanted(ploader.buffer()))
return;
snippet_ = support::trim(latexString(ploader.buffer()));
@ -100,8 +99,10 @@ void PreviewedInset::removePreview()
bool PreviewedInset::previewReady() const
{
if (!Previews::activated() || !previewWanted() ||
!view() || !view()->buffer())
if (!Previews::activated() || !view() || !view()->buffer())
return false;
if (!previewWanted(*view()->buffer()))
return false;
if (!pimage_ || snippet_ != pimage_->snippet()) {

View File

@ -42,7 +42,7 @@ public:
/** Find the PreviewLoader, add a LaTeX snippet to it and
* start the loading process.
*/
void generatePreview();
void generatePreview(Buffer const &);
/** Add a LaTeX snippet to the PreviewLoader but do not start the
* loading process.
@ -73,7 +73,7 @@ private:
void imageReady(PreviewImage const &) const;
/// Does the owning inset want a preview?
virtual bool previewWanted() const = 0;
virtual bool previewWanted(Buffer const &) const = 0;
/// a wrapper to Inset::latex
virtual string const latexString(Buffer const &) const = 0;

View File

@ -1,3 +1,18 @@
2003-09-19 Angus Leeming <leeming@lyx.org>
* inset.h (generatePreview): passed a 'Buffer const &' arg.
* insetcommand.C (string2params): clear params using the default c-tor.
* insetinclude[Ch]: get rid of the masterFilename_ parameter in
InsetInclude::Params. No more data in this struct than in
InsetCommandParams, so get rid of it and use InsetCommandParams instead.
(c-tor): no need to pass a 'Buffer const &' arg anymore.
(clone): remove #warning as it's now redundant.
(set): add a 'Buffer const &' arg. Make private.
(loadIfNeeded) move out of the class definition and into namespace anon.
(getMasterFilename, getFileName): ditto.
2003-09-18 Angus Leeming <leeming@lyx.org>
* insetcommand.C (setParams): use the params' copy constructor.

View File

@ -304,7 +304,7 @@ public:
* Most insets have no interest in this capability, so the method
* defaults to empty.
*/
virtual void generatePreview() const {}
virtual void generatePreview(Buffer const &) const {}
protected:
///

View File

@ -131,9 +131,7 @@ string const InsetCommandMailer::inset2string(Buffer const &) const
void InsetCommandMailer::string2params(string const & in,
InsetCommandParams & params)
{
params.setCmdName(string());
params.setContents(string());
params.setOptions(string());
params = InsetCommandParams();
if (in.empty())
return;

View File

@ -50,6 +50,7 @@ using lyx::support::IsFileReadable;
using lyx::support::IsLyXFilename;
using lyx::support::MakeAbsPath;
using lyx::support::MakeDisplayPath;
using lyx::support::OnlyFilename;
using lyx::support::OnlyPath;
using lyx::support::subst;
@ -70,7 +71,7 @@ public:
PreviewImpl(InsetInclude & p) : PreviewedInset(p) {}
///
bool previewWanted() const;
bool previewWanted(Buffer const &) const;
///
string const latexString(Buffer const &) const;
///
@ -81,7 +82,7 @@ public:
///
bool monitoring() const { return monitor_.get(); }
///
void startMonitoring();
void startMonitoring(string const & file);
///
void stopMonitoring() { monitor_.reset(); }
@ -104,23 +105,13 @@ string const uniqueID()
} // namespace anon
InsetInclude::InsetInclude(Params const & p)
InsetInclude::InsetInclude(InsetCommandParams const & p)
: params_(p), include_label(uniqueID()),
preview_(new PreviewImpl(*this)),
set_label_(false)
{}
InsetInclude::InsetInclude(InsetCommandParams const & p, Buffer const & b)
: include_label(uniqueID()),
preview_(new PreviewImpl(*this)),
set_label_(false)
{
params_.cparams = p;
params_.masterFilename_ = b.fileName();
}
InsetInclude::InsetInclude(InsetInclude const & other)
: InsetOld(other),
params_(other.params_),
@ -142,11 +133,10 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
switch (cmd.action) {
case LFUN_INSET_MODIFY: {
InsetInclude::Params p;
InsetCommandParams p;
InsetIncludeMailer::string2params(cmd.argument, p);
if (!p.cparams.getCmdName().empty()) {
p.masterFilename_ = cmd.view()->buffer()->fileName();
set(p);
if (!p.getCmdName().empty()) {
set(p, *cmd.view()->buffer());
cmd.view()->updateInset(this);
}
return DISPATCHED;
@ -171,7 +161,7 @@ dispatch_result InsetInclude::localDispatch(FuncRequest const & cmd)
}
InsetInclude::Params const & InsetInclude::params() const
InsetCommandParams const & InsetInclude::params() const
{
return params_;
}
@ -188,9 +178,9 @@ enum Types {
};
Types type(InsetInclude::Params const & params)
Types type(InsetCommandParams const & params)
{
string const command_name = params.cparams.getCmdName();
string const command_name = params.getCmdName();
if (command_name == "input")
return INPUT;
@ -202,9 +192,9 @@ Types type(InsetInclude::Params const & params)
}
bool isVerbatim(InsetInclude::Params const & params)
bool isVerbatim(InsetCommandParams const & params)
{
string const command_name = params.cparams.getCmdName();
string const command_name = params.getCmdName();
return command_name == "verbatiminput" ||
command_name == "verbatiminput*";
}
@ -212,26 +202,23 @@ bool isVerbatim(InsetInclude::Params const & params)
} // namespace anon
void InsetInclude::set(Params const & p)
void InsetInclude::set(InsetCommandParams const & p, Buffer const & buffer)
{
params_ = p;
set_label_ = false;
if (preview_->monitoring())
preview_->stopMonitoring();
if (lyx::graphics::PreviewedInset::activated() &&
type(params_) == INPUT)
preview_->generatePreview();
preview_->generatePreview(buffer);
}
auto_ptr<InsetBase> InsetInclude::clone() const
{
//Params p(params_);
//p.masterFilename_ = buffer.fileName();
#warning FIXME: broken cross-doc copy/paste - must fix
return auto_ptr<InsetBase>(new InsetInclude(params_));
return auto_ptr<InsetBase>(new InsetInclude(*this));
}
@ -243,8 +230,8 @@ void InsetInclude::write(Buffer const &, ostream & os) const
void InsetInclude::write(ostream & os) const
{
os << "Include " << params_.cparams.getCommand() << '\n'
<< "preview " << tostr(params_.cparams.preview()) << '\n';
os << "Include " << params_.getCommand() << '\n'
<< "preview " << tostr(params_.preview()) << '\n';
}
@ -256,7 +243,7 @@ void InsetInclude::read(Buffer const &, LyXLex & lex)
void InsetInclude::read(LyXLex & lex)
{
params_.cparams.read(lex);
params_.read(lex);
}
@ -273,64 +260,74 @@ string const InsetInclude::getScreenLabel(Buffer const &) const
temp += ": ";
if (params_.cparams.getContents().empty())
if (params_.getContents().empty())
temp += "???";
else
temp += params_.cparams.getContents();
temp += OnlyFilename(params_.getContents());
return temp;
}
string const InsetInclude::getFileName() const
namespace {
string const masterFilename(Buffer const & buffer)
{
return MakeAbsPath(params_.cparams.getContents(),
OnlyPath(getMasterFilename()));
return buffer.fileName();
}
string const InsetInclude::getMasterFilename() const
string const includedFilename(Buffer const & buffer,
InsetCommandParams const & params)
{
return params_.masterFilename_;
return MakeAbsPath(params.getContents(),
OnlyPath(masterFilename(buffer)));
}
bool InsetInclude::loadIfNeeded() const
/// return true if the file is or got loaded.
bool loadIfNeeded(Buffer const & buffer, InsetCommandParams const & params)
{
if (isVerbatim(params_))
if (isVerbatim(params))
return false;
if (!IsLyXFilename(getFileName()))
string const included_file = includedFilename(buffer, params);
if (!IsLyXFilename(included_file))
return false;
if (bufferlist.exists(getFileName()))
if (bufferlist.exists(included_file))
return true;
// the readonly flag can/will be wrong, not anymore I think.
FileInfo finfo(getFileName());
FileInfo finfo(included_file);
if (!finfo.isOK())
return false;
return loadLyXFile(bufferlist.newBuffer(getFileName()),
getFileName());
return loadLyXFile(bufferlist.newBuffer(included_file),
included_file);
}
} // namespace anon
int InsetInclude::latex(Buffer const & buffer, ostream & os,
LatexRunParams const & runparams) const
{
string incfile(params_.cparams.getContents());
string incfile(params_.getContents());
// Do nothing if no file name has been specified
if (incfile.empty())
return 0;
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
string const included_file = includedFilename(buffer, params_);
if (loadIfNeeded(buffer, params_)) {
Buffer * tmp = bufferlist.getBuffer(included_file);
// FIXME: this should be a GUI warning
if (tmp->params().textclass != buffer.params().textclass) {
lyxerr << "WARNING: Included file `"
<< MakeDisplayPath(getFileName())
<< MakeDisplayPath(included_file)
<< "' has textclass `"
<< tmp->params().getLyXTextClass().name()
<< "' while parent file has textclass `"
@ -340,7 +337,7 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
}
// write it to a file (so far the complete file)
string writefile = ChangeExtension(getFileName(), ".tex");
string writefile = ChangeExtension(included_file, ".tex");
if (!buffer.temppath().empty() && !runparams.nice) {
incfile = subst(incfile, '/','@');
@ -349,32 +346,33 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
#endif
writefile = AddName(buffer.temppath(), incfile);
} else
writefile = getFileName();
writefile = included_file;
writefile = ChangeExtension(writefile, ".tex");
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
lyxerr[Debug::LATEX] << "writefile:" << writefile << endl;
tmp->markDepClean(buffer.temppath());
tmp->makeLaTeXFile(writefile, OnlyPath(getMasterFilename()),
tmp->makeLaTeXFile(writefile,
OnlyPath(masterFilename(buffer)),
runparams, false);
}
if (isVerbatim(params_)) {
os << '\\' << params_.cparams.getCmdName() << '{' << incfile << '}';
os << '\\' << params_.getCmdName() << '{' << incfile << '}';
} else if (type(params_) == INPUT) {
// \input wants file with extension (default is .tex)
if (!IsLyXFilename(getFileName())) {
os << '\\' << params_.cparams.getCmdName() << '{' << incfile << '}';
if (!IsLyXFilename(included_file)) {
os << '\\' << params_.getCmdName() << '{' << incfile << '}';
} else {
os << '\\' << params_.cparams.getCmdName() << '{'
os << '\\' << params_.getCmdName() << '{'
<< ChangeExtension(incfile, ".tex")
<< '}';
}
} else {
// \include don't want extension and demands that the
// file really have .tex
os << '\\' << params_.cparams.getCmdName() << '{'
os << '\\' << params_.getCmdName() << '{'
<< ChangeExtension(incfile, string())
<< '}';
}
@ -383,34 +381,36 @@ int InsetInclude::latex(Buffer const & buffer, ostream & os,
}
int InsetInclude::ascii(Buffer const &, ostream & os, int) const
int InsetInclude::ascii(Buffer const & buffer, ostream & os, int) const
{
if (isVerbatim(params_))
os << GetFileContents(getFileName());
os << GetFileContents(includedFilename(buffer, params_));
return 0;
}
int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os) const
{
string incfile(params_.cparams.getContents());
string incfile(params_.getContents());
// Do nothing if no file name has been specified
if (incfile.empty())
return 0;
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
string const included_file = includedFilename(buffer, params_);
if (loadIfNeeded(buffer, params_)) {
Buffer * tmp = bufferlist.getBuffer(included_file);
// write it to a file (so far the complete file)
string writefile = ChangeExtension(getFileName(), ".sgml");
string writefile = ChangeExtension(included_file, ".sgml");
if (!buffer.temppath().empty() && !buffer.niceFile()) {
incfile = subst(incfile, '/','@');
writefile = AddName(buffer.temppath(), incfile);
} else
writefile = getFileName();
writefile = included_file;
if (IsLyXFilename(getFileName()))
if (IsLyXFilename(included_file))
writefile = ChangeExtension(writefile, ".sgml");
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
@ -421,7 +421,7 @@ int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os) const
if (isVerbatim(params_)) {
os << "<![CDATA["
<< GetFileContents(getFileName())
<< GetFileContents(included_file)
<< "]]>";
} else
os << '&' << include_label << ';';
@ -433,23 +433,25 @@ int InsetInclude::linuxdoc(Buffer const & buffer, ostream & os) const
int InsetInclude::docbook(Buffer const & buffer, ostream & os,
bool /*mixcont*/) const
{
string incfile(params_.cparams.getContents());
string incfile(params_.getContents());
// Do nothing if no file name has been specified
if (incfile.empty())
return 0;
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
string const included_file = includedFilename(buffer, params_);
if (loadIfNeeded(buffer, params_)) {
Buffer * tmp = bufferlist.getBuffer(included_file);
// write it to a file (so far the complete file)
string writefile = ChangeExtension(getFileName(), ".sgml");
string writefile = ChangeExtension(included_file, ".sgml");
if (!buffer.temppath().empty() && !buffer.niceFile()) {
incfile = subst(incfile, '/','@');
writefile = AddName(buffer.temppath(), incfile);
} else
writefile = getFileName();
if (IsLyXFilename(getFileName()))
writefile = included_file;
if (IsLyXFilename(included_file))
writefile = ChangeExtension(writefile, ".sgml");
lyxerr[Debug::LATEX] << "incfile:" << incfile << endl;
@ -471,18 +473,22 @@ int InsetInclude::docbook(Buffer const & buffer, ostream & os,
void InsetInclude::validate(LaTeXFeatures & features) const
{
string incfile(params_.cparams.getContents());
string incfile(params_.getContents());
string writefile;
Buffer const & b = features.buffer();
Buffer const & buffer = features.buffer();
if (!b.temppath().empty() && !b.niceFile() && !isVerbatim(params_)) {
string const included_file = includedFilename(buffer, params_);
if (!buffer.temppath().empty() &&
!buffer.niceFile() &&
!isVerbatim(params_)) {
incfile = subst(incfile, '/','@');
writefile = AddName(b.temppath(), incfile);
writefile = AddName(buffer.temppath(), incfile);
} else
writefile = getFileName();
writefile = included_file;
if (IsLyXFilename(getFileName()))
if (IsLyXFilename(included_file))
writefile = ChangeExtension(writefile, ".sgml");
features.includeFile(include_label, writefile);
@ -493,36 +499,39 @@ void InsetInclude::validate(LaTeXFeatures & features) const
// Here we must do the fun stuff...
// Load the file in the include if it needs
// to be loaded:
if (loadIfNeeded()) {
if (loadIfNeeded(buffer, params_)) {
// a file got loaded
Buffer * const tmp = bufferlist.getBuffer(getFileName());
Buffer * const tmp = bufferlist.getBuffer(included_file);
if (tmp) {
tmp->niceFile() = b.niceFile();
tmp->niceFile() = buffer.niceFile();
tmp->validate(features);
}
}
}
void InsetInclude::getLabelList(Buffer const &, std::vector<string> & list) const
void InsetInclude::getLabelList(Buffer const & buffer,
std::vector<string> & list) const
{
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
if (loadIfNeeded(buffer, params_)) {
string const included_file = includedFilename(buffer, params_);
Buffer * tmp = bufferlist.getBuffer(included_file);
tmp->setParentName("");
tmp->getLabelList(list);
tmp->setParentName(getMasterFilename());
tmp->setParentName(masterFilename(buffer));
}
}
void InsetInclude::fillWithBibKeys(Buffer const &,
void InsetInclude::fillWithBibKeys(Buffer const & buffer,
std::vector<std::pair<string,string> > & keys) const
{
if (loadIfNeeded()) {
Buffer * tmp = bufferlist.getBuffer(getFileName());
if (loadIfNeeded(buffer, params_)) {
string const included_file = includedFilename(buffer, params_);
Buffer * tmp = bufferlist.getBuffer(included_file);
tmp->setParentName("");
tmp->fillWithBibKeys(keys);
tmp->setParentName(getMasterFilename());
tmp->setParentName(masterFilename(buffer));
}
}
@ -559,8 +568,11 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const
return;
}
if (!preview_->monitoring())
preview_->startMonitoring();
if (!preview_->monitoring()) {
string const included_file =
includedFilename(*view()->buffer(), params_);
preview_->startMonitoring(included_file);
}
pi.pain.image(x + button_.box().x1, y - dim_.asc, dim_.wid, dim_.height(),
*(preview_->pimage()->image()));
@ -583,11 +595,13 @@ void InsetInclude::addPreview(lyx::graphics::PreviewLoader & ploader) const
}
bool InsetInclude::PreviewImpl::previewWanted() const
bool InsetInclude::PreviewImpl::previewWanted(Buffer const & buffer) const
{
string const included_file = includedFilename(buffer, parent().params());
return type(parent().params_) == INPUT &&
parent().params_.cparams.preview() &&
IsFileReadable(parent().getFileName());
parent().params_.preview() &&
IsFileReadable(included_file);
}
@ -602,9 +616,9 @@ string const InsetInclude::PreviewImpl::latexString(Buffer const & buffer) const
}
void InsetInclude::PreviewImpl::startMonitoring()
void InsetInclude::PreviewImpl::startMonitoring(string const & file)
{
monitor_.reset(new FileMonitor(parent().getFileName(), 2000));
monitor_.reset(new FileMonitor(file, 2000));
monitor_->connect(boost::bind(&PreviewImpl::restartLoading, this));
monitor_->start();
}
@ -613,9 +627,11 @@ void InsetInclude::PreviewImpl::startMonitoring()
void InsetInclude::PreviewImpl::restartLoading()
{
removePreview();
if (view())
if (!view())
return;
view()->updateInset(&parent());
generatePreview();
if (view()->buffer())
generatePreview(*view()->buffer());
}
@ -633,9 +649,9 @@ string const InsetIncludeMailer::inset2string(Buffer const &) const
void InsetIncludeMailer::string2params(string const & in,
InsetInclude::Params & params)
InsetCommandParams & params)
{
params = InsetInclude::Params();
params = InsetCommandParams();
if (in.empty())
return;
@ -669,10 +685,9 @@ void InsetIncludeMailer::string2params(string const & in,
string const
InsetIncludeMailer::params2string(InsetInclude::Params const & params)
InsetIncludeMailer::params2string(InsetCommandParams const & params)
{
InsetInclude inset(params);
inset.set(params);
ostringstream data;
data << name_ << ' ';
inset.write(data);

View File

@ -12,7 +12,8 @@
#ifndef INSET_INCLUDE_H
#define INSET_INCLUDE_H
#include "insetcommand.h"
#include "inset.h"
#include "insetcommandparams.h"
#include "renderers.h"
#include <boost/scoped_ptr.hpp>
@ -26,22 +27,13 @@ struct LaTeXFeatures;
/// for including tex/lyx files
class InsetInclude: public InsetOld {
public:
struct Params {
Params(InsetCommandParams const & cp = InsetCommandParams("input"),
string const & name = string())
: cparams(cp),
masterFilename_(name) {}
InsetCommandParams cparams;
string masterFilename_;
};
///
InsetInclude(InsetCommandParams const &);
InsetInclude(InsetInclude const &);
~InsetInclude();
///
InsetInclude(Params const &);
InsetInclude(InsetCommandParams const &, Buffer const &);
InsetInclude(InsetInclude const &);
~InsetInclude();
virtual std::auto_ptr<InsetBase> clone() const;
///
virtual dispatch_result localDispatch(FuncRequest const & cmd);
@ -54,12 +46,8 @@ public:
virtual BufferView * view() const;
/// get the parameters
Params const & params(void) const;
/// set the parameters
void set(Params const & params);
InsetCommandParams const & params(void) const;
///
virtual std::auto_ptr<InsetBase> clone() const;
///
InsetOld::Code lyxCode() const { return InsetOld::INCLUDE_CODE; }
/** Fills \c list
@ -76,17 +64,13 @@ public:
void fillWithBibKeys(Buffer const & buffer,
std::vector<std::pair<string,string> > & keys) const;
///
EDITABLE editable() const
{
return IS_EDITABLE;
}
EDITABLE editable() const { return IS_EDITABLE; }
///
void write(Buffer const &, std::ostream &) const;
///
void read(Buffer const &, LyXLex &);
///
int latex(Buffer const &, std::ostream &,
LatexRunParams const &) const;
int latex(Buffer const &, std::ostream &, LatexRunParams const &) const;
///
int ascii(Buffer const &, std::ostream &, int linelen) const;
///
@ -95,29 +79,23 @@ public:
int docbook(Buffer const &, std::ostream &, bool mixcont) const;
///
void validate(LaTeXFeatures &) const;
///
void addPreview(lyx::graphics::PreviewLoader &) const;
private:
friend class InsetIncludeMailer;
/// return true if the file is or got loaded.
bool loadIfNeeded() const;
/// set the parameters
void set(InsetCommandParams const & params, Buffer const &);
/// get the text displayed on the button
string const getScreenLabel(Buffer const &) const;
///
void write(std::ostream &) const;
///
void read(LyXLex &);
/// get the text displayed on the button
string const getScreenLabel(Buffer const &) const;
/// get the filename of the master buffer
string const getMasterFilename() const;
/// get the included file name
string const getFileName() const;
/// the parameters
Params params_;
InsetCommandParams params_;
/// holds the entity name that defines the file location (SGML)
string const include_label;
@ -146,9 +124,9 @@ public:
///
virtual string const inset2string(Buffer const &) const;
///
static void string2params(string const &, InsetInclude::Params &);
static void string2params(string const &, InsetCommandParams &);
///
static string const params2string(InsetInclude::Params const &);
static string const params2string(InsetCommandParams const &);
private:
///
static string const name_;

View File

@ -1,3 +1,10 @@
2003-09-19 Angus Leeming <leeming@lyx.org>
* formula.[Ch] (previewWanted, generatePreview): now passed a
'Bufer const &' arg.
* formalabase.C (insetUnlock): pass a buffer arg to generatePreview.
2003-09-18 Angus Leeming <leeming@lyx.org>
* matheformula.[Ch] (getLabelList):

View File

@ -44,7 +44,7 @@ public:
private:
///
bool previewWanted() const;
bool previewWanted(Buffer const &) const;
///
string const latexString(Buffer const &) const;
///
@ -302,13 +302,13 @@ void InsetFormula::addPreview(lyx::graphics::PreviewLoader & ploader) const
}
void InsetFormula::generatePreview() const
void InsetFormula::generatePreview(Buffer const & buffer) const
{
preview_->generatePreview();
preview_->generatePreview(buffer);
}
bool InsetFormula::PreviewImpl::previewWanted() const
bool InsetFormula::PreviewImpl::previewWanted(Buffer const &) const
{
return !parent().par_->asNestInset()->editing();
}

View File

@ -67,7 +67,7 @@ public:
///
MathAtom & par() { return par_; }
///
void generatePreview() const;
void generatePreview(Buffer const &) const;
///
void addPreview(lyx::graphics::PreviewLoader &) const;
///

View File

@ -144,7 +144,8 @@ void InsetFormulaBase::insetUnlock(BufferView * bv)
}
releaseMathCursor(bv);
}
generatePreview();
if (bv->buffer())
generatePreview(*bv->buffer());
bv->updateInset(this);
}