#include "support/lstrings.h"
#include "support/lyxalgo.h"
#include "support/path.h"
+#include "support/path_defines.h"
#include "support/tostr.h"
+#include "support/LAssert.h"
+#include "support/translator.h"
#include <boost/bind.hpp>
using std::ostream;
using std::endl;
+using std::auto_ptr;
+
+namespace lyx {
+namespace graphics {
+/// The translator between the DisplayType and the corresponding lyx string.
+extern Translator<DisplayType, string> displayTranslator;
+}
+}
namespace {
InsetExternal::InsetExternal(InsetExternal const & other)
- : Inset(other),
+ : InsetOld(other),
boost::signals::trackable(),
params_(other.params_),
renderer_(other.renderer_->clone())
}
-InsetBase * InsetExternal::clone() const
+auto_ptr<InsetBase> InsetExternal::clone() const
{
- InsetExternal * inset = new InsetExternal(*this);
- return inset;
+ return auto_ptr<InsetBase>(new InsetExternal(*this));
}
case LFUN_EXTERNAL_EDIT: {
Assert(cmd.view());
- Buffer const * buffer = cmd.view()->buffer();
+ Buffer const & buffer = *cmd.view()->buffer();
InsetExternal::Params p;
InsetExternalMailer::string2params(cmd.argument, buffer, p);
- editExternal(p, buffer);
+ editExternal(p, &buffer);
return DISPATCHED_NOUPDATE;
}
Buffer const * buffer = cmd.view()->buffer();
InsetExternal::Params p;
- InsetExternalMailer::string2params(cmd.argument, buffer, p);
- setParams(p);
+ InsetExternalMailer::string2params(cmd.argument, *buffer, p);
+ setParams(p, buffer);
cmd.view()->updateInset(this);
return DISPATCHED;
}
}
-string const getScreenLabel(InsetExternal::Params const & params)
+string const getScreenLabel(InsetExternal::Params const & params,
+ Buffer const * buffer)
{
ExternalTemplate const * const ptr = getTemplatePtr(params);
if (!ptr)
return bformat(_("External template %1$s is not installed"),
params.templatename);
- return doSubstitution(params, 0, ptr->guiName);
+ return doSubstitution(params, buffer, ptr->guiName);
}
} // namespace anon
}
-void InsetExternal::setParams(Params const & p)
+void InsetExternal::setParams(Params const & p, Buffer const * buffer)
{
// The stored params; what we would like to happen in an ideal world.
params_.filename = p.filename;
renderer_.reset(button_ptr);
}
- button_ptr->update(getScreenLabel(params_), true);
+ button_ptr->update(getScreenLabel(params_, buffer), true);
} else {
GraphicRenderer * graphic_ptr =
}
-BufferView * InsetExternal::view() const
-{
- return renderer_->view();
-}
-
-
-string const InsetExternal::editMessage() const
-{
- return getScreenLabel(params_);
-}
-
-
void InsetExternal::write(Buffer const * buffer, ostream & os) const
{
os << "External\n"
{ "template", EX_TEMPLATE }
};
- lex.pushTable(external_tags, EX_END);
+ pushpophelper pph(lex, external_tags, EX_END);
bool found_end = false;
bool read_error = false;
"Missing \\end_inset.");
}
- lex.popTable();
-
// Replace the inset's store
- setParams(params);
+ setParams(params, buffer);
lyxerr[Debug::INFO] << "InsetExternal::Read: "
<< "template: '" << params_.templatename
Buffer const * buffer, string const & s)
{
string result;
- string const absfilename = params.filename.absFilename();
- string const basename = ChangeExtension(absfilename, string());
- string filepath;
+ string const buffer_path = buffer ? buffer->filePath() : string();
+ string const filename = params.filename.outputFilename(buffer_path);
+ string const basename = ChangeExtension(filename, string());
+ string const filepath = OnlyPath(filename);
- result = subst(s, "$$FName", absfilename);
+ result = subst(s, "$$FName", filename);
result = subst(result, "$$Basename", basename);
result = subst(result, "$$FPath", filepath);
result = subst(result, "$$Tempname", params.tempname);
- result = subst(result, "$$Sysdir", system_lyxdir);
+ result = subst(result, "$$Sysdir", system_lyxdir());
// Handle the $$Contents(filename) syntax
if (contains(result, "$$Contents(\"")) {
{}
-string const InsetExternalMailer::inset2string() const
+string const InsetExternalMailer::inset2string(Buffer const & buffer) const
{
- BufferView * bv = inset_.view();
- if (!bv)
- return string();
- return params2string(inset_.params(), bv->buffer());
+ return params2string(inset_.params(), buffer);
}
void InsetExternalMailer::string2params(string const & in,
- Buffer const * buffer,
+ Buffer const & buffer,
InsetExternal::Params & params)
{
params = InsetExternal::Params();
if (lex.isOK()) {
InsetExternal inset;
- inset.read(buffer, lex);
+ inset.read(&buffer, lex);
params = inset.params();
}
}
string const
InsetExternalMailer::params2string(InsetExternal::Params const & params,
- Buffer const * buffer)
+ Buffer const & buffer)
{
InsetExternal inset;
- inset.setParams(params);
+ inset.setParams(params, &buffer);
ostringstream data;
data << name_ << ' ';
- inset.write(buffer, data);
+ inset.write(&buffer, data);
data << "\\end_inset\n";
return STRCONV(data.str());
}