Hello,

I noticed there are some closed entries in the bug tracker about this already, 
but I've had this problem for a long time and it still appears in LyX 1.6.8 (I 
am using Mac OS X):

1) Insert a new graphic and select an image via the file selection dialog.
2) The graphics dialog now shows a relative path to the image file.
3) Close the graphics dialog, duplicate the image via copy'n'paste, and open 
the duplicated image's graphics dialog.
4) The filename is now an absolute path.

This is of course a pain when sending the LyX document to your collaborators.

I downloaded the source code of LyX 1.6.8 and was able to track it down:

1) When copying an image, the relative path is converted into an absolute path.
2) In pasteClipboardText (CutAndPaste.cpp, line 912), a temporary Buffer is 
created (line 926) that holds the pasted LyX paragraphs.
3) The paragraphs are parsed and new InsetGraphics are created from the 
absolute paths supplied in the pasted text.
4) The DocFileName class which holds the image filename thinks that it should 
output absolute paths now because it was given an absolute path initially.

Obviously, (1) is necessary for inter-document copy'n'paste, but it would be 
awesome if either the information "absolute/relative path" was preserved during 
copy'n'paste or graphics paths were relative by default.  I guess the latter is 
easier to implement and here is a possible solution (comments appreciated):

A) DocFileName::set must be forced to always try relative paths by default.  
Change support/FileName.cpp, line 1076 to:
        save_abs_path_ = isAbsolute(to_utf8(makeRelPath(from_utf8(name), 
from_utf8(buffer_path))));
(This was save_abs_path_ = isAbsolute(name), but now tries to make a relative 
path first and only if that fails (makeRelPath returns an absolute path) it 
will save absolute paths.)

B) The temporary Buffer in which the InsetGraphics is created must have a 
proper filename that defines the base path.  Change CutAndPaste.cpp, line 926 
so that the buffer takes on the target buffer's filename:
                        Buffer buffer(cur.buffer().absFileName(), true);
(It's marked read-only and the next line is buffer.setUnnamed(true), so I 
assume there's no danger of accidentally the whole target buffer.)

It might be sensible to add a checkbox "Save absolute path" to the graphics 
dialog to let the user decide on a case-by-case basis.  Also, the preferences 
could contain a "Save absolute paths by default" checkbox.  But this is beyond 
my current Qt coding capabilities...

Cheers,
  Christian


PS: As a side note, I tested the above fix and it works, but I am having some 
general trouble to get LyX to work correctly from the sources.  I downloaded 
and installed the Qt sources (4.7.1), but after compiling LyX, I had to 
manually copy qt_menu.nib to /Applications/LyX.app/Resources because it would 
crash otherwise.  Also, the toolbars look different and the text body font is 
sans-serif.  I don't know what went wrong there (the 1.6.8 binary looks and 
behaves normal on my machine).  Any hints on that would be highly appreciated 
as I can't really enjoy my own bug-fix right now... ;-)

Reply via email to