Hello everybody,
As I told you last week, I am working on extending the CmdUtils API to
make it easier to create aliases for existing Ubiquity command both
programmaticaly and _from the command line_.
I would like to show you what I have achieved so far, hoping that you
will be interested enough to help me a little bit, as I am quite an
Ubiquity beginner (but proud to make my first steps in the Mozilla
universe : )
Currently in Ubiquity it is already possible to define synonyms for a
command, but it is impossible for any one else than the creator of the
command to do so, because it requires to modify directly the source
code of the command, and changes will be overwritten as soon as the
feed will be updated.
I am trying to make it possible for a developer to create an alias for
a command, and possibly to define pre-filled argument for the original
command. The user would then be able to define for example an alias
named "en-fr" for the command "translate", that will "behave" just
like the original command but translating directly the input text from
English to French.
(The code of the following functions is availaible on gist:
http://gist.github.com/61752 )
I have already created two low level functions to achieve that:
CmdUtils.executeCommand and CmdUtils.previewCommand that do exactly
what you expect them to do, and that can be used in any ubiquity
command, for any purpose (command chaining for example).
I am trying to create a high level function to make it dead easy to
create an alias: CmdUtils.CreateAlias. Just a quick example of how we
could use this function when it will be ready:
CmdUtils.CreateAlias({
name: 'test2',
for: 'translate',
modifiers: {
from: {data: 'fr', text: 'french'},
to: {data: 'en', text: 'english'}
}
});
I have some problem with this function:
- It is not possible to create an alias for a command created in the
Ubiquity Command Editor, because it is not part of the list of
available command when the alias is being created : (
- Usually when a command is created, its arguments are parsed: a
collection like
{"from": noun_type_language, "to": noun_type_language }
becomes
{
from: {_name: "language", getLangName: function(), suggest: function
()},
to: {_name: "language", getLangName: function(), suggest: function
()},
}
For some reason this "transformation" doesn't occur when using
CreateAlias, although I am using the standard CreateCommand function
with the same arguments : (
Once those problems will be solved, I will create a new Ubiquity
command named "create-alias", to give the power of alias creation to
end-users : ). Something like "create-alias fr-en for translate with
from french to english",
but I am not sure about the syntax yet. I already foresee a
difficulty: I will have to parse the string provided to the "with"
modifiers as arguments for the original command.
Again, your feedback and help will be greatly appreciated !
Thank you in advance,
Louis-Rémi Babé