views:

216

answers:

5

Right now, when I notice a problem on a page on my PHP web site, I have to look at the URL, mentally deduce what file is responsible for displaying that page, then navigate the Eclipse PDT file tree to open that file. This is annoying and uses brain power that could have been applied to solving the issue instead.

I would like my PHP web site to display on every page a link that I could click to automatically open the correct file in Eclipse.

I can easily compute the complete absolute path for the file I need to open (for example, open C:/xampp/htdocs/controllers/Foo/Bar.php when visiting /foo/bar), and I can make sure that Eclipse is currently open with the correct project loaded, but I'm stuck on how I can have Firefox/Chrome/IE tell Eclipse to open that specific file.

Edit

I'm going along the way of a data: URI, by adding a link to my file that contains the name of the file, with an unusual MIME type.

<a href="data:link/php;base64,IkM6XHhhb[snip]GhwIgo=">
  View controller
</a>

The base64-encoded content is the absolute path to the file on my computer. When I click the link, Firefox lets me bind the content type to a new application, so I chose a batch file I wrote myself:

for /f "delims=" %%i in (%1) do (
  notepad.exe "%%i"
)

This works. Now, I would like the file to be opened in the already opened window of Eclipse. What do I have to replace notepad.exe with in the above batch?

+2  A: 

I've tried similar things in the past, but this isn't as easy as it should be. The end result was always that Firefox would need an extension to execute a local file (I never found one that would do the job), and IE won't do it at all any more (save, maybe, for some complicated proprietary VBScript/WScript).

I see two workarounds to do this:

  1. A function that displays the file path on your page in a big fat dialog window, making it easy to copy and paste into the Windows + R "Execute" Dialog

  2. Alternatively, registering a custom Protocol (e.g. eclipse://) in your operating system, and tying that protocol to Eclipse. This is a pretty great way actually, I haven't tried this yet but definitely will in the next project I need this. Mozillazine: Register protocol (see the .reg file example)

Pekka
Symfony does something like the custom protocol for stacktraces. I don't know exactly what it does (I don't use the IDE they built the feature for) but @Victor check out Symfony.
Coronatus
Interesting. I thought about using a data: url for downloading a file with a custom extension containing the path to the local file, and binding that custom extension to a batch file that would open the file in Eclipse. But I can't seem to get Eclipse to open a PHP file on the disk in the currently opened instance. Windows+R doesn't seem to open the file in Eclipse, either.
Victor Nicollet
@Victor the Windows+R issue you should be able to sort out by associating Eclipse with the .php extension (I think it's Shift+Right click on a PHP file in Explorer -> "Open with...." -> Choose "Select application" -> ... (wording is approximate, I only have a german Windows 7 at hand)).
Pekka
This might help with creating the handler for the custom protocol: http://www.ibm.com/developerworks/library/os-eclipse-rcpurl/
Sam Hasler
+1 for the <kbd>kbd</kbd> tag.
ring0
@ring0 you, Sir, are a true connoisseur!
Pekka
A: 

You get the local path with FILE.

Maybe you try something like this?

<?php
'127.0.0.1' == $_SERVER["REMOTE_ADDR"] and print __FILE__;
?>
toscho
Please read the question.
Victor Nicollet
@Viktor: Toscho is actually providing some good advice, if incomplete. That is, rather than hardcoding the location of each PHP script within its source code, one could instead dynamically extract that location using the \_\_FILE__ magic constant. You could then construct an eclipse://extracted_file_name_here URI (or use some other mechanism to open the file--it's beside the point). This would obviously be less work, as well as more robust, than hardcoding the location.
@user359996: finding the name of the included file is a solved problem. Not only that, but it's already solved in a manner that is far more robust than using __FILE__ : I use the dispatcher code to deduce the action being executed, and the class autoloading code to determine what file it lies in. My problem is that I can't get the file to open in eclipse (though I managed to open it in notepad!). Constructing the mechanism to open the file is the entire point of the question. How can you say it's beside the point??
Victor Nicollet
A: 

Is integrating Eclipse with Xdebug an option? I've done this with TextMate so that generated error messages are clickable to take me to the correct line in the right file. (See this question for details).

Nev Stokes
A: 

Since you seem to be using Windows, then one possible (but not tested) solution might be

for /f "delims=" %%i in (%1) do(                                                                                
  START "" "C:\Program Files\eclipse\eclipse.exe" "%%i"
)

When %%i is replaced with an absolute file path, the target opens inside an existing window or a new one if Eclipse is not running. Alternatively, it's possible to specify a workspace with the "data" command line argument (more details here, see "Selecting a workspace").

And if hardcoding a path inside a batch file doesn't seem robust enough then you can always declare a corresponding environment variable in System Properties:

for /f "delims=" %%i in (%1) do (                                                                                
  START "" "%eclipse%" "%%i"
)

One shortcoming of Eclipse is the lack of support for opening a file at a specific line via CLI. However Netbeans can do it. In other words, with Netbeans you could go straight to the offending line with a single click.

Saul
+1  A: 

[pathtoeclipse]\eclipsec.exe -name Eclipse --launcher.openFile [fullpathtoyourfilehere]

I am not sure if it works with Galileo (i am on Helios)

Further reading: https://bugs.eclipse.org/bugs/show_bug.cgi?id=4922 (it is a long, long story)

ts
A long but __interesting__ story. Thank you for the heads up. Sounds like my version won't work any time soon...
Victor Nicollet