Extending Shuriken
February 8th, 2009
This is the first of a series of articles, I am planning to write explaining how to create your own modules for extending Shuriken. In this article, the hello world is implemented for Shuriken.
Shuriken is an application launcher that is trying to bring you the power and flexibility of the famous Quicksilver on OSX. It is developed in .NET and C#, but you can use any .NET language to develop your own module. All you will need is Visual Studio 2008 any Express Edition or better.
Setting up your project
The first thing is download the latest release of Shuriken from Shuriken project site on Codeplex.com and unzip it. Run it and notice that a plugin folder is created in your installation directory.
Next is to fire up Visual Studio.NET 2008 and create Class Library project.
The next is to add the Shuriken.Base.dll as a reference to your project. This dll can be found next to your Shuriken.exe and contains all the interfaces and classes that you will need to use to write your own modules.
After adding the reference your project structure should look like this.
Subjects and Actions
There are two main concepts in Shuriken, the Subject and the Action. A Subject is normally on the first pane and this is the Notepad on the picture. The Action is the second pane on the UI and in this case the Reveal action. After pressing enter the Reveal action will show the location of the Notepad subject.
When you write modules then you most of the time creating subjects and actions. Let’s start with the action. All we need to create a new class and implement the ISubject interface from the Shuriken.Base namespace.
1: using System;
2: using Shuriken.Base;
3:
4: namespace HelloWorldSubject
5: {
6: public class HelloWorldSubject : Shuriken.Base.ISubject
7: {
8: #region ISubject Members
9:
10: public System.Collections.Generic.List<IAction> GetListOfActions()
11: {
12: return new System.Collections.Generic.List<IAction>();
13: }
14:
15: #endregion
16:
17: #region IObject Members
18:
19: public string Description
20: {
21: get { return "First Shuriken plugin ever"; }
22: }
23:
24: public string Icon
25: {
26: get
27: {
28: return string.Empty;
29: }
30: set
31: {
32:
33: }
34: }
35:
36: public string Name
37: {
38: get { return "Hello World!"; }
39: }
40:
41: #endregion
42: }
43: }
There are couple of methods you will need to implement in your class. The first is called GetListOfActions which needs to be only returning an empty list for now.
The Description property is returning a string that is going to be the description for our subject. The Name property is going to be the name of this subject and the Icon will be the icon displayed. In the code I gave Hello World as the name and left the Icon property to be and empty.
To have something meaningful happening to our subject an action is needed as well.
1: [DefaultAction]
2: [ActionName("Say It")]
3: public class HelloWorldAction : Shuriken.Base.BaseAction
4: {
5: public override bool CanExecuteOn(ISubject subject)
6: {
7: if (subject.Name.Equals("Hello World!"))
8: {
9: return true;
10: }
11:
12: return false;
13: }
14:
15: public override void Execute(ISubject subject)
16: {
17: System.Windows.Forms.MessageBox.Show("Hello World!");
18: }
19: }
The HelloWorldAction is created by either implementing the IAction interface or extending the BaseAction class. I did the later for simplicity sake. Extending the BaseAction class is simpler and can be done with attributes as well. There are two attributes used DefaultAction and ActionName.
DefaultAction will tell Shuriken that this is the default action for the a subject, meaning that this will be the first action always. ActionName will be the name of the action.
There are also two methods that we need to implement. The first method is called CanExecuteOn and it tells us, if the subject is supported by this action. The second method is called Execute and it is called when the user hits enter and the action is called.
After finishing the two class, you will need to compile the project and drop the HelloWorldSubject.dll to the plugin folder and restart Shuriken. Then invoke the UI and start typing Hello World…. after hitting enter you should end up with the Hello World! dialog box displaying.
Shuriken is an application launcher utility, that is developed by me in my free time. It is open source and free. If you would like to download Shuriken or help to develop it, please visit Shuriken on codeplex.
http://www.codeplex.com/shuriken
Popularity: 23% [?]
Leave a Reply