Add Buffer member in InsetExternalParams and InsetGraphicsParams.
Remove Buffer argument from string2params and params2string.
string const newId = cmd.getArg(0);
bool fetchId = newId.empty(); //if we wait for groupId from first graphics inset
- InsetGraphicsParams grp_par;
+ InsetGraphicsParams grp_par(&buffer_);
if (!fetchId)
- InsetGraphics::string2params(graphics::getGroupParams(buffer_, newId), buffer_, grp_par);
+ InsetGraphics::string2params(graphics::getGroupParams(buffer_, newId), grp_par);
if (!from.nextInset()) //move to closest inset
from.forwardInset();
// create inset for graphic
InsetGraphics * inset = new InsetGraphics(cur.buffer());
- InsetGraphicsParams params;
+ InsetGraphicsParams params(cur.buffer());
params.filename = support::DocFileName(filename.absFileName(), false);
inset->setParams(params);
cur.recordUndo();
string id = to_utf8(cmd.argument());
string grp = graphics::getGroupParams(bv->buffer(), id);
- InsetGraphicsParams tmp, inspar = ins->getParams();
+ InsetGraphicsParams tmp(&bv->buffer()), inspar = ins->getParams();
if (id.empty())
inspar.groupId = to_utf8(cmd.argument());
else {
- InsetGraphics::string2params(grp, bv->buffer(), tmp);
+ InsetGraphics::string2params(grp, tmp);
tmp.filename = inspar.filename;
inspar = tmp;
}
}
case EXTERNAL_CODE: {
- InsetExternalParams iep;
- InsetExternal::string2params(to_utf8(cmd.argument()), *buf, iep);
+ InsetExternalParams iep(buf);
+ InsetExternal::string2params(to_utf8(cmd.argument()), iep);
auto inset = make_unique<InsetExternal>(buf);
inset->setBuffer(*buf);
inset->setParams(iep);
}
case GRAPHICS_CODE: {
- InsetGraphicsParams igp;
- InsetGraphics::string2params(to_utf8(cmd.argument()), *buf, igp);
+ InsetGraphicsParams igp(buf);
+ InsetGraphics::string2params(to_utf8(cmd.argument()), igp);
auto inset = make_unique<InsetGraphics>(buf);
inset->setParams(igp);
return inset.release();
GuiExternal::GuiExternal(GuiView & lv)
- : GuiDialog(lv, "external", qt_("External Material")), bbChanged_(false)
+ : GuiDialog(lv, "external", qt_("External Material")),
+ params_(&buffer()), bbChanged_(false)
{
setupUi(this);
bool GuiExternal::initialiseParams(string const & sdata)
{
- InsetExternal::string2params(sdata, buffer(), params_);
+ InsetExternal::string2params(sdata, params_);
return true;
}
void GuiExternal::clearParams()
{
- params_ = InsetExternalParams();
+ params_ = InsetExternalParams(&buffer());
}
void GuiExternal::dispatchParams()
{
- string const lfun = InsetExternal::params2string(params_, buffer());
+ string const lfun = InsetExternal::params2string(params_);
dispatch(FuncRequest(getLfun(), lfun));
connectToNewInset();
}
GuiGraphics::GuiGraphics(GuiView & lv)
- : GuiDialog(lv, "graphics", qt_("Graphics")), bbChanged(false)
+ : GuiDialog(lv, "graphics", qt_("Graphics")),
+ bbChanged(false), params_(&buffer())
{
setupUi(this);
// group exists: load params into the dialog
groupCO->blockSignals(true);
- InsetGraphics::string2params(grp, buffer(), params_);
+ params_.setBuffer(&buffer());
+ InsetGraphics::string2params(grp, params_);
paramsToDialog(params_);
groupCO->blockSignals(false);
bool GuiGraphics::initialiseParams(string const & sdata)
{
- InsetGraphics::string2params(sdata, buffer(), params_);
+ params_.setBuffer(&buffer());
+ InsetGraphics::string2params(sdata, params_);
paramsToDialog(params_);
current_group_ = params_.groupId;
return true;
void GuiGraphics::clearParams()
{
- params_ = InsetGraphicsParams();
+ params_ = InsetGraphicsParams(&buffer());
}
void GuiGraphics::dispatchParams()
{
InsetGraphicsParams tmp_params(params_);
- string const lfun = InsetGraphics::params2string(tmp_params, buffer());
+ tmp_params.setBuffer(&buffer());
+ string const lfun = InsetGraphics::params2string(tmp_params);
dispatch(FuncRequest(getLfun(), lfun));
connectToNewInset();
}
break;
}
case EXTERNAL_CODE: {
- InsetExternalParams p;
- data = InsetExternal::params2string(p, buffer);
+ InsetExternalParams p(&buffer);
+ data = InsetExternal::params2string(p);
break;
}
case FLOAT_CODE: {
break;
}
case GRAPHICS_CODE: {
- InsetGraphicsParams p;
- data = InsetGraphics::params2string(p, buffer);
+ InsetGraphicsParams p(&buffer);
+ data = InsetGraphics::params2string(p);
break;
}
case MATH_SPACE_CODE: {
} // namespace external
-InsetExternalParams::InsetExternalParams()
+InsetExternalParams::InsetExternalParams(Buffer const * b)
: display(true),
preview_mode(PREVIEW_OFF),
lyxscale(defaultLyxScale),
- draft(false)
+ draft(false),
+ buffer_(b)
{
if (defaultTemplateName.empty()) {
external::TemplateManager const & etm =
}
-void InsetExternalParams::write(Buffer const & buf, ostream & os) const
+void InsetExternalParams::write(ostream & os) const
{
os << "External\n"
<< "\ttemplate " << templatename() << '\n';
if (!filename.empty())
- os << "\tfilename " << filename.outputFileName(buf.filePath()) << '\n';
+ os << "\tfilename " << filename.outputFileName(buffer_->filePath()) << '\n';
if (!display)
os << "\tdisplay false\n";
}
-bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
+void InsetExternalParams::read(Lexer & lex)
{
enum {
EX_TEMPLATE = 1,
case EX_FILENAME: {
lex.eatLine();
string const name = lex.getString();
- filename = buffer.getReferencedFileName(name);
+ filename = buffer_->getReferencedFileName(name);
break;
}
if (lyxerr.debugging(Debug::EXTERNAL)) {
lyxerr << "InsetExternalParams::read:\n";
- write(buffer, lyxerr);
+ write(lyxerr);
}
- return !read_error;
+ if (read_error)
+ throw ExceptionMessage(WarningException, from_ascii("Read Error: "),
+ from_ascii("Wrong tag in External inset"));
}
InsetExternal::InsetExternal(Buffer * buf)
- : Inset(buf), renderer_(new RenderButton)
+ : Inset(buf), params_(buf), renderer_(new RenderButton)
{
}
switch (cmd.action()) {
case LFUN_INSET_EDIT: {
- InsetExternalParams p = params();
+ InsetExternalParams p(params());
+ p.setBuffer(&buffer());
if (!cmd.argument().empty())
- string2params(to_utf8(cmd.argument()), buffer(), p);
+ string2params(to_utf8(cmd.argument()), p);
external::editExternal(p, buffer());
break;
}
case LFUN_INSET_MODIFY: {
- InsetExternalParams p;
- string2params(to_utf8(cmd.argument()), buffer(), p);
+ InsetExternalParams p(&buffer());
+ string2params(to_utf8(cmd.argument()), p);
cur.recordUndo();
setParams(p);
break;
}
- case LFUN_INSET_DIALOG_UPDATE:
+ case LFUN_INSET_DIALOG_UPDATE: {
+ InsetExternalParams p(params());
+ p.setBuffer(&cur.bv().buffer());
cur.bv().updateDialog("external",
- params2string(params(), cur.bv().buffer()));
+ params2string(p));
break;
+ }
default:
Inset::doDispatch(cur, cmd);
bool InsetExternal::showInsetDialog(BufferView * bv) const
{
- bv->showDialog("external", params2string(params(), bv->buffer()),
+ InsetExternalParams p(params());
+ p.setBuffer(&bv->buffer());
+ bv->showDialog("external", params2string(p),
const_cast<InsetExternal *>(this));
return true;
}
void InsetExternal::write(ostream & os) const
{
- params_.write(buffer(), os);
+ params_.write(os);
}
void InsetExternal::read(Lexer & lex)
{
- InsetExternalParams params;
- if (params.read(buffer(), lex))
- setParams(params);
+ InsetExternalParams params(&buffer());
+ try {
+ params.read(lex);
+ } catch (ExceptionMessage &) {
+ return;
+ }
+ setParams(params);
}
}
-void InsetExternal::string2params(string const & in, Buffer const & buffer,
- InsetExternalParams & params)
+void InsetExternal::string2params(string const & in, InsetExternalParams & params)
{
- params = InsetExternalParams();
+ params = InsetExternalParams(params.buffer());
if (in.empty())
return;
return;
}
- params.read(buffer, lex);
+ params.read(lex);
}
-string InsetExternal::params2string(InsetExternalParams const & params,
- Buffer const & buffer)
+string InsetExternal::params2string(InsetExternalParams const & params)
{
ostringstream data;
data << "external" << ' ';
- params.write(buffer, data);
+ params.write(data);
data << "\\end_inset\n";
return data.str();
}
/// hold parameters settable from the GUI
-class InsetExternalParams {
+class InsetExternalParams : public InsetParams {
public:
- InsetExternalParams();
+ explicit InsetExternalParams(Buffer const * b);
+ InsetExternalParams(InsetExternalParams const &) = default;
- void write(Buffer const &, std::ostream &) const;
- bool read(Buffer const &, Lexer &);
+ void write(std::ostream &) const override;
+ void read(Lexer &) override;
+
+ Buffer const * buffer() { return buffer_; }
+ void setBuffer(Buffer const * b) { buffer_ = b; }
/// The name of the tempfile used for manipulations.
support::FileName tempname() const { return tempname_(); }
private:
external::TempName tempname_;
std::string templatename_;
+ Buffer const * buffer_;
};
///
~InsetExternal();
///
- static void string2params(std::string const &, Buffer const &,
- InsetExternalParams &);
+ static void string2params(std::string const &, InsetExternalParams &);
///
- static std::string params2string(InsetExternalParams const &,
- Buffer const &);
+ static std::string params2string(InsetExternalParams const &);
///
InsetExternalParams const & params() const;
///
}
-void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
- InsetGraphicsParams & params)
+void readInsetGraphics(Lexer & lex, bool allowOrigin, InsetGraphicsParams & params)
{
bool finished = false;
if (token == "\\end_inset") {
finished = true;
} else {
- if (!params.Read(lex, token, buf, allowOrigin))
+ if (!params.read(lex, token, allowOrigin))
lyxerr << "Unknown token, "
<< token
<< ", skipping."
InsetGraphics::InsetGraphics(Buffer * buf)
- : Inset(buf), graphic_label(xml::uniqueID(from_ascii("graph"))),
+ : Inset(buf), params_(buf), graphic_label(xml::uniqueID(from_ascii("graph"))),
graphic_(new RenderGraphic(this))
{
}
InsetGraphics::InsetGraphics(InsetGraphics const & ig)
- : Inset(ig),
+ : Inset(ig), params_(nullptr),
graphic_label(xml::uniqueID(from_ascii("graph"))),
graphic_(new RenderGraphic(*ig.graphic_, this))
{
{
switch (cmd.action()) {
case LFUN_INSET_EDIT: {
- InsetGraphicsParams p = params();
+ InsetGraphicsParams p(params());
+ p.setBuffer(&buffer());
if (!cmd.argument().empty())
- string2params(to_utf8(cmd.argument()), buffer(), p);
+ string2params(to_utf8(cmd.argument()), p);
editGraphics(p);
break;
}
break;
}
- InsetGraphicsParams p;
- string2params(to_utf8(cmd.argument()), buffer(), p);
+ InsetGraphicsParams p(&buffer());
+ string2params(to_utf8(cmd.argument()), p);
if (p.filename.empty()) {
cur.noScreenUpdate();
break;
break;
}
- case LFUN_INSET_DIALOG_UPDATE:
- cur.bv().updateDialog("graphics", params2string(params(), buffer()));
+ case LFUN_INSET_DIALOG_UPDATE: {
+ InsetGraphicsParams p(params());
+ p.setBuffer(&buffer());
+ cur.bv().updateDialog("graphics", params2string(p));
break;
+ }
case LFUN_GRAPHICS_RELOAD:
params_.filename.refresh();
bool InsetGraphics::showInsetDialog(BufferView * bv) const
{
- bv->showDialog("graphics", params2string(params(), bv->buffer()),
+ InsetGraphicsParams p(params());
+ p.setBuffer(&bv->buffer());
+ bv->showDialog("graphics", params2string(p),
const_cast<InsetGraphics *>(this));
return true;
}
void InsetGraphics::write(ostream & os) const
{
os << "Graphics\n";
- params().Write(os, buffer());
+ params().write(os);
}
{
lex.setContext("InsetGraphics::read");
//lex >> "Graphics";
- readInsetGraphics(lex, buffer(), true, params_);
+ readInsetGraphics(lex, true, params_);
graphic_->update(params().as_grfxParams());
}
}
-void InsetGraphics::string2params(string const & in, Buffer const & buffer,
- InsetGraphicsParams & params)
+void InsetGraphics::string2params(string const & in, InsetGraphicsParams & params)
{
if (in.empty())
return;
lex.setStream(data);
lex.setContext("InsetGraphics::string2params");
lex >> "graphics";
- params = InsetGraphicsParams();
- readInsetGraphics(lex, buffer, false, params);
+ params = InsetGraphicsParams(params.buffer());
+ readInsetGraphics(lex, false, params);
}
-string InsetGraphics::params2string(InsetGraphicsParams const & params,
- Buffer const & buffer)
+string InsetGraphics::params2string(InsetGraphicsParams const & params)
{
ostringstream data;
data << "graphics" << ' ';
- params.Write(data, buffer);
+ params.write(data);
data << "\\end_inset\n";
return data.str();
}
InsetGraphicsParams const & inspar = ins->getParams();
if (inspar.groupId == groupId) {
InsetGraphicsParams tmp = inspar;
+ tmp.setBuffer(&b);
tmp.filename.erase();
- return InsetGraphics::params2string(tmp, b);
+ return InsetGraphics::params2string(tmp);
}
}
return string();
void unifyGraphicsGroups(Buffer & b, string const & argument)
{
- InsetGraphicsParams params;
- InsetGraphics::string2params(argument, b, params);
+ InsetGraphicsParams params(&b);
+ InsetGraphics::string2params(argument, params);
// This handles undo groups automagically
UndoGroupHelper ugh(&b);
///
static void string2params(std::string const & data,
- Buffer const & buffer,
InsetGraphicsParams &);
///
- static std::string params2string(InsetGraphicsParams const &,
- Buffer const &);
+ static std::string params2string(InsetGraphicsParams const &);
/** Set the inset parameters, used by the GUIndependent dialog.
Return true of new params are different from what was so far.
namespace lyx {
-InsetGraphicsParams::InsetGraphicsParams()
+InsetGraphicsParams::InsetGraphicsParams(Buffer const * b)
{
- init();
+ init(b);
}
}
-void InsetGraphicsParams::init()
+void InsetGraphicsParams::init(Buffer const * b)
{
filename.erase();
lyxscale = 100; // lyx scaling in percentage
rotateOrigin.erase(); // Origin of rotation
special.erase(); // additional userdefined stuff
groupId.clear();
+ buffer_ = b;
}
rotateOrigin = params.rotateOrigin;
special = params.special;
groupId = params.groupId;
+
+ buffer_ = params.buffer_;
}
}
-void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
+void InsetGraphicsParams::write(ostream & os) const
{
// Do not write the default values
if (!filename.empty())
- os << "\tfilename " << filename.outputFileName(buffer.filePath()) << '\n';
+ os << "\tfilename " << filename.outputFileName(buffer_->filePath()) << '\n';
if (lyxscale != 100)
os << "\tlyxscale " << lyxscale << '\n';
if (!display)
}
-bool InsetGraphicsParams::Read(Lexer & lex, string const & token,
- Buffer const & buf, bool allowOrigin)
+bool InsetGraphicsParams::read(Lexer & lex, string const & token, bool allowOrigin)
{
if (token == "filename") {
lex.eatLine();
if (allowOrigin)
- filename = buf.getReferencedFileName(lex.getString());
+ filename = buffer_->getReferencedFileName(lex.getString());
else
- filename.set(lex.getString(), buf.filePath());
+ filename.set(lex.getString(), buffer_->filePath());
} else if (token == "lyxscale") {
lex.next();
lyxscale = lex.getInteger();
#ifndef INSETGRAPHICSPARAMS_H
#define INSETGRAPHICSPARAMS_H
+#include "insets/InsetParams.h"
#include "graphics/GraphicsParams.h"
std::string rotateOrigin;
/// any userdefined special command
std::string special;
+ ///
+ Buffer const * buffer_;
/// Does this need to be handled specifically
/// in dark mode? (use by InsetInfo)
bool darkModeSensitive;
///
- InsetGraphicsParams();
+ InsetGraphicsParams(Buffer const * b);
///
InsetGraphicsParams(InsetGraphicsParams const &);
///
InsetGraphicsParams & operator=(InsetGraphicsParams const &);
/// Save the parameters in the LyX format stream.
/// Buffer is needed to figure out if a figure is embedded.
- void Write(std::ostream & os, Buffer const & buf) const;
+ void write(std::ostream & os) const;
/// If the token belongs to our parameters, read it.
- bool Read(Lexer & lex, std::string const & token, Buffer const & buf,
- bool allowOrigin);
+ bool read(Lexer & lex, std::string const & token, bool allowOrigin);
/// convert
// Only a subset of InsetGraphicsParams is needed for display purposes.
// This function also interrogates lyxrc to ascertain whether
// to display or not.
graphics::Params as_grfxParams() const;
+ ///
+ Buffer const * buffer() { return buffer_; }
+ ///
+ void setBuffer(Buffer const * b) { buffer_ = b; }
// FIXME UNICODE. Write functions need to use odostream instead of ostream firstly.
/// Identification of the graphics template. No template equals empty string.
std::string groupId;
private:
/// Initialize the object to a default status.
- void init();
+ void init(Buffer const * b);
/// Copy the other objects content to us, used in copy c-tor and assignment
void copy(InsetGraphicsParams const & params);
};
}
}
InsetGraphics * inset = new InsetGraphics(buffer_);
- InsetGraphicsParams igp;
+ InsetGraphicsParams igp(buffer_);
igp.filename = file;
igp.lyxscale = percent_scale;
igp.scale = string();