Quantcast
Channel: Horizontal Integration » C#
Viewing all articles
Browse latest Browse all 30

Icons!

$
0
0

As a Sitecore developer you’re faced with many challenges, however there are none more difficult than choosing the right icon.  Hours can be spend trying to figure out if your data is best represented by one green cube or three; a house with a purple roof or blue.  What if I told you there was a better way?  We’ll there is, and that’s to create your own icons!

In this post I’ll be covering how to create icons for use in Sitecore, getting into Sitecore and available for use as well as updating the set icon dialog.  I’ll also provide a few icons that you can use in your solution.

The first thing you should know about icons is where they live.  All of the icons shipped with Sitecore can be found at [Website]\sitecore\shell\Themes\Standard.  If you notice there’s a number of folders and a bunch of zip files.  These are two different ways to manage icons, controlled by the Icons.UseZippedIcons Sitecore setting.  This post will focus on using the zipped icons, if your solution has zipped icons disabled the following may not apply (I’d also be curious why, if you don’t mind commenting).

Probably the easiest way to get started is to copy an existing icon zip file and rename it (Or you can use the one I’ve provided below).  The folder structure within the zip file is important to preserve.  You’ll notice a folder with the same name of the zip and a number of sub-folders for different sized icons within that.

Zip file.

Icons1

Within each of these folders are the icon images.  In my case I have two icons.

Icons2

Once you’ve zipped up these images and copied the file to Sitecore you should be able to use the icons, however they won’t show up yet in the set icon dialog so you’ll have to manually set the path.  You could also update one of the icon sets Sitecore provides, but that’s the easy way out and there’s no fun in that.

 

To get our set icon dialog updated we’ll need to make a few more changes (as of Sitecore 7.1).

 

First lets create a new class.  I’m calling it SetIconDialog and it should extend: “Sitecore.Shell.Applications.ContentManager.Dialogs. SetIcon.SetIconForm”

Next let’s open up Website\sitecore\shell\Applications\Content Manager\Dialogs\Set Icon\Set Icon.xml and update the CodeBeside node to use our new class.  Since we’ve got this file open lets also add a list item to the Combobox “Selector” and a ScrollBox to the Border element “List”

Icons3

We now have a spot for our custom icons, from here we’ll just need to update our code beside class.  To begin we’ll need to add a reference to the Scrollbox we added like so:

protected Scrollbox CustomIconsList { get ; set ; }

 

From here things get a little weird.  Unfortunately, many of SetIconForm’s methods we would use to load our icons are private, so we’ll have to re-write them.  Or just use reflector.  Once we’ve copied these methods we’ll override the OnLoad method to look like this:

protected override void OnLoad (EventArgs e)
{
base .OnLoad ( e);

if (! Context .ClientPage . IsEvent)
{
RenderIcons (CustomIconsList , "CustomIcons" );
}
}

At this point everything should be working and we should be able to view and select our custom icons but lets take a little deeper look into how Sitecore manages these.

Icons4

If you start digging into what happens when you call RenderIcons you’ll notice that Sitecore will write out an html file and supporting image files to the temp directory (in our case Website/temp).  There is also an IconCache folder contained within.

Icons5

The html file is fairly simple and will list out a map to each of the icons in our Zip.


<map name="CustomIcons">
<area shape="rect" coords="4,4,36,36" href="#" alt="Cube red" sc_path="CustomIcons/32x32/cube_red.png"/>
<area shape="rect" coords="44,4,76,36" href="#" alt="Cubes red" sc_path="CustomIcons/32x32/cubes_red.png"/>
</map>

This uses an icon preview file also created in this folder.

Icons6
Thanks for bearing with me on this, this may not be the most practical thing in the world but it will give you a little look behind the scenes into how Sitecore works.  Plus it’s kind of fun to have custom icons.  Who doesn’t love a good icon?
Further reading:


Viewing all articles
Browse latest Browse all 30

Trending Articles