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;
using DarkWynter.Engine.Utilities;
namespace DarkWynter.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
{
///
/// Allows user to load xml FormName attribute into form header, etc.
///
public static string UCAD_FormName;
///
/// The upper-right panel of the display area.
///
public static Panel UCAD_Main_Panel;
///
/// The left panel of the display area.
///
public static Panel UCAD_Left_Panel;
///
/// The bottom panel of the display area.
///
public static Panel UCAD_Bottom_Panel;
///
/// The bottom panel of the display area.
///
public static Panel UCAD_Top_Panel;
public static SplitContainer UCAD_Bottom_SplitContainer;
public static SplitContainer UCAD_Left_SplitContainer;
public static SplitContainer UCAD_Right_SplitContainer;
public UCAD()
{
InitializeComponent();
UCAD_Main_Panel = this.panelMain;
UCAD_Left_Panel = this.panelLeft;
UCAD_Bottom_Panel = this.panelBottom;
UCAD_Bottom_SplitContainer = this.UCAD_BottomSplitContainer;
UCAD_Left_SplitContainer = this.UCAD_LeftSplitContainer;
UCAD_Right_SplitContainer = this.UCAD_RightSplitContainer;
// Auto load default menu
load_UCAD_File("UCAD_CompilerLibrary.xml");
ToggleFullscreen_Click(new Object(), new EventArgs());
}
#region UCAD ToolStrip
private void loadUCADToolStripMenuItem_Click(object sender, EventArgs e)
{
load_UCAD_Dialog();
}
private void loadG2LToolStripMenuItem_Click(object sender, EventArgs e)
{
load_UCAD_File("UCAD_CompilerLibrary.xml");
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
//string name = Logging.CreateFileName();
//Logging.writeG2LLog(name);
//Logging.writeG2LSurvey(name);
Application.Exit();
}
#endregion
///
/// Choose which UCAD xml file to open using a File Dialog.
///
///
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)
{
this.SuspendLayout();
// 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
UCAD_FormName = UCAD_node.Attributes["formText"].Value;
// Add a custom MenuStrip to the Tool Container
this.toolStripContainer2.BottomToolStripPanel.Controls.Add(
new UCAD_MenuStrip(UCAD_node)
);
}
}
}
catch
{
System.Diagnostics.Debug.WriteLine("Error reading xml");
throw new Exception("Error reading XML");
}
this.ResumeLayout(false);
this.PerformLayout();
}
///
/// 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)
{
// Type Checking
if (sender is UCAD_Control)
{
// Get currently selected button
UCAD_Control UCAD_Item = sender as UCAD_Control;
if (UCAD_Item.GetControlLocation() == "Main")
{
// Add the buttons UserControl to the main panel
UCAD.UCAD_Main_Panel.Controls.Clear();
UCAD.UCAD_Main_Panel.Controls.Add(UCAD_Item.GetUserControl());
}
if (UCAD_Item.GetControlLocation() == "Side")
{
// Add the buttons UserControl to the main panel
UCAD.UCAD_Left_Panel.Controls.Clear();
UCAD.UCAD_Left_Panel.Controls.Add(UCAD_Item.GetUserControl());
}
if (UCAD_Item.GetControlLocation() == "Bottom")
{
// Add the buttons UserControl to the main panel
UCAD.UCAD_Bottom_Panel.Controls.Clear();
UCAD.UCAD_Bottom_Panel.Controls.Add(UCAD_Item.GetUserControl());
}
}
}
public static void LeftPanelCollapse()
{
UCAD.UCAD_Left_SplitContainer.Panel1Collapsed = true;
}
public static void RightPanelCollapse()
{
UCAD.UCAD_Right_SplitContainer.Panel2Collapsed = true;
}
public static void BottomPanelCollapse()
{
UCAD.UCAD_Bottom_SplitContainer.Panel2Collapsed = true;
}
public static void LeftPanelExpand()
{
UCAD.UCAD_Left_SplitContainer.Panel1Collapsed = false;
}
public static void RightPanelExpand()
{
UCAD.UCAD_Right_SplitContainer.Panel2Collapsed = false;
}
public static void BottomPanelExpand()
{
UCAD.UCAD_Bottom_SplitContainer.Panel2Collapsed = false;
}
private void ToggleFullscreen_Click(object sender, EventArgs e)
{
if (UCAD.UCAD_Left_SplitContainer.Panel1Collapsed == true)
{
UCAD.LeftPanelExpand();
UCAD.RightPanelExpand();
UCAD.BottomPanelExpand();
toggleFullscreenToolStripMenuItem.Text = "Full-Screen";
}
else
{
UCAD.LeftPanelCollapse();
UCAD.RightPanelCollapse();
UCAD.BottomPanelCollapse();
toggleFullscreenToolStripMenuItem.Text = "Editor-Mode";
}
}
//private void bottomBarCollapseToolStripMenuItem_Click(object sender, EventArgs e)
//{
// if (UCAD.UCAD_TopBottom_SplitContainer.Panel1Collapsed == true)
// {
// UCAD.BottomPanelExpand();
// bottomBarCollapseToolStripMenuItem.Text = "Bottombar-Collapse";
// }
// else
// {
// UCAD.BottomPanelCollapse();
// bottomBarCollapseToolStripMenuItem.Text = "Bottombar-Expand";
// }
//}
}
}