private void BuildControls() { List <ActionVerb> actions = new List <ActionVerb>(); if (!RuntimeInfo.Inst.IsElevated) { actions.Add(new ActionVerb() { Name = "Run", Verb = "" }); actions.Add(new ActionVerb() { Name = "RunAs Admin", Verb = "runas" }); } var menu = GUIUtility.GenerateActionMenus(runAsContext.Name, "ContextMenu", actions, EditorsToolStripActionMenuItem_Click); runAsContext.Items.AddRange(menu); if (RuntimeInfo.Inst.ToolBar != null && RuntimeInfo.Inst.ToolBar.Count > 0) { GenerateToolbar(mainToolBar, RuntimeInfo.Inst.ToolBar, actions); } RuntimeInfo.Inst.UpdateMenuBar(mainMenu, actions, EditorsToolStripMenuItem_Click, EditorsToolStripActionMenuItem_Click); if (RuntimeInfo.Inst.ContextMenu != null && RuntimeInfo.Inst.ContextMenu.Count > 0) { GenerateContextMenu(envlistContextMenu, RuntimeInfo.Inst.ContextMenu); } }
private void GenerateToolbar(ToolStrip rootToolStrip, List <ToolBarItem> toolsBarItem, List <ActionVerb> actions) { rootToolStrip.SuspendLayout(); foreach (var item in toolsBarItem) { if (item.Group.Count > 1) { bool toolAvaialble = false; var splitButton = new ToolStripSplitButton(); splitButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; splitButton.Image = Image.FromFile(string.Format(@"{0}\Resource\{1}.png", RuntimeInfo.Inst.LaunchEnvExeDir, item.Name)); splitButton.Name = string.Format("{0}_toolStripBttn{1}", rootToolStrip.Name, item.Name); splitButton.Text = item.Name; splitButton.Tag = item.Name; splitButton.MouseDown += StripButton_MouseDown; foreach (var splitItem in item.Group) { //if dynamic path tool then don't check the file path if (string.IsNullOrWhiteSpace(splitItem.Path) || File.Exists(splitItem.Path)) { toolAvaialble = true; var toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); toolStripMenuItem.Image = Image.FromFile(string.Format(@"{0}\Resource\{1}.png", RuntimeInfo.Inst.LaunchEnvExeDir, splitItem.Name)); toolStripMenuItem.Name = string.Format("{0}_toolStripBttn{1}_{2}", rootToolStrip.Name, item.Name, splitItem.Name); toolStripMenuItem.Text = splitItem.Name; toolStripMenuItem.Tag = splitItem.Name; toolStripMenuItem.Click += EditorsToolStripMenuItem_Click; if (RuntimeInfo.Inst.ShowRunAsForAll) { var retMenu = GUIUtility.GenerateActionMenus(toolStripMenuItem.Name, toolStripMenuItem.Tag as string, actions, EditorsToolStripActionMenuItem_Click); if (retMenu.Length > 0) { toolStripMenuItem.DropDownItems.AddRange(retMenu); } } splitButton.DropDownItems.Add(toolStripMenuItem); } } if (toolAvaialble) { rootToolStrip.Items.Add(splitButton); _toolStripItem.Add(splitButton); } } else { var splitItem = item.Group.FirstOrDefault(); if (splitItem != null) { //if dynamic path tool then don't check the file path if (string.IsNullOrWhiteSpace(splitItem.Path) || File.Exists(splitItem.Path)) { ToolStripItem stripButton = new ToolStripButton(); stripButton.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; stripButton.Image = Image.FromFile(string.Format(@"{0}\Resource\{1}.png", RuntimeInfo.Inst.LaunchEnvExeDir, splitItem.Name)); stripButton.Name = string.Format("{0}_toolStripBttn{1}", rootToolStrip.Name, splitItem.Name); stripButton.Text = splitItem.Name; stripButton.Tag = splitItem.Name; stripButton.MouseDown += StripButton_MouseDown; rootToolStrip.Items.Add(stripButton); } } } } rootToolStrip.ResumeLayout(false); rootToolStrip.PerformLayout(); }