using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;
using System.Windows.Forms;
using System.Drawing;
using CommonService;
namespace DiagramUI
{
/// <summary>
/// Performer of container UI
/// </summary>
static public class ContainerPerformerUI
{
/// <summary>
/// Initialization of containers tools
/// </summary>
/// <param name="baseDirectory">Base directory</param>
/// <param name="tools">Tools</param>
/// <param name="tabControl">Tab control</param>
/// <param name="resources">Resources</param>
static public void InitContainers(string baseDirectory, ToolsDiagram tools, TabControl tabControl,
Dictionary<string, object>[] resources)
{
string cont = baseDirectory;
if (cont[cont.Length - 1] != Path.DirectorySeparatorChar)
{
cont = cont + Path.DirectorySeparatorChar;
}
cont = cont + "Containers" +
Path.DirectorySeparatorChar + "Containers.xml";
if (!File.Exists(cont))
{
return;
}
XmlDocument doc = new XmlDocument();
doc.Load(cont);
XmlNodeList contPages = doc.GetElementsByTagName("Page");
// int k = 0;
LightDictionary<string, ButtonWrapper[]> dict = new LightDictionary<string, ButtonWrapper[]>();
foreach (XmlElement page in contPages)
{
//int np = 0;
XmlNodeList list = page.GetElementsByTagName("Aggregate");
List<ButtonWrapper> buttons = new List<ButtonWrapper>();
foreach (XmlElement el in list)
{
string ico = AppDomain.CurrentDomain.BaseDirectory + el.Attributes["icon"].Value;
Image image = Image.FromFile(ico);
//ObjectContainers.ImageList.Images.Add(Image.FromFile(ico));
string name = el.Attributes["name"].Value;
string hint = el.Attributes["hint"].Value;
bool isArrow = el.Attributes["arrow"].Value.Equals("true");
ButtonWrapper button = null;
if (isArrow)
{
button = new ButtonWrapper(typeof(LibraryArrowWrapper), name, hint, image, null, true, true);
}
else
{
bool b = true;
if (el.Attributes["wrapper"] != null)
{
if (el.GetAttribute("wrapper").Equals("true"))
{
button = new ButtonWrapper(typeof(LibraryObjectWrapper), name, hint, image, null, true, false);
b = false;
}
}
if (b)
{
button = new ButtonWrapper(typeof(ObjectContainer), name, hint, image, null, true, false);
}
}
buttons.Add(button);
}
XmlAttribute an = page.Attributes["pageName"];
dict.Add(new string[] { an.Value }, new ButtonWrapper[][] { buttons.ToArray() });
// TabPage tp = new TabPage(an.Value);
// tp.ToolTipText = page.Attributes["pageHint"].Value;
// tabControl.Controls.Add(tp);
// tp.Controls.Add(ObjectContainers);
}
ButtonWrapper.Add(dict, tabControl, tools, new Size(25, 25), resources, false);
}
}
}