|
|
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 Mesnac.Docking;
|
|
|
using Mesnac.PlugIn.View;
|
|
|
|
|
|
namespace Mesnac.Gui.Workbench
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 工作台窗口类
|
|
|
/// </summary>
|
|
|
public partial class WorkspaceWindow : DockContent,IWorkbenchWindow
|
|
|
{
|
|
|
private IViewContent _content;
|
|
|
|
|
|
#region 构造方法
|
|
|
|
|
|
public WorkspaceWindow(IViewContent content)
|
|
|
{
|
|
|
this._content = content;
|
|
|
InitializeComponent();
|
|
|
|
|
|
this._content.MyOwner = this; //设置视图内容所有者为当前工作区窗口
|
|
|
this._content.TitleNameChanged += new EventHandler(SetTitleEvent);
|
|
|
SetTitleEvent(this, EventArgs.Empty);
|
|
|
|
|
|
this.TabText = this._content.TitleName;
|
|
|
this.Text = this._content.TitleName;
|
|
|
//填充控件
|
|
|
Form frm = this._content.Control as Form;
|
|
|
if (frm != null)
|
|
|
{
|
|
|
frm.TopLevel = false;
|
|
|
frm.ControlBox = false;
|
|
|
frm.FormBorderStyle = FormBorderStyle.None;
|
|
|
frm.Visible = true;
|
|
|
frm.WindowState = FormWindowState.Normal;
|
|
|
frm.AutoScroll = true;
|
|
|
frm.Dock = DockStyle.Fill;
|
|
|
this.Controls.Add(frm);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this._content.Control.Dock = DockStyle.Fill;
|
|
|
this.Controls.Add(this._content.Control);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 标题更业务处理
|
|
|
/// <summary>
|
|
|
/// 标题更改事件
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void SetTitleEvent(object sender, EventArgs e)
|
|
|
{
|
|
|
if (this._content == null)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
this.SetToolTipText();
|
|
|
string newTitle = this._content.TitleName;
|
|
|
|
|
|
if (newTitle != Title)
|
|
|
{
|
|
|
Title = newTitle;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 设置提示文本
|
|
|
/// </summary>
|
|
|
private void SetToolTipText()
|
|
|
{
|
|
|
if (this._content != null)
|
|
|
{
|
|
|
base.ToolTipText = this._content.TitleName;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
base.ToolTipText = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 释放面板
|
|
|
|
|
|
/// <summary>
|
|
|
/// 释放面板
|
|
|
/// </summary>
|
|
|
public void DetachContent()
|
|
|
{
|
|
|
this._content = null;
|
|
|
this.Controls.Clear();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 实现IWorkbenchWindow成员
|
|
|
|
|
|
#region 实现IWorkbenchWindow属性
|
|
|
|
|
|
/// <summary>
|
|
|
/// 工作台窗口标题
|
|
|
/// </summary>
|
|
|
public string Title
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return this.Text;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
this.Text = value;
|
|
|
OnTitleChange(EventArgs.Empty);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 视图对象
|
|
|
/// </summary>
|
|
|
public IViewContent ViewContent
|
|
|
{
|
|
|
get { return this._content; }
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 活动视图对象
|
|
|
/// </summary>
|
|
|
public IViewContent ActiveViewContent
|
|
|
{
|
|
|
get { return this._content; }
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 实现IWorkbenchWindow方法
|
|
|
|
|
|
/// <summary>
|
|
|
/// 关闭工作台窗口方法
|
|
|
/// </summary>
|
|
|
/// <param name="isRealClose">是否真正关闭窗口(true为关闭,false为隐藏)</param>
|
|
|
/// <returns>关闭成功返回真</returns>
|
|
|
public bool CloseWindow(bool isRealClose)
|
|
|
{
|
|
|
if (isRealClose)
|
|
|
{
|
|
|
this.Close();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.Visible = false;
|
|
|
this.Hide();
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 选中
|
|
|
/// </summary>
|
|
|
public void SelectWindow()
|
|
|
{
|
|
|
this.Visible = true;
|
|
|
//this.Show();
|
|
|
this.Activate();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 重绘组件方法
|
|
|
/// </summary>
|
|
|
public virtual void RedrawContent()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 实现IWorkbenchWindow事件
|
|
|
|
|
|
protected virtual void OnTitleChange(EventArgs e)
|
|
|
{
|
|
|
if (TitleChanged != null)
|
|
|
{
|
|
|
TitleChanged(this, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 触发Reload事件
|
|
|
/// </summary>
|
|
|
/// <param name="e">事件对象</param>
|
|
|
public void TriggerReloadEvent(EventArgs e)
|
|
|
{
|
|
|
this._content.TriggerReloadEvent(e);
|
|
|
}
|
|
|
|
|
|
public event EventHandler TitleChanged;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 工作台窗口关闭处理
|
|
|
|
|
|
private void WorkspaceWindow_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
{
|
|
|
if (!this._content.IsRealClose)
|
|
|
{
|
|
|
e.Cancel = true;
|
|
|
this.Visible = false;
|
|
|
this.Hide();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Form frm = this._content.Control as Form;
|
|
|
if (frm != null)
|
|
|
{
|
|
|
this.Controls.Remove(frm);
|
|
|
frm.Close();
|
|
|
frm = null;
|
|
|
}
|
|
|
WorkbenchSingleton.Workbench.ViewContentCollection.Remove(this._content);
|
|
|
string[] keys = new string[WorkbenchSingleton.Workbench.ViewContentDic.Keys.Count];
|
|
|
WorkbenchSingleton.Workbench.ViewContentDic.Keys.CopyTo(keys, 0);
|
|
|
foreach (string key in keys)
|
|
|
{
|
|
|
if (this._content == WorkbenchSingleton.Workbench.ViewContentDic[key])
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.ViewContentDic.Remove(key);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|