Here is a question for you: Do you want to display true, embedded
filename, or the may-not-exist external filename in the graphics
dialog? The attached patch does the former, but in a ugly way:

1. call updateDialog("graphics"); in setEmbed().
LFUN_INSET_DIALOG_UPDATE is triggered as expected.

2. params2string uses *external filename*, using EmbeddedFiles()'s
look up facility, because it is the same function used to write to
.lyx file.

3. In GuiGraphics.cpp, params().filename has to be converted to
embedded filename again.

Also, we do not really want to display '/tmp/adfdf223234234/filename'.
Some more lines are needed to display "Embedded:filename".

Bo
Index: src/insets/InsetGraphics.cpp
===================================================================
--- src/insets/InsetGraphics.cpp	(revision 20261)
+++ src/insets/InsetGraphics.cpp	(working copy)
@@ -248,8 +248,6 @@
 	params_.filename.set(file.availableFile(&buf), buf.filePath());
 	LYXERR(Debug::FILES) << " to " 
 		<< params_.filename.toFilesystemEncoding() << std::endl;
-	// FIXME: graphics dialog is not updated even if the underlying
-	// filename is updated. What should I do?
 }
 
 
Index: src/insets/InsetGraphicsParams.cpp
===================================================================
--- src/insets/InsetGraphicsParams.cpp	(revision 20261)
+++ src/insets/InsetGraphicsParams.cpp	(working copy)
@@ -157,6 +157,9 @@
 
 	if (!filename.empty()) {
 		// when we save, we still use the original filename
+		// This ensures that the external filename will be written 
+		// to .lyx file, but causes trouble in graphics dialog update
+		// In that dialog, true filename has to be displayed.
 		EmbeddedFiles::EmbeddedFileList::const_iterator it = 
 			buffer.embeddedFiles().find(filename.toFilesystemEncoding());
 		if (it != buffer.embeddedFiles().end())
Index: src/frontends/qt4/GuiGraphics.cpp
===================================================================
--- src/frontends/qt4/GuiGraphics.cpp	(revision 20261)
+++ src/frontends/qt4/GuiGraphics.cpp	(working copy)
@@ -56,6 +56,9 @@
 
 
 namespace lyx {
+
+using support::DocFileName;
+
 namespace frontend {
 
 
@@ -422,8 +425,9 @@
 			break;
 	}
 
-	string const name =
-		igp.filename.outputFilename(controller().bufferFilepath());
+	// this file may be embedded
+	DocFileName const & af = controller().availableFile(igp.filename);
+	string const name = af.outputFilename(controller().bufferFilepath());
 	filename->setText(toqstr(name));
 
 	// set the bounding box values
Index: src/frontends/controllers/ControlEmbeddedFiles.cpp
===================================================================
--- src/frontends/controllers/ControlEmbeddedFiles.cpp	(revision 20262)
+++ src/frontends/controllers/ControlEmbeddedFiles.cpp	(working copy)
@@ -111,6 +111,9 @@
 		else
 			item.extract(&buffer());
 		item.updateInsets(&buffer());
+		// FIXME: unless we record the type of file item, we will
+		// need to update all possible dialogs (bibtex etc).
+		updateDialog("graphics");
 	}
 	if (embed)
 		dispatchMessage("Embed file " + item.outputFilename(buffer().filePath()));
Index: src/frontends/controllers/ControlGraphics.h
===================================================================
--- src/frontends/controllers/ControlGraphics.h	(revision 20261)
+++ src/frontends/controllers/ControlGraphics.h	(working copy)
@@ -18,6 +18,7 @@
 #include "Dialog.h"
 
 #include "support/docstring.h"
+#include "support/FileName.h"
 
 #include <utility>
 #include <vector>
@@ -61,6 +62,10 @@
 	bool isFilenameValid(std::string const & fname) const;
 	/// edit file
 	void editGraphics();
+	/// in case that the file is embedded, we need to display
+	/// its embedded filename. Note that params() always holds
+	/// the external filename.
+	support::DocFileName const availableFile(support::DocFileName const &) const;
 
 private:
 	///
Index: src/frontends/controllers/ControlGraphics.cpp
===================================================================
--- src/frontends/controllers/ControlGraphics.cpp	(revision 20261)
+++ src/frontends/controllers/ControlGraphics.cpp	(working copy)
@@ -18,6 +18,8 @@
 #include "FuncRequest.h"
 #include "gettext.h"
 #include "LyXRC.h"
+#include "Buffer.h"
+#include "EmbeddedFiles.h"
 
 #include "graphics/GraphicsCache.h"
 #include "graphics/GraphicsCacheItem.h"
@@ -45,6 +47,7 @@
 using support::addName;
 using support::FileFilterList;
 using support::FileName;
+using support::DocFileName;
 using support::isFileReadable;
 using support::makeAbsPath;
 using support::package;
@@ -149,6 +152,16 @@
 }
 
 
+DocFileName const ControlGraphics::availableFile(DocFileName const & filename) const
+{
+	EmbeddedFiles const & files = buffer().embeddedFiles();
+	EmbeddedFiles::EmbeddedFileList::const_iterator it = files.find(filename.absFilename());
+	if (it != files.end())
+		return DocFileName(it->availableFile(&buffer()));
+	return filename;
+}
+
+
 namespace {
 
 char const * const bb_units[] = { "bp", "cm", "mm", "in" };

Reply via email to