The next rev of TaskClerk was released at the weekend, you can get the details here. Excellent work JP, thank you.
Building a Plug-in
My favourite feature of this new release is a very minor change to the foundation assembly. There has been a change in visibility on the MenuItem property in the PluginNotifyMenuItem class. This will save many of lines of code when writing a simple plug-in to hack-in and get a reference to the containing parent menu item.
For example, I wanted to add a feature that put all my "pinned" tasks, collected via the Instant Access popup (ALT+F12), on to the main notify context menu; here's the code I can now write:
private void PopulateMenuItems()
{
this.MenuItem.MenuItems.Clear();
InstantAccessData data = InstantAccessData.Create();
if (data.IsDataAvailable)
{
foreach (TaskDescription description in
data.PinnedTaskDescriptions)
{
MenuItem item = new MenuItem(description.Name, item_Click);
item.Tag = description;
this.MenuItem.MenuItems.Add(item);
}
}
else { this.MenuItem.MenuItems.Add("(no favorites)"); }
}
private void item_Click(object sender, EventArgs e)
{
AppContext.Current.HandleNewTaskActivity
((TaskDescription)((MenuItem)sender).Tag, DateTime.Now);
}
Inherit a class from PluginNotifyMenuItem, call the PopulateMenuItems method in the constructor, add a FileSystemWatcher - or add a feature request to the news groups for TaskClerk for an alert ;-) - to monitor the data file for Instant Access; call the method on change, delete etc., but only do this if you want dynamic updating for the favourites menu (TIP: the data file will probably be locked when the change notification is raised (as it is writing to it), wait a second for that operation to complete before requesting the data (Thread.Sleep)).
The results look something like:
The C# source code for the plug-in is available upon request. Enjoy.

1 comments:
This is a great article Paul, hopefully it will be the start of lots of addins for TaskClerk built by other developers. Thank you.
Post a Comment