Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365982 - [commands] default parameter values based on item
Summary: [commands] default parameter values based on item
Status: RESOLVED FIXED
Alias: None
Product: Orion
Classification: ECD
Component: Client (show other bugs)
Version: 0.3   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 0.4 RC1   Edit
Assignee: Susan McCourt CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 370255 370978
  Show dependency tree
 
Reported: 2011-12-07 23:36 EST by Susan McCourt CLA
Modified: 2012-02-09 00:46 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Susan McCourt CLA 2011-12-07 23:36:55 EST
I wanted to convert the "rename" command to use parameters.  The trouble is that the default name shown in the box should be the current name of the item.  We need a way to express the default based on the item in the command invocation.  

Probably just supply a default value function for the parameter which takes the command invocation (so that it could look at anything needed)...
Comment 1 Susan McCourt CLA 2011-12-09 13:21:54 EST
tooltip has the same issue.
If we wanted to distinguish, say, single vs. plural.
Or provide more contextual tooltips for git, it would be nice to know the commandInvocation/items.
Comment 2 Susan McCourt CLA 2012-02-08 12:51:59 EST
bug 370978 is more general case of this:

not only do we want to supply the parameter value, but we may choose to remove a parameter completely because we don't need it.  (ie, a non-private repo doesn't need credentials, but secure one does.)
Comment 3 Susan McCourt CLA 2012-02-08 13:03:13 EST
there may be something simple we could try. 

We could put a function in the parameters description that computes the command parameters when the item is known (before doing the slideout).  This would be a callback *in* the parameter description not in the command.  That way we aren't penalizing commands who don't use parameters.

I will investigate.
Comment 4 Susan McCourt CLA 2012-02-08 13:03:44 EST
I'm not sure this bug truly blocks 370255 but would probably simplify it
Comment 5 Szymon Brandys CLA 2012-02-08 13:08:20 EST
We need to remember that Git commands know that credentials are needed once #callback is already called. For instance GitFetch command #callback does the following: tries to fetch, it gets a request for credentials from the server, shows the dialog and still being in #callback the command retries the fetch call.
Comment 6 Susan McCourt CLA 2012-02-09 00:45:45 EST
fixed.
what I've done is define a function that can be attached to the parameters.  This function is called before the command service decides whether a slideout should be invoked before a callback.  So the parameters can be defined on the fly.

So where you before had:
var gitAuthParameters = new mCommands.ParametersDescription([new mCommands.CommandParameter("sshuser", "text", "SSH User Name:"), new mCommands.CommandParameter("sshpassword", "password", "SSH Password:")], true);

you can now say
var gitAuthParameters = new mCommands.ParametersDescription([new mCommands.CommandParameter("sshuser", "text", "SSH User Name:"), new mCommands.CommandParameter("sshpassword", "password", "SSH Password:")], true, function(data) {
   if (data.items.... means no need to authenticate) {
     return null;
   } else if (data.items.....means we know the user but not password) {
     return [new mCommands.CommandParameter("sshpassword", password", "SSH Password:"];
   } else { // we really need both
     return [new mCommands.CommandParameter("sshuser", "text", "SSH User Name:"), new mCommands.CommandParameter("sshpassword", "password", "SSH Password:")]
   }
});

I tested this for some simple cases and verified that it was called before the slideout opens and changes the content/values of slideout.  There might be things I didn't think about, please open bugs if this doesn't work for you.

(In reply to comment #5)
> We need to remember that Git commands know that credentials are needed once
> #callback is already called. For instance GitFetch command #callback does the
> following: tries to fetch, it gets a request for credentials from the server,
> shows the dialog and still being in #callback the command retries the fetch
> call.

It can't work the way you describe.  By definition, parameters are used to determine what should be collected by the command *before* a callback is called.  However you should still be fine, move the credential logic to the parameter callback.  I will annotate more in the dependent bugs.
Comment 7 Susan McCourt CLA 2012-02-09 00:46:11 EST
fixed.