
Below, I create a simple Google search action by implementing the IAction interface from the Do.Addins library. I give the action a name, a description, and I use the stock “search” icon. I specify that this action only supports the ITextItem type, which is simply a type representing the text the user entered. In the Perform method, I assemble the URL for performing a Google search using the text from the first item (I know it’s an ITextItem because that’s all this action supports). Finally, I open that URL with a method provided by the Do.Addins.Util.Environment class.*
using System;
using Do.Addins;
using Do.Universe;
namespace GoogleAction
{
class GoogleAction : IAction
{
public string Name { get { return "Google"; } }
public string Description { get { return "Search Google."; } }
public string Icon { get { return "search"; } }
public Type[] SupportedItemTypes {
get { return new Type[] { typeof (ITextItem) }; }
}
public Type[] SupportedModifierItemTypes {
get { return null; }
}
public bool ModifierItemsOptional {
get { return false; }
}
public bool SupportsItem (IItem item) {
return true;
}
public bool SupportsModifierItemForItems (IItem[] items, IItem modItem) {
return false;
}
public IItem[] DynamicModifierItemsForItem (IItem item) {
return null;
}
public IItem[] Perform (IItem[] items, IItem[] modItems) {
string query;
query = "http://www.google.com/search?q=" + (items[0] as ITextItem).Text;
Util.Environment.Open (query);
return null;
}
}
}
Then, compile the plugin, install it, and restart GNOME Do:
$ gmcs -target:library -r:System -r:/usr/lib/do/Do.Addins GoogleAction.cs
$ mv GoogleAction.dll ~/.do/plugins
$ killall gnome-do
$ gnome-do
Get it? Got it? Good.
*Note: Real plugins should be more robust, do some error checking, have comments, etc. This is only a sample.
The Buzz {1 trackbacks/pingbacks}
The Conversation {10 comments}
I like how this works a lot. It seems more logical to type “Google blah”. Let’s say I want to send an IM to someone whose screen name is Gimp or something. Rather than having to type Gimp (in which case I would get either the GIMP or their name, I find it more logical to do “im gimp” for the IM and “gimp” for the program. Just my opinion obviously.
This is very cool to know. I hadn’t realized that commands actually came up in the first pane. I thought only IItems could. This opens up some possibilities.
Thanks for taking a sec for this quick intro.
Awesome. Thanks for spelling this out. I was able to make some simple changes to the template and search Wikipedia and my del.icio.us bookmarks. I tried to set this up for ubuntuforums.org but I’m not sure how to convert my text into their searchid.
I did have a little trouble getting this to work. I had installed Gnome-Do through Synaptic and I got a permission error when I ran gmcs. I removed it and then built from the trunk and it worked fine. Is this normal or is this a lack of understanding on my part?
“I got a permission error when I ran gmcs” - weird. I have no idea what happened!
I suggest you make an abstract “WebSearchCommand” class, and then you could easily create new web search commands by subclassing it, and implementing a SearchURLWithQueryString method. This way you could create your Wikipedia, del.icio.us, etc commands in 5-10 lines each.
Huh, interesting, how come my gnome-do is rectangular boxed? instead of round boxed
Apologies, didn’t know I can’t put HTML in comments
Here’s a snapshot of my gnome-do, weird behavior indeed
http://img337.imageshack.us/my.php?image=gnomedoiu9.png
You need compositing turned on for the pretty window.
The command to download and install at http://do.davebsd.com/?q=content/download has a typo. Either the && or the ; should be there, but not both. The line’s right on the launchpad page, wrong on http://do.davebsd.com/?q=content/download.
Nice little bit of software!
Using Gnome Do in Ubuntu Gutsy, that path for Do.Addins library is wrong. I have tha library just in “/usr/lib/do/”.
And works fine!
Wow, it’s very easy make a addins for some web search with the GoogleCommand, making some little changes on the code I make a Youtube search videos with Gnome Do.
Very nice and easy.
Bye
Leave Your Own Comment
You can follow any responses to this entry via its RSS comments feed. You can also leave a trackback if the inclination is there.