A little update on what I've been playing with in the .NET world recently.

Back in Delphi 3 (released around 1997 if memory serves), Borland introduced a great little component called TActionList. This component revolutionized the way we designed our applications, because it centralized all the UI logic in one place.

The concept, for those who never used Delphi, is that a TActionList is a collection of TAction components. Each TAction has properties you'd expect to see on a button or menu item - text, tooltip, enabled, visible etc etc. Every UI control in Delphi had an "Action" property, so that you could "hook them up" to the TAction they pointed to.

What made this revolutionary is that all your UI logic could be kept in one place. If you needed to lock the user out of a specific action, you'd simply disable that TAction component, and every menu item, toolbar button, link label etc would disable along with it. Likewise for other properties like Visible. TActionList even gave you a convenient "OnUpdate" event in which you could do all this UI updating.

The .NET framework, unfortunately, has no such component. If you have a MenuItem and ToolStripButton that both do the same thing, you have to remember to enable/disable both of them. WPF (formerly "Avalon") apparently introduces a new "command framework" that does this sort of stuff ... but that's no help to all us WinForms coders out there.

So I decided to write my own.

Basically I'm using the ExtenderProvider framework to add an "Action" property to all the UI controls that implement IButtonControl, and all the ToolStrip items. You can drop an ActionList component onto your form, define the Actions within it, and catch its Update event to tell the UI when to enable or disable each action. Each Action component has an Execute event in which you define what happens when that action gets executed.

The great part about this is that you can use the action itself to go back and update the UI. Check out this example of a "View|Toolbar" menu item. I'll do it all in code so you can see what goes on.

 private MadProps.Windows.Action viewToolbar; private void Form1_Load(object sender, EventArgs e) { // create a viewToolbar action viewToolbar = new MadProps.Windows.Action(); viewToolbar.Text = "Toolbar"; viewToolbar.ToolTipText = "Shows or hides the toolbar"; viewToolbar.Execute += viewToolbar_Execute; // create our actionlist and add viewToolbar to it MadProps.Windows.ActionList al = new MadProps.Windows.ActionList(); al.Actions.Add(viewToolbar); al.Update += al_Update; // assign the viewToolbar action to the "View|Toolbar" menu item al.SetAction(viewToolbarMenuItem, viewToolbar); } void al_Update(object sender, EventArgs e) { viewToolbar.Checked = toolStrip1.Visible; } void viewToolbar_Execute(object sender, EventArgs e) { toolStrip1.Visible = !viewToolbar.Checked; } 

So now we have a fully-functioning "View|Toolbar" menu item, whose "Checked" property is kept up-to-date by the action itself.

I'll continue to refine this component - I want to use it in Comicster. If you would like a copy, let me know.