/// <summary> /// Adds a recent at the top of the dropdown collection. Deletes an old /// one if found. Limits count to 8 recents. /// </summary> void recent_add() { ToolStripItemCollection recents = it_Recent.DropDownItems; ToolStripItem it; bool found = false; for (int i = 0; i != recents.Count; ++i) { if ((it = recents[i]).Text == _pfe) { found = true; if (i != 0) { recents.Remove(it); recents.Insert(0, it); } break; } } if (!found) { it = new ToolStripMenuItem(_pfe); it.Click += Click_recent; recents.Insert(0, it); if (recents.Count > 8) // up to 8 recents { recents.Remove(recents[recents.Count - 1]); } } }
public void Insert_Index_OutOfRange() { ToolStrip toolStrip = CreateToolStrip(); ToolStripItemCollection items = new ToolStripItemCollection( toolStrip, new ToolStripItem [0]); try { items.Insert(-1, new ToolStripButton()); Assert.Fail("#A1"); } catch (ArgumentOutOfRangeException ex) { Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType(), "#A2"); Assert.IsNull(ex.InnerException, "#A3"); Assert.IsNotNull(ex.Message, "#A4"); Assert.AreEqual("index", ex.ParamName, "#A5"); } try { items.Insert(1, new ToolStripButton()); Assert.Fail("#B1"); } catch (ArgumentOutOfRangeException ex) { Assert.AreEqual(typeof(ArgumentOutOfRangeException), ex.GetType(), "#B2"); Assert.IsNull(ex.InnerException, "#B3"); Assert.IsNotNull(ex.Message, "#B4"); Assert.AreEqual("index", ex.ParamName, "#B5"); } }
public void Insert_Owned() { ToolStrip toolStrip = CreateToolStrip(); ToolStripItemCollection items = toolStrip.Items; MockToolStripButton buttonA = new MockToolStripButton("A"); items.Insert(0, buttonA); Assert.AreEqual(1, items.Count, "#A1"); Assert.AreEqual(1, itemsAdded.Count, "#A2"); Assert.AreSame(buttonA, items [0], "#A3"); Assert.AreSame(toolStrip, buttonA.Owner, "#A4"); Assert.IsNull(buttonA.ParentToolStrip, "#A5"); MockToolStripButton buttonB = new MockToolStripButton("B"); items.Insert(0, buttonB); Assert.AreEqual(2, items.Count, "#B1"); Assert.AreEqual(2, itemsAdded.Count, "#B2"); Assert.AreSame(buttonB, items [0], "#B3"); Assert.AreSame(buttonA, items [1], "#B4"); Assert.AreSame(toolStrip, buttonB.Owner, "#B5"); Assert.IsNull(buttonB.ParentToolStrip, "#B6"); MockToolStripButton buttonC = new MockToolStripButton("C"); items.Insert(1, buttonC); Assert.AreEqual(3, items.Count, "#C1"); Assert.AreEqual(3, itemsAdded.Count, "#C2"); Assert.AreSame(buttonB, items [0], "#C3"); Assert.AreSame(buttonC, items [1], "#C4"); Assert.AreSame(buttonA, items [2], "#C5"); Assert.AreSame(toolStrip, buttonC.Owner, "#C6"); Assert.IsNull(buttonC.ParentToolStrip, "#C7"); }
private void SetHelpers(ToolStripItemCollection dropdown, ToolStripItem tss, string prefix, IEnumerable <HelperManager.Helper> helpers) { if (helpers.Count() == 0) { return; } int i = dropdown.IndexOf(tss); int j = 0; dropdown.Insert(++i, new ToolStripSeparator() { Name = prefix + j, }); foreach (var helper in helpers) { ToolStripMenuItem tsiHelper = new ToolStripMenuItem(helper.label, null, tsHelper_Click) { Name = prefix + j, Tag = j++, }; dropdown.Insert(++i, tsiHelper); } }
IMenuItem IMenu.AddCommand(string name, string afterMenuName, string text, Image image, Keys keys, ICommand command) { IMenuItem menuItem = ((IMenu)this)[name]; if (menuItem != null) { return(menuItem); } menuItem = ((IMenu)this)[afterMenuName]; int index = menuItem == null ? 0 : itemCollection.IndexOf(((MenuItem)menuItem).Item) + 1; ToolStripMenuItem item = new ToolStripMenuItem(text); item.Name = "menuItem" + name; item.Image = image; item.ShortcutKeys = keys; if (command != null) { item.Click += (sender, e) => command.Execute(sender); } itemCollection.Insert(index, item); IMenuItem newMenuItem = new MenuItem(item); items.Add(newMenuItem); return(newMenuItem); }
private void SetupContextMenu(ToolStripItemCollection items) { while (items[0] != mReRead) { var menuItem = items[0]; items.RemoveAt(0); menuItem.Dispose(); } m_FactoryManager.CreateDefaultRoots(); var index = 0; foreach (var root in m_FactoryManager.DefaultRoots) { var menuItem = new ToolStripMenuItem(string.Format(Resources.PagesView_OpenTab, root.Name)); menuItem.Tag = root; menuItem.ImageIndex = App.Images.IndexOf(root.ImageName); menuItem.Click += PluginOnClick; items.Insert(index, menuItem); index++; } if (index > 0) { items.Insert(index, new ToolStripSeparator()); } }
public void Remove_StandAlone() { ToolStrip toolStrip = CreateToolStrip(); ToolStripItemCollection items = new ToolStripItemCollection( toolStrip, new ToolStripItem [0]); MockToolStripButton buttonA = new MockToolStripButton("A"); MockToolStripButton buttonB = new MockToolStripButton("B"); MockToolStripButton buttonC = new MockToolStripButton("B"); items.Insert(0, buttonA); items.Insert(0, buttonB); items.Remove(buttonB); Assert.AreEqual(1, items.Count, "#A1"); Assert.AreEqual(0, itemsRemoved.Count, "#A2"); Assert.AreSame(buttonA, items [0], "#A3"); items.Remove((ToolStripItem)null); Assert.AreEqual(1, items.Count, "#B1"); Assert.AreEqual(0, itemsRemoved.Count, "#B2"); Assert.AreSame(buttonA, items [0], "#B3"); items.Remove(buttonC); Assert.AreEqual(1, items.Count, "#C1"); Assert.AreEqual(0, itemsRemoved.Count, "#C2"); Assert.AreSame(buttonA, items [0], "#C3"); items.Remove(buttonA); Assert.AreEqual(0, items.Count, "#D1"); Assert.AreEqual(0, itemsRemoved.Count, "#D2"); items.Remove(buttonA); Assert.AreEqual(0, items.Count, "#E1"); Assert.AreEqual(0, itemsRemoved.Count, "#E2"); // remove item owned by other toolstrip ToolStrip otherToolStrip = new ToolStrip(); MockToolStripButton buttonD = new MockToolStripButton("B"); otherToolStrip.Items.Add(buttonD); Assert.AreSame(otherToolStrip, buttonD.Owner, "#F1"); Assert.IsNull(buttonD.ParentToolStrip, "#F2"); items.Remove(buttonD); Assert.AreEqual(0, items.Count, "#F3"); Assert.AreEqual(0, itemsRemoved.Count, "#F4"); Assert.AreSame(otherToolStrip, buttonD.Owner, "#F5"); Assert.IsNull(buttonD.ParentToolStrip, "#F6"); }
public static void SortedAdd(this ToolStripItemCollection strip, ToolStripMenuItem item) { int i = 0; for (i = 0; i < strip.Count; i++) { if (string.Compare(strip[i].Text, item.Text) > 0) { strip.Insert(i, item); return; } } strip.Insert(i, item); }
private void fileToolStripMenuItem_DropDownOpening(object sender, EventArgs e) { // Update MRU on file menu if (Program.mru.mruFiles.Count > 0) { ToolStripItemCollection items = fileToolStripMenuItem.DropDownItems; int index = 0; for (; index < items.Count; index++) { if ((string)items[index].Tag == "MRU") { // Remove anything after the tag, till the next separator while (items.Count > index + 1 && !(items[index + 1] is ToolStripSeparator)) { items.RemoveAt(index + 1); } // Hide tag items[index].Visible = false; index++; // Add MRUs foreach (MRUFile f in Program.mru.mruFiles) { ToolStripMenuItem item = new ToolStripMenuItem(f.filename); item.ToolTipText = f.filepath; items.Insert(index, item); item.Click += MRU_Item_Click; index++; } break; } } } }
private IEnumerable <GameMenuItem> AddGameMenuItems(ToolStripItemCollection itemsCollection, IEnumerable <GameDescriptor> gameDescriptors, bool insertToTop = false) { foreach (var gameDescriptor in gameDescriptors) { var libraryBrandColor = registry.GetGameLibraryBrandColor(gameDescriptor); var addedToFavorites = registry.GetGameAddedToFavorites(gameDescriptor); var gameItem = new GameMenuItem( libraryBrandColor, addedToFavorites, gameDescriptor.Name, null, (obj, args) => OnGameMenuItemClicked(gameDescriptor)); gameDescriptorsMap.Add(gameItem, gameDescriptor); if (insertToTop) { itemsCollection.Insert(0, gameItem); } else { itemsCollection.Add(gameItem); } yield return(gameItem); } }
// Maintains separators between different command groups private void MaintainSeparateGroups(ToolStripItemCollection commands, ToolStripItem item, object groupTag) { int index = commands.IndexOf(item); if (index > 0) // look for previous item { ToolStripItem prevItem = commands[index - 1]; object prevTag = prevItem.Tag; while (prevTag == null) { ToolStripMenuItem prevMenuItem = prevItem as ToolStripMenuItem; if (prevMenuItem == null) { break; } ToolStripItemCollection prevItems = prevMenuItem.DropDownItems; prevItem = prevItems[prevItems.Count - 1]; prevTag = prevItem.Tag; } // add a separator if the new command is from a different group CommandInfo prevInfo = GetCommandInfo(prevTag); if (prevInfo != null && !TagsEqual(groupTag, prevInfo.GroupTag)) { commands.Insert(index, new ToolStripSeparator()); } } }
private static int BuildMenuContentsForGroup(int index, ICommandTarget target, ToolStripItemCollection children, IPoderosaMenuGroup grp) { int count = 0; foreach (IPoderosaMenu m in grp.ChildMenus) { ToolStripMenuItem mi = new ToolStripMenuItem(); children.Insert(index++, mi); //途中挿入のことも mi.DropDownOpening += new EventHandler(OnPopupMenu); mi.Enabled = m.IsEnabled(target); mi.Checked = mi.Enabled ? m.IsChecked(target) : false; mi.Text = m.Text; //Enabledを先に mi.Tag = new MenuItemTag(grp, m, target); IPoderosaMenuFolder folder; IPoderosaMenuItem leaf; if ((folder = m as IPoderosaMenuFolder) != null) { BuildMenuContents(mi, folder); } else if ((leaf = m as IPoderosaMenuItem) != null) { mi.Click += new EventHandler(OnClickMenu); IGeneralCommand gc = leaf.AssociatedCommand as IGeneralCommand; if (gc != null) { mi.ShortcutKeyDisplayString = WinFormsUtil.FormatShortcut(CommandManagerPlugin.Instance.CurrentKeyBinds.GetKey(gc)); } } count++; } return(count); }
void _menuManager_Added(object sender, MenuEvent e) { ToolStripItemCollection collection = GetMenuCollection(e.At); if (collection == null) { ToolStripItem[] coll = mainMenu.Items.Find(e.Name, true); if (coll.Length == 1) { (coll.FirstOrDefault() as ToolStripMenuItem).DropDownItems.Add(e.Item); } } else { if (e.Insert) { collection.Insert(e.Index, e.Item); } else { collection.Add(e.Item); } Util.Sort(collection); } }
public void AddMenuItem(ToolStripItemCollection collection, int index, String fileName, EventHandler handler) { ToolStripMenuItem item = new ToolStripMenuItem(); item.Text = fileName; item.Click += new EventHandler(handler); collection.Insert(index, item); }
/// <summary> /// See <see cref="UIElementAdapter{TUIElement}.Add(TUIElement)"/> for more information. /// </summary> protected override ToolStripItem Add(ToolStripItem uiElement) { if (collection == null) { throw new InvalidOperationException(); } collection.Insert(GetInsertingIndex(uiElement), uiElement); return(uiElement); }
AddItems ( ToolStripSplitButton toolStripSplitButton ) { const String MethodName = "AddItems"; this.ArgumentChecker.CheckArgumentNotNull( MethodName, "toolStripSplitButton", toolStripSplitButton); AssertValid(); if (m_oToolStripSplitButton != null) { this.ArgumentChecker.ThrowArgumentException(MethodName, "toolStripSplitButton", "This method has already been called. Don't call it twice." ); } m_oToolStripSplitButton = toolStripSplitButton; m_oToolStripSplitButton.ButtonClick += new EventHandler( this.m_oToolStripSplitButton_ButtonClick); ToolStripItemCollection oItems = m_oToolStripSplitButton.DropDownItems; Int32 iInsertionIndex = 0; foreach (LayoutInfo oLayoutInfo in AllLayouts.GetAllLayouts()) { ToolStripItem oToolStripItem; if (oLayoutInfo == AllLayouts.LayoutGroupSeparator) { oToolStripItem = new ToolStripSeparator(); } else { oToolStripItem = new ToolStripMenuItem(oLayoutInfo.Text, null, new EventHandler(this.OnLayoutMenuItemClick)); oToolStripItem.Tag = oLayoutInfo; oToolStripItem.ToolTipText = oLayoutInfo.Description.TrimEnd('.'); } // Don't call ToolStripItemCollection.Add(), because the // ToolStripSplitButton may already have items added to it by the // caller. The items added here should precede any existing items. oItems.Insert(iInsertionIndex, oToolStripItem); iInsertionIndex++; } }
private void SetPreviewControlItems(ToolStripItemCollection dropdown, ToolStripItem tss, string prefix, IEnumerable <ToolStripItem> items) { int i = dropdown.Count - 1; int j = dropdown.Count - dropdown.IndexOf(tss); foreach (var item in items) { item.Name = prefix + (++j); dropdown.Insert(++i, item); } }
/// <summary> /// If the predicted retention time is auto calculated, add a "Show {Prediction} score" menu item. /// If there are retention time alignments available for the specified chromFileInfoId, then adds /// a "Align Times To {Specified File}" menu item to a context menu. /// </summary> private int InsertAlignmentMenuItems(ToolStripItemCollection items, ChromFileInfoId chromFileInfoId, int iInsert) { var predictRT = Document.Settings.PeptideSettings.Prediction.RetentionTime; if (predictRT != null && predictRT.IsAutoCalculated) { var menuItem = new ToolStripMenuItem(string.Format(Resources.SkylineWindow_ShowCalculatorScoreFormat, predictRT.Calculator.Name), null, (sender, eventArgs) => SkylineWindow.AlignToRtPrediction = !SkylineWindow.AlignToRtPrediction) { Checked = SkylineWindow.AlignToRtPrediction, }; items.Insert(iInsert++, menuItem); } if (null != chromFileInfoId && DocumentUI.Settings.HasResults && !DocumentUI.Settings.DocumentRetentionTimes.FileAlignments.IsEmpty) { foreach (var chromatogramSet in DocumentUI.Settings.MeasuredResults.Chromatograms) { var chromFileInfo = chromatogramSet.GetFileInfo(chromFileInfoId); if (null == chromFileInfo) { continue; } string fileItemName = Path.GetFileNameWithoutExtension(SampleHelp.GetFileName(chromFileInfo.FilePath)); var menuItemText = string.Format(Resources.SkylineWindow_AlignTimesToFileFormat, fileItemName); var alignToFileItem = new ToolStripMenuItem(menuItemText); if (ReferenceEquals(chromFileInfoId, SkylineWindow.AlignToFile)) { alignToFileItem.Click += (sender, eventArgs) => SkylineWindow.AlignToFile = null; alignToFileItem.Checked = true; } else { alignToFileItem.Click += (sender, eventArgs) => SkylineWindow.AlignToFile = chromFileInfoId; alignToFileItem.Checked = false; } items.Insert(iInsert++, alignToFileItem); } } return(iInsert); }
/// <summary> /// Merge my items into the given target at the given index. /// </summary> public void MergeInto(ToolStripItemCollection target, int index) { if (index > 0) { var sep = new ToolStripSeparator(); items.Insert(0, sep); } foreach (var item in items) { target.Insert(index++, item); } }
private void InsertMenuEntry(ToolStripItemCollection collection, int idx, string content) { var menuItem = new ToolStripMenuItem(content); menuItem.Click += MRUMenuItemClick; menuItem.Tag = content; if (first) { menuItem.ShortcutKeys = Keys.F4; first = false; } collection.Insert(idx, menuItem); }
/// <summary> /// Add one single MenuItem (and all needed Parents) /// </summary> /// <param name="item"></param> /// <param name="parts"></param> public static void AddMenuItem(ref SimPe.Events.ChangedResourceEvent ev, ToolStripItemCollection parent, ToolMenuItemExt item, string[] parts) { System.Reflection.Assembly a = typeof(LoadFileWrappersExt).Assembly; for (int i = 0; i < parts.Length - 1; i++) { string name = SimPe.Localization.GetString(parts[i]); ToolStripMenuItem mi = null; //find an existing Menu Item if (parent != null) { foreach (ToolStripMenuItem oi in parent) { if (oi.Text.ToLower().Trim() == name.ToLower().Trim()) { mi = oi; break; } } } if (mi == null) { mi = new ToolStripMenuItem(name); if (parent != null) { System.IO.Stream imgstr = a.GetManifestResourceStream("SimPe." + parts[i] + ".png"); if (imgstr != null) { mi.Image = System.Drawing.Image.FromStream(imgstr); } parent.Insert(0, mi); } } parent = mi.DropDownItems; } if (item.ToolExt != null) { LoadFileWrappersExt.SetShurtcutKey(item, item.ToolExt.Shortcut); item.Image = item.ToolExt.Icon; //item.ToolTipText = item.ToolExt.ToString(); } parent.Add(item); ev += new SimPe.Events.ChangedResourceEvent(item.ChangeEnabledStateEventHandler); item.ChangeEnabledStateEventHandler(item, new SimPe.Events.ResourceEventArgs(null)); }
// ReSharper disable once UnusedMethodReturnValue.Local private static ToolStripSeparator AddMenuSeparator(ToolStripItemCollection itemsCollection, bool insertToTop = false) { var separator = new ToolStripSeparator(); if (insertToTop) { itemsCollection.Insert(0, separator); } else { itemsCollection.Add(separator); } return(separator); }
private static void ReplaceItems(ToolStripItemCollection collection, IEnumerable <ToolStripItem> oldItems, IEnumerable <ToolStripItem> newItems) { int insertIndex = collection.IndexOf(oldItems.First()); foreach (ToolStripItem itemToRemove in oldItems) { collection.Remove(itemToRemove); } foreach (ToolStripItem itemToAdd in newItems) { collection.Insert(insertIndex++, itemToAdd); } }
private bool InsertItemAboveSeparator(ToolStripItemCollection menuItems, ToolStripMenuItem item) { bool inserted = false; for (int i = 0; i < menuItems.Count; i++) { if (menuItems[i] is ToolStripSeparator) { menuItems.Insert(i, item); inserted = true; break; } } return(inserted); }
public void Insert_Item_Null() { ToolStrip toolStrip = CreateToolStrip(); ToolStripItemCollection items = new ToolStripItemCollection( toolStrip, new ToolStripItem [0]); try { items.Insert(0, (ToolStripItem)null); Assert.Fail("#1"); } catch (ArgumentNullException ex) { Assert.AreEqual(typeof(ArgumentNullException), ex.GetType(), "#2"); Assert.IsNull(ex.InnerException, "#3"); Assert.IsNotNull(ex.Message, "#4"); Assert.AreEqual("value", ex.ParamName, "#5"); } }
public override bool Loaded() { Host2 = Host; but = new ToolStripMenuItem("SprayPlanner"); but.Click += but_Click; bool hit = false; ToolStripItemCollection col = Host.FPMenuMap.Items; col.Insert(0, but); this.mapOverlayFD = new GMapOverlay("return_point"); this.mapOverlayFP = new GMapOverlay("return_point"); Host.FDGMapControl.Overlays.Add(this.mapOverlayFD); Host.FPGMapControl.Overlays.Add(this.mapOverlayFP); if (Host.config.ContainsKey("sprayplan_pump_pwm")) { pump_pwm = double.Parse(Host.config["sprayplan_pump_pwm"].ToString()); } if (Host.config.ContainsKey("sprayplan_pump_servo")) { pump_servo = double.Parse(Host.config["sprayplan_pump_servo"].ToString()); } if (Host.config.ContainsKey("sprayplan_spinner_pwm")) { spinner_pwm = double.Parse(Host.config["sprayplan_spinner_pwm"].ToString()); } if (Host.config.ContainsKey("sprayplan_spinner_servo")) { spinner_servo = double.Parse(Host.config["sprayplan_spinner_servo"].ToString()); } if (Host.config.ContainsKey("sprayplan_tank_low")) { tank_low = int.Parse(Host.config["sprayplan_tank_low"].ToString()); } if (Host.config.ContainsKey("sprayplan_spray_delay")) { spray_delay = int.Parse(Host.config["sprayplan_spray_delay"].ToString()); } return(true); }
public virtual void AddBarItem(IWindowsBarItem item, GetPriorityHandler getPriority) { // Add the item to the sorted list BarItemComparer newBarItemComparer = new BarItemComparer(item, getPriority); _sortedBarItems.Add(newBarItemComparer, item); int index = _sortedBarItems.IndexOfKey(newBarItemComparer) + _reservedItems; if (index > _items.Count) { _items.Add(((IToolStripItemContainer)item).Item); } else { _items.Insert(index, ((IToolStripItemContainer)item).Item); } }
public override bool Loaded() { /* Register with Device Change event */ Host.DeviceChanged += deviceChanged; /* Add to Flight Planner Map Menu */ ToolStripMenuItem trkrHome = new ToolStripMenuItem(Strings.TrackerHome) { Name = "trkrHomeMenuItem" }; ToolStripMenuItem obtainFrmMod = new ToolStripMenuItem(Strings.ObtainFromModule); obtainFrmMod.Click += setTrackerHomeFromModule; ToolStripMenuItem setAtLoc = new ToolStripMenuItem(Strings.SetHere); setAtLoc.Click += setFromPlannerLocation; trkrHome.DropDownItems.AddRange(new ToolStripItem[] { obtainFrmMod, setAtLoc }); ToolStripItemCollection col = Host.FPMenuMap.Items; int index = col.Count; foreach (ToolStripItem item in col) { if (item.Text.Equals(Strings.TrackerHome)) { index = col.IndexOf(item); col.Remove(item); break; } } if (index != col.Count) { col.Insert(index, trkrHome); } else { col.Add(trkrHome); } if (getDevice() != null) { _Available = true; } return(true); }
private void MergeMenu(ToolStripItemCollection source, ToolStripItemCollection dest) { while (source.Count > 0) { ToolStripMenuItem item = (ToolStripMenuItem)source[0]; if (item.MergeAction == MergeAction.Insert) { for (int index = 0; index < dest.Count; ++index) { if (dest[index].MergeIndex > item.MergeIndex) { dest.Insert(index, item); break; } } } else if (item.MergeAction == MergeAction.Append) { dest.Add(item); } else if (item.MergeAction == MergeAction.MatchOnly) { ToolStripMenuItem match = null; foreach (ToolStripMenuItem destitem in dest) { if (destitem.Text == item.Text) { match = destitem; break; } } if (match == null) { throw new ApplicationException("Can't merge with nonexistent menu '" + item.Text + "'"); } MergeMenu(item.DropDownItems, match.DropDownItems); source.Remove(item); } else { throw new ApplicationException("Unsupported menu merge action"); } } }
private static void ToggleItem(ToolStripItemCollection items, ToolStripItem item, bool visible, bool first = false) { if (visible) { if (first) { items.Insert(0, item); } else { items.Add(item); } } else if (items.Contains(item)) { items.Remove(item); } }