Skip to content

Instantly share code, notes, and snippets.

@JRondeau16
Created July 28, 2017 18:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JRondeau16/e5d8cf16c045570351c1fba8fd1919aa to your computer and use it in GitHub Desktop.
Save JRondeau16/e5d8cf16c045570351c1fba8fd1919aa to your computer and use it in GitHub Desktop.
Tabbed Select Rendering Form
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web.UI;
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Shell.Applications.Dialogs.ItemLister;
using Sitecore.Web.UI.HtmlControls;
using Sitecore.Web.UI.WebControls;
namespace [YOUR_NAMESPACE]
{
public class TabbedSelectRenderingForm : Sitecore.Shell.Applications.Dialogs.SelectRendering.SelectRenderingForm
{
protected Tabstrip Tabs;
protected override void OnLoad(EventArgs e)
{
Assert.ArgumentNotNull((object) e, "e");
IsOpenPropertiesChecked = Registry.GetBool("/Current_User/SelectRendering/IsOpenPropertiesChecked");
SelectRenderingOptions renderingOptions = SelectItemOptions.Parse<SelectRenderingOptions>();
base.OnLoad(e);
if (Context.ClientPage.IsEvent)
return;
var groupedRenderings = renderingOptions.Items?.GroupBy(i => i.Parent.Name).ToArray() ?? new IGrouping<string, Item>[0];
if (renderingOptions.ShowTree || groupedRenderings.Length == 0)
{
var gridPanel = Renderings.Parent as GridPanel;
gridPanel?.SetExtensibleProperty(Tabs, "class", "scDisplayNone");
}
else
{
foreach (var renderingGroup in groupedRenderings)
{
var newTab = new Tab
{
Header = renderingGroup.Key,
CssClass = "scTabPage"
};
newTab.Controls.Add(new LiteralControl(RenderPreviews(renderingGroup)));
Tabs.Controls.Add(newTab);
}
Renderings.Visible = false;
var gridPanel = Renderings.Parent as GridPanel;
gridPanel?.SetExtensibleProperty(Renderings, "class", "scDisplayNone");
}
}
private string RenderPreviews(IEnumerable<Item> renderingGroup)
{
var privateBaseMethod = typeof (Sitecore.Shell.Applications.Dialogs.SelectRendering.SelectRenderingForm)
.GetMethod("RenderPreviews", BindingFlags.NonPublic | BindingFlags.Instance, null, new [] { renderingGroup.GetType() }, null);
return (string) privateBaseMethod.Invoke(this, new object[] {renderingGroup});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment