public ButtonItem[] BuildSubmenu(object owner) { IFileService fileService = (IFileService)NetFocus.DataStructure.Services.ServiceManager.Services.GetService(typeof(IFileService)); ResourceService ResourceService = (ResourceService)ServiceManager.Services.GetService(typeof(ResourceService)); StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService)); RecentOpenMemeto recentOpen = fileService.RecentOpenMemeto; if (recentOpen.RecentFile.Count > 0) { SdMenuCommand[] items = new SdMenuCommand[recentOpen.RecentFile.Count]; for (int i = 0; i < recentOpen.RecentFile.Count; ++i) { items[i] = new SdMenuCommand(recentOpen.RecentFile[i].ToString(), new EventHandler(LoadRecentFile)); items[i].Description = stringParserService.Parse(ResourceService.GetString("XML.MainMenu.FileMenu.LoadRecentFileDescription"), new string[,] { {"FILE", recentOpen.RecentFile[i].ToString()} }); } return items; } SdMenuCommand defaultMenu = new SdMenuCommand(ResourceService.GetString("XML.MainMenu.FileMenu.NoRecentFileDescription")); defaultMenu.Enabled = false; return new ButtonItem[] { defaultMenu }; }
public override object BuildItem(object owner, ArrayList subItems, ConditionCollection conditions) { SdMenuCommand newItem = null; StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService)); object o = null; if (Class != null) { o = AddIn.CreateObject(Class);//说明当前菜单项是没有子菜单项�?即它有自己的功能,其功能由Class类具体实�?这种菜单项也是最常见�? } if (o != null) { if (o is ISubmenuBuilder) { return ((ISubmenuBuilder)o).BuildSubmenu(owner); } if (o is IMenuCommand) { newItem = new SdMenuCommand(stringParserService.Parse(Label), new EventHandler(new MenuEventHandler(owner, (IMenuCommand)o).Execute)); if(beginGroup == "true") { newItem.BeginGroup = true; } } } if (newItem == null) {//说明当前菜单项既不是Link类型�?也没有指出其Class属�?所以有可能是一个包含子菜单的菜单项. newItem = new SdMenuCommand(stringParserService.Parse(Label)); if (subItems != null && subItems.Count > 0) {//判断是否有子菜单�? foreach (object item in subItems) { if (item is ButtonItem) {//添加一个子菜单�? newItem.SubItems.Add((ButtonItem)item); } else {//添加一组子菜单�? newItem.SubItems.AddRange((ButtonItem[])item); } } } } Debug.Assert(newItem != null);//到这里为�?newItem即当前菜单项不应该为空了. if (Icon != null) {//为菜单设置Icon. ResourceService ResourceService = (ResourceService)ServiceManager.Services.GetService(typeof(ResourceService)); newItem.Image = ResourceService.GetBitmap(Icon); } newItem.Description = description; newItem.MouseEnter +=new EventHandler(newItem_MouseEnter); newItem.MouseLeave +=new EventHandler(newItem_MouseLeave); if (Shortcut != null) {//为菜单设置Shortcut. try { newItem.Shortcuts.Add((eShortcut)Enum.Parse(eShortcut.F1.GetType(),Shortcut)); } catch (Exception) { } } return newItem;//最后返回当前菜单项. }
public ButtonItem[] BuildSubmenu(object owner) { SdMenuCommand[] items = new SdMenuCommand[ToolLoader.Tool.Count]; for (int i = 0; i < ToolLoader.Tool.Count; ++i) { SdMenuCommand item = new SdMenuCommand(ToolLoader.Tool[i].ToString(), new EventHandler(ToolEvt)); item.Description = "启动工具: " + String.Join(String.Empty, ToolLoader.Tool[i].ToString().Split('&')); items[i] = item; } return items; }