ContextMenu - interface definition + features

OK, so I've spent a bit more time thinking about how I want the interface for my Context menu to feel and, after quite a bit of poking around to learn about how others have designed controls with a fimiliar structure I have settled on this:

// Contains a collection of clickable menu items
class ContextMenu : Control
{
    // The command name to associate with members of this menu
    public virtual string CommandName
    // Gets the collection of items in the list control.
    public virtual ContextMenuItems Items
}

// Represents a clickable item within a context menu
// Items can be handled either within the client or on
// the server via a postback based on whether or not the
// ClientNotificationFunction property is declared
public sealed class ContextMenuItem
{
    // Gets or sets the text of the menu item
    public virtual string Text
    // Gets or sets the name of the custom client-side 
    // script to use for client-side event notifications.
    public virtual string ClientNotificationFunction
    // The command argument to associate with this menu item
    public virtual string CommandArgument
}

// represents a collection of ContextMenuItem items
public sealed class ContextMenuItems : BaseCollection
{
}

// Opens the specified context menu
class ContextMenuLink : Control
{
    // Gets or sets the id of the menu to associate with this link
    public virtual string ContextMenu
    // Gets or sets the url of an image to display for the link. 
    public virtual string ImageUrl
    // Gets or sets the Text of the link
    public virtual string Text
}

 

In designing the public interface for the ContextMenu types I've borrowed heavily from Framework designs and, probably more so from some of Andy Smith's great controls. Some of the ideas that I've "borrowed" from Andy on this project have come from his DialogWindow assemblies. To be concise, I've used his "best practices" methods of emitting and referencing client scripts and also used his example of using a custom TypeConverter on a property (refer his DialogOpenLink type) so that I can display a custom list of available ContextMenu's control id' s in the designer for the ContextMenu property of the ContextMenuLink type.

What all this allows me to do is to create any number of ContextMenuLink items and associate each one with a ContextMenu. The part that I haven't reached as yet is how get each ContextMenuLink to "seed" a ContextMenu with some "contextual" information about who called it. This would be useful in the case where you had a column of ContextMenuLink items in a DataGrid and you needed the resulting ContextMenu to have some stateful information about a data item in the row that was clicked on.

At my current rate of progress I should have something coded and ready to work in a page by the weekend, so, hopefully by mid-next week I should have the project and associate .chm documentation uploaded as a GotDotNet User Sample. I've got a couple of other server controls up on GotDotNet but this will be the first time that I've written one in VB.NET. I'll have to download the VBCodeCommenter so that I can generate the Xml files to generate my .chm file.

No Comments