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.
253 lines
6.7 KiB
C#
253 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Windows.Forms;
|
|
using System.Text;
|
|
|
|
namespace Mesnac.PlugIn.View
|
|
{
|
|
public class DefaultViewContent : Form, IViewContent
|
|
{
|
|
private string _viewContentID = String.Empty;
|
|
private object _myOwner = null;
|
|
private string _titleName = null;
|
|
private bool _isRealClose = false;
|
|
private List<ActionItem> _actionList = null;
|
|
|
|
#region 实现IViewContent成员
|
|
|
|
public virtual string ViewContentID
|
|
{
|
|
get
|
|
{
|
|
return this._viewContentID;
|
|
}
|
|
set
|
|
{
|
|
this._viewContentID = value;
|
|
}
|
|
}
|
|
|
|
public virtual object MyOwner
|
|
{
|
|
get
|
|
{
|
|
|
|
if (this._myOwner == null)
|
|
{
|
|
this._myOwner = this;
|
|
}
|
|
return this._myOwner;
|
|
}
|
|
set
|
|
{
|
|
this._myOwner = value;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 功能描述
|
|
/// </summary>
|
|
public virtual string TitleName
|
|
{
|
|
get
|
|
{
|
|
if (String.IsNullOrWhiteSpace(this._titleName))
|
|
{
|
|
return this.Text;
|
|
}
|
|
else
|
|
{
|
|
return this._titleName;
|
|
}
|
|
}
|
|
set
|
|
{
|
|
this._titleName = value;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 是否真正关闭
|
|
/// </summary>
|
|
public bool IsRealClose
|
|
{
|
|
get { return _isRealClose; }
|
|
set { _isRealClose = value; }
|
|
}
|
|
/// <summary>
|
|
/// 视图控件集合
|
|
/// </summary>
|
|
public Control Control
|
|
{
|
|
get
|
|
{
|
|
return this;
|
|
}
|
|
}
|
|
public List<Control> AllControls
|
|
{
|
|
get
|
|
{
|
|
List<Control> lst = new List<Control>();
|
|
lst = this.GetAllControls(lst, this);
|
|
return lst;
|
|
}
|
|
}
|
|
|
|
public List<Control> GetAllControls(List<Control> allControls, Control topControl)
|
|
{
|
|
if (allControls == null) allControls = new List<Control>();
|
|
if (topControl.Controls != null && topControl.Controls.Count > 0)
|
|
{
|
|
foreach (Control c in topControl.Controls)
|
|
{
|
|
allControls = GetAllControls(allControls, c);
|
|
allControls.Add(c);
|
|
}
|
|
}
|
|
return allControls;
|
|
}
|
|
/// <summary>
|
|
/// 操作项集合
|
|
/// </summary>
|
|
public virtual List<ActionItem> ActionList
|
|
{
|
|
get
|
|
{
|
|
if (this._actionList == null || this._actionList.Count == 0)
|
|
{
|
|
List<ActionItem> lst = new List<ActionItem>();
|
|
foreach (Control c in this.AllControls)
|
|
{
|
|
|
|
//按钮
|
|
if (c is Button)
|
|
{
|
|
string actionName = c.Text;
|
|
if (c.Text.IndexOf("(") > 0)
|
|
{
|
|
actionName = c.Text.Substring(0, c.Text.IndexOf("(") - 1);
|
|
}
|
|
lst.Add(new ActionItem(c.Text, c));
|
|
}
|
|
//菜单项
|
|
|
|
//工具栏按钮
|
|
|
|
}
|
|
|
|
return lst;
|
|
}
|
|
else
|
|
{
|
|
return this._actionList;
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 添加一个操作项
|
|
/// </summary>
|
|
/// <param name="actionItem"></param>
|
|
public virtual void AddActionItem(ActionItem actionItem)
|
|
{
|
|
if (this._actionList == null)
|
|
{
|
|
this._actionList = new List<ActionItem>();
|
|
}
|
|
this._actionList.Add(actionItem);
|
|
}
|
|
/// <summary>
|
|
/// 向操作集合中添加一个操作项
|
|
/// </summary>
|
|
/// <param name="actionName">操作名称</param>
|
|
/// <param name="control">功能控件</param>
|
|
public virtual void AddActionItem(string actionName, Control control)
|
|
{
|
|
if (this._actionList == null)
|
|
{
|
|
this._actionList = new List<ActionItem>();
|
|
}
|
|
this._actionList.Add(new ActionItem(actionName, control));
|
|
}
|
|
/// <summary>
|
|
/// 移除操作项
|
|
/// </summary>
|
|
/// <param name="control"></param>
|
|
public virtual void RemoveActionItem(Control control)
|
|
{
|
|
if (this._actionList != null)
|
|
{
|
|
for (int i = 0; i < this._actionList.Count; i++)
|
|
{
|
|
if (this._actionList[i].Control == control)
|
|
{
|
|
this._actionList.RemoveAt(i);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 清空操作项集合
|
|
/// </summary>
|
|
public virtual void ClearActionList()
|
|
{
|
|
if (this._actionList != null)
|
|
{
|
|
this._actionList.Clear();
|
|
}
|
|
else
|
|
{
|
|
this._actionList = new List<ActionItem>();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 触发重新载入事件
|
|
/// </summary>
|
|
/// <param name="e">事件对象</param>
|
|
public void TriggerReloadEvent(System.EventArgs e)
|
|
{
|
|
if (Reload != null)
|
|
{
|
|
Reload(this, e);
|
|
}
|
|
}
|
|
|
|
public virtual void RedrawContent()
|
|
{
|
|
|
|
}
|
|
|
|
public virtual event EventHandler TitleNameChanged;
|
|
/// <summary>
|
|
/// 重新载入事件
|
|
/// </summary>
|
|
public virtual event EventHandler Reload;
|
|
|
|
#endregion
|
|
|
|
#region 辅助方法
|
|
|
|
/// <summary>
|
|
/// 获取源控件的顶层容器
|
|
/// </summary>
|
|
/// <param name="source">源控件</param>
|
|
/// <returns>返回顶层容器</returns>
|
|
private Control GetTopContainer(Control source)
|
|
{
|
|
Control c = source.Parent;
|
|
if (c == null)
|
|
{
|
|
return this;
|
|
}
|
|
else
|
|
{
|
|
return GetTopContainer(c);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|