Thanks for the reply.

On Dec 8, 2010, at 8:47 AM, Vincent van Ravesteijn wrote:
> 
> InsetGraphics::prepareFile():
> 
>       string const orig_file = params().filename.absFilename();
>       // this is for dryrun and display purposes, do not use latexFilename
>       string const rel_file = 
> params().filename.relFilename(buffer().filePath());
>       LYXERR0(orig_file);
>       LYXERR0(buffer().filePath());
>       LYXERR0(rel_file);
> 
> and
> 
> GuiGraphics::paramsToDialog():
> 
>       string const name =
>               igp.filename.outputFilename(fromqstr(bufferFilepath()));
>       LYXERR0(name);
> 
> I put in some debugging macros you can use to output some debug info.
> If you can compile LyX you can try and see what they give you and why
> the copies don't get a relative filename.

It seems like prepareFile() is not called during copy'n'paste.  I added the 
suggested debug statements (with Debug::GRAPHICS level), in addition to a few 
others that I put in various places yesterday.  The "-dbg graphics" output is 
below.

I think prepareFile() is only called by InsetGraphics::latex() – but it's 
important that relative paths are saved to the LyX file, not only to the LaTeX 
output.

>> 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...
>> 
> 
> We are thinking about this in a slightly different context.  When to
> use a relative path ? It is obvious for
> 
> "C:\Documents\test.lyx"
> "C:\Documents\images\text.jpg"
> 
> to represent the image path as "images\text.jpg", and for
> 
> "C:\Documents\chapters\test.lyx"
> "C:\Documents\images\test.jpg"
> 
> to represent the image path as "..\images\test.jpg", but what should we do for
> 
> "C:\Documents\chapters\first\firstsection\test.lyx"
> "C:\UnrelatedPath\test\images\large\color\test.jpg" ?
> 
> Should we now have a relative path
> "..\..\..\..\UnrelatedPath\test\images\large\color\texst.jpg" ? This
> doesn't really make sense.

Yes, I agree.  If I understand it correctly, the makeRelPath function mirrors 
these thoughts and would return an absolute path for your last example, right?

Cheers,
  Christian


===== Debugging Output =====

I have a document at "/Users/ct/newfile1.lyx" with one image in it, 
"Desktop/WAN_map.pdf".

I select the image and hit Cmd-C to copy it (the 0 after the filename is the 
value of DocFileName::save_abs_path_):

insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(143): Write(ostream, Buffer)
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0

(The last bunch of copy(...) appears when I move the cursor to deselect the 
copied image.)

Now I hit Cmd-V:

insets/InsetGraphics.cpp(136): Token: 'filename'
insets/InsetGraphicsParams.cpp(189): Read(Lexer, string, string)
insets/InsetGraphics.cpp(136): Token: 'lyxscale'
insets/InsetGraphicsParams.cpp(189): Read(Lexer, string, string)
insets/InsetGraphics.cpp(136): Token: '\end_inset'
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 1
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 1

Now I click on the pasted image to open the graphics dialog:

insets/InsetGraphicsParams.cpp(143): Write(ostream, Buffer)
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename =  1
insets/InsetGraphics.cpp(136): Token: 'filename'
insets/InsetGraphicsParams.cpp(189): Read(Lexer, string, string)
insets/InsetGraphics.cpp(136): Token: 'lyxscale'
insets/InsetGraphicsParams.cpp(189): Read(Lexer, string, string)
insets/InsetGraphics.cpp(136): Token: '\end_inset'
GuiGraphics.cpp(554): paramsToDialog: name = /Users/ct/Desktop/WAN_map.pdf
FileName.cpp(946): Recognised Fileformat: pdf
FileName.cpp(946): Recognised Fileformat: pdf
filetools.cpp(850): [readBB_from_PSFile] no(e)ps-format
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 1

For comparison, this happens when I click the original image:

insets/InsetGraphicsParams.cpp(143): Write(ostream, Buffer)
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename =  1
insets/InsetGraphics.cpp(136): Token: 'filename'
insets/InsetGraphicsParams.cpp(189): Read(Lexer, string, string)
insets/InsetGraphics.cpp(136): Token: 'lyxscale'
insets/InsetGraphicsParams.cpp(189): Read(Lexer, string, string)
insets/InsetGraphics.cpp(136): Token: '\end_inset'
GuiGraphics.cpp(554): paramsToDialog: name = Desktop/WAN_map.pdf
FileName.cpp(946): Recognised Fileformat: pdf
FileName.cpp(946): Recognised Fileformat: pdf
filetools.cpp(850): [readBB_from_PSFile] no(e)ps-format
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 0
insets/InsetGraphicsParams.cpp(88): copy(InsetGraphicsParams)
insets/InsetGraphicsParams.cpp(89):   filename = /Users/ct/Desktop/WAN_map.pdf 1



Reply via email to