|
|
using System;
|
|
|
using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Drawing;
|
|
|
using System.Xml;
|
|
|
using System.ComponentModel;
|
|
|
using System.ComponentModel.Design;
|
|
|
|
|
|
using System.IO;
|
|
|
using ICSharpCode.Core;
|
|
|
using Mesnac.Gui.Workbench;
|
|
|
|
|
|
using Mesnac.Controls.Default;
|
|
|
using Mesnac.Gui.Common;
|
|
|
using Mesnac.Gui.Edit.Global;
|
|
|
using Mesnac.Gui.Edit.Common;
|
|
|
using Mesnac.Gui.Edit.Dialog;
|
|
|
using Mesnac.Gui.Edit.Pad;
|
|
|
using Mesnac.Gui.Edit.ViewContent;
|
|
|
using Mesnac.Core.Service;
|
|
|
using Mesnac.Basic;
|
|
|
using Host;
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
namespace Mesnac.Gui.Edit.ViewContent
|
|
|
{
|
|
|
#region 显示辅助类
|
|
|
|
|
|
/// <summary>
|
|
|
/// 显示辅助类,保存通用方法和变量
|
|
|
/// </summary>
|
|
|
/// <typeparam name="T"></typeparam>
|
|
|
public class DisplayUtil<T>
|
|
|
{
|
|
|
#region 面板处理辅助方法
|
|
|
/// <summary>
|
|
|
/// 获取面板实例
|
|
|
/// </summary>
|
|
|
public static T PadInstance
|
|
|
{
|
|
|
get{
|
|
|
Mesnac.PlugIn.Pad.PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(T));
|
|
|
object pad = pd == null ? null : pd.PadContent;
|
|
|
return (T)pad;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 工程处理辅助方法
|
|
|
|
|
|
/// <summary>
|
|
|
/// 清除工程
|
|
|
/// </summary>
|
|
|
public static void ClearProject()
|
|
|
{
|
|
|
//清除仿真画面
|
|
|
Mesnac.Gui.Common.RunEngine.Instance.CloseAllForms();
|
|
|
|
|
|
ProjectWindow projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
PropertyWindow propertyWindow = DisplayUtil<PropertyWindow>.PadInstance;
|
|
|
ActionWindow actionWindow = DisplayUtil<ActionWindow>.PadInstance;
|
|
|
EventWindow eventWindow = DisplayUtil<EventWindow>.PadInstance;
|
|
|
|
|
|
//保存工程处理
|
|
|
if (projectWindow != null && projectWindow.Tree != null && projectWindow.Tree.Nodes.Count > 0)
|
|
|
{
|
|
|
string msgContent = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_CloseProject")); //正在关闭工程{0},需要保存吗?
|
|
|
string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption"));
|
|
|
msgContent = String.Format(msgContent, projectWindow.Tree.Nodes[0].Text);
|
|
|
DialogResult result = MessageBox.Show(msgContent, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
|
if (result == DialogResult.Yes)
|
|
|
{
|
|
|
new SaveProjectCommand().Run();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//0、清除事件属性
|
|
|
if (eventWindow != null)
|
|
|
{
|
|
|
eventWindow.PropertyGrid.SelectedObject = null;
|
|
|
eventWindow.CmbControls.Items.Clear();
|
|
|
}
|
|
|
//1、清除动画属性
|
|
|
if (actionWindow != null)
|
|
|
{
|
|
|
actionWindow.PropertyGrid.SelectedObject = null;
|
|
|
actionWindow.CmbControls.Items.Clear();
|
|
|
}
|
|
|
//2、清除属性窗口
|
|
|
if (propertyWindow != null)
|
|
|
{
|
|
|
propertyWindow.PropertyGrid.SelectedObject = null;
|
|
|
propertyWindow.CmbControls.Items.Clear();
|
|
|
}
|
|
|
//3、关闭所有打开的设计画面,并清除画面集合
|
|
|
//foreach(Mesnac.PlugIn.View.IViewContent vc in WorkbenchSingleton.Workbench.ViewContentCollection)
|
|
|
//{
|
|
|
// vc.IsRealClose = true;
|
|
|
//}
|
|
|
WorkbenchSingleton.Workbench.CloseAllViews();
|
|
|
//4、清除工程树
|
|
|
if (projectWindow != null)
|
|
|
{
|
|
|
projectWindow.Tree.Nodes.Clear();
|
|
|
}
|
|
|
//5、清除设备集合
|
|
|
|
|
|
//6、清除工程路径
|
|
|
AppConfigHandler.Instance.FullFileName = String.Empty;
|
|
|
}
|
|
|
/// <summaryre
|
|
|
/// 创建form的名称,根据类型决定
|
|
|
/// </summary>
|
|
|
/// <param name="type"></param>
|
|
|
/// <returns></returns>
|
|
|
public static string CreateFormName(CreateType type)
|
|
|
{
|
|
|
int count = 1;
|
|
|
string text = String.Empty;
|
|
|
ProjectWindow projectWindow = null;
|
|
|
switch (type)
|
|
|
{
|
|
|
case CreateType.Form:
|
|
|
text = "Form" + count.ToString();
|
|
|
projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
if (projectWindow != null)
|
|
|
{
|
|
|
TreeNode nodeForm = projectWindow.Tree.GetFirstNodeByNodeName(FixNodeName.NodeFormName);
|
|
|
bool flag = false;
|
|
|
while (!flag)
|
|
|
{
|
|
|
foreach (TreeNode node in nodeForm.Nodes)
|
|
|
{
|
|
|
if (node.Text == text)
|
|
|
{
|
|
|
flag = true;
|
|
|
}
|
|
|
}
|
|
|
if (flag)
|
|
|
{
|
|
|
count++;
|
|
|
text = "Form" + count.ToString();
|
|
|
flag = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
flag = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return text;
|
|
|
case CreateType.Command:
|
|
|
text = "Command" + count.ToString();
|
|
|
projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
TreeNode nodeAction = projectWindow.Tree.GetFirstNodeByNodeName(FixNodeName.NodeCommandName);
|
|
|
if (nodeAction != null)
|
|
|
{
|
|
|
bool flag = false;
|
|
|
while (!flag)
|
|
|
{
|
|
|
foreach (TreeNode node in nodeAction.Nodes)
|
|
|
{
|
|
|
if (node.Text == text)
|
|
|
{
|
|
|
flag = true;
|
|
|
}
|
|
|
}
|
|
|
if (flag)
|
|
|
{
|
|
|
count++;
|
|
|
text = "Command" + count.ToString();
|
|
|
flag = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
flag = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return text;
|
|
|
default:
|
|
|
return "error";
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 保存节点对应的画面文件
|
|
|
/// </summary>
|
|
|
/// <param name="node"></param>
|
|
|
public static void SaveFormByNode(CreateType ct, TreeNode node)
|
|
|
{
|
|
|
switch (ct)
|
|
|
{
|
|
|
case CreateType.Form: //画面
|
|
|
FrmContainer fc = null;
|
|
|
Mesnac.PlugIn.View.IWorkbenchWindow win = WorkbenchSingleton.Workbench.GetViewByViewContentID(node.Name);
|
|
|
if (win != null)
|
|
|
{
|
|
|
fc = win.ViewContent as FrmContainer;
|
|
|
}
|
|
|
//FrmContainer fc = this._editFormList[node.Name];
|
|
|
if (fc != null)
|
|
|
{
|
|
|
string path = Path.Combine(Path.GetDirectoryName(AppConfigHandler.Instance.FullFileName), node.GetPathNoRoot()) + ".xml";
|
|
|
if (fc.Controls.Count > 0)
|
|
|
{
|
|
|
HostControl currentHostControl = fc.Controls[0] as HostControl;
|
|
|
if (currentHostControl != null)
|
|
|
{
|
|
|
Loader.MesnacHostLoader loder = currentHostControl.HostSurface.Loader as Loader.MesnacHostLoader;
|
|
|
if (loder.IsUnSave)
|
|
|
{
|
|
|
loder.PerformFlushWorker(PublicConfig.Instance.PropertyXmlDoc, PublicConfig.Instance.ActionXmlDoc, PublicConfig.Instance.EventXmlDoc);
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(path)))
|
|
|
{
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
|
|
}
|
|
|
//((Loader.BasicHostLoader)currentHostControl.HostSurface.Loader).Save(path);
|
|
|
((Loader.MesnacHostLoader)currentHostControl.HostSurface.Loader).Save(path, PublicConfig.Instance.PropertyXmlDoc, PublicConfig.Instance.ActionXmlDoc, PublicConfig.Instance.EventXmlDoc);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
case CreateType.Command:
|
|
|
string path1 = Path.Combine(Path.GetDirectoryName(AppConfigHandler.Instance.FullFileName), Mesnac.Basic.FixNodeName.NodeCommandName + ".xml");
|
|
|
if (!Directory.Exists(Path.GetDirectoryName(path1)))
|
|
|
{
|
|
|
Directory.CreateDirectory(Path.GetDirectoryName(path1));
|
|
|
}
|
|
|
if (!File.Exists(path1))
|
|
|
{
|
|
|
string xmlstr = "<Object type=\"ActionFrom\" name=\"Action\" > </Object>";
|
|
|
XmlDocument dom = new XmlDocument();
|
|
|
dom.LoadXml(xmlstr);
|
|
|
dom.Save(path1);
|
|
|
}
|
|
|
break;
|
|
|
case CreateType.Device: //设备
|
|
|
{
|
|
|
Mesnac.Equips.Factory.Instance.SaveConfig();
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取工程数据源文件
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public static string GetProjectDataSourceFile()
|
|
|
{
|
|
|
string fileName = String.Empty;
|
|
|
ProjectWindow projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
if (projectWindow != null)
|
|
|
{
|
|
|
TreeNode node = projectWindow.Tree.GetFirstNodeByNodeName(FixNodeName.NodeDataSourceName);
|
|
|
fileName = Path.Combine(Path.GetDirectoryName(AppConfigHandler.Instance.FullFileName), node.GetPathNoRoot()) + ".xml";
|
|
|
return fileName;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
LoggingService<DisplayUtil<T>>.Debug("获取工程数据源文件失败,原因:工程面板未初始化!");
|
|
|
return String.Empty;
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 重置工程数据源工厂,从文件读取数据
|
|
|
/// </summary>
|
|
|
public static void ResetProjectDataSourceFactory(params CallBackDelegate[] callBack)
|
|
|
{
|
|
|
string fileName = GetProjectDataSourceFile();
|
|
|
if (!String.IsNullOrEmpty(fileName))
|
|
|
{
|
|
|
DataSourceFactory.Instance.RefreshDataFromFile(fileName, callBack);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 保存工程数据源
|
|
|
/// </summary>
|
|
|
public static void SaveProjectDataSource(params CallBackDelegate[] callBack)
|
|
|
{
|
|
|
string fileName = GetProjectDataSourceFile();
|
|
|
if (!String.IsNullOrEmpty(fileName))
|
|
|
{
|
|
|
DataSourceFactory.Instance.RefreshDataToFile(fileName, callBack);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 菜单处理辅助方法
|
|
|
|
|
|
/// <summary>
|
|
|
/// 执行编辑菜单命令函数
|
|
|
/// </summary>
|
|
|
/// <param name="cmd"></param>
|
|
|
public static void PerformAction(CommandID cmd)
|
|
|
{
|
|
|
if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null)
|
|
|
{
|
|
|
LoggingService<DisplayUtil<T>>.Debug("当前画面实例为空!");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null || this.dockPanelMain.ActiveDocument == null)
|
|
|
//{
|
|
|
// LoggingService<DisplayUtil<T>>.Warn("当前画面实例为空!");
|
|
|
// return;
|
|
|
//}
|
|
|
|
|
|
////判断是否有激活的画面设计器
|
|
|
//if (!this.dockPanelMain.ActiveDocument.DockHandler.IsActivated || !(this.dockPanelMain.ActiveDocument.DockHandler.Form is FrmContainer))
|
|
|
//{
|
|
|
// LoggingService<DisplayUtil<T>>.Warn("没有活动画面!");
|
|
|
// return;
|
|
|
//}
|
|
|
|
|
|
|
|
|
IMenuCommandService ims = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService;
|
|
|
try
|
|
|
{
|
|
|
ims.GlobalInvoke(cmd);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LoggingService<DisplayUtil<T>>.Error(ex.Message + "\r\n" + ex.StackTrace);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 文件菜单处理
|
|
|
|
|
|
#region 新建工程
|
|
|
|
|
|
/// <summary>
|
|
|
/// 新建工程
|
|
|
/// </summary>
|
|
|
public class NewProjectCommand : AbstractCommand
|
|
|
{
|
|
|
private ProjectWindow _projectWindow = null;
|
|
|
|
|
|
public override void Run()
|
|
|
{
|
|
|
this._projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
if (this._projectWindow != null)
|
|
|
{
|
|
|
FrmNewProject frmPrj = new FrmNewProject();
|
|
|
DialogResult result = frmPrj.ShowDialog(WorkbenchSingleton.MainForm);
|
|
|
if (result == DialogResult.OK)
|
|
|
{
|
|
|
//new SaveProjectCommand().Run(); //先保存工程
|
|
|
DisplayUtil<ProjectWindow>.ClearProject(); //清除工程
|
|
|
AppConfigHandler.Instance.FullFileName = frmPrj.FullFileName;
|
|
|
bool isLoad = frmPrj.IsLoad;
|
|
|
if (isLoad)
|
|
|
{
|
|
|
this._projectWindow.Tree.LoadFromXml(AppConfigHandler.Instance.FullFileName);
|
|
|
this._projectWindow.RedrawContent(); //重绘
|
|
|
AppConfigHandler.Instance.CurrentProjectWizardName = this._projectWindow.Tree.Nodes[0].Tag as string; //保存过工程类型名称
|
|
|
TreeNode tnDeviceName = this._projectWindow.Tree.GetFirstNodeByNodeName(FixNodeName.NodeDeviceName);
|
|
|
Mesnac.Equips.Factory.Instance.ProjectWizardName = AppConfigHandler.Instance.CurrentProjectWizardName; //为设备接口设置工程模板名称
|
|
|
Mesnac.Equips.Factory.Instance.ConfigFile = Path.Combine(Path.GetDirectoryName(AppConfigHandler.Instance.FullFileName), tnDeviceName.GetPathNoRoot()) + ".xml";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Mesnac.Equips.Factory.Instance.ProjectWizardName = AppConfigHandler.Instance.CurrentProjectWizardName; //为设备接口设置工程模板名称
|
|
|
this._projectWindow.GenerateProjectTree(AppConfigHandler.Instance.FullFileName);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 打开工程
|
|
|
/// <summary>
|
|
|
/// 打开工程
|
|
|
/// </summary>
|
|
|
public class OpenProjectCommand : AbstractCommand
|
|
|
{
|
|
|
private ProjectWindow _projectWindow = null;
|
|
|
|
|
|
public OpenProjectCommand()
|
|
|
{
|
|
|
this._projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
}
|
|
|
|
|
|
|
|
|
public override void Run()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
|
|
openFileDialog.Filter = "*.mprj|*.mprj";
|
|
|
DialogResult result = openFileDialog.ShowDialog(WorkbenchSingleton.MainForm);
|
|
|
if (result == DialogResult.OK)
|
|
|
{
|
|
|
new SaveProjectCommand().Run(); //先保存工程
|
|
|
DisplayUtil<ProjectWindow>.ClearProject(); //清除工程
|
|
|
AppConfigHandler.Instance.FullFileName = openFileDialog.FileName;
|
|
|
this._projectWindow.Tree.LoadFromXml(AppConfigHandler.Instance.FullFileName); //初始化工程树
|
|
|
this._projectWindow.RedrawContent(); //重绘
|
|
|
if (this._projectWindow.Tree.Nodes != null && this._projectWindow.Tree.Nodes.Count > 0)
|
|
|
{
|
|
|
this._projectWindow.Tree.SelectedNode = this._projectWindow.Tree.Nodes[0];
|
|
|
}
|
|
|
AppConfigHandler.Instance.CurrentProjectWizardName = this._projectWindow.Tree.Nodes[0].Tag as string; //保存过工程类型名称
|
|
|
TreeNode tnDeviceName = this._projectWindow.Tree.GetFirstNodeByNodeName(FixNodeName.NodeDeviceName);
|
|
|
if (tnDeviceName != null)
|
|
|
{
|
|
|
string deviceFile = Path.Combine(Path.GetDirectoryName(AppConfigHandler.Instance.FullFileName), tnDeviceName.GetPathNoRoot()) + ".xml";
|
|
|
Mesnac.Equips.Factory.Instance.ProjectWizardName = AppConfigHandler.Instance.CurrentProjectWizardName; //为设备接口设置工程模板名称
|
|
|
Mesnac.Equips.Factory.Instance.ConfigFile = deviceFile; //为设备接口设置设备配置文件完整路径
|
|
|
}
|
|
|
DisplayUtil<ProjectWindow>.ResetProjectDataSourceFactory(); //刷新数据源工厂
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LoggingService<OpenProjectCommand>.Error(ex.Message + "\r\n" + ex.StackTrace);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 保存工程
|
|
|
/// <summary>
|
|
|
/// 保存工程类
|
|
|
/// </summary>
|
|
|
public class SaveProjectCommand : AbstractCommand
|
|
|
{
|
|
|
private ProjectWindow _projectWindow = null;
|
|
|
|
|
|
public SaveProjectCommand()
|
|
|
{
|
|
|
this._projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
}
|
|
|
|
|
|
public override void Run()
|
|
|
{
|
|
|
TreeNode[] parentNode = null;
|
|
|
//保存画面
|
|
|
parentNode = this._projectWindow.Tree.Nodes.Find(FixNodeName.NodeFormName, true);
|
|
|
if (parentNode != null && parentNode.Length == 1)
|
|
|
{
|
|
|
foreach (TreeNode tn in parentNode[0].Nodes)
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.SaveFormByNode(CreateType.Form, tn);
|
|
|
}
|
|
|
}
|
|
|
//保存设备
|
|
|
|
|
|
Mesnac.Equips.Factory.Instance.SaveConfig();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 关闭工程
|
|
|
/// <summary>
|
|
|
/// 关闭工程类
|
|
|
/// </summary>
|
|
|
public class CloseProjectCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.ClearProject();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 新建画面
|
|
|
/// <summary>
|
|
|
/// 新建画面
|
|
|
/// </summary>
|
|
|
public class NewFormCommand : AbstractCommand
|
|
|
{
|
|
|
private string[] fileNames;
|
|
|
private ProjectWindow _projectWindow;
|
|
|
private PropertyWindow _propertyWindow;
|
|
|
private ActionWindow _actionWindow;
|
|
|
private EventWindow _eventWindow;
|
|
|
private bool _ShouldUpdateSelectableObjects = false;
|
|
|
private string _resultFileName;
|
|
|
|
|
|
public NewFormCommand()
|
|
|
{
|
|
|
this._projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
this._propertyWindow = DisplayUtil<PropertyWindow>.PadInstance;
|
|
|
this._actionWindow = DisplayUtil<ActionWindow>.PadInstance;
|
|
|
this._eventWindow = DisplayUtil<EventWindow>.PadInstance;
|
|
|
}
|
|
|
|
|
|
public NewFormCommand(params string[] fileNames)
|
|
|
{
|
|
|
this.fileNames = fileNames;
|
|
|
this._projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
this._propertyWindow = DisplayUtil<PropertyWindow>.PadInstance;
|
|
|
this._actionWindow = DisplayUtil<ActionWindow>.PadInstance;
|
|
|
this._eventWindow = DisplayUtil<EventWindow>.PadInstance;
|
|
|
}
|
|
|
|
|
|
public override void Run()
|
|
|
{
|
|
|
if (this.fileNames == null || this.fileNames.Length == 0)
|
|
|
{
|
|
|
this._resultFileName = this.CreateNewForm();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
this._resultFileName = this.CreateNewForm(this.fileNames);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public string ResultFileName
|
|
|
{
|
|
|
get { return this._resultFileName; }
|
|
|
}
|
|
|
|
|
|
#region 新建画面宿设计器
|
|
|
|
|
|
/// <summary>
|
|
|
/// 新建、载入画面
|
|
|
/// </summary>
|
|
|
/// <param name="fileNames">要载入的画面的文件名</param>
|
|
|
/// <returns>返回新建或载入的画面的文件名</returns>
|
|
|
public string CreateNewForm(params string[] fileNames)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
#region 画面初始化
|
|
|
|
|
|
bool isNew = true; //是否是新建画面,true为新建,false为加载
|
|
|
|
|
|
string frmName = DisplayUtil<ProjectWindow>.CreateFormName(CreateType.Form); //获取画面文件名称
|
|
|
string nodeText = String.Empty; //获取画面节点名称
|
|
|
HostControl hc = null;
|
|
|
if (fileNames != null && fileNames.Length > 0)
|
|
|
{
|
|
|
isNew = false;
|
|
|
frmName = Path.GetFileNameWithoutExtension(fileNames[0]);
|
|
|
hc = MesnacServiceManager.Instance.HostSurfaceManager.LoadNewHost(fileNames[0]);
|
|
|
TreeNode currNode = this._projectWindow.Tree.GetFirstNodeByNodeName(frmName);
|
|
|
if (currNode != null)
|
|
|
{
|
|
|
nodeText = currNode.Text;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
nodeText = frmName;
|
|
|
}
|
|
|
}
|
|
|
if (isNew)
|
|
|
{
|
|
|
//如果是新建则弹出新建文件对话框
|
|
|
FrmNew frmNew = new FrmNew(frmName, CreateType.Form);
|
|
|
DialogResult result = frmNew.ShowDialog(WorkbenchSingleton.MainForm);
|
|
|
if (result == DialogResult.Cancel)
|
|
|
{
|
|
|
return String.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
frmName = frmNew.FileName;
|
|
|
nodeText = String.IsNullOrEmpty(frmNew.NodeName) ? frmName : frmNew.NodeName;
|
|
|
//hc = MesnacServiceManager.Instance.HostSurfaceManager.GetNewHost(typeof(Form), LoaderType.BasicDesignerLoader, frmName);
|
|
|
hc = MesnacServiceManager.Instance.HostSurfaceManager.GetNewHost(typeof(FrmRunTemplate), LoaderType.BasicDesignerLoader, frmName);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#region 初始化设计器画面窗体名称
|
|
|
|
|
|
if (isNew)
|
|
|
{
|
|
|
((Form)hc.DesignerHost.RootComponent).Text = nodeText;
|
|
|
}
|
|
|
//((Form)hc.DesignerHost.RootComponent).BackColor = Color.FromArgb(39, 72, 98); //设置默认底色
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
//新建容器窗口
|
|
|
FrmContainer fc = new FrmContainer();
|
|
|
fc.Name = frmName;
|
|
|
fc.TitleName = nodeText;
|
|
|
fc.ViewContentID = frmName; //用于在ViewContent集合中查找
|
|
|
hc.Dock = DockStyle.Fill;
|
|
|
hc.Parent = fc;
|
|
|
fc.IsRealClose = false;
|
|
|
fc.FormClosing += new FormClosingEventHandler(fc_FormClosing);
|
|
|
MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface = hc.HostSurface;
|
|
|
hc.HostSurface._selectionService.SelectionChanged += new EventHandler(FormDesignerHelper._selectionService_SelectionChanged);
|
|
|
MesnacServiceManager.Instance.Host = (System.ComponentModel.Design.IDesignerHost)MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(System.ComponentModel.Design.IDesignerHost));
|
|
|
this._propertyWindow.PropertyGrid.Site = (new Mesnac.Core.Service.IDEContainer(MesnacServiceManager.Instance.Host)).CreateSite(this._propertyWindow.PropertyGrid);
|
|
|
this._actionWindow.PropertyGrid.Site = (new Mesnac.Core.Service.IDEContainer(MesnacServiceManager.Instance.Host)).CreateSite(this._actionWindow.PropertyGrid);
|
|
|
this._eventWindow.PropertyGrid.Site = (new Mesnac.Core.Service.IDEContainer(MesnacServiceManager.Instance.Host)).CreateSite(this._eventWindow.PropertyGrid);
|
|
|
|
|
|
WorkbenchSingleton.Workbench.ShowView(fc, true);
|
|
|
|
|
|
if (fc.MyOwner != null)
|
|
|
{
|
|
|
(fc.MyOwner as Form).Activated += new EventHandler(fc_Activated);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
fc.Activated += new EventHandler(fc_Activated);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 设计器及设计器中组件的事件处理
|
|
|
|
|
|
// 增/删/重命名组件的事件
|
|
|
System.ComponentModel.Design.IComponentChangeService componentChangeService = (System.ComponentModel.Design.IComponentChangeService)MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(System.ComponentModel.Design.IComponentChangeService));
|
|
|
componentChangeService.ComponentAdded += ComponentListChanged;
|
|
|
componentChangeService.ComponentRemoved += ComponentListChanged;
|
|
|
componentChangeService.ComponentRename += ComponentListChanged;
|
|
|
MesnacServiceManager.Instance.Host.TransactionClosed += new System.ComponentModel.Design.DesignerTransactionCloseEventHandler(TransactionClosed);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
this.InitPropertyWindow(); //初始化各属性窗口组合框
|
|
|
|
|
|
if (isNew)
|
|
|
{
|
|
|
this.RefereshProjectTree(CreateType.Form, frmName, nodeText);
|
|
|
}
|
|
|
|
|
|
return frmName;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
MessageBox.Show("新建设计画面错误\n" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
return String.Empty;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 创建命令
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public string CreateActionFrm()
|
|
|
{
|
|
|
bool isNew = true; //新建
|
|
|
string frmName = DisplayUtil<ProjectWindow>.CreateFormName(CreateType.Command); //获取命令名称
|
|
|
if (isNew)
|
|
|
{
|
|
|
//如果是新建则弹出新建文件对话框
|
|
|
FrmNew frmNew = new FrmNew(frmName, CreateType.Command);
|
|
|
DialogResult result = frmNew.ShowDialog(WorkbenchSingleton.MainForm);
|
|
|
if (result == DialogResult.Cancel)
|
|
|
{
|
|
|
return String.Empty;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
frmName = frmNew.FileName;
|
|
|
}
|
|
|
}
|
|
|
//保存工程树文件
|
|
|
if (isNew)
|
|
|
{
|
|
|
this.RefereshProjectTree(CreateType.Command, frmName, frmName);
|
|
|
}
|
|
|
return frmName;
|
|
|
}
|
|
|
|
|
|
void hc_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
|
|
|
{
|
|
|
MessageBox.Show(e.KeyValue.ToString());
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 新建画面时,初始化画面窗口的属性
|
|
|
/// </summary>
|
|
|
private void InitPropertyWindow()
|
|
|
{
|
|
|
if (MesnacServiceManager.Instance.Host != null)
|
|
|
{
|
|
|
FormDesignerHelper.UpdateComboBox();
|
|
|
FormDesignerHelper.SelectedObjectsChanged();
|
|
|
System.ComponentModel.Design.ISelectionService ss = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(System.ComponentModel.Design.ISelectionService)) as System.ComponentModel.Design.ISelectionService;
|
|
|
FormDesignerHelper.RefreshComponentProperties(ss);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 刷新工程树
|
|
|
/// </summary>
|
|
|
/// <param name="frmName">画面文件名</param>
|
|
|
private void RefereshProjectTree(CreateType ct ,string frmName, string nodeName)
|
|
|
{
|
|
|
TreeNode currentNode = this._projectWindow.Tree.SelectedNode;
|
|
|
if (currentNode != null)
|
|
|
{
|
|
|
TreeNode node = new TreeNode();
|
|
|
node.Name = frmName;
|
|
|
node.Text = nodeName;
|
|
|
node.ToolTipText = frmName;
|
|
|
node.Tag = frmName;
|
|
|
switch (ct)
|
|
|
{
|
|
|
case CreateType.Form:
|
|
|
node.ImageIndex = 3;
|
|
|
node.SelectedImageIndex = 3;
|
|
|
break;
|
|
|
case CreateType.Command:
|
|
|
node.ImageIndex = 4;
|
|
|
node.SelectedImageIndex = 4;
|
|
|
node.ToolTipText = CreateType.Command.ToString();
|
|
|
break;
|
|
|
case CreateType.Device:
|
|
|
node.ImageIndex = 5;
|
|
|
node.SelectedImageIndex = 5;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
currentNode.Nodes.Add(node);
|
|
|
currentNode.Expand();
|
|
|
//保存工程树文件
|
|
|
this._projectWindow.Tree.SaveToXml(AppConfigHandler.Instance.FullFileName);
|
|
|
//保存文件
|
|
|
DisplayUtil<ProjectWindow>.SaveFormByNode(ct, node);
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 在激活某个设计器时,重新设置设置宿主主机的活动设计面
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void fc_Activated(object sender, EventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FrmContainer fc = null;
|
|
|
if (sender is WorkspaceWindow)
|
|
|
{
|
|
|
fc = (sender as WorkspaceWindow).ActiveViewContent as FrmContainer;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
fc = sender as FrmContainer;
|
|
|
}
|
|
|
HostControl hc = fc.Controls[0] as HostControl;
|
|
|
MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface = hc.HostSurface;
|
|
|
MesnacServiceManager.Instance.Host = (System.ComponentModel.Design.IDesignerHost)MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(System.ComponentModel.Design.IDesignerHost));
|
|
|
WorkbenchSingleton.Workbench.CurrentViewContent = fc;
|
|
|
this.InitPropertyWindow();
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService<NewFormCommand>.Error(ex.Message, ex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 宿主设计器中的组件列表发生变化时的事件处理程序(向设计器中增加组件、删除设计器中组件时的处理程序)
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void ComponentListChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
//设置更新选中对象标志为true
|
|
|
_ShouldUpdateSelectableObjects = true;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 宿主设计器中的每个事务操作结束时的处理程序
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void TransactionClosed(object sender, System.ComponentModel.Design.DesignerTransactionCloseEventArgs e)
|
|
|
{
|
|
|
if (_ShouldUpdateSelectableObjects)
|
|
|
{
|
|
|
FormDesignerHelper.UpdateComboBox(); //更新组合框控件列表
|
|
|
_ShouldUpdateSelectableObjects = false; //设置更新选中对象标志为false
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 关闭某个设计器是自动保存设计画面
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void fc_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
{
|
|
|
FrmContainer fc = sender as FrmContainer;
|
|
|
TreeNode[] nodes = this._projectWindow.Tree.Nodes.Find(fc.Name, true);
|
|
|
if (nodes != null && nodes.Length > 0)
|
|
|
{
|
|
|
//关闭宿主设计器时,保存画面
|
|
|
DisplayUtil<ProjectWindow>.SaveFormByNode(CreateType.Form, nodes[0]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 退出应用程序
|
|
|
/// <summary>
|
|
|
/// 退出应用程序
|
|
|
/// </summary>
|
|
|
public class ExitCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
//1、先清除工程
|
|
|
DisplayUtil<ProjectWindow>.ClearProject();
|
|
|
|
|
|
//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)
|
|
|
//{
|
|
|
// WorkbenchSingleton.Workbench.CloseFlag = true; //设置系统关闭标识
|
|
|
// (WorkbenchSingleton.Workbench as System.Windows.Forms.Form).Close();
|
|
|
//}
|
|
|
|
|
|
WorkbenchSingleton.Workbench.CloseFlag = false; //设置系统关闭标识
|
|
|
(WorkbenchSingleton.Workbench as System.Windows.Forms.Form).Close();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 编辑菜单处理
|
|
|
|
|
|
#region 撤销
|
|
|
/// <summary>
|
|
|
/// 插销
|
|
|
/// </summary>
|
|
|
public class UndoCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null)
|
|
|
{
|
|
|
LoggingService<UndoCommand>.Warn("当前画面实例为空!");
|
|
|
return;
|
|
|
}
|
|
|
UndoEngineExt ims = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(UndoEngine)) as UndoEngineExt;
|
|
|
ims.Undo();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 重做
|
|
|
/// <summary>
|
|
|
/// 重做
|
|
|
/// </summary>
|
|
|
public class RedoCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null)
|
|
|
{
|
|
|
LoggingService<RedoCommand>.Warn("当前画面实例为空!");
|
|
|
return;
|
|
|
}
|
|
|
UndoEngineExt ims = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(UndoEngine)) as UndoEngineExt;
|
|
|
ims.Redo();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 剪切
|
|
|
/// <summary>
|
|
|
/// 剪切
|
|
|
/// </summary>
|
|
|
public class CutCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.Cut);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 复制
|
|
|
/// <summary>
|
|
|
/// 复制
|
|
|
/// </summary>
|
|
|
public class CopyCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.Copy);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 粘贴
|
|
|
/// <summary>
|
|
|
/// 粘贴
|
|
|
/// </summary>
|
|
|
public class PasteCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.Paste);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 删除
|
|
|
/// <summary>
|
|
|
/// 删除
|
|
|
/// </summary>
|
|
|
public class DeleteCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.Delete);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 全选
|
|
|
/// <summary>
|
|
|
/// 全选
|
|
|
/// </summary>
|
|
|
public class SelectAllCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.SelectAll);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
#endregion
|
|
|
|
|
|
#region 视图菜单处理
|
|
|
|
|
|
#region 解决方案资源管理器
|
|
|
/// <summary>
|
|
|
/// 解决方案资源管理器
|
|
|
/// </summary>
|
|
|
public class SolutionWindowCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
Mesnac.PlugIn.Pad.PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(Mesnac.Gui.Edit.Pad.ProjectWindow));
|
|
|
if (pd != null)
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.ShowPad(pd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 属性窗口
|
|
|
/// <summary>
|
|
|
/// 属性窗口
|
|
|
/// </summary>
|
|
|
public class PropertyWindowCommand : AbstractCommand
|
|
|
{
|
|
|
|
|
|
public override void Run()
|
|
|
{
|
|
|
Mesnac.PlugIn.Pad.PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(Mesnac.Gui.Edit.Pad.PropertyWindow));
|
|
|
if (pd != null)
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.ShowPad(pd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 工具箱
|
|
|
/// <summary>
|
|
|
/// 工具箱
|
|
|
/// </summary>
|
|
|
public class ToolBoxWindowCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
Mesnac.PlugIn.Pad.PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(Mesnac.Gui.Edit.Pad.ToolBoxWindow));
|
|
|
if (pd != null)
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.ShowPad(pd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 动画窗口
|
|
|
/// <summary>
|
|
|
/// 动画窗口
|
|
|
/// </summary>
|
|
|
public class ActionWindowCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
Mesnac.PlugIn.Pad.PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(Mesnac.Gui.Edit.Pad.ActionWindow));
|
|
|
if (pd != null)
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.ShowPad(pd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 事件窗口
|
|
|
/// <summary>
|
|
|
/// 事件窗口
|
|
|
/// </summary>
|
|
|
public class EventWindowCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
Mesnac.PlugIn.Pad.PadDescriptor pd = WorkbenchSingleton.Workbench.GetPad(typeof(Mesnac.Gui.Edit.Pad.EventWindow));
|
|
|
if (pd != null)
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.ShowPad(pd);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 布局菜单处理
|
|
|
|
|
|
#region 对齐到网格
|
|
|
/// <summary>
|
|
|
/// 对齐到网格
|
|
|
/// </summary>
|
|
|
public class AlignToGridCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.AlignToGrid);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 左对齐
|
|
|
/// <summary>
|
|
|
/// 左对齐
|
|
|
/// </summary>
|
|
|
public class AlignLeftCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.AlignLeft);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 居中对齐
|
|
|
/// <summary>
|
|
|
/// 居中对齐
|
|
|
/// </summary>
|
|
|
public class AlignHorizontalCentersCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.AlignHorizontalCenters);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 右对齐
|
|
|
/// <summary>
|
|
|
/// 右对齐
|
|
|
/// </summary>
|
|
|
public class AlignRightCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.AlignRight);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 顶端对齐
|
|
|
/// <summary>
|
|
|
/// 顶端对齐
|
|
|
/// </summary>
|
|
|
public class AlignTopCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.AlignTop);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 中间对齐
|
|
|
/// <summary>
|
|
|
/// 中间对齐
|
|
|
/// </summary>
|
|
|
public class AlignVerticalCentersCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.AlignVerticalCenters);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 底部对齐
|
|
|
/// <summary>
|
|
|
/// 底部对齐
|
|
|
/// </summary>
|
|
|
public class AlignBottomCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.AlignBottom);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 使宽度相同
|
|
|
/// <summary>
|
|
|
/// 使宽度相同
|
|
|
/// </summary>
|
|
|
public class SizeToControlWidthCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.SizeToControlWidth);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 使高度相同
|
|
|
/// <summary>
|
|
|
/// 使高度相同
|
|
|
/// </summary>
|
|
|
public class SizeToControlHeightCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.SizeToControlHeight);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 使大小相同
|
|
|
/// <summary>
|
|
|
/// 使大小相同
|
|
|
/// </summary>
|
|
|
public class SizeToControlCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.SizeToControl);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 按网格调整大小
|
|
|
/// <summary>
|
|
|
/// 按网格调整大小
|
|
|
/// </summary>
|
|
|
public class SizeToGridCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.SizeToGrid);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 使水平间距相等
|
|
|
/// <summary>
|
|
|
/// 使水平间距相等
|
|
|
/// </summary>
|
|
|
public class HorizSpaceMakeEqualCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.HorizSpaceMakeEqual);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 增加水平间距
|
|
|
/// <summary>
|
|
|
/// 增加水平间距
|
|
|
/// </summary>
|
|
|
public class HorizSpaceIncreaseCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.HorizSpaceIncrease);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 减小水平间距
|
|
|
/// <summary>
|
|
|
/// 减小水平间距
|
|
|
/// </summary>
|
|
|
public class HorizSpaceDecreaseCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.HorizSpaceDecrease);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 移除水平间距
|
|
|
/// <summary>
|
|
|
/// 移除水平间距
|
|
|
/// </summary>
|
|
|
public class HorizSpaceConcatenateCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.HorizSpaceConcatenate);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 使垂直间距相等
|
|
|
/// <summary>
|
|
|
/// 使垂直间距相等
|
|
|
/// </summary>
|
|
|
public class VertSpaceMakeEqualCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.VertSpaceMakeEqual);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 增加垂直间距
|
|
|
/// <summary>
|
|
|
/// 增加垂直间距
|
|
|
/// </summary>
|
|
|
public class VertSpaceIncreaseCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.VertSpaceIncrease);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 减小垂直间距
|
|
|
/// <summary>
|
|
|
/// 减小垂直间距
|
|
|
/// </summary>
|
|
|
public class VertSpaceDecreaseCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.VertSpaceDecrease);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 取消垂直间距
|
|
|
/// <summary>
|
|
|
/// 取消垂直间距
|
|
|
/// </summary>
|
|
|
public class VertSpaceConcatenateCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.VertSpaceConcatenate);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 水平居中
|
|
|
/// <summary>
|
|
|
/// 水平居中
|
|
|
/// </summary>
|
|
|
public class CenterHorizontallyCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.CenterHorizontally);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 垂直居中
|
|
|
/// <summary>
|
|
|
/// 垂直居中
|
|
|
/// </summary>
|
|
|
public class CenterVerticallyCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.CenterVertically);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 置于顶层
|
|
|
/// <summary>
|
|
|
/// 置于顶层
|
|
|
/// </summary>
|
|
|
public class BringToFrontCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.BringToFront);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 置于底层
|
|
|
/// <summary>
|
|
|
/// 置于底层
|
|
|
/// </summary>
|
|
|
public class SendToBackCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.SendToBack);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 前移一层
|
|
|
/// <summary>
|
|
|
/// 前移一层
|
|
|
/// </summary>
|
|
|
public class BringForwardCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.BringForward);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 后移一层
|
|
|
/// <summary>
|
|
|
/// 后移一层
|
|
|
/// </summary>
|
|
|
public class SendBackwardCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
DisplayUtil<ProjectWindow>.PerformAction(StandardCommands.SendBackward);
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 全屏切换
|
|
|
/// <summary>
|
|
|
/// 全屏切换
|
|
|
/// </summary>
|
|
|
public class ToggleFullscreenCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
WorkbenchSingleton.Workbench.FullScreen = !WorkbenchSingleton.Workbench.FullScreen;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 菜单、工具栏按钮启用、禁用操作
|
|
|
|
|
|
#region 工程保存、关闭
|
|
|
/// <summary>
|
|
|
/// 工程保存、关闭
|
|
|
/// </summary>
|
|
|
public class MCEditProjectStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object caller, Condition condition)
|
|
|
{
|
|
|
if (DisplayUtil<ProjectWindow>.PadInstance != null && DisplayUtil<ProjectWindow>.PadInstance.Tree.Nodes.Count == 0)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 编辑菜单
|
|
|
/// <summary>
|
|
|
/// 编辑菜单
|
|
|
/// </summary>
|
|
|
public class MCEditEditStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
if (DisplayUtil<ProjectWindow>.PadInstance != null && DisplayUtil<ProjectWindow>.PadInstance.Tree.Nodes.Count == 0 || MesnacServiceManager.Instance.Host == null)
|
|
|
{
|
|
|
//没有工程 禁用编辑
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 撤销、重做、仿真
|
|
|
/// <summary>
|
|
|
/// 仿真
|
|
|
/// </summary>
|
|
|
public class MCEditDesignerExistsStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
WorkspaceWindow window = WorkbenchSingleton.Workbench.ActiveContent as WorkspaceWindow;
|
|
|
if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface != null && window != null && window.ViewContent is FrmContainer)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 撤销
|
|
|
/// </summary>
|
|
|
public class MCEditUndoStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
UndoEngineExt ims = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(UndoEngine)) as UndoEngineExt;
|
|
|
if (ims.EnableUndo)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 重做
|
|
|
/// </summary>
|
|
|
public class MCEditRedoStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
UndoEngineExt ims = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(UndoEngine)) as UndoEngineExt;
|
|
|
if (ims.EnableRedo)
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 工程面板
|
|
|
/// <summary>
|
|
|
/// 工程面板
|
|
|
/// </summary>
|
|
|
public class MCEditProjectWindowStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
ProjectWindow projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
if (projectWindow != null && projectWindow.Visible)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 工具箱
|
|
|
/// <summary>
|
|
|
/// 工具箱
|
|
|
/// </summary>
|
|
|
public class MCEditToolBoxWindowStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
ToolBoxWindow toolBoxWindow = DisplayUtil<ToolBoxWindow>.PadInstance;
|
|
|
if (toolBoxWindow != null && toolBoxWindow.Visible)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 属性面板
|
|
|
/// <summary>
|
|
|
/// 属性面板
|
|
|
/// </summary>
|
|
|
public class MCEditPropertyWindowStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
PropertyWindow propertyWindow = DisplayUtil<PropertyWindow>.PadInstance;
|
|
|
if (propertyWindow != null && propertyWindow.Visible)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 动画面板
|
|
|
/// <summary>
|
|
|
/// 动画面板
|
|
|
/// </summary>
|
|
|
public class MCEditActionWindowStateConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
ActionWindow actionWindow = DisplayUtil<ActionWindow>.PadInstance;
|
|
|
if (actionWindow != null && actionWindow.Visible)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 布局
|
|
|
/// <summary>
|
|
|
/// 布局,未选中任何控件
|
|
|
/// </summary>
|
|
|
public class MCEditLayoutEmptyConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
object[] selectedcomp = FormDesignerHelper.GetSelectComponents();
|
|
|
if (selectedcomp == null || selectedcomp.Length > 0 && selectedcomp[0] is System.Windows.Forms.Form)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 布局,设计器中只有一个组件
|
|
|
/// </summary>
|
|
|
public class MCEditLayoutOnlyOneConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
ComponentCollection allComponents = FormDesignerHelper.GetAllComponents();
|
|
|
object[] selectedcomp = FormDesignerHelper.GetSelectComponents();
|
|
|
if (allComponents != null && allComponents.Count == 2 && selectedcomp != null && selectedcomp.Length > 0 && !(selectedcomp[0] is System.Windows.Forms.Form))
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 布局,只选中一个控件
|
|
|
/// </summary>
|
|
|
public class MCEditLayoutSelectOneConditionEvaluator : IConditionEvaluator
|
|
|
{
|
|
|
public bool IsValid(object owner, Condition condition)
|
|
|
{
|
|
|
ComponentCollection allComponents = FormDesignerHelper.GetAllComponents();
|
|
|
object[] selectedcomp = FormDesignerHelper.GetSelectComponents();
|
|
|
if (allComponents != null && allComponents.Count > 2 && selectedcomp != null && selectedcomp.Length <= 1)
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 运行仿真
|
|
|
/// <summary>
|
|
|
/// 运行方针
|
|
|
/// </summary>
|
|
|
public class RunCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
if (WorkbenchSingleton.Workbench.ActiveContent is WorkspaceWindow)
|
|
|
{
|
|
|
WorkspaceWindow window = WorkbenchSingleton.Workbench.ActiveContent as WorkspaceWindow;
|
|
|
if (window.ActiveViewContent is FrmContainer)
|
|
|
{
|
|
|
FrmContainer frm = window.ActiveViewContent as FrmContainer;
|
|
|
ProjectWindow projectWindow = DisplayUtil<ProjectWindow>.PadInstance;
|
|
|
if (projectWindow != null)
|
|
|
{
|
|
|
TreeNode currNode = projectWindow.Tree.GetFirstNodeByNodeName(frm.Name);
|
|
|
if (currNode != null)
|
|
|
{
|
|
|
projectWindow.Tree.SelectedNode = currNode;
|
|
|
projectWindow.RunSimulation();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 语言菜单处理
|
|
|
|
|
|
#region 中文
|
|
|
|
|
|
public class ChineseCommand : AbstractCommand
|
|
|
{
|
|
|
|
|
|
public override void Run()
|
|
|
{
|
|
|
LanguageHelper.SetCurrentCultureInfo("zh-CN");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 英文
|
|
|
|
|
|
public class EnglishCommand : AbstractCommand
|
|
|
{
|
|
|
|
|
|
public override void Run()
|
|
|
{
|
|
|
LanguageHelper.SetCurrentCultureInfo("en-US");
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 测试
|
|
|
/// <summary>
|
|
|
/// 测试
|
|
|
/// </summary>
|
|
|
public class TestCommand : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 报表设计器
|
|
|
|
|
|
public class ReportDesigner : AbstractCommand
|
|
|
{
|
|
|
public override void Run()
|
|
|
{
|
|
|
//ReportDesiger rd = new ReportDesiger();
|
|
|
//rd.Show();
|
|
|
FastReport.Report report = new FastReport.Report();
|
|
|
report.Design();
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
}
|