Hmmm, opening file F in project P1 triggers a project change to project P2 but keeping file F open (and did it actually get opened in P1?).
Maybe what you need is to capture the open _before_ it happens, so you can stash the filename, switch projects and then open the file in the right one.