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> 2003-09-19 Juergen Spitzmueller <j.spitzmueller@gmx.de>
* paragraph.C: use appropriate alignment tags inside floats (bug 1290) * paragraph.C: use appropriate alignment tags inside floats (bug 1290)

View File

@ -24,7 +24,6 @@
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "insets/insetinclude.h"
#include "insets/insettabular.h" #include "insets/insettabular.h"
#include "support/lstrings.h" #include "support/lstrings.h"
@ -297,14 +296,6 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
for (; lit != eit; ++lit) { for (; lit != eit; ++lit) {
switch (lit->inset->lyxCode()) { 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: { case InsetOld::TABULAR_CODE: {
InsetTabular * it = static_cast<InsetTabular*>(lit->inset); InsetTabular * it = static_cast<InsetTabular*>(lit->inset);
it->buffer(const_cast<Buffer*>(&buffer)); it->buffer(const_cast<Buffer*>(&buffer));

View File

@ -231,7 +231,7 @@ InsetOld * createInset(FuncRequest const & cmd)
return inset; return inset;
} else if (name == "include") { } else if (name == "include") {
InsetInclude::Params iip; InsetCommandParams iip;
InsetIncludeMailer::string2params(cmd.argument, iip); InsetIncludeMailer::string2params(cmd.argument, iip);
return new InsetInclude(iip); return new InsetInclude(iip);
@ -328,7 +328,7 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
} else if (cmdName == "index") { } else if (cmdName == "index") {
inset = new InsetIndex(inscmd); inset = new InsetIndex(inscmd);
} else if (cmdName == "include") { } else if (cmdName == "include") {
inset = new InsetInclude(inscmd, buf); inset = new InsetInclude(inscmd);
} else if (cmdName == "label") { } else if (cmdName == "label") {
inset = new InsetLabel(inscmd); inset = new InsetLabel(inscmd);
} else if (cmdName == "url" } else if (cmdName == "url"
@ -373,7 +373,7 @@ InsetOld * readInset(LyXLex & lex, Buffer const & buf)
inset = new InsetBranch(buf.params(), tmptok); inset = new InsetBranch(buf.params(), tmptok);
} else if (tmptok == "Include") { } else if (tmptok == "Include") {
InsetCommandParams p("Include"); InsetCommandParams p("Include");
inset = new InsetInclude(p, buf); inset = new InsetInclude(p);
} else if (tmptok == "Environment") { } else if (tmptok == "Environment") {
lex.next(); lex.next();
inset = new InsetEnvironment(buf.params(), lex.getString()); 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> 2003-09-18 Angus Leeming <leeming@lyx.org>
* ControlCommand.C (clearParams): simplify. * ControlCommand.C (clearParams): simplify.

View File

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

View File

@ -16,7 +16,7 @@
#include "Dialog.h" #include "Dialog.h"
#include "insets/insetinclude.h" // InsetIncludeParams #include "insets/insetcommandparams.h"
/** A controller for the Include file dialog. /** A controller for the Include file dialog.
@ -45,10 +45,9 @@ public:
virtual bool isBufferDependent() const { return true; } virtual bool isBufferDependent() const { return true; }
/// ///
InsetInclude::Params const & params() const InsetCommandParams const & params() const { return params_; }
{ return inset_->params(); }
/// ///
void setParams(InsetInclude::Params const &); void setParams(InsetCommandParams const &);
/// Browse for a file /// Browse for a file
string const Browse(string const &, Type); string const Browse(string const &, Type);
@ -60,7 +59,7 @@ public:
bool fileExists(string const & file); bool fileExists(string const & file);
private: private:
/// ///
boost::scoped_ptr<InsetInclude> inset_; InsetCommandParams params_;
}; };
#endif // CONTROLINCLUDE_H #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> 2003-09-18 Angus Leeming <leeming@lyx.org>
* QInclude.C (apply): No need to set InsetInclude::Params::flag; * QInclude.C (apply): No need to set InsetInclude::Params::flag;

View File

@ -47,16 +47,16 @@ void QInclude::build_dialog()
void QInclude::update_contents() 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->setChecked(false);
dialog_->visiblespaceCB->setEnabled(false); dialog_->visiblespaceCB->setEnabled(false);
dialog_->previewCB->setChecked(false); dialog_->previewCB->setChecked(false);
dialog_->previewCB->setEnabled(false); dialog_->previewCB->setEnabled(false);
string cmdname = controller().params().cparams.getCmdName(); string cmdname = controller().params().getCmdName();
if (cmdname != "include" && if (cmdname != "include" &&
cmdname != "verbatiminput" && cmdname != "verbatiminput" &&
cmdname != "verbatiminput*") cmdname != "verbatiminput*")
@ -65,7 +65,7 @@ void QInclude::update_contents()
if (cmdname == "input") { if (cmdname == "input") {
dialog_->typeCO->setCurrentItem(0); dialog_->typeCO->setCurrentItem(0);
dialog_->previewCB->setEnabled(true); dialog_->previewCB->setEnabled(true);
dialog_->previewCB->setChecked(params.cparams.preview()); dialog_->previewCB->setChecked(params.preview());
} else if (cmdname == "include") { } else if (cmdname == "include") {
dialog_->typeCO->setCurrentItem(1); dialog_->typeCO->setCurrentItem(1);
@ -84,21 +84,21 @@ void QInclude::update_contents()
void QInclude::apply() void QInclude::apply()
{ {
InsetInclude::Params params = controller().params(); InsetCommandParams params = controller().params();
params.cparams.setContents(fromqstr(dialog_->filenameED->text())); params.setContents(fromqstr(dialog_->filenameED->text()));
params.cparams.preview(dialog_->previewCB->isChecked()); params.preview(dialog_->previewCB->isChecked());
int const item = dialog_->typeCO->currentItem(); int const item = dialog_->typeCO->currentItem();
if (item == 0) if (item == 0)
params.cparams.setCmdName("input"); params.setCmdName("input");
else if (item == 1) else if (item == 1)
params.cparams.setCmdName("include"); params.setCmdName("include");
else { else {
if (dialog_->visiblespaceCB->isChecked()) if (dialog_->visiblespaceCB->isChecked())
params.cparams.setCmdName("verbatiminput*"); params.setCmdName("verbatiminput*");
else else
params.cparams.setCmdName("verbatiminput"); params.setCmdName("verbatiminput");
} }
controller().setParams(params); 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> 2003-09-18 Angus Leeming <leeming@lyx.org>
* FormInclude.C (apply): No need to set InsetInclude::Params::flag; * FormInclude.C (apply): No need to set InsetInclude::Params::flag;

View File

@ -79,9 +79,9 @@ void FormInclude::build()
void FormInclude::update() void FormInclude::update()
{ {
string const filename = controller().params().cparams.getContents(); string const filename = controller().params().getContents();
string const cmdname = controller().params().cparams.getCmdName(); string const cmdname = controller().params().getCmdName();
bool const preview = static_cast<bool>((controller().params().cparams.preview())); bool const preview = static_cast<bool>((controller().params().preview()));
fl_set_input(dialog_->input_filename, filename.c_str()); fl_set_input(dialog_->input_filename, filename.c_str());
@ -114,21 +114,21 @@ void FormInclude::update()
void FormInclude::apply() void FormInclude::apply()
{ {
InsetInclude::Params params = controller().params(); InsetCommandParams params = controller().params();
params.cparams.preview(fl_get_button(dialog_->check_preview)); params.preview(fl_get_button(dialog_->check_preview));
params.cparams.setContents(getString(dialog_->input_filename)); params.setContents(getString(dialog_->input_filename));
ControlInclude::Type const type = ControlInclude::Type(type_.get()); ControlInclude::Type const type = ControlInclude::Type(type_.get());
if (type == ControlInclude::INPUT) if (type == ControlInclude::INPUT)
params.cparams.setCmdName("input"); params.setCmdName("input");
else if (type == ControlInclude::INCLUDE) else if (type == ControlInclude::INCLUDE)
params.cparams.setCmdName("include"); params.setCmdName("include");
else if (type == ControlInclude::VERBATIM) { else if (type == ControlInclude::VERBATIM) {
if (fl_get_button(dialog_->check_visiblespace)) if (fl_get_button(dialog_->check_visiblespace))
params.cparams.setCmdName("verbatiminput*"); params.setCmdName("verbatiminput*");
else else
params.cparams.setCmdName("verbatiminput"); params.setCmdName("verbatiminput");
} }
controller().setParams(params); 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> 2003-09-18 Angus Leeming <leeming@lyx.org>
* PreviewedInset.C (latexString): add a Buffer const & arg. * 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() || if (!Previews::activated() || !previewWanted(buffer))
!view() || !view()->buffer())
return; return;
Previews & previews = Previews::get(); Previews & previews = Previews::get();
PreviewLoader & loader = previews.loader(*view()->buffer()); PreviewLoader & loader = previews.loader(buffer);
addPreview(loader); addPreview(loader);
if (!snippet_.empty()) if (!snippet_.empty())
loader.startLoading(); loader.startLoading();
@ -62,7 +61,7 @@ void PreviewedInset::generatePreview()
void PreviewedInset::addPreview(PreviewLoader & ploader) void PreviewedInset::addPreview(PreviewLoader & ploader)
{ {
if (!Previews::activated() || !previewWanted()) if (!Previews::activated() || !previewWanted(ploader.buffer()))
return; return;
snippet_ = support::trim(latexString(ploader.buffer())); snippet_ = support::trim(latexString(ploader.buffer()));
@ -100,8 +99,10 @@ void PreviewedInset::removePreview()
bool PreviewedInset::previewReady() const bool PreviewedInset::previewReady() const
{ {
if (!Previews::activated() || !previewWanted() || if (!Previews::activated() || !view() || !view()->buffer())
!view() || !view()->buffer()) return false;
if (!previewWanted(*view()->buffer()))
return false; return false;
if (!pimage_ || snippet_ != pimage_->snippet()) { if (!pimage_ || snippet_ != pimage_->snippet()) {

View File

@ -42,7 +42,7 @@ public:
/** Find the PreviewLoader, add a LaTeX snippet to it and /** Find the PreviewLoader, add a LaTeX snippet to it and
* start the loading process. * start the loading process.
*/ */
void generatePreview(); void generatePreview(Buffer const &);
/** Add a LaTeX snippet to the PreviewLoader but do not start the /** Add a LaTeX snippet to the PreviewLoader but do not start the
* loading process. * loading process.
@ -73,7 +73,7 @@ private:
void imageReady(PreviewImage const &) const; void imageReady(PreviewImage const &) const;
/// Does the owning inset want a preview? /// Does the owning inset want a preview?
virtual bool previewWanted() const = 0; virtual bool previewWanted(Buffer const &) const = 0;
/// a wrapper to Inset::latex /// a wrapper to Inset::latex
virtual string const latexString(Buffer const &) const = 0; 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> 2003-09-18 Angus Leeming <leeming@lyx.org>
* insetcommand.C (setParams): use the params' copy constructor. * 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 * Most insets have no interest in this capability, so the method
* defaults to empty. * defaults to empty.
*/ */
virtual void generatePreview() const {} virtual void generatePreview(Buffer const &) const {}
protected: protected:
/// ///

View File

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

View File

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

View File

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

View File

@ -44,7 +44,7 @@ public:
private: private:
/// ///
bool previewWanted() const; bool previewWanted(Buffer const &) const;
/// ///
string const latexString(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(); return !parent().par_->asNestInset()->editing();
} }

View File

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

View File

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