/// <summary> /// 将一个扩展转换成WinShellApplication对象。 /// </summary> /// <param name="extension">指定的扩展对象。</param> /// <returns>返回的WinShellApplication对象。</returns> public WinShellApplication AddApplicationForExtension(Extension extension) { WinShellApplication app = null; List<XmlNode> data = extension.Data; if (data != null && data.Count > 0) { // 1 将扩展的Application XML节点转换成WinShellApplication对象。 XmlNode topNode = data[0]; if (topNode.NodeType == XmlNodeType.Element && topNode.Attributes != null && topNode.Attributes["Title"] != null) { string appTitle = topNode.Attributes["Title"].Value; string appToolTip = topNode.Attributes["ToolTip"].Value; string appIcon = topNode.Attributes["Icon"].Value; if (!string.IsNullOrEmpty(appTitle)) { string parentGuid = Guid.NewGuid().ToString(); int topNodeLevel = 0; app = new WinShellApplication(appTitle, appToolTip, appIcon, extension.Owner); // 2 递归的将扩展的Menu XML节点及其子节点转换成WinShellMenu对象。 CreateWinShellMenusFromXmlNode(app.Menus, app, null, topNode, topNodeLevel); // 3 将Application对象保存起来。 _instance.AddApplication(app); } } } return app; }
/// <summary> /// 将扩展的Menu对应的XML节点解析成WinShellMenu集合。 /// </summary> /// <param name="menus">顶层WinShellMenu集合。</param> /// <param name="application">所属的WinShellApplication。</param> /// <param name="parent">父菜单。</param> /// <param name="topNode">顶层XML节点。</param> /// <param name="nodeLevel">XML节点层次。</param> private void CreateWinShellMenusFromXmlNode(List <WinShellMenu> menus, WinShellApplication application, WinShellMenu parent, XmlNode topNode, int nodeLevel) { if (menus == null) { menus = new List <WinShellMenu>(); } foreach (XmlNode childNode in topNode.ChildNodes) { if (childNode.NodeType == XmlNodeType.Element) { string type = null; if (childNode.Attributes["Class"] != null) { type = childNode.Attributes["Class"].Value; } string text = childNode.Attributes["Text"] == null ? string.Empty : childNode.Attributes["Text"].Value; string toolTip = childNode.Attributes["ToolTip"] == null ? string.Empty : childNode.Attributes["ToolTip"].Value; string icon = childNode.Attributes["Icon"] == null ? string.Empty : childNode.Attributes["Icon"].Value; string guid = Guid.NewGuid().ToString(); // 创建WinShellMenu对象。 WinShellMenu winShellMenu = new WinShellMenu(application, parent, text, toolTip, icon, type, nodeLevel, guid); menus.Add(winShellMenu); // 递归创建子节点对象。 int childNodeLevel = nodeLevel + 1; CreateWinShellMenusFromXmlNode(winShellMenu.Children, application, winShellMenu, childNode, childNodeLevel); } } }
private void RemoveApplication(WinShellApplication app) { if (app != null && Applications.Contains(app)) { Applications.Remove(app); } }
/// <summary> /// 将一个扩展转换成WinShellApplication对象。 /// </summary> /// <param name="extension">指定的扩展对象。</param> /// <returns>返回的WinShellApplication对象。</returns> public WinShellApplication AddApplicationForExtension(Extension extension) { WinShellApplication app = null; List <XmlNode> data = extension.Data; if (data != null && data.Count > 0) { // 1 将扩展的Application XML节点转换成WinShellApplication对象。 XmlNode topNode = data[0]; if (topNode.NodeType == XmlNodeType.Element && topNode.Attributes != null && topNode.Attributes["Title"] != null) { string appTitle = topNode.Attributes["Title"].Value; string appToolTip = topNode.Attributes["ToolTip"].Value; string appIcon = topNode.Attributes["Icon"].Value; if (!string.IsNullOrEmpty(appTitle)) { string parentGuid = Guid.NewGuid().ToString(); int topNodeLevel = 0; app = new WinShellApplication(appTitle, appToolTip, appIcon, extension.Owner); // 2 递归的将扩展的Menu XML节点及其子节点转换成WinShellMenu对象。 CreateWinShellMenusFromXmlNode(app.Menus, app, null, topNode, topNodeLevel); // 3 将Application对象保存起来。 _instance.AddApplication(app); } } } return(app); }
private void AddApplication(WinShellApplication app) { if (app != null) { Applications.Add(app); } }
public override bool Equals(object obj) { if (obj != null && obj is WinShellApplication) { WinShellApplication other = obj as WinShellApplication; return(Equals(BundleID, other.BundleID)); } return(false); }
/// <summary> /// 获取指定插件的顶层菜单对象。 /// </summary> /// <param name="bundle">指定插件。</param> /// <returns>顶层菜单对象集合。</returns> public List <WinShellMenu> GetTopWinShellMenus(IBundle bundle) { WinShellApplication app = GetWinShellApplication(bundle); if (app != null) { return(app.Menus); } return(null); }
public WinShellMenu(WinShellApplication application, WinShellMenu parent, string text, string tooltip, string icon, string className, int level, string guid) { Application = application; Parent = parent; Text = text; Tooltip = tooltip; Icon = icon; ClassName = className; Level = level; Guid = guid; Children = new List <WinShellMenu>(); }
public WinShellMenu(WinShellApplication application, WinShellMenu parent, string text, string tooltip, string icon, string className, int level, string guid) { Application = application; Parent = parent; Text = text; Tooltip = tooltip; Icon = icon; ClassName = className; Level = level; Guid = guid; Children = new List<WinShellMenu>(); }
private void RemoveApplication(WinShellApplication app) { if (app != null && Applications.Contains(app)) { Applications.Remove(app); } }
/// <summary> /// 将扩展的Menu对应的XML节点解析成WinShellMenu集合。 /// </summary> /// <param name="menus">顶层WinShellMenu集合。</param> /// <param name="application">所属的WinShellApplication。</param> /// <param name="parent">父菜单。</param> /// <param name="topNode">顶层XML节点。</param> /// <param name="nodeLevel">XML节点层次。</param> private void CreateWinShellMenusFromXmlNode(List<WinShellMenu> menus, WinShellApplication application, WinShellMenu parent, XmlNode topNode, int nodeLevel) { if (menus == null) { menus = new List<WinShellMenu>(); } foreach (XmlNode childNode in topNode.ChildNodes) { if (childNode.NodeType == XmlNodeType.Element) { string type = null; if (childNode.Attributes["Class"] != null) type = childNode.Attributes["Class"].Value; string text = childNode.Attributes["Text"] == null ? string.Empty : childNode.Attributes["Text"].Value; string toolTip = childNode.Attributes["ToolTip"] == null ? string.Empty : childNode.Attributes["ToolTip"].Value; string icon = childNode.Attributes["Icon"] == null ? string.Empty : childNode.Attributes["Icon"].Value; string guid = Guid.NewGuid().ToString(); // 创建WinShellMenu对象。 WinShellMenu winShellMenu = new WinShellMenu(application, parent, text, toolTip, icon, type, nodeLevel, guid); menus.Add(winShellMenu); // 递归创建子节点对象。 int childNodeLevel = nodeLevel + 1; CreateWinShellMenusFromXmlNode(winShellMenu.Children, application, winShellMenu, childNode, childNodeLevel); } } }
private void AddApplication(WinShellApplication app) { if (app != null) Applications.Add(app); }
private void RemoveMenuStripForApplication(WinShellApplication application) { RemoveMenuStripForApplicationDelegate del = (WinShellApplication app) => { if (ApplicationMenuStripMap.ContainsKey(app)) { // 删除菜单、Map、显示的TabPage TopMenuStrip.Items.Remove(ApplicationMenuStripMap[app]); ApplicationMenuStripMap.Remove(app); foreach (TabPage tab in WorkspaceTabControl.TabPages) { var menu = tab.Tag as WinShellMenu; if (menu.Application.Equals(app)) // 清除Selection { var index = WorkspaceTabControl.SelectedIndex; if (index > 0 && tab.Equals(WorkspaceTabControl.SelectedTab)) { WorkspaceTabControl.SelectedIndex = index - 1; } WorkspaceTabControl.TabPages.Remove(tab); } } } }; // 如果当前线程不是界面线程,则通过Invoke来处理界面变更 if (InvokeRequired) { Invoke(del, application); } else // 否则,直接操作界面 { del(application); } }
private void CreateMenuStripForApplication(WinShellApplication application) { CreateMenuStripForApplicationDelegate del = (WinShellApplication app) => { // 为WinShellApplication创建根菜单节点 var topToolStripItem = TopMenuStrip.Items.Add(app.Title, LoadImage(app.Bundle, app.Icon)) as ToolStripMenuItem; topToolStripItem.ToolTipText = app.ToolTip; // 创建子菜单节点 CreateChildMenu(app.Menus, topToolStripItem.DropDownItems); // 添加到WinShellApplication和顶层菜单节点对应表 ApplicationMenuStripMap.Add(app, topToolStripItem); }; // 如果当前线程不是界面线程,则通过Invoke来处理界面变更 if (InvokeRequired) { Invoke(del, application); } else // 否则,直接操作界面 { del(application); } }