"in pop-up" now opens correct file, but the link still display's the wrong filename (mainfile of the target context).
I realize it would be better if I could change the value of $file, as the most of the existing code should "just work" in that case.