Command Panel: Automatically generating commands

Command Panel: Automatically generating commands

Posted on March 09, 2009 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.] 

The automatic command generation, is actually a feature of the Control Panel class and it is not to be confused with Command Panel. The process of generating commands automatically has been explained from a practical angle in this article. In this article, however, we are going to examine the mechanics behind this feature - or in other words - how Control Panel class generates commands on a Control Panel.

 


Command Panel and its Commands collection


Command Panel base class contains a following property in its declaration:

public IList<CommandItem> Commands 
The Commands collection can contain any number of CommandItem objects, which become the source for the databinding of the built-in repeater. So the way that Control Panel is able to automatically generate commands based on its Views is very simple: for each View Control Panel creates a new CommandItem and then adds this CommandItem to its built in CommandPanel’s collection of Commands. The actual code that does this looks like following: 
if (this.AutoGenerateViewCommands && this.Views.Count > 0) 
                CommandPanel pnl = new CommandPanel(); 
                pnl.Name = "Views"
                foreach (IViewInfo info in this.Views.Values) 
                { 
                    pnl.AddCommand(info.ViewName 
                    , ControlUtils.SliceRoute(this.Route, this.Name) 
                    , null 
                    , null 
                    , null 
                    , info.Title 
                    , info.Description 
                    , info.ViewCommandCssClass); 
                } 
                list.Add(pnl); 
 

As you can see, if auto generation of View commands is turned on and there are some Views, we create a new instance of CommandPanel class, then for each View we call AddCommand method of the control panel (which is going to add a command to the collection - we could do this manually also) and finally we add the newly created Command Panel to the list of Command Panels (remember that we can have more than one Command Panel).

 


Why is this important?


The reason for this article to be published is to demonstrate that there is no magic behind the automatically generated commands. In the next articles we will be demonstrating various ways of creating Command Panels and managing commands. Knowing that we are, really, only working with a collection to which a repeater gets bound should flatten the learning curve.
progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation