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 }); }
void ToolEvt(object sender, EventArgs e) { SdMenuCommand item = (SdMenuCommand)sender; StringParserService stringParserService = (StringParserService)ServiceManager.Services.GetService(typeof(StringParserService)); for (int i = 0; i < ToolLoader.Tool.Count; ++i) { if (item.Text == ToolLoader.Tool[i].ToString()) { ExternalTool tool = (ExternalTool)ToolLoader.Tool[i]; stringParserService.Properties["StartupPath"] = Application.StartupPath; string command = stringParserService.Parse(tool.Command); try { ProcessStartInfo startinfo = new ProcessStartInfo(command, ""); startinfo.WorkingDirectory = ""; Process.Start(startinfo); } catch (Exception ex) { MessageBox.Show(command + "\n" + ex.ToString(), "启动程序时出错:", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; } } }
/// <summary> /// Creates an item with the specified sub items. And the current /// Condition status for this item. /// </summary> public override object BuildItem(object owner, ArrayList subItems, ConditionCollection conditions) { MenuCommand newItem = null; object o = null; if (Class != null) { o = AddIn.CreateObject(Class); } if (o != null) { if (o is IMenuCommand) { IMenuCommand menuCommand = (IMenuCommand)o; menuCommand.Owner = owner; newItem = new SdMenuCommand(conditions, owner, Label, menuCommand); } } if (newItem == null) { MenuCommand menuCommand = new SdMenuCommand(conditions, owner, Label); if (subItems != null && subItems.Count > 0) { foreach (object item in subItems) { if (item != null && item is MenuCommand) { menuCommand.MenuCommands.Add((MenuCommand)item); } } } newItem = menuCommand; } if (Shortcut != null && newItem is SdMenuCommand) { try { foreach (string key in this.shortcut) { ((SdMenuCommand)newItem).Shortcut |= (System.Windows.Forms.Shortcut)Enum.Parse(typeof(System.Windows.Forms.Shortcut), key); } } catch (Exception) { ((SdMenuCommand)newItem).Shortcut = System.Windows.Forms.Shortcut.None; } } newItem.Enabled = true; //action != ConditionFailedAction.Disable; return(newItem); }
void LoadRecentFile(object sender, EventArgs e) { SdMenuCommand item = (SdMenuCommand)sender; IFileService fileService = (IFileService)NetFocus.DataStructure.Services.ServiceManager.Services.GetService(typeof(IFileService)); fileService.OpenFile(item.Text); WorkbenchSingleton.Workbench.ActiveViewContent.ViewSelected -= AlgorithmManager.Algorithms.ClearPadsHandler; WorkbenchSingleton.Workbench.ActiveViewContent.ViewSelected += AlgorithmManager.Algorithms.ClearPadsHandler; WorkbenchSingleton.Workbench.ActiveViewContent.SelectView(); AlgorithmManager.Algorithms.Timer.Enabled = false; }
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); }
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); //最后返回当前菜单项. }