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 显示辅助类 /// /// 显示辅助类,保存通用方法和变量 /// /// public class DisplayUtil { #region 面板处理辅助方法 /// /// 获取面板实例 /// 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 工程处理辅助方法 /// /// 清除工程 /// public static void ClearProject() { //清除仿真画面 Mesnac.Gui.Common.RunEngine.Instance.CloseAllForms(); ProjectWindow projectWindow = DisplayUtil.PadInstance; PropertyWindow propertyWindow = DisplayUtil.PadInstance; ActionWindow actionWindow = DisplayUtil.PadInstance; EventWindow eventWindow = DisplayUtil.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; } /// /// /// 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.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.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"; } } /// /// 保存节点对应的画面文件 /// /// 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 = " "; XmlDocument dom = new XmlDocument(); dom.LoadXml(xmlstr); dom.Save(path1); } break; case CreateType.Device: //设备 { Mesnac.Equips.Factory.Instance.SaveConfig(); } break; } } /// /// 获取工程数据源文件 /// /// public static string GetProjectDataSourceFile() { string fileName = String.Empty; ProjectWindow projectWindow = DisplayUtil.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>.Debug("获取工程数据源文件失败,原因:工程面板未初始化!"); return String.Empty; } } /// /// 重置工程数据源工厂,从文件读取数据 /// public static void ResetProjectDataSourceFactory(params CallBackDelegate[] callBack) { string fileName = GetProjectDataSourceFile(); if (!String.IsNullOrEmpty(fileName)) { DataSourceFactory.Instance.RefreshDataFromFile(fileName, callBack); } } /// /// 保存工程数据源 /// public static void SaveProjectDataSource(params CallBackDelegate[] callBack) { string fileName = GetProjectDataSourceFile(); if (!String.IsNullOrEmpty(fileName)) { DataSourceFactory.Instance.RefreshDataToFile(fileName, callBack); } } #endregion #region 菜单处理辅助方法 /// /// 执行编辑菜单命令函数 /// /// public static void PerformAction(CommandID cmd) { if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null) { LoggingService>.Debug("当前画面实例为空!"); return; } //if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null || this.dockPanelMain.ActiveDocument == null) //{ // LoggingService>.Warn("当前画面实例为空!"); // return; //} ////判断是否有激活的画面设计器 //if (!this.dockPanelMain.ActiveDocument.DockHandler.IsActivated || !(this.dockPanelMain.ActiveDocument.DockHandler.Form is FrmContainer)) //{ // LoggingService>.Warn("没有活动画面!"); // return; //} IMenuCommandService ims = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(IMenuCommandService)) as IMenuCommandService; try { ims.GlobalInvoke(cmd); } catch (Exception ex) { LoggingService>.Error(ex.Message + "\r\n" + ex.StackTrace); } } #endregion } #endregion #region 文件菜单处理 #region 新建工程 /// /// 新建工程 /// public class NewProjectCommand : AbstractCommand { private ProjectWindow _projectWindow = null; public override void Run() { this._projectWindow = DisplayUtil.PadInstance; if (this._projectWindow != null) { FrmNewProject frmPrj = new FrmNewProject(); DialogResult result = frmPrj.ShowDialog(WorkbenchSingleton.MainForm); if (result == DialogResult.OK) { //new SaveProjectCommand().Run(); //先保存工程 DisplayUtil.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 打开工程 /// /// 打开工程 /// public class OpenProjectCommand : AbstractCommand { private ProjectWindow _projectWindow = null; public OpenProjectCommand() { this._projectWindow = DisplayUtil.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.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.ResetProjectDataSourceFactory(); //刷新数据源工厂 } } catch (Exception ex) { LoggingService.Error(ex.Message + "\r\n" + ex.StackTrace); } } } #endregion #region 保存工程 /// /// 保存工程类 /// public class SaveProjectCommand : AbstractCommand { private ProjectWindow _projectWindow = null; public SaveProjectCommand() { this._projectWindow = DisplayUtil.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.SaveFormByNode(CreateType.Form, tn); } } //保存设备 Mesnac.Equips.Factory.Instance.SaveConfig(); } } #endregion #region 关闭工程 /// /// 关闭工程类 /// public class CloseProjectCommand : AbstractCommand { public override void Run() { DisplayUtil.ClearProject(); } } #endregion #region 新建画面 /// /// 新建画面 /// 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.PadInstance; this._propertyWindow = DisplayUtil.PadInstance; this._actionWindow = DisplayUtil.PadInstance; this._eventWindow = DisplayUtil.PadInstance; } public NewFormCommand(params string[] fileNames) { this.fileNames = fileNames; this._projectWindow = DisplayUtil.PadInstance; this._propertyWindow = DisplayUtil.PadInstance; this._actionWindow = DisplayUtil.PadInstance; this._eventWindow = DisplayUtil.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 新建画面宿设计器 /// /// 新建、载入画面 /// /// 要载入的画面的文件名 /// 返回新建或载入的画面的文件名 public string CreateNewForm(params string[] fileNames) { try { #region 画面初始化 bool isNew = true; //是否是新建画面,true为新建,false为加载 string frmName = DisplayUtil.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; } } /// /// 创建命令 /// /// public string CreateActionFrm() { bool isNew = true; //新建 string frmName = DisplayUtil.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()); } /// /// 新建画面时,初始化画面窗口的属性 /// 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); } } /// /// 刷新工程树 /// /// 画面文件名 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.SaveFormByNode(ct, node); } } /// /// 在激活某个设计器时,重新设置设置宿主主机的活动设计面 /// /// /// 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.Error(ex.Message, ex); } } /// /// 宿主设计器中的组件列表发生变化时的事件处理程序(向设计器中增加组件、删除设计器中组件时的处理程序) /// /// /// private void ComponentListChanged(object sender, EventArgs e) { //设置更新选中对象标志为true _ShouldUpdateSelectableObjects = true; } /// /// 宿主设计器中的每个事务操作结束时的处理程序 /// /// /// private void TransactionClosed(object sender, System.ComponentModel.Design.DesignerTransactionCloseEventArgs e) { if (_ShouldUpdateSelectableObjects) { FormDesignerHelper.UpdateComboBox(); //更新组合框控件列表 _ShouldUpdateSelectableObjects = false; //设置更新选中对象标志为false } } /// /// 关闭某个设计器是自动保存设计画面 /// /// /// 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.SaveFormByNode(CreateType.Form, nodes[0]); } } #endregion } #endregion #region 退出应用程序 /// /// 退出应用程序 /// public class ExitCommand : AbstractCommand { public override void Run() { //1、先清除工程 DisplayUtil.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 撤销 /// /// 插销 /// public class UndoCommand : AbstractCommand { public override void Run() { if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null) { LoggingService.Warn("当前画面实例为空!"); return; } UndoEngineExt ims = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(UndoEngine)) as UndoEngineExt; ims.Undo(); } } #endregion #region 重做 /// /// 重做 /// public class RedoCommand : AbstractCommand { public override void Run() { if (MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface == null) { LoggingService.Warn("当前画面实例为空!"); return; } UndoEngineExt ims = MesnacServiceManager.Instance.HostSurfaceManager.ActiveDesignSurface.GetService(typeof(UndoEngine)) as UndoEngineExt; ims.Redo(); } } #endregion #region 剪切 /// /// 剪切 /// public class CutCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.Cut); } } #endregion #region 复制 /// /// 复制 /// public class CopyCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.Copy); } } #endregion #region 粘贴 /// /// 粘贴 /// public class PasteCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.Paste); } } #endregion #region 删除 /// /// 删除 /// public class DeleteCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.Delete); } } #endregion #region 全选 /// /// 全选 /// public class SelectAllCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.SelectAll); } } #endregion #endregion #region 视图菜单处理 #region 解决方案资源管理器 /// /// 解决方案资源管理器 /// 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 属性窗口 /// /// 属性窗口 /// 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 工具箱 /// /// 工具箱 /// 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 动画窗口 /// /// 动画窗口 /// 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 事件窗口 /// /// 事件窗口 /// 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 对齐到网格 /// /// 对齐到网格 /// public class AlignToGridCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.AlignToGrid); } } #endregion #region 左对齐 /// /// 左对齐 /// public class AlignLeftCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.AlignLeft); } } #endregion #region 居中对齐 /// /// 居中对齐 /// public class AlignHorizontalCentersCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.AlignHorizontalCenters); } } #endregion #region 右对齐 /// /// 右对齐 /// public class AlignRightCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.AlignRight); } } #endregion #region 顶端对齐 /// /// 顶端对齐 /// public class AlignTopCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.AlignTop); } } #endregion #region 中间对齐 /// /// 中间对齐 /// public class AlignVerticalCentersCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.AlignVerticalCenters); } } #endregion #region 底部对齐 /// /// 底部对齐 /// public class AlignBottomCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.AlignBottom); } } #endregion #region 使宽度相同 /// /// 使宽度相同 /// public class SizeToControlWidthCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.SizeToControlWidth); } } #endregion #region 使高度相同 /// /// 使高度相同 /// public class SizeToControlHeightCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.SizeToControlHeight); } } #endregion #region 使大小相同 /// /// 使大小相同 /// public class SizeToControlCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.SizeToControl); } } #endregion #region 按网格调整大小 /// /// 按网格调整大小 /// public class SizeToGridCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.SizeToGrid); } } #endregion #region 使水平间距相等 /// /// 使水平间距相等 /// public class HorizSpaceMakeEqualCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.HorizSpaceMakeEqual); } } #endregion #region 增加水平间距 /// /// 增加水平间距 /// public class HorizSpaceIncreaseCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.HorizSpaceIncrease); } } #endregion #region 减小水平间距 /// /// 减小水平间距 /// public class HorizSpaceDecreaseCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.HorizSpaceDecrease); } } #endregion #region 移除水平间距 /// /// 移除水平间距 /// public class HorizSpaceConcatenateCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.HorizSpaceConcatenate); } } #endregion #region 使垂直间距相等 /// /// 使垂直间距相等 /// public class VertSpaceMakeEqualCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.VertSpaceMakeEqual); } } #endregion #region 增加垂直间距 /// /// 增加垂直间距 /// public class VertSpaceIncreaseCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.VertSpaceIncrease); } } #endregion #region 减小垂直间距 /// /// 减小垂直间距 /// public class VertSpaceDecreaseCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.VertSpaceDecrease); } } #endregion #region 取消垂直间距 /// /// 取消垂直间距 /// public class VertSpaceConcatenateCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.VertSpaceConcatenate); } } #endregion #region 水平居中 /// /// 水平居中 /// public class CenterHorizontallyCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.CenterHorizontally); } } #endregion #region 垂直居中 /// /// 垂直居中 /// public class CenterVerticallyCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.CenterVertically); } } #endregion #region 置于顶层 /// /// 置于顶层 /// public class BringToFrontCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.BringToFront); } } #endregion #region 置于底层 /// /// 置于底层 /// public class SendToBackCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.SendToBack); } } #endregion #region 前移一层 /// /// 前移一层 /// public class BringForwardCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.BringForward); } } #endregion #region 后移一层 /// /// 后移一层 /// public class SendBackwardCommand : AbstractCommand { public override void Run() { DisplayUtil.PerformAction(StandardCommands.SendBackward); } } #endregion #endregion #region 全屏切换 /// /// 全屏切换 /// public class ToggleFullscreenCommand : AbstractCommand { public override void Run() { WorkbenchSingleton.Workbench.FullScreen = !WorkbenchSingleton.Workbench.FullScreen; } } #endregion #region 菜单、工具栏按钮启用、禁用操作 #region 工程保存、关闭 /// /// 工程保存、关闭 /// public class MCEditProjectStateConditionEvaluator : IConditionEvaluator { public bool IsValid(object caller, Condition condition) { if (DisplayUtil.PadInstance != null && DisplayUtil.PadInstance.Tree.Nodes.Count == 0) { return false; } else { return true; } } } #endregion #region 编辑菜单 /// /// 编辑菜单 /// public class MCEditEditStateConditionEvaluator : IConditionEvaluator { public bool IsValid(object owner, Condition condition) { if (DisplayUtil.PadInstance != null && DisplayUtil.PadInstance.Tree.Nodes.Count == 0 || MesnacServiceManager.Instance.Host == null) { //没有工程 禁用编辑 return false; } else { return true; } } } #endregion #region 撤销、重做、仿真 /// /// 仿真 /// 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; } } } /// /// 撤销 /// 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; } } } /// /// 重做 /// 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 工程面板 /// /// 工程面板 /// public class MCEditProjectWindowStateConditionEvaluator : IConditionEvaluator { public bool IsValid(object owner, Condition condition) { ProjectWindow projectWindow = DisplayUtil.PadInstance; if (projectWindow != null && projectWindow.Visible) { return false; } else { return true; } } } #endregion #region 工具箱 /// /// 工具箱 /// public class MCEditToolBoxWindowStateConditionEvaluator : IConditionEvaluator { public bool IsValid(object owner, Condition condition) { ToolBoxWindow toolBoxWindow = DisplayUtil.PadInstance; if (toolBoxWindow != null && toolBoxWindow.Visible) { return false; } else { return true; } } } #endregion #region 属性面板 /// /// 属性面板 /// public class MCEditPropertyWindowStateConditionEvaluator : IConditionEvaluator { public bool IsValid(object owner, Condition condition) { PropertyWindow propertyWindow = DisplayUtil.PadInstance; if (propertyWindow != null && propertyWindow.Visible) { return false; } else { return true; } } } #endregion #region 动画面板 /// /// 动画面板 /// public class MCEditActionWindowStateConditionEvaluator : IConditionEvaluator { public bool IsValid(object owner, Condition condition) { ActionWindow actionWindow = DisplayUtil.PadInstance; if (actionWindow != null && actionWindow.Visible) { return false; } else { return true; } } } #endregion #region 布局 /// /// 布局,未选中任何控件 /// 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; } } } /// /// 布局,设计器中只有一个组件 /// 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; } } } /// /// 布局,只选中一个控件 /// 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 运行仿真 /// /// 运行方针 /// 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.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 测试 /// /// 测试 /// 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 }