You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
4.4 KiB
C#
134 lines
4.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
using Mesnac.PlugIn.Pad;
|
|
using Mesnac.Core.Util;
|
|
using Mesnac.Gui.Edit.Global;
|
|
using Mesnac.Gui.Edit.Common;
|
|
|
|
namespace Mesnac.Gui.Edit.Pad
|
|
{
|
|
public partial class ToolBoxWindow : DefaultPadContent
|
|
{
|
|
/// <summary>
|
|
/// 控件库配置文件
|
|
/// </summary>
|
|
private readonly string _controlLibraryFile = Application.StartupPath + AppConfigHandler.Instance.ControlLibraryFile;
|
|
|
|
public ToolBoxWindow()
|
|
{
|
|
InitializeComponent();
|
|
|
|
this.InitControls();
|
|
}
|
|
|
|
#region 重写DefaultPadContent的RedrawContent方法
|
|
|
|
/// <summary>
|
|
/// 重绘组件事件触发时执行
|
|
/// </summary>
|
|
public override void RedrawContent()
|
|
{
|
|
base.RedrawContent();
|
|
foreach (Mesnac.UI.ToolBox.ToolBoxCategory cate in this.toolBox1.Categories)
|
|
{
|
|
cate.Items.Clear();
|
|
}
|
|
this.toolBox1.Categories.Clear();
|
|
|
|
this.InitControls();
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 工具箱控件
|
|
/// </summary>
|
|
public Mesnac.UI.ToolBox.ToolBox ToolBox
|
|
{
|
|
get
|
|
{
|
|
return this.toolBox1;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 初始化工具箱控件
|
|
/// </summary>
|
|
public void InitControls()
|
|
{
|
|
#region 添加ToolBox
|
|
|
|
string culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
|
|
string controlfile = Path.Combine(Path.GetDirectoryName(this._controlLibraryFile), Path.GetFileNameWithoutExtension(this._controlLibraryFile));
|
|
controlfile += "." + culture + Path.GetExtension(this._controlLibraryFile);
|
|
if (!File.Exists(controlfile))
|
|
{
|
|
controlfile = this._controlLibraryFile;
|
|
}
|
|
|
|
if (File.Exists(controlfile))
|
|
{
|
|
|
|
ComponentLibraryLoader componentLibraryLoader = new ComponentLibraryLoader();
|
|
componentLibraryLoader.LoadToolComponentLibrary(controlfile);
|
|
|
|
foreach (Category category in componentLibraryLoader.Categories)
|
|
{
|
|
if (category.IsEnabled)
|
|
{
|
|
Mesnac.UI.ToolBox.ToolBoxCategory cate = new Mesnac.UI.ToolBox.ToolBoxCategory();
|
|
cate.ImageIndex = -1;
|
|
cate.IsOpen = false;
|
|
cate.Name = category.Name;
|
|
cate.Parent = null;
|
|
|
|
Mesnac.UI.ToolBox.ToolBoxItem item = new Mesnac.UI.ToolBox.ToolBoxItem();
|
|
item.Tag = null;
|
|
item.Name = "<Pointer>";
|
|
item.Parent = null;
|
|
cate.Items.Add(item);
|
|
|
|
foreach (ToolComponent component in category.ToolComponents)
|
|
{
|
|
item = new Mesnac.UI.ToolBox.ToolBoxItem();
|
|
|
|
System.Drawing.Design.ToolboxItem toolboxItem = new System.Drawing.Design.ToolboxItem();
|
|
toolboxItem.TypeName = component.FullName;
|
|
toolboxItem.Bitmap = componentLibraryLoader.GetIcon(component);
|
|
toolboxItem.DisplayName = component.Name;
|
|
Assembly asm = component.LoadAssembly();
|
|
toolboxItem.AssemblyName = asm.GetName();
|
|
|
|
item.Image = toolboxItem.Bitmap;
|
|
item.Tag = toolboxItem;
|
|
//item.Name = component.Name;
|
|
item.Name = String.IsNullOrWhiteSpace(component.ChineseName) ? component.Name : component.ChineseName;
|
|
item.Parent = null;
|
|
|
|
cate.Items.Add(item);
|
|
}
|
|
|
|
this.toolBox1.Categories.Add(cate);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
private void MesnacToolBoxWindow_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
e.Cancel = true;
|
|
this.Hide();
|
|
}
|
|
}
|
|
}
|