[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
As a developer, you will be mostly concerned about CommandPanel class when you are adding commands manually. In our built-in blogs module we are using this approach to create various command panels depending on the current view. Take a look at the following example to see how is this achieved.
As you can see if we are in BlogsView or BlogsPermissionsView we create and display one command panel. If any other View is the current View, we create three different command panels and display them instead.
CommandPanel is the class used by Sitefinity which represents the one single command panel. If you are creating a custom command panel (based on Composite Control or User Control) you do not need to inherit from this class, but rather implement the ICommandPanelEx interface on your class.
When, on the other hand, you are automatically generating commands or adding commands manually you will be using CommandPanel class. In this article, we are going to give an overview of the usage and members of the CommandPanel class.
Usage
As a developer, you will be mostly concerned about CommandPanel class when you are adding commands manually. In our built-in blogs module we are using this approach to create various command panels depending on the current view. Take a look at the following example to see how is this achieved.
switch (viewMode) |
{ |
case "BlogsView": |
case "BlogsPermissionsView": |
Cms.Web.UI.Backend.CommandPanel blogsCommandPanel = new Cms.Web.UI.Backend.CommandPanel(); |
blogsCommandPanel.Title = Messages.ExploreBlogsMogule; |
blogsCommandPanel.AddCommand("BlogsView", ControlUtils.SliceRoute(GetControlPanelRoute(), this.Name), null, Messages.AllBlogs, Messages.AllBlogsDescription, "all"); |
blogsCommandPanel.AddCommand("BlogsPermissionsView", ControlUtils.SliceRoute(GetControlPanelRoute(), this.Name), null, Messages.Permissions, Messages.PermissionsDescription, "globalPerm"); |
list.Add(blogsCommandPanel); |
break; |
default: |
// helper command panel |
Cms.Web.UI.Backend.CommandPanel helperCommandPanel = new Cms.Web.UI.Backend.CommandPanel(); |
helperCommandPanel.AddCommand("BlogsView", "BlogsControlPanel", null, null, Messages.AllBlogs, null, "backWrapp"); |
list.Add(helperCommandPanel); |
// posts command panel |
Cms.Web.UI.Backend.CommandPanel postsCommandPanel = new Cms.Web.UI.Backend.CommandPanel(); |
postsCommandPanel.Title = Messages.ExploreThisBlog; |
postsCommandPanel.AddCommand("PostsView", ControlUtils.SliceRoute(GetControlPanelRoute(), this.Name), null, this.ParentId.ToString(), null, Messages.Posts, null, "all"); |
if(this.Manager.Provider.AllowComments) |
postsCommandPanel.AddCommand("BlogCommentsView", ControlUtils.SliceRoute(GetControlPanelRoute(), this.Name), null, this.ParentId.ToString(), null, Messages.Comments, null, "all"); |
postsCommandPanel.AddCommand("BlogCategoriesView", ControlUtils.SliceRoute(GetControlPanelRoute(), this.Name), null, this.ParentId.ToString(), null, Messages.Categories, null, "all"); |
postsCommandPanel.AddCommand("BlogTagsView", ControlUtils.SliceRoute(GetControlPanelRoute(), this.Name), null, this.ParentId.ToString(), null, Messages.Tags, null, "all"); |
list.Add(postsCommandPanel); |
// blog settings command panel |
Cms.Web.UI.Backend.CommandPanel blogSettingsPanel = new Cms.Web.UI.Backend.CommandPanel(); |
blogSettingsPanel.Title = Messages.BlogSettingsTitle; |
blogSettingsPanel.AddCommand("BlogsSettingsView", "BlogsControlPanel.BlogSettingsView", null, this.ParentId.ToString(), Messages.BlogSettingsTitle, null, "settings"); |
list.Add(blogSettingsPanel); |
break; |
} |
The process of creating a new CommandPanel is very simple. We create a new instance of the CommandPanel class, set its title, add any number of commands we need and finally, we add the instance of the CommandPanel to the collection of command panels stored by the control panel.
Properties
- int SelectedItemIndex
Gets or sets the index of currently selected command. - IList<CommandItem> Commands
Gets the list of all commands defined for this particular CommandPanel. - string LayoutTemplatePath
Gets the path of the external layout template for this control. For more information on the way templates work in Sitefinity 3.6 please take a look at this article. - ITemplate LayoutTemplate
Gets the layout template to be used by CommandPanel. For more information on the way templates work in Sitefinity 3.6 please take a look at this article. - LayoutContainer Container
Gets the instance of the container in which CommandPanel template has been instantiated. LayoutContainer class inherits from GenericContainer class. - bool HasDescription
Determines whether commands in the CommandPanel contain description. If so, command panel will be rendered as a definition list, otherwise as an unordered list. - string ParameterKey
Gets the parameter key of the command panel in order to allow other Views to communicate with command panel. For more information and example usage, please take a look at the ParameterKey property of the ViewModeControl. - string ParentIdKey
Gets the key of the parent id parameter of the command panel in order to allow other Views to communicate with command panel. For more information and example usage, please take a look at the ParentIdKey property of the ViewModeControl.
Methods
- void AddCommand(string commandName, List<string> commandRoute, string commandArgs, string title, string description, string cssClass)
Adds command to the ControlPanel. The example usage of this method looks like this:
blogsCommandPanel.AddCommand("BlogsView", ControlUtils.SliceRoute(GetControlPanelRoute(), this.Name), null, Messages.AllBlogs, Messages.AllBlogsDescription, "all"); - void AddCommand(string commandName, List<string> commandRoute, string parameter, string parentId, string commandArgs, string title, string description, string cssClass)
Adds the command to the CommandPanel (overload). The method is very similar to the previous one, with two additional arguments which allow us to pass the parameter and parentId with the command. The example usage of this method can be found in blogs, where it is important that we pass the parent id (blog id) with the post commands, so that we only work with the posts associated with the currently opened blog:
postsCommandPanel.AddCommand("PostsView", ControlUtils.SliceRoute(GetControlPanelRoute(), this.Name), null, this.ParentId.ToString(), null, Messages.Posts, null, "all");
ICommandPanelEx members
- Telerik.Web.IControlPanel ControlPanel
Gets or sets the reference to the control panel to which this command panel belongs to. - string Name
Gets or sets the name of the command panel which distinguishes it from other command panels. - string Title
Gets or sets the title of the command panel to be rendered on the page as the title of that group of commands.