Example #1
0
 public ToolboxItem(string caption, int iconIndex, ToolboxType type)
 {
     _caption   = caption;
     _iconIndex = iconIndex;
     _type      = type;
 }
Example #2
0
        /// <summary>
        /// Registers widget to the toolbox. http://www.sitefinity.com/developer-network/forums/general-
        /// discussions-/registering-custom-control-in-toolbox.
        /// </summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="title">The title.</param>
        /// <param name="description">(Optional) The description.</param>
        /// <param name="cssClass">(Optional) The CSS class.</param>
        /// <param name="resourceClassId">(Optional) The resource class identifier.</param>
        /// <param name="layoutTemplate">(Optional) The layout template.</param>
        /// <param name="sectionName">(Optional) Name of the section.</param>
        /// <param name="sectionOrdinal">(Optional) The section ordinal.</param>
        /// <param name="toolboxType">(Optional) Type of the toolbox.</param>
        public static void RegisterToolboxWidget <T>(string title, string description = null, string cssClass = null, string resourceClassId = null, string layoutTemplate = "", string sectionName = Constants.VALUE_TOOLBOX_SECTION_NAME, int?sectionOrdinal = null, ToolboxType toolboxType = ToolboxType.PageControls)
        {
            var manager = Config.GetManager();

            using (new ElevatedModeRegion(manager))
            {
                var config = manager.GetSection <ToolboxesConfig>();

                //GET PAGE TOOLBOX
                var controls = config.Toolboxes[toolboxType.ToString()];
                var section  = controls
                               .Sections
                               .FirstOrDefault <ToolboxSection>(x => x.Name == sectionName);

                //CREATE THE SECTION IF APPLICABLE
                if (section == null)
                {
                    section = new ToolboxSection(controls.Sections)
                    {
                        Name        = _webHelper.GenerateSafeName(sectionName, true),
                        Title       = sectionName,
                        Description = sectionName,
                        Ordinal     = sectionOrdinal.GetValueOrDefault(99)
                    };

                    //SET ORDINALS FOR SECTIONS
                    if (sectionOrdinal.HasValue)
                    {
                        //HANDLE ORDINAL CONFLICTS
                        foreach (var item in controls.Sections
                                 .Where <ToolboxSection>(x => x.Ordinal == sectionOrdinal.Value))
                        {
                            item.Ordinal += 0.1F;
                        }
                    }

                    controls.Sections.Add(section);
                }

                //REGISTER IN TOOLBOX IF APPLICABLE
                var control = typeof(T);
                if (!section.Tools.Any <ToolboxItem>(t => t.Name == control.Name))
                {
                    //GENERATE NAME FOR TOOLBOX ITEM
                    var name = _webHelper.GenerateSafeName(title, true);

                    //VALIDATE NAME
                    if (Char.IsNumber(name, 0))
                    {
                        name = section.Name + name;
                    }

                    //CREATE WIDGET OBJECT
                    var widget = new ToolboxItem(section.Tools)
                    {
                        Name            = name,
                        Title           = title,
                        Description     = description ?? title,
                        CssClass        = cssClass,
                        ResourceClassId = resourceClassId
                    };

                    //HANDLE WEB FORM AND MVC WIDGETS DIFFERENTLY
                    if (typeof(Controller).IsAssignableFrom(control))
                    {
                        //DEFINE AS MVC WIDGET
                        widget.ControlType    = string.Format("{0}, {1}", typeof(MvcControllerProxy).FullName, typeof(MvcControllerProxy).Assembly);
                        widget.ControllerType = control.FullName;
                        widget.Parameters.Add("ControllerName", control.FullName);
                    }
                    else
                    {
                        //DEFINE AS WEB FORM WIDGET
                        widget.ControlType = control.FullName;
                    }

                    //ASSIGN TEMPLATE IF APPLICABLE
                    if (!string.IsNullOrWhiteSpace(layoutTemplate))
                    {
                        widget.LayoutTemplate = layoutTemplate;
                    }

                    //REGISTER TO SYSTEM
                    section.Tools.Add(widget);
                    manager.SaveSection(config);
                }
            }
        }
Example #3
0
 public ExportSpaceObjectToolboxAttribute(ToolboxType toolboxType)
     :base(typeof(ISpaceObjectToolbox))
 {
     this.ToolboxType = toolboxType;
 }
Example #4
0
		public ToolboxItem(string caption, int iconIndex, ToolboxType type)
		{
			_caption=caption;
			_iconIndex=iconIndex;
			_type=type;
		}