#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 grfx = lyx::graphics;
+namespace lyx {
+namespace graphics {
+/// The translator between the DisplayType and the corresponding lyx string.
+extern Translator<DisplayType, string> displayTranslator;
+}
+}
namespace {
-grfx::DisplayType const defaultDisplayType = grfx::NoDisplay;
+lyx::graphics::DisplayType const defaultDisplayType = lyx::graphics::NoDisplay;
unsigned int defaultLyxScale = 100;
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));
}
}
-InsetExternal::Params const & InsetExternal::params() const
-{
- return params_;
-}
-
-
dispatch_result InsetExternal::localDispatch(FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_EXTERNAL_EDIT: {
Assert(cmd.view());
+ Buffer const & buffer = *cmd.view()->buffer();
InsetExternal::Params p;
- InsetExternalMailer::string2params(cmd.argument, p);
- editExternal(p, cmd.view()->buffer());
+ InsetExternalMailer::string2params(cmd.argument, buffer, p);
+ editExternal(p, &buffer);
return DISPATCHED_NOUPDATE;
}
case LFUN_INSET_MODIFY: {
Assert(cmd.view());
+ Buffer const * buffer = cmd.view()->buffer();
InsetExternal::Params p;
- InsetExternalMailer::string2params(cmd.argument, p);
- setParams(p, cmd.view()->buffer()->filePath());
+ InsetExternalMailer::string2params(cmd.argument, *buffer, p);
+ setParams(p, buffer);
cmd.view()->updateInset(this);
return DISPATCHED;
}
void InsetExternal::metrics(MetricsInfo & mi, Dimension & dim) const
{
renderer_->metrics(mi, dim);
+ dim_ = dim;
}
namespace {
-grfx::Params get_grfx_params(InsetExternal::Params const & eparams,
- string const & filepath)
+lyx::graphics::Params get_grfx_params(InsetExternal::Params const & eparams)
{
- grfx::Params gparams;
-
- if (!eparams.filename.empty()) {
- Assert(AbsolutePath(filepath));
- gparams.filename = MakeAbsPath(eparams.filename, filepath);
- }
+ lyx::graphics::Params gparams;
+ gparams.filename = eparams.filename.absFilename();
gparams.scale = eparams.lyxscale;
gparams.display = eparams.display;
- if (gparams.display == grfx::DefaultDisplay)
+ if (gparams.display == lyx::graphics::DefaultDisplay)
gparams.display = lyxrc.display_graphics;
// Override the above if we're not using a gui
if (!lyx_gui::use_gui)
- gparams.display = grfx::NoDisplay;
+ gparams.display = lyx::graphics::NoDisplay;
return gparams;
}
}
-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, string const & filepath)
+InsetExternal::Params const & InsetExternal::params() const
+{
+ return params_;
+}
+
+
+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;
// We display the inset as a button by default.
bool display_button = (!getTemplatePtr(params_) ||
params_.filename.empty() ||
- filepath.empty() ||
- params_.display == grfx::NoDisplay);
+ params_.display == lyx::graphics::NoDisplay);
if (display_button) {
ButtonRenderer * button_ptr =
renderer_.reset(button_ptr);
}
- button_ptr->update(getScreenLabel(params_), true);
+ button_ptr->update(getScreenLabel(params_, buffer), true);
} else {
GraphicRenderer * graphic_ptr =
renderer_.reset(graphic_ptr);
}
- graphic_ptr->update(get_grfx_params(params_, filepath));
+ graphic_ptr->update(get_grfx_params(params_));
}
}
-string const InsetExternal::editMessage() const
-{
- return getScreenLabel(params_);
-}
-
-
-void InsetExternal::write(Buffer const *, ostream & os) const
+void InsetExternal::write(Buffer const * buffer, ostream & os) const
{
os << "External\n"
<< "\ttemplate " << params_.templatename << '\n';
if (!params_.filename.empty())
- os << "\tfilename " << params_.filename << '\n';
+ os << "\tfilename "
+ << params_.filename.outputFilename(buffer->filePath())
+ << '\n';
if (params_.display != defaultDisplayType)
- os << "\tdisplay " << grfx::displayTranslator.find(params_.display)
+ os << "\tdisplay " << lyx::graphics::displayTranslator.find(params_.display)
<< '\n';
if (params_.lyxscale != defaultLyxScale)
{ "template", EX_TEMPLATE }
};
- lex.pushTable(external_tags, EX_END);
+ pushpophelper pph(lex, external_tags, EX_END);
bool found_end = false;
bool read_error = false;
case EX_FILENAME: {
lex.next();
string const name = lex.getString();
- params.filename = name;
+ params.filename.set(name, buffer->filePath());
break;
}
case EX_DISPLAY: {
lex.next();
string const name = lex.getString();
- params.display = grfx::displayTranslator.find(name);
+ params.display = lyx::graphics::displayTranslator.find(name);
break;
}
"Missing \\end_inset.");
}
- lex.popTable();
-
// Replace the inset's store
- string const path = buffer ? buffer->filePath() : string();
- setParams(params, path);
+ setParams(params, buffer);
lyxerr[Debug::INFO] << "InsetExternal::Read: "
- << "template: '" << params_.templatename
- << "' filename: '" << params_.filename
- << "' display: '" << params_.display
- << "' scale: '" << params_.lyxscale
- << '\'' << endl;
+ << "template: '" << params_.templatename
+ << "' filename: '" << params_.filename.absFilename()
+ << "' display: '" << params_.display
+ << "' scale: '" << params_.lyxscale
+ << '\'' << endl;
}
if (from_format.empty())
return;
- string from_file = params_.filename.empty() ?
- string() : MakeAbsPath(params_.filename, buf->filePath());
+ string from_file = params_.filename.absFilename();
if (from_format == "*") {
if (from_file.empty())
Buffer const * buffer, string const & s)
{
string result;
- string const basename = ChangeExtension(params.filename, 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", params.filename);
+ 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
{
- return params2string(inset_.params());
+ return params2string(inset_.params(), buffer);
}
void InsetExternalMailer::string2params(string const & in,
+ Buffer const & buffer,
InsetExternal::Params & params)
{
params = InsetExternal::Params();
if (lex.isOK()) {
InsetExternal inset;
- inset.read(0, lex);
+ inset.read(&buffer, lex);
params = inset.params();
}
}
string const
-InsetExternalMailer::params2string(InsetExternal::Params const & params)
+InsetExternalMailer::params2string(InsetExternal::Params const & params,
+ Buffer const & buffer)
{
InsetExternal inset;
- inset.setParams(params, string());
+ inset.setParams(params, &buffer);
ostringstream data;
data << name_ << ' ';
- inset.write(0, data);
+ inset.write(&buffer, data);
data << "\\end_inset\n";
return STRCONV(data.str());
}