|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.ComponentModel;
|
|
|
using System.Data;
|
|
|
using System.Drawing;
|
|
|
using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Configuration;
|
|
|
using System.Reflection;
|
|
|
using System.IO;
|
|
|
|
|
|
using ICSharpCode.Core;
|
|
|
using Mesnac.Core;
|
|
|
using Mesnac.Core.Service;
|
|
|
using Mesnac.PlugIn.Pad;
|
|
|
using Mesnac.PlugIn.View;
|
|
|
using Mesnac.PlugIn.Workbench;
|
|
|
using Mesnac.Gui.PlugIn;
|
|
|
|
|
|
namespace Mesnac.Gui.Workbench
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 默认工作台类
|
|
|
/// </summary>
|
|
|
public partial class DefaultWorkbench : Form , IWorkbench
|
|
|
{
|
|
|
#region 变量声明
|
|
|
|
|
|
private readonly string _mesnacPlugInPath = Path.Combine(Application.StartupPath, ConfigurationManager.AppSettings["MesnacPlugInPath"]); //自定义插件目录
|
|
|
private readonly static string _mainMenuPath = "/Mesnac/Workbench/MainMenu";
|
|
|
private readonly static string _toolStripPath = "/Mesnac/Workbench/Toolbar";
|
|
|
private readonly static string _padContentPath = "/Mesnac/Workbench/Pads";
|
|
|
private const string _BoundProperty = "FormBounds";
|
|
|
private const string _WindowIsMaximized = "WindowIsMaximized";
|
|
|
private const string _WindowIsFullScreen = "WindowIsFullScreen";
|
|
|
private Rectangle _NormalBounds; //窗体位置
|
|
|
private FormWindowState _WindowState = FormWindowState.Normal;
|
|
|
private bool _fullScreen = false;
|
|
|
private bool _closeFlag = false;
|
|
|
|
|
|
private MenuStrip _topMenu = null; //顶层菜单
|
|
|
private ToolStrip _toolStrip = null; //工具栏
|
|
|
private IWorkbenchLayout _layout = null; //工作台布局管理器
|
|
|
private ToolStripItem[] _viewItem; //面板菜单项集合
|
|
|
|
|
|
private List<PadDescriptor> _padContentCollection = new List<PadDescriptor>(); //面板集合
|
|
|
private List<IViewContent> _viewContentCollection = new List<IViewContent>(); //视图窗口集合
|
|
|
private Dictionary<string, IViewContent> _viewContentDic = new Dictionary<string, IViewContent>(); //视图窗口集合
|
|
|
|
|
|
private List<PlugInDescriptor> _plugInCollection = new List<PlugInDescriptor>(); //自定义插件集合
|
|
|
private object _currentViewContent; //当前视图对象
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 默认构造方法
|
|
|
|
|
|
public DefaultWorkbench()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
string app_title = StringParser.Parse(ResourceService.GetString("Mesnac_App_Title"));
|
|
|
this.Text = app_title;
|
|
|
this.Icon = null;
|
|
|
this.StartPosition = FormStartPosition.CenterScreen;
|
|
|
this._NormalBounds = PropertyService.Get<Rectangle>(_BoundProperty, new Rectangle(60, 80, 640, 480));
|
|
|
this.Bounds = this._NormalBounds;
|
|
|
bool bMax = PropertyService.Get<bool>(_WindowIsMaximized, false);
|
|
|
if (bMax)
|
|
|
{
|
|
|
this._WindowState = FormWindowState.Maximized;
|
|
|
this.WindowState = FormWindowState.Maximized;
|
|
|
}
|
|
|
this._fullScreen = PropertyService.Get<bool>(_WindowIsFullScreen, false);
|
|
|
if (this._fullScreen)
|
|
|
{
|
|
|
this.FormBorderStyle = FormBorderStyle.None;
|
|
|
this.WindowState = FormWindowState.Maximized;
|
|
|
}
|
|
|
this.AllowDrop = true;
|
|
|
PadDescriptor.BringPadToFrontEvent += delegate(PadDescriptor padDesc)
|
|
|
{
|
|
|
foreach (PadDescriptor pd in PadContentCollection)
|
|
|
{
|
|
|
if (pd.Equals(padDesc))
|
|
|
{
|
|
|
this._layout.ShowPad(padDesc, true);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
this.ShowPad(padDesc);
|
|
|
};
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 初始化工作空间
|
|
|
/// <summary>
|
|
|
/// 初始化工作空间
|
|
|
/// </summary>
|
|
|
public void InitializeWorkspace()
|
|
|
{
|
|
|
MesnacServiceManager.Instance.LoggingService.Info("初始化工作区...");
|
|
|
//this.UpdateRenderer();
|
|
|
try
|
|
|
{
|
|
|
//从插件文件中获取面板集合
|
|
|
List<PadDescriptor> pads = AddInTree.GetTreeNode(_padContentPath).BuildChildItems<PadDescriptor>(this, null);
|
|
|
this._padContentCollection.AddRange(pads);
|
|
|
|
|
|
//还原布局配置文件中的面板布局
|
|
|
this._layout.LoadConfiguration();
|
|
|
|
|
|
//面板呈现
|
|
|
List<ToolStripItem> padItems = new List<ToolStripItem>();
|
|
|
foreach (PadDescriptor content in pads)
|
|
|
{
|
|
|
if (content != null)
|
|
|
{
|
|
|
if (content.IsVisible)
|
|
|
{
|
|
|
this.ShowPad(content);
|
|
|
}
|
|
|
padItems.Add(new MyMenuItem(content));
|
|
|
}
|
|
|
}
|
|
|
if (padItems.Count > 0)
|
|
|
{
|
|
|
this._viewItem = padItems.ToArray() as ToolStripItem[];
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
MesnacServiceManager.Instance.LoggingService.Error(ex.Message);
|
|
|
}
|
|
|
|
|
|
//添加工具栏
|
|
|
LoggingService.Info("创建主工具栏");
|
|
|
this.CreateMainToolStrip();
|
|
|
//创建主菜单
|
|
|
LoggingService.Info("创建主菜单");
|
|
|
this.CreateMainMenu();
|
|
|
|
|
|
//刷新插件
|
|
|
this.RefreshPlugIn();
|
|
|
|
|
|
//初始化工作完毕时触发完成事件
|
|
|
if (this.InitFinished != null)
|
|
|
{
|
|
|
this.InitFinished(this, EventArgs.Empty);
|
|
|
}
|
|
|
|
|
|
#region 工具栏状态处理
|
|
|
|
|
|
Application.Idle += delegate(object sender, EventArgs e)
|
|
|
{
|
|
|
Mesnac.Core.ToolbarService.UpdateToolbar(this._toolStrip);
|
|
|
};
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 辅助方法
|
|
|
/// <summary>
|
|
|
/// 创建主工具栏
|
|
|
/// </summary>
|
|
|
public void CreateMainToolStrip()
|
|
|
{
|
|
|
if (this._toolStrip != null)
|
|
|
{
|
|
|
this._toolStrip.Items.Clear();
|
|
|
}
|
|
|
this._toolStrip = Mesnac.Core.ToolbarService.CreateToolStrip(this, this._toolStrip, DefaultWorkbench._toolStripPath);
|
|
|
if (this._toolStrip != null)
|
|
|
{
|
|
|
this._toolStrip.Parent = this;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 创建主菜单
|
|
|
/// </summary>
|
|
|
public void CreateMainMenu()
|
|
|
{
|
|
|
if (this._topMenu == null)
|
|
|
{
|
|
|
this._topMenu = new MenuStrip();
|
|
|
}
|
|
|
this._topMenu.Items.Clear();
|
|
|
try
|
|
|
{
|
|
|
//解析菜单
|
|
|
Mesnac.Core.MenuService.AddItemsToMenu(this._topMenu.Items, this, DefaultWorkbench._mainMenuPath); //加载主菜单
|
|
|
if (this._viewItem != null)
|
|
|
{
|
|
|
string mnuWinText = StringParser.Parse(ResourceService.GetString("Mesnac_MainMenu_Window"));
|
|
|
ToolStripMenuItem mnuPads = new Mesnac.Core.CustomerMenu("Mesnac_MainMenu_Window", mnuWinText);
|
|
|
mnuPads.DropDownItems.AddRange(this._viewItem);
|
|
|
this._topMenu.Items.Add(mnuPads);
|
|
|
}
|
|
|
this._topMenu.Parent = this;
|
|
|
this.UpdateMenus();
|
|
|
}
|
|
|
catch (TreePathNotFoundException ex)
|
|
|
{
|
|
|
MesnacServiceManager.Instance.LoggingService.Error(ex.Message);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新菜单
|
|
|
/// </summary>
|
|
|
private void UpdateMenus()
|
|
|
{
|
|
|
foreach (object o in this._topMenu.Items)
|
|
|
{
|
|
|
if (o is IStatusUpdate)
|
|
|
{
|
|
|
((IStatusUpdate)o).UpdateStatus();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 更新呈现
|
|
|
/// </summary>
|
|
|
public void UpdateRenderer()
|
|
|
{
|
|
|
//bool pro = PropertyService.Get<bool>("ICSharpCode.SharpDevelop.Gui.UseProfessionalRenderer", true);
|
|
|
//if (pro)
|
|
|
//{
|
|
|
// ToolStripManager.Renderer = new ToolStripProfessionalRenderer();
|
|
|
//}
|
|
|
//else
|
|
|
//{
|
|
|
// ProfessionalColorTable colorTable = new ProfessionalColorTable();
|
|
|
// colorTable.UseSystemColors = true;
|
|
|
// ToolStripManager.Renderer = new ToolStripProfessionalRenderer(colorTable);
|
|
|
//}
|
|
|
|
|
|
//更新标题呈现
|
|
|
string app_title = StringParser.Parse(ResourceService.GetString("Mesnac_App_Title"));
|
|
|
this.Text = app_title;
|
|
|
|
|
|
//更新面板呈现
|
|
|
|
|
|
foreach (PadDescriptor pad in this._padContentCollection)
|
|
|
{
|
|
|
if (this._layout.ContentHash.ContainsKey(pad.Class))
|
|
|
{
|
|
|
this._layout.ContentHash[pad.Class].Text = ICSharpCode.Core.StringParser.Parse(pad.Title); ;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//更新工具栏呈现
|
|
|
if (this._toolStrip != null)
|
|
|
{
|
|
|
ToolbarService.UpdateToolbarText(this._toolStrip);
|
|
|
}
|
|
|
|
|
|
//更新菜单呈现
|
|
|
foreach (object o in this._topMenu.Items)
|
|
|
{
|
|
|
if (o is IStatusUpdate)
|
|
|
{
|
|
|
((IStatusUpdate)o).UpdateText();
|
|
|
}
|
|
|
//更新面板菜单项
|
|
|
ToolStripMenuItem mnu = o as ToolStripMenuItem;
|
|
|
if (null != mnu)
|
|
|
{
|
|
|
if (mnu.Name == "Mesnac_MainMenu_Window")
|
|
|
{
|
|
|
string mnuWinText = StringParser.Parse(ResourceService.GetString("Mesnac_MainMenu_Window"));
|
|
|
mnu.Text = mnuWinText;
|
|
|
foreach (ToolStripMenuItem item in mnu.DropDownItems)
|
|
|
{
|
|
|
MyMenuItem mnuItem = item as MyMenuItem;
|
|
|
if (null != mnuItem)
|
|
|
{
|
|
|
mnuItem.UpdateText();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//触发刷新控制台界面事件
|
|
|
if (this.RefreshUI != null)
|
|
|
{
|
|
|
this.RefreshUI(this, System.EventArgs.Empty);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 重写窗体类的方法
|
|
|
|
|
|
protected override void WndProc(ref Message m)
|
|
|
{
|
|
|
if (m.Msg == 0x0010)//WM_CLOSE
|
|
|
{
|
|
|
LoggingService.Debug(m.Msg);
|
|
|
|
|
|
if (this.CloseFlag)
|
|
|
{
|
|
|
string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption"));
|
|
|
string msg = StringParser.Parse(ResourceService.GetString("Dialog_MessageBox_ExtAsk"));
|
|
|
DialogResult result = MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
|
if (result == DialogResult.Yes)
|
|
|
{
|
|
|
this.CloseFlag = false;
|
|
|
this.Close();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
//this.CloseFlag = true;
|
|
|
//this.Close();
|
|
|
}
|
|
|
}
|
|
|
base.WndProc(ref m);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 系统关闭事件处理
|
|
|
/// </summary>
|
|
|
/// <param name="e"></param>
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
{
|
|
|
//触发系统关闭事件
|
|
|
if (this.ShutDown != null)
|
|
|
{
|
|
|
this.ShutDown(this, EventArgs.Empty);
|
|
|
MesnacServiceManager.Instance.LoggingService.Info("触发Workbench关闭事件...");
|
|
|
}
|
|
|
//重新设置窗体关闭,覆盖其他窗体的Cancel设置
|
|
|
MesnacServiceManager.Instance.LoggingService.Info("正在关闭...1");
|
|
|
//文档处理
|
|
|
this.CloseAllViews();
|
|
|
//布局处理
|
|
|
this._layout.Detach();
|
|
|
MesnacServiceManager.Instance.LoggingService.Info("正在关闭...2");
|
|
|
//面板处理
|
|
|
foreach (PadDescriptor padDescriptor in this._padContentCollection)
|
|
|
{
|
|
|
padDescriptor.Dispose();
|
|
|
}
|
|
|
//全屏处理
|
|
|
if (this._fullScreen)
|
|
|
{
|
|
|
PropertyService.Set<bool>(_WindowIsFullScreen, true);
|
|
|
if (this._WindowState == FormWindowState.Maximized)
|
|
|
{
|
|
|
PropertyService.Set<bool>(_WindowIsMaximized, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PropertyService.Set<bool>(_WindowIsMaximized, false);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PropertyService.Set<bool>(_WindowIsFullScreen, false);
|
|
|
if (this._WindowState == FormWindowState.Maximized)
|
|
|
{
|
|
|
PropertyService.Set<bool>(_WindowIsMaximized, true);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
PropertyService.Set<bool>(_WindowIsMaximized, false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Application.ExitThread();
|
|
|
base.OnClosing(e);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 实现IWorkbench接口成员
|
|
|
|
|
|
#region 实现IWorkbench接口属性
|
|
|
/// <summary>
|
|
|
/// 工作区主菜单
|
|
|
/// </summary>
|
|
|
public MenuStrip TopMenu { get { return this._topMenu; } }
|
|
|
/// <summary>
|
|
|
/// 工作区工具栏
|
|
|
/// </summary>
|
|
|
public ToolStrip ToolStrip { get { return this._toolStrip; } }
|
|
|
/// <summary>
|
|
|
/// 工作台布局
|
|
|
/// </summary>
|
|
|
public IWorkbenchLayout WorkbenchLayout
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return this._layout;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
if (this._layout != null)
|
|
|
{
|
|
|
this._layout.Detach();
|
|
|
}
|
|
|
this._layout = value;
|
|
|
//this._layout.Owner = this; //设置布局所有者
|
|
|
//value.Attach();
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 是否全屏
|
|
|
/// </summary>
|
|
|
public bool FullScreen
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return this._fullScreen;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
if (this._fullScreen == value)
|
|
|
return;
|
|
|
this._fullScreen = value;
|
|
|
if (this._fullScreen)
|
|
|
{
|
|
|
this._WindowState = this.WindowState;
|
|
|
this._NormalBounds = this.Bounds;
|
|
|
this.Visible = false;
|
|
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
|
|
|
this.WindowState = FormWindowState.Maximized;
|
|
|
this.Visible = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
|
|
|
this.Bounds = this._NormalBounds;
|
|
|
this.WindowState = this._WindowState;
|
|
|
}
|
|
|
this._layout.SetFullScreenPads(!value);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 关闭系统标识
|
|
|
/// </summary>
|
|
|
public bool CloseFlag { get { return this._closeFlag; } set { this._closeFlag = value; } }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 标题文本
|
|
|
/// </summary>
|
|
|
public string Title
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return this.Text;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
this.Text = value;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 面板集合
|
|
|
/// </summary>
|
|
|
public List<PadDescriptor> PadContentCollection
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
System.Diagnostics.Debug.Assert(this._padContentCollection != null);
|
|
|
return this._padContentCollection;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 视图窗口集合
|
|
|
/// </summary>
|
|
|
public List<IViewContent> ViewContentCollection
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
System.Diagnostics.Debug.Assert(this._viewContentCollection != null);
|
|
|
return this._viewContentCollection;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 视图窗口集合
|
|
|
/// </summary>
|
|
|
public Dictionary<string, IViewContent> ViewContentDic
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
System.Diagnostics.Debug.Assert(this._viewContentDic != null);
|
|
|
return this._viewContentDic;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 插件集合
|
|
|
/// </summary>
|
|
|
public List<PlugInDescriptor> PlugInCollection
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
System.Diagnostics.Debug.Assert(this._plugInCollection != null);
|
|
|
return this._plugInCollection;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 活动内容
|
|
|
/// </summary>
|
|
|
public object ActiveContent
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
if (this._layout == null)
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
return this._layout.ActiveConent;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 当前视图对象
|
|
|
/// </summary>
|
|
|
public object CurrentViewContent
|
|
|
{
|
|
|
get
|
|
|
{
|
|
|
return this._currentViewContent;
|
|
|
}
|
|
|
set
|
|
|
{
|
|
|
this._currentViewContent = value;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 实现IWorkbench接口方法
|
|
|
|
|
|
#region 显示面板 ShowPad(PadDescriptor content)
|
|
|
/// <summary>
|
|
|
/// 显示面板
|
|
|
/// </summary>
|
|
|
/// <param name="content">面板描述器对象</param>
|
|
|
public virtual void ShowPad(PadDescriptor content)
|
|
|
{
|
|
|
this._padContentCollection.Add(content);
|
|
|
if (this._layout != null)
|
|
|
{
|
|
|
this._layout.ShowPad(content);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取面板描述器 PadDescriptor GetPad(Type type)
|
|
|
/// <summary>
|
|
|
/// 获取面板描述器
|
|
|
/// </summary>
|
|
|
/// <param name="type">面板类型</param>
|
|
|
/// <returns>返回对应类型的面板描述器对象</returns>
|
|
|
public virtual PadDescriptor GetPad(Type type)
|
|
|
{
|
|
|
foreach (PadDescriptor pad in this._padContentCollection)
|
|
|
{
|
|
|
if (pad.Class == type.FullName)
|
|
|
{
|
|
|
return pad;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 显示视图内容 ShowView(IViewContent content)
|
|
|
/// <summary>
|
|
|
/// 显示视图内容
|
|
|
/// </summary>
|
|
|
/// <param name="content">要显示的视图对象</param>
|
|
|
public virtual void ShowView(IViewContent content)
|
|
|
{
|
|
|
//System.Diagnostics.Debug.Assert(this._layout != null);
|
|
|
//同类型的窗口只显示一个
|
|
|
bool flag = false;
|
|
|
foreach (IViewContent c in this._viewContentCollection)
|
|
|
{
|
|
|
if (content.GetType().FullName == c.GetType().FullName)
|
|
|
{
|
|
|
content = c;
|
|
|
flag = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
if (!flag)
|
|
|
{
|
|
|
this._viewContentCollection.Add(content);
|
|
|
}
|
|
|
this._layout.ShowView(content);
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).SelectWindow();
|
|
|
}
|
|
|
this._currentViewContent = content;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 显示一个视图窗口 ShowView(IViewContent content, bool isAllowRepeat)
|
|
|
/// <summary>
|
|
|
/// 显示一个视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="content">视图内容</param>
|
|
|
/// <param name="isAllowRepeat">是否允许重复保存</param>
|
|
|
public virtual void ShowView(IViewContent content, bool isAllowRepeat)
|
|
|
{
|
|
|
if (isAllowRepeat)
|
|
|
{
|
|
|
//System.Diagnostics.Debug.Assert(this._layout != null);
|
|
|
//同类型的窗口可以有多个
|
|
|
this._viewContentCollection.Add(content);
|
|
|
this._layout.ShowView(content);
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).SelectWindow();
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this.ShowView(content);
|
|
|
}
|
|
|
this._currentViewContent = content;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 显示一个视图窗口 ShowView(string key, IViewContent content)
|
|
|
|
|
|
/// <summary>
|
|
|
/// 显示一个视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="key">视图窗口标识</param>
|
|
|
/// <param name="content">视图内容</param>
|
|
|
public virtual void ShowView(string key, IViewContent content)
|
|
|
{
|
|
|
if (!this._viewContentDic.ContainsKey(key))
|
|
|
{
|
|
|
this._viewContentDic.Add(key, content);
|
|
|
this._layout.ShowView(content);
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).SelectWindow();
|
|
|
}
|
|
|
this._currentViewContent = content;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
content = this._viewContentDic[key];
|
|
|
this._layout.ShowView(content);
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).TriggerReloadEvent(null); //触发重新加载事件
|
|
|
(content.MyOwner as IWorkbenchWindow).SelectWindow();
|
|
|
}
|
|
|
this._currentViewContent = content;
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 显示一个视图窗口 ShowView(string key, IViewContent content, Mesnac.Docking.DockState dockState)
|
|
|
/// <summary>
|
|
|
/// 显示一个视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="key">视图窗口标识</param>
|
|
|
/// <param name="content">视图内容</param>
|
|
|
/// <param name="dockState">视图显示的停靠方式</param>
|
|
|
public virtual void ShowView(string key, IViewContent content, Mesnac.Docking.DockState dockState)
|
|
|
{
|
|
|
if (!this._viewContentDic.ContainsKey(key))
|
|
|
{
|
|
|
this._viewContentDic.Add(key, content);
|
|
|
this._layout.ShowView(content, dockState);
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).SelectWindow();
|
|
|
}
|
|
|
this._currentViewContent = content;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
content = this._viewContentDic[key];
|
|
|
this._layout.ShowView(content, dockState);
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).TriggerReloadEvent(null); //触发重新加载事件
|
|
|
(content.MyOwner as IWorkbenchWindow).SelectWindow();
|
|
|
}
|
|
|
this._currentViewContent = content;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取视图窗口 GetViewByKey(string key)
|
|
|
/// <summary>
|
|
|
/// 获取视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="key">视图窗口标识</param>
|
|
|
/// <returns>返回对应视图标识的工作台窗口</returns>
|
|
|
public virtual IWorkbenchWindow GetViewByKey(string key)
|
|
|
{
|
|
|
if (this._viewContentDic.ContainsKey(key))
|
|
|
{
|
|
|
return this._viewContentDic[key].MyOwner as IWorkbenchWindow;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取视图窗口 GetViewByViewContentID(string viewContentID)
|
|
|
/// <summary>
|
|
|
/// 根据视图ID获取对应的工作台窗口
|
|
|
/// </summary>
|
|
|
/// <param name="viewContentID">视图ID</param>
|
|
|
/// <returns>返回对应的工作台窗口</returns>
|
|
|
public virtual IWorkbenchWindow GetViewByViewContentID(string viewContentID)
|
|
|
{
|
|
|
foreach (IViewContent vc in this._viewContentCollection)
|
|
|
{
|
|
|
if (vc.ViewContentID == viewContentID)
|
|
|
{
|
|
|
return vc.MyOwner as IWorkbenchWindow;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 根据视图类型,获取对应类型的所有视图窗口 GetViewByType(Type type)
|
|
|
/// <summary>
|
|
|
/// 根据视图类型,获取对应类型的所有视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="type">视图类型</param>
|
|
|
/// <returns>返回对应类型的工作台窗口</returns>
|
|
|
public virtual IWorkbenchWindow GetViewByType(Type type)
|
|
|
{
|
|
|
foreach (IViewContent vc in this._viewContentCollection)
|
|
|
{
|
|
|
if (vc.GetType() == type)
|
|
|
{
|
|
|
return vc.MyOwner as IWorkbenchWindow;
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 根据视图类型,获取对应类型的所有视图窗口 GetViewsByType(Type type)
|
|
|
/// <summary>
|
|
|
/// 根据视图类型,获取对应类型的所有视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="type">要获取的视图类型</param>
|
|
|
/// <returns>返回对应类型的视图(工作台窗口)的集合</returns>
|
|
|
public virtual List<IWorkbenchWindow> GetViewsByType(Type type)
|
|
|
{
|
|
|
List<IWorkbenchWindow> lst = new List<IWorkbenchWindow>();
|
|
|
foreach (IViewContent vc in this._viewContentCollection)
|
|
|
{
|
|
|
if (vc.GetType() == type)
|
|
|
{
|
|
|
lst.Add(vc.MyOwner as IWorkbenchWindow);
|
|
|
}
|
|
|
}
|
|
|
return lst;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取自定义视图窗口集合 GetCustomerViews()
|
|
|
/// <summary>
|
|
|
/// 获取自定义视图窗口集合
|
|
|
/// </summary>
|
|
|
/// <returns>返回自定义视图窗口集合</returns>
|
|
|
public virtual List<IWorkbenchWindow> GetCustomerViews()
|
|
|
{
|
|
|
List<IWorkbenchWindow> lst = new List<IWorkbenchWindow>();
|
|
|
foreach (IViewContent vc in this._viewContentDic.Values)
|
|
|
{
|
|
|
lst.Add(vc.MyOwner as IWorkbenchWindow);
|
|
|
}
|
|
|
return lst;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 关闭某个视图窗口 CloseView(IViewContent content)
|
|
|
/// <summary>
|
|
|
/// 关闭某个视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="content">要关闭的视图对象</param>
|
|
|
public virtual void CloseView(IViewContent content)
|
|
|
{
|
|
|
if (this._viewContentCollection.Contains(content))
|
|
|
{
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).CloseWindow(true);
|
|
|
}
|
|
|
this._viewContentCollection.Remove(content);
|
|
|
}
|
|
|
content.Dispose();
|
|
|
content = null;
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 关闭一个视图窗口 CloseView(IViewContent content, bool isRealClose)
|
|
|
/// <summary>
|
|
|
/// 关闭一个视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="content">要关闭的视图对象</param>
|
|
|
/// <param name="isRealClose">是否真正关闭</param>
|
|
|
public virtual void CloseView(IViewContent content, bool isRealClose)
|
|
|
{
|
|
|
if (isRealClose)
|
|
|
{
|
|
|
this.CloseView(content);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (this._viewContentCollection.Contains(content))
|
|
|
{
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).CloseWindow(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 关闭所有视图窗口 CloseAllViews()
|
|
|
/// <summary>
|
|
|
/// 关闭所有视图窗口
|
|
|
/// </summary>
|
|
|
public virtual void CloseAllViews()
|
|
|
{
|
|
|
List<IViewContent> fullList = new List<IViewContent>(this._viewContentCollection);
|
|
|
foreach (IViewContent content in fullList)
|
|
|
{
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).CloseWindow(true);
|
|
|
}
|
|
|
}
|
|
|
this._viewContentCollection.Clear();
|
|
|
string[] keys = new string[this._viewContentDic.Keys.Count];
|
|
|
this._viewContentDic.Keys.CopyTo(keys, 0);
|
|
|
foreach (string key in keys)
|
|
|
{
|
|
|
IViewContent content = this._viewContentDic[key];
|
|
|
content.IsRealClose = true;
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).CloseWindow(true);
|
|
|
}
|
|
|
if (this._viewContentDic.ContainsKey(key))
|
|
|
{
|
|
|
this._viewContentDic.Remove(key);
|
|
|
}
|
|
|
content.Dispose();
|
|
|
content = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 关闭所有视图窗口 CloseAllViews(bool isRealClose)
|
|
|
/// <summary>
|
|
|
/// 关闭所有视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="isRealClose">是否真正关闭</param>
|
|
|
public virtual void CloseAllViews(bool isRealClose)
|
|
|
{
|
|
|
if (isRealClose)
|
|
|
{
|
|
|
this.CloseAllViews();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
List<IViewContent> fullList = new List<IViewContent>(this._viewContentCollection);
|
|
|
foreach (IViewContent content in fullList)
|
|
|
{
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).CloseWindow(false);
|
|
|
}
|
|
|
}
|
|
|
string[] keys = new string[this._viewContentDic.Keys.Count];
|
|
|
this._viewContentDic.Keys.CopyTo(keys, 0);
|
|
|
foreach (string key in keys)
|
|
|
{
|
|
|
IViewContent content = this._viewContentDic[key];
|
|
|
content.IsRealClose = false;
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).CloseWindow(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 根据键值关闭一个视图窗口 CloseViewByKey(string key)
|
|
|
/// <summary>
|
|
|
/// 根据键值关闭一个视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="key">要关闭的视图键值</param>
|
|
|
public virtual void CloseViewByKey(string key)
|
|
|
{
|
|
|
if (this._viewContentDic.ContainsKey(key))
|
|
|
{
|
|
|
IViewContent content = this._viewContentDic[key];
|
|
|
content.IsRealClose = true;
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).CloseWindow(true);
|
|
|
}
|
|
|
content.Dispose();
|
|
|
content = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 根据键值关闭一个视图窗口 CloseViewByKey(string key, bool isRealClose)
|
|
|
/// <summary>
|
|
|
/// 根据键值关闭一个视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="key">要关闭的视图键值</param>
|
|
|
/// <param name="isRealClose">是否真正关闭</param>
|
|
|
public virtual void CloseViewByKey(string key, bool isRealClose)
|
|
|
{
|
|
|
if (isRealClose)
|
|
|
{
|
|
|
this.CloseViewByKey(key);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (this._viewContentDic.ContainsKey(key))
|
|
|
{
|
|
|
IViewContent content = this._viewContentDic[key];
|
|
|
content.IsRealClose = false;
|
|
|
if (content.MyOwner is IWorkbenchWindow)
|
|
|
{
|
|
|
(content.MyOwner as IWorkbenchWindow).CloseWindow(false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 关闭所有的键视图窗口 CloseAllKeysView()
|
|
|
/// <summary>
|
|
|
/// 关闭所有的键视图窗口
|
|
|
/// </summary>
|
|
|
public virtual void CloseAllKeysView()
|
|
|
{
|
|
|
string[] keys = new string[this._viewContentDic.Keys.Count];
|
|
|
this._viewContentDic.Keys.CopyTo(keys, 0);
|
|
|
foreach (string key in keys)
|
|
|
{
|
|
|
this.CloseViewByKey(key);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 关闭所有的键视图窗口 CloseAllKeysView(bool isRealClose)
|
|
|
/// <summary>
|
|
|
/// 关闭所有的键视图窗口
|
|
|
/// </summary>
|
|
|
/// <param name="isRealClose">是否真正关闭</param>
|
|
|
public virtual void CloseAllKeysView(bool isRealClose)
|
|
|
{
|
|
|
if (isRealClose)
|
|
|
{
|
|
|
this.CloseAllKeysView();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string[] keys = new string[this._viewContentDic.Keys.Count];
|
|
|
this._viewContentDic.Keys.CopyTo(keys, 0);
|
|
|
foreach (string key in keys)
|
|
|
{
|
|
|
this.CloseViewByKey(key, false);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 刷新自定义插件 RefreshPlugIn()
|
|
|
/// <summary>
|
|
|
/// 刷新插件
|
|
|
/// </summary>
|
|
|
public virtual void RefreshPlugIn()
|
|
|
{
|
|
|
LoggingService.Info("刷新插件...");
|
|
|
this.CloseAllViews();
|
|
|
if (!Directory.Exists(this._mesnacPlugInPath))
|
|
|
{
|
|
|
Directory.CreateDirectory(this._mesnacPlugInPath);
|
|
|
}
|
|
|
if (this._plugInCollection != null && this._plugInCollection.Count > 0)
|
|
|
{
|
|
|
foreach (PlugInDescriptor p in this._plugInCollection)
|
|
|
{
|
|
|
if (p.ViewContents != null && p.ViewContents.Count > 0)
|
|
|
{
|
|
|
foreach (IViewContent viewContent in p.ViewContents)
|
|
|
{
|
|
|
viewContent.Dispose();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
this._plugInCollection.Clear();
|
|
|
}
|
|
|
this._plugInCollection = PlugInService.ScanPlugIn(this._mesnacPlugInPath);
|
|
|
if (AfterRefreshPlugIn != null)
|
|
|
{
|
|
|
AfterRefreshPlugIn(this._plugInCollection, EventArgs.Empty); //触发事件
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 重绘所有组件 RedrawAllComponents()
|
|
|
/// <summary>
|
|
|
/// 重绘所有组件
|
|
|
/// </summary>
|
|
|
public virtual void RedrawAllComponents()
|
|
|
{
|
|
|
//顶层菜单处理
|
|
|
foreach (ToolStripItem item in this._topMenu.Items)
|
|
|
{
|
|
|
if (item is IStatusUpdate)
|
|
|
((IStatusUpdate)item).UpdateText();
|
|
|
}
|
|
|
|
|
|
//面板处理
|
|
|
foreach (PadDescriptor content in this._padContentCollection)
|
|
|
{
|
|
|
content.RedrawConent();
|
|
|
}
|
|
|
|
|
|
//视图窗口处理
|
|
|
|
|
|
foreach (IViewContent content in this._viewContentCollection)
|
|
|
{
|
|
|
content.RedrawContent();
|
|
|
}
|
|
|
|
|
|
if (this._layout != null)
|
|
|
{
|
|
|
this._layout.RedrawAllComponents();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 退出系统方法
|
|
|
|
|
|
/// <summary>
|
|
|
/// 退出系统方法
|
|
|
/// </summary>
|
|
|
public void Exit()
|
|
|
{
|
|
|
this.Close();
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 实现IWorkbench接口事件
|
|
|
|
|
|
/// <summary>
|
|
|
/// 刷新插件事件
|
|
|
/// </summary>
|
|
|
public event EventHandler AfterRefreshPlugIn;
|
|
|
/// <summary>
|
|
|
/// 初始化完毕事件
|
|
|
/// </summary>
|
|
|
public event EventHandler InitFinished;
|
|
|
/// <summary>
|
|
|
/// 刷新工作台界面事件
|
|
|
/// </summary>
|
|
|
public event EventHandler RefreshUI;
|
|
|
/// <summary>
|
|
|
/// 系统即将关闭事件
|
|
|
/// </summary>
|
|
|
public event EventHandler ShutDown;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 内部自定义菜单项类
|
|
|
|
|
|
/// <summary>
|
|
|
/// 内部自定义菜单项类,对应系统面板
|
|
|
/// </summary>
|
|
|
class MyMenuItem : ToolStripMenuItem , IStatusUpdate
|
|
|
{
|
|
|
private PadDescriptor _padDescriptor;
|
|
|
|
|
|
public MyMenuItem(PadDescriptor padDescriptor)
|
|
|
: base()
|
|
|
{
|
|
|
this._padDescriptor = padDescriptor;
|
|
|
this.Name = padDescriptor.ID;
|
|
|
this.Text = StringParser.Parse(this._padDescriptor.Title);
|
|
|
|
|
|
if (this._padDescriptor.Icon != null)
|
|
|
{
|
|
|
base.Image = MesnacServiceManager.Instance.IconService.GetBitmap(padDescriptor.Icon);
|
|
|
}
|
|
|
if (this._padDescriptor.Shortcut != null)
|
|
|
{
|
|
|
this.ShortcutKeys = Mesnac.Core.MenuCommand.ParseShortcut(padDescriptor.Shortcut);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
protected override void OnClick(EventArgs e)
|
|
|
{
|
|
|
base.OnClick(e);
|
|
|
this._padDescriptor.BringPadToFront();
|
|
|
}
|
|
|
|
|
|
public string ID
|
|
|
{
|
|
|
get { return this.Name; }
|
|
|
}
|
|
|
|
|
|
public void UpdateStatus()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
public void UpdateText()
|
|
|
{
|
|
|
this.Text = StringParser.Parse(this._padDescriptor.Title);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
}
|