This patch prevents InsetGraphics from being created without a Buffer. Comments?

rh

Index: src/CutAndPaste.cpp
===================================================================
--- src/CutAndPaste.cpp	(revision 23930)
+++ src/CutAndPaste.cpp	(working copy)
@@ -859,7 +859,7 @@
 		return;
 
 	// create inset for graphic
-	InsetGraphics * inset = new InsetGraphics;
+	InsetGraphics * inset = new InsetGraphics(cur.buffer());
 	InsetGraphicsParams params;
 	params.filename = EmbeddedFile(filename.absFilename(), cur.buffer().filePath());
 	inset->setParams(params);
Index: src/factory.cpp
===================================================================
--- src/factory.cpp	(revision 23932)
+++ src/factory.cpp	(working copy)
@@ -259,7 +259,7 @@
 			case GRAPHICS_CODE: {
 				InsetGraphicsParams igp;
 				InsetGraphicsMailer::string2params(to_utf8(cmd.argument()), buf, igp);
-				auto_ptr<InsetGraphics> inset(new InsetGraphics);
+				auto_ptr<InsetGraphics> inset(new InsetGraphics(buf));
 				inset->setParams(igp);
 				return inset.release();
 			}
@@ -504,7 +504,7 @@
 		} else if (tmptok == "Formula") {
 			inset.reset(new InsetMathHull);
 		} else if (tmptok == "Graphics") {
-			inset.reset(new InsetGraphics);
+			inset.reset(new InsetGraphics(const_cast<Buffer &>(buf)));
 		} else if (tmptok == "Note") {
 			inset.reset(new InsetNote(buf, tmptok));
 		} else if (tmptok == "Box") {
Index: src/insets/InsetGraphics.cpp
===================================================================
--- src/insets/InsetGraphics.cpp	(revision 23930)
+++ src/insets/InsetGraphics.cpp	(working copy)
@@ -126,10 +126,12 @@
 } // namespace anon
 
 
-InsetGraphics::InsetGraphics()
+InsetGraphics::InsetGraphics(Buffer & buf)
 	: graphic_label(sgml::uniqueID(from_ascii("graph"))),
 	  graphic_(new RenderGraphic(this))
-{}
+{
+	Inset::setBuffer(buf);
+}
 
 
 InsetGraphics::InsetGraphics(InsetGraphics const & ig)
@@ -273,7 +275,7 @@
 	string const token = lex.getString();
 
 	if (token == "Graphics")
-		readInsetGraphics(lex, buffer().filePath());
+		readInsetGraphics(lex, buffer().filePath(), params_);
 	else
 		LYXERR(Debug::GRAPHICS, "Not a Graphics inset!");
 
@@ -282,7 +284,8 @@
 }
 
 
-void InsetGraphics::readInsetGraphics(Lexer & lex, string const & bufpath)
+void InsetGraphics::readInsetGraphics(Lexer & lex, string const & bufpath,
+	InsetGraphicsParams & params)
 {
 	bool finished = false;
 
@@ -298,7 +301,7 @@
 		if (token == "\\end_inset") {
 			finished = true;
 		} else {
-			if (!params_.Read(lex, token, bufpath))
+			if (!params.Read(lex, token, bufpath))
 				lyxerr << "Unknown token, " << token << ", skipping."
 					<< endl;
 		}
@@ -963,7 +966,6 @@
 					Buffer const & buffer,
 					InsetGraphicsParams & params)
 {
-	params = InsetGraphicsParams();
 	if (in.empty())
 		return;
 
@@ -976,9 +978,8 @@
 	if (!lex || name != name_)
 		return print_mailer_error("InsetGraphicsMailer", in, 1, name_);
 
-	InsetGraphics inset;
-	inset.readInsetGraphics(lex, buffer.filePath());
-	params = inset.params();
+	params = InsetGraphicsParams();
+	InsetGraphics::readInsetGraphics(lex, buffer.filePath(), params);
 }
 
 
Index: src/insets/InsetGraphics.h
===================================================================
--- src/insets/InsetGraphics.h	(revision 23930)
+++ src/insets/InsetGraphics.h	(working copy)
@@ -30,7 +30,7 @@
 class InsetGraphics : public Inset, public boost::signals::trackable {
 public:
 	///
-	InsetGraphics();
+	InsetGraphics(Buffer & buf);
 	///
 	~InsetGraphics();
 	///
@@ -99,7 +99,8 @@
 	virtual Inset * clone() const;
 
 	/// Read the inset native format
-	void readInsetGraphics(Lexer & lex, std::string const & bufpath);
+	static void readInsetGraphics(Lexer & lex, std::string const & bufpath,
+			InsetGraphicsParams & params);
 
 	/// Get the status message, depends on the image loading status.
 	std::string const statusMessage() const;

Reply via email to