Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 126079

Summary: [Commands] request: add commands to open/show resource with path parameter
Product: [Eclipse Project] Platform Reporter: Christopher Daly <cjdaly>
Component: UIAssignee: Douglas Pollock <douglas.pollock>
Status: VERIFIED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: larryisaacs, pwebster, Szymon.Brandys
Version: 3.2   
Target Milestone: 3.2 M5   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
patch with openFileByPath / showResourceByPath commands
none
removed definitionId from action org.eclipse.ui.OpenWorkspaceFile none

Description Christopher Daly CLA 2006-02-01 14:35:39 EST
I'm going to attach a patch that adds 2 commands to org.eclipse.ui.ide.  One is to open a file resource and the other shows a resource in the Navigator view.  Both take a single, non-optional, parameter indicating the path of the resource to open/show.  These are different from existing commands/actions in that the existing ones look at selection instead of using parameters.

I was a little unsure of whether these should go in org.eclipse.ui.ide or org.eclipse.ui.workbench and what the best name for the java package.  If you see a better organization of things let me know and I'll revise the patch.
Comment 1 Christopher Daly CLA 2006-02-01 14:38:52 EST
Created attachment 33959 [details]
patch with openFileByPath / showResourceByPath commands
Comment 2 Douglas Pollock CLA 2006-02-03 16:30:58 EST
The patch is good, but I've made a small change.  I merged the open resource command you provided with the open resource command already provided by org.eclipse.ui.ide.  This command's id is "org.eclipse.ui.navigate.openResource".

By implementing enough interfaces, it is possible to put use this handler in the default case, as well as including it in an action set.  So, without parameters, it prompts the user.  With parameters it opens the given resource.
Comment 3 Douglas Pollock CLA 2006-02-14 15:36:46 EST
This is not easy for me to verify.  Chris: is this working for you guys?
Comment 4 Christopher Daly CLA 2006-02-14 16:50:39 EST
I'm actually seeing a problem with org.eclipse.ui.navigate.openResource.  The parameters get lost so you always get the open file dialog instead of opening the file specified with the filePath parameter.

I'm going to look into this more and try to figure out what the proper fix is.  I hope we can get a fix in for M5.
Comment 5 Christopher Daly CLA 2006-02-14 17:17:32 EST
The problem might be that an action still has "org.eclipse.ui.navigate.openResource" set as it's definitionId.  See the action with id org.eclipse.ui.OpenWorkspaceFile in the plugin.xml in org.eclipse.ui.ide.

So the fix might be as simple as clearing that definitionId line.

I don't have a recent I-build at the moment.  I'm going to download one and checkout org.eclipse.ui.ide so I can try this.


What I'm noticing is we get into ActionDelegateHandlerProxy.execute(ExecutionEvent) and that calls one of several delegate.runX() methods.  But this doesn't pass along the ExecutionEvent, so the parameters are effectively thrown away at this point.

I suspect removing the definitionId would get us directly to the handler without going through ActionDelegateHandlerProxy.
Comment 6 Douglas Pollock CLA 2006-02-14 17:21:56 EST
Yes, it would.  Can you try that change and let me know?  If it works for you, I'll commit it for 3.2 M5.
Comment 7 Christopher Daly CLA 2006-02-14 18:43:56 EST
Created attachment 34727 [details]
removed definitionId from action org.eclipse.ui.OpenWorkspaceFile

Ok, the fix discussed above works.  It's a one line change, but here's a patch anyway.
Comment 8 Douglas Pollock CLA 2006-02-16 09:47:25 EST
Fixed in CVS.
Comment 9 Douglas Pollock CLA 2006-02-16 15:11:13 EST
Chris: does this work for you in I20060216-1200 or later?
Comment 10 Christopher Daly CLA 2006-02-16 16:25:08 EST
I just checked I20060216-1200 and it is now working correctly there.
Comment 11 Paul Webster CLA 2006-06-08 07:30:58 EDT
Chris, this might be an odd question, but what do you do to get the parameter into the ExecutionEvent?

PW
Comment 12 Christopher Daly CLA 2006-06-08 12:40:36 EDT
I'm not sure I understand your question, but maybe this helps:  Look at CommandManager.deserialize(...)  and see how it composes a ParameterizedCommand with the command id and the various parameters.  Once you have the ParameterizedCommand you can call executeWithChecks(...).  So you don't need to touch the ExecutionEvent yourself.
Comment 13 Paul Webster CLA 2006-06-09 06:55:39 EDT
Thanx, Chris, but I'm more interested in what causes this parameter to be added in the first place.  What user action, what usecase, would cause a command with this parameter to be generated?

Is it used for testing?

Later,
PW
Comment 14 Christopher Daly CLA 2006-06-12 03:52:28 EDT
Hi Paul, see bug 123921 for more on the rationale for adding the parameter to this command.  An example might be something like this:

-the user has imported a sample into the workspace
-help or a cheatsheet content associated with the sample has some text with a link to content in the sample
-when user clicks the link, some file in the sample is opened.

So for example a cheatsheet might say, "now you need to add a dependency to your plugin.  click _here_ to open the plugin manifest editor and then select the Dependencies tab....".  Where the _here_ link specifies the path of the plugin.xml in the sample project.
Comment 15 Paul Webster CLA 2006-06-12 07:00:53 EDT
Ah, thanx Chris.  So something like this is really useful for UA.

PW
Comment 16 Torkild Resheim CLA 2006-09-01 03:54:57 EDT
I could not get "org.eclipse.ui.navigate.openResource" to work from a cheat sheet. Upon investigation I found that no parameters reached the command handler. Just as described in this bug.

I see the patch removes the definitionID from the "org.eclipse.ui.OpenWorkspaceFile" action, however in my Eclipse 3.2 (M20060629-1905) it is still present.
Comment 17 Larry Isaacs CLA 2009-05-06 21:36:34 EDT
To finish the prior comment, the fix for Bug 134834 added the definitionId back in and it is still present at HEAD.  Though I have been debugging this with Eclipse 3.4.2, I think it likely this is still broken in Eclipse 3.5.  Perhaps this bug should be re-opened.

Fortunately for the Hello World Plug-in cheat sheet provided by PDE, if focus is in the plug-in manifest editor, the "org.eclipse.ui.navigate.openResource" command works since the handler is HandlerProxy instead of ActionDelegateHandlerProxy.  However, it would be useful to get this working reliably for all use cases.  For now, I can work around the problem by dup'ing the "org.eclipse.ui.navigate.openResource" command in my own plug-in and assigning it a new ID, then using that one in my cheat sheet.