using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.ComponentModel.Design;
namespace UCAD_Shell
{
// Create the UserControl as a Design-Time Control Container
[Designer("System.Windows.Forms.Design.ParentControlDesigner, System.Design", typeof(IDesigner))]
///
/// UserControl Assembly Description (UCAD)
/// UCAD uses an xml description to automatically load (Forms.) UserControls from compiled dll libraries
///
/// UCAD automatically configures a TabPane per dll loaded.
/// Each TabPane contains a Button per UserControl that provides access to it's interface.
/// An optional Label syntax enables submenu configurations.
///
/// Configurable Color settings are found in UCAD_Settings.cs
///
/// This file (UCAD.cs) is configured as a UserControl to allow embedding into parent Forms, etc.
/// It also provides an interaction point for modifying the layout of the UCAD control.
///
/// To ship a final application built on UCAD, reconfigure to load UCAD_Xml file from the loaded lib.
/// Alternatively, you may consider embedding the xml file into the final exe.
///
///
public partial class UCAD : UserControl
{
public static Panel UCAD_MainWindow_Panel;
public static TabControl UCAD_SideBar_tabControl;
public UCAD()
{
InitializeComponent();
UCAD_MainWindow_Panel = this.UCAD_panel;
UCAD_SideBar_tabControl = this.UCAD_tabControl;
}
public void load_UCAD_Dialog()
{
List fileNames = new List();
// Launch the FolderBrowserDialog Control
if (this.openFileDialog1.ShowDialog() == DialogResult.OK)
{
// Record FolderBrowserDialog result in Directory TextBox, enabling user to inspect and edit the path.
fileNames.AddRange(this.openFileDialog1.FileNames);
}
// Load all user requested UCAD files
for (int i = 0; i < fileNames.Count; i++)
{
load_UCAD_File(fileNames[i]);
}
}
public void load_UCAD_File(string xmlFileName)
{
// Read the Xml File
try
{
XmlDocument reader = new XmlDocument();
reader.Load(xmlFileName);
// Unpack the UCAD file
foreach (XmlNode UCAD_node in reader.ChildNodes)
{
// Root xml node
if (UCAD_node.Name == "UserControlAssemblyDescription")
{
// Text used in the Forms Title Bar
this.Text = UCAD_node.Attributes["formText"].Value;
// Upack the Tabs
foreach (XmlNode tabNode in UCAD_node.ChildNodes)
{
if (tabNode.Name == "Tab")
{
// Create a custom TabPage and add to the TabControl
UCAD.UCAD_SideBar_tabControl.Controls.Add(new UCAD_Tab(tabNode));
}
}
}
}
}
catch
{
System.Diagnostics.Debug.WriteLine("Error reading xml");
throw new Exception("Error reading XML");
}
}
///
/// Handles UCAD_Button Click events.
/// Gets the UCAD_Button's UserControl and adds it to the main panel
///
/// UCAD_Button that the user clicked.
/// Generic EventArgs
public static void button_Click(object sender, EventArgs e)
{
// Reset all buttons to Defaults
for (int i = 0; i < UCAD.UCAD_SideBar_tabControl.Controls.Count; i++)
{
// Type Checking
if (UCAD.UCAD_SideBar_tabControl.Controls[i] is UCAD_Tab)
{
// Deactivate button
(UCAD.UCAD_SideBar_tabControl.Controls[i] as UCAD_Tab).ResetButtonDefaults();
}
}
// Type Checking
if (sender is UCAD_Button)
{
// Get currently selected button
UCAD_Button button = sender as UCAD_Button;
button.ActivateButton(button);
// Add the buttons UserControl to the main panel
UCAD.UCAD_MainWindow_Panel.Controls.Clear();
UCAD.UCAD_MainWindow_Panel.Controls.Add(button.GetUserControl());
}
}
}
}