using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.Core;
namespace Mesnac.PlugIn.Pad
{
///
/// 面板描述符类
///
public class PadDescriptor : IDisposable
{
#region 定义变量
private Codon codon; //密码子
private IPadContent padContent; //面板对象
private bool padContentCreated; //面板是否创建
#endregion
#region 构造方法
///
/// 构造方法
///
///
public PadDescriptor(Codon codon)
{
this.codon = codon;
}
#endregion
#region 定义属性
///
/// 面板ID
///
public string ID
{
get { return this.codon.Properties["id"]; }
}
///
/// 面板标题
///
public string Title
{
get { return this.codon.Properties["title"]; }
}
///
/// 面板图标,如果没有定义图标,允许为空
///
public string Icon
{
get { return this.codon.Properties["icon"]; }
}
///
/// 面板类别(用于菜单分类)
///
public string Category
{
get { return this.codon.Properties["category"]; }
}
///
/// 菜单快捷键
///
public string Shortcut
{
get { return this.codon.Properties["shortcut"]; }
}
///
/// 关联类
///
public string Class
{
get { return this.codon.Properties["class"]; }
}
public string DockState
{
get { return this.codon.Properties["dockState"]; }
}
///
/// 是否显示
///
public bool IsVisible
{
get
{
string isVisible = this.codon.Properties["isVisible"];
if (!String.IsNullOrEmpty(isVisible))
{
bool result = true;
if (bool.TryParse(isVisible, out result))
{
return result;
}
}
return true;
}
}
///
/// 获取焦点
///
public bool HasFocus
{
//get { return (this.padContent != null) ? this.padContent.Control.ContainsFocus : false; }
get
{
if (this.padContent != null && this.padContent.Control != null)
{
return this.padContent.Control.ContainsFocus;
}
return false;
}
}
///
/// 获取面板对象
///
public IPadContent PadContent
{
get { this.CreatePad(); return this.padContent; }
}
#endregion
#region 定义方法
///
/// 创建面板
///
public void CreatePad()
{
if (!this.padContentCreated)
{
this.padContentCreated = true;
this.padContent = this.codon.AddIn.CreateObject(this.Class) as IPadContent;
}
}
///
/// 面板上移
///
public void BringPadToFront()
{
this.CreatePad();
if (this.padContent == null) return;
//触发事件
if (BringPadToFrontEvent != null)
BringPadToFrontEvent(this);
}
///
/// 重绘面板
///
public void RedrawConent()
{
if (this.padContent != null)
{
this.padContent.RedrawContent();
}
}
///
/// 释放面板对象
///
public void Dispose()
{
if (this.padContent != null)
{
this.padContent.Dispose();
this.padContent = null;
}
}
#endregion
#region 定义委托和事件
public delegate void BringPadToFrontHnd(PadDescriptor padDesc);
public static event BringPadToFrontHnd BringPadToFrontEvent;
#endregion
}
}