]> git.lyx.org Git - features.git/commitdiff
Move Buffer argument from methods to constructor to unify interfaces
authorYuriy Skalko <yuriy.skalko@gmail.com>
Mon, 21 Dec 2020 11:38:34 +0000 (13:38 +0200)
committerYuriy Skalko <yuriy.skalko@gmail.com>
Fri, 15 Jan 2021 19:09:15 +0000 (21:09 +0200)
Add Buffer member in InsetExternalParams and InsetGraphicsParams.
Remove Buffer argument from string2params and params2string.

14 files changed:
src/BufferView.cpp
src/CutAndPaste.cpp
src/Text3.cpp
src/factory.cpp
src/frontends/qt/GuiExternal.cpp
src/frontends/qt/GuiGraphics.cpp
src/insets/InsetCommand.cpp
src/insets/InsetExternal.cpp
src/insets/InsetExternal.h
src/insets/InsetGraphics.cpp
src/insets/InsetGraphics.h
src/insets/InsetGraphicsParams.cpp
src/insets/InsetGraphicsParams.h
src/insets/InsetInfo.cpp

index ec89084de756cf3699efcf3297d2f8d27d75672c..dafab28c7be9e6ef7a9cc1546b5578d23b0dabd1 100644 (file)
@@ -1743,9 +1743,9 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                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();
index fc555c1375bf157f91ea57d7a39544fa1feaf50f..598413e36909cb6132c7c7051674f1dbf6b4eb38 100644 (file)
@@ -1351,7 +1351,7 @@ void pasteClipboardGraphics(Cursor & cur, ErrorList & /* errorList */,
 
        // 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();
index 25bc7ec24986d095d6237d5b1ebbb5cfb84383e9..a59eec8b97703d4fd3c0c8b0bd245878ecf83025 100644 (file)
@@ -1387,12 +1387,12 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
 
                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;
                }
index 6f17797ada95b88c45961f23f7a6b9ca5cf212ad..0fb4f1b8a3c4ce6119e6619ad317a3aaeb1ae580 100644 (file)
@@ -312,8 +312,8 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
                        }
 
                        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);
@@ -321,8 +321,8 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
                        }
 
                        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();
index 62c56c982d40618bd369f00a108a1e6dbdd99329..25f0e657332b639eba577c7a85334f89f39d4bc0 100644 (file)
@@ -83,7 +83,8 @@ char const * const origin_gui_strs[] = {
 
 
 GuiExternal::GuiExternal(GuiView & lv)
-       : GuiDialog(lv, "external", qt_("External Material")), bbChanged_(false)
+       : GuiDialog(lv, "external", qt_("External Material")),
+         params_(&buffer()), bbChanged_(false)
 {
        setupUi(this);
 
@@ -629,20 +630,20 @@ void GuiExternal::applyView()
 
 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();
 }
index 9d045275adb08c7aa3cd19dd5f560badcf4a9a78..db911613bcf384542c514d7a2f4e9b225a1dbed5 100644 (file)
@@ -110,7 +110,8 @@ static void setAutoTextCB(QCheckBox * checkBox, QLineEdit * lineEdit,
 
 
 GuiGraphics::GuiGraphics(GuiView & lv)
-       : GuiDialog(lv, "graphics", qt_("Graphics")), bbChanged(false)
+       : GuiDialog(lv, "graphics", qt_("Graphics")),
+         bbChanged(false), params_(&buffer())
 {
        setupUi(this);
 
@@ -309,7 +310,8 @@ void GuiGraphics::changeGroup(int /* index */)
 
        // 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);
 
@@ -752,7 +754,8 @@ bool GuiGraphics::isValid()
 
 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;
@@ -761,14 +764,15 @@ bool GuiGraphics::initialiseParams(string const & sdata)
 
 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();
 }
index 9ca958b5f880857c6195614fa93dcdf9d14cc50c..1089247f839bae998f137f70eab5ab1ca6391712 100644 (file)
@@ -383,8 +383,8 @@ bool decodeInsetParam(string const & name, string & data,
                break;
        }
        case EXTERNAL_CODE: {
-               InsetExternalParams p;
-               data = InsetExternal::params2string(p, buffer);
+               InsetExternalParams p(&buffer);
+               data = InsetExternal::params2string(p);
                break;
        }
        case FLOAT_CODE:  {
@@ -403,8 +403,8 @@ bool decodeInsetParam(string const & name, string & data,
                break;
        }
        case GRAPHICS_CODE: {
-               InsetGraphicsParams p;
-               data = InsetGraphics::params2string(p, buffer);
+               InsetGraphicsParams p(&buffer);
+               data = InsetGraphics::params2string(p);
                break;
        }
        case MATH_SPACE_CODE: {
index 92308db704c3c020bddc3525f5054b024433d994..eba87560567ae180e35f92b9c69ef1df128c9149 100644 (file)
@@ -117,11 +117,12 @@ support::FileName TempName::operator()() const
 } // 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 =
@@ -176,13 +177,13 @@ void InsetExternalParams::settemplate(string const & name)
 }
 
 
-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";
@@ -233,7 +234,7 @@ void InsetExternalParams::write(Buffer const & buf, ostream & os) const
 }
 
 
-bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
+void InsetExternalParams::read(Lexer & lex)
 {
        enum {
                EX_TEMPLATE = 1,
@@ -286,7 +287,7 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
                case EX_FILENAME: {
                        lex.eatLine();
                        string const name = lex.getString();
-                       filename = buffer.getReferencedFileName(name);
+                       filename = buffer_->getReferencedFileName(name);
                        break;
                }
 
@@ -385,10 +386,12 @@ bool InsetExternalParams::read(Buffer const & buffer, Lexer & lex)
 
        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"));
 }
 
 
@@ -419,7 +422,7 @@ docstring screenLabel(InsetExternalParams const & params,
 
 
 InsetExternal::InsetExternal(Buffer * buf)
-       : Inset(buf), renderer_(new RenderButton)
+       : Inset(buf), params_(buf), renderer_(new RenderButton)
 {
 }
 
@@ -456,25 +459,29 @@ void InsetExternal::doDispatch(Cursor & cur, FuncRequest & cmd)
        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);
@@ -511,7 +518,9 @@ void InsetExternal::addToToc(DocIterator const & cpit, bool output_active,
 
 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;
 }
@@ -681,15 +690,19 @@ void InsetExternal::fileChanged() const
 
 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);
 }
 
 
@@ -890,10 +903,9 @@ string InsetExternal::contextMenuName() const
 }
 
 
-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;
 
@@ -919,16 +931,15 @@ void InsetExternal::string2params(string const & in, Buffer const & buffer,
                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();
 }
index f124445f5eea4723d50612b0f6abb2bf361365d9..1649802d07fc91b81bcd6535a7da06a0e62b7e14 100644 (file)
@@ -46,12 +46,16 @@ private:
 
 
 /// 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_(); }
@@ -82,6 +86,7 @@ public:
 private:
        external::TempName tempname_;
        std::string templatename_;
+       Buffer const * buffer_;
 };
 
 
@@ -98,11 +103,9 @@ public:
        ///
        ~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;
        ///
index 7daa40d9aaf392438b293f99ac81b2b18b7ee25f..8d56fc9f1cd2696bc8bb9bffedf31d86875a080a 100644 (file)
@@ -148,8 +148,7 @@ string findTargetFormat(string const & format, OutputParams const & runparams)
 }
 
 
-void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
-       InsetGraphicsParams & params)
+void readInsetGraphics(Lexer & lex, bool allowOrigin, InsetGraphicsParams & params)
 {
        bool finished = false;
 
@@ -165,7 +164,7 @@ void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
                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."
@@ -178,14 +177,14 @@ void readInsetGraphics(Lexer & lex, Buffer const & buf, bool allowOrigin,
 
 
 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))
 {
@@ -210,9 +209,10 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        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;
        }
@@ -223,8 +223,8 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
                        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;
@@ -240,9 +240,12 @@ void InsetGraphics::doDispatch(Cursor & cur, FuncRequest & cmd)
                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();
@@ -278,7 +281,9 @@ bool InsetGraphics::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 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;
 }
@@ -300,7 +305,7 @@ void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 void InsetGraphics::write(ostream & os) const
 {
        os << "Graphics\n";
-       params().Write(os, buffer());
+       params().write(os);
 }
 
 
@@ -308,7 +313,7 @@ void InsetGraphics::read(Lexer & lex)
 {
        lex.setContext("InsetGraphics::read");
        //lex >> "Graphics";
-       readInsetGraphics(lex, buffer(), true, params_);
+       readInsetGraphics(lex, true, params_);
        graphic_->update(params().as_grfxParams());
 }
 
@@ -1158,8 +1163,7 @@ string InsetGraphics::contextMenuName() const
 }
 
 
-void InsetGraphics::string2params(string const & in, Buffer const & buffer,
-       InsetGraphicsParams & params)
+void InsetGraphics::string2params(string const & in, InsetGraphicsParams & params)
 {
        if (in.empty())
                return;
@@ -1169,17 +1173,16 @@ void InsetGraphics::string2params(string const & in, Buffer const & buffer,
        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();
 }
@@ -1232,8 +1235,9 @@ string getGroupParams(Buffer const & b, string const & groupId)
                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();
@@ -1242,8 +1246,8 @@ string getGroupParams(Buffer const & b, string const & groupId)
 
 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);
index 2f0156dfc9adfb0944db8a8027a0c2a29ea23bd2..151e4313f2ac34b5ee0262e722988fc521d7b110 100644 (file)
@@ -40,11 +40,9 @@ public:
 
        ///
        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.
index 13b57c07753ea97223a90a3ef55aeb7e78687d00..a33ef661033c0c5eb44d20695bafc01617e125c8 100644 (file)
@@ -35,9 +35,9 @@ using namespace lyx::support;
 namespace lyx {
 
 
-InsetGraphicsParams::InsetGraphicsParams()
+InsetGraphicsParams::InsetGraphicsParams(Buffer const * b)
 {
-       init();
+       init(b);
 }
 
 
@@ -60,7 +60,7 @@ InsetGraphicsParams & InsetGraphicsParams::operator=(InsetGraphicsParams const &
 }
 
 
-void InsetGraphicsParams::init()
+void InsetGraphicsParams::init(Buffer const * b)
 {
        filename.erase();
        lyxscale = 100;                 // lyx scaling in percentage
@@ -80,6 +80,7 @@ void InsetGraphicsParams::init()
        rotateOrigin.erase();           // Origin of rotation
        special.erase();                // additional userdefined stuff
        groupId.clear();
+       buffer_ = b;
 }
 
 
@@ -103,6 +104,8 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & params)
        rotateOrigin = params.rotateOrigin;
        special = params.special;
        groupId = params.groupId;
+
+       buffer_ = params.buffer_;
 }
 
 
@@ -137,11 +140,11 @@ bool operator!=(InsetGraphicsParams const & left,
 }
 
 
-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)
@@ -180,15 +183,14 @@ void InsetGraphicsParams::Write(ostream & os, Buffer const & buffer) const
 }
 
 
-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();
index 1aa0b23d5b68cd8f742ca3aa9c6f0e443375558a..bae4d3598218c21db42cc958391469e197c6c8d8 100644 (file)
@@ -13,6 +13,7 @@
 #ifndef INSETGRAPHICSPARAMS_H
 #define INSETGRAPHICSPARAMS_H
 
+#include "insets/InsetParams.h"
 
 #include "graphics/GraphicsParams.h"
 
@@ -62,35 +63,40 @@ public:
        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);
 };
index 819d8ff62e55ec92eb8858ecdb556642b8787a87..dc321d6e4b9dd211945afe7efbf3567a22959d32 100644 (file)
@@ -1073,7 +1073,7 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype, bool cons
                        }
                }
                InsetGraphics * inset = new InsetGraphics(buffer_);
-               InsetGraphicsParams igp;
+               InsetGraphicsParams igp(buffer_);
                igp.filename = file;
                igp.lyxscale = percent_scale;
                igp.scale = string();