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); }
public override bool Loaded() { Host2 = Host; but = new ToolStripMenuItem("SimpleGrid"); but.Click += but_Click; bool hit = false; ToolStripItemCollection col = Host.FPMenuMap.Items; int index = col.Count; foreach (ToolStripItem item in col) { if (item.Text.Equals(Strings.AutoWP)) { index = col.IndexOf(item); ((ToolStripMenuItem)item).DropDownItems.Add(but); hit = true; break; } } if (hit == false) { col.Add(but); } return(true); }
public override bool Loaded() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GridUI)); but = new ToolStripMenuItem(Name); but.Click += but_Click; bool hit = false; ToolStripItemCollection col = Host.FPMenuMap.Items; int index = col.Count; foreach (ToolStripItem item in col) { if (item.Name.Equals("autoWPToolStripMenuItem")) { index = col.IndexOf(item); ((ToolStripMenuItem)item).DropDownItems.Add(but); hit = true; break; } } if (hit == false) { col.Add(but); } return(true); }
public override bool Loaded() { Grid.Host2 = Host; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GridUIv2)); var temp = (string)(resources.GetObject("$this.Text")); but = new ToolStripMenuItem(temp); but.Click += but_Click; bool hit = false; ToolStripItemCollection col = Host.FPMenuMap.Items; int index = col.Count; foreach (ToolStripItem item in col) { if (item.Text.Equals(Strings.AutoWP)) { index = col.IndexOf(item); ((ToolStripMenuItem)item).DropDownItems.Add(but); hit = true; break; } } if (hit == false) { col.Add(but); } return(true); }
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); } }
// 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()); } } }
public int Compare(object x, object y) { ToolStripItem oItem1 = (ToolStripItem)x; ToolStripItem oItem2 = (ToolStripItem)y; var cmd1 = oItem1.Tag as IAtomicCommand; var cmd2 = oItem2.Tag as IAtomicCommand; var explicitOrder = (cmd1?.Weight ?? 0) - (cmd2?.Weight ?? 0); // if there is no difference in explicit weight if (explicitOrder == 0) { // use the original weight it had in the menu return(_originalOrder.IndexOf(oItem1) - _originalOrder.IndexOf(oItem2)); } return(explicitOrder); }
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); } }
public void SpectrumToolStripCheckBox(ToolStripMenuItem it) { if (it.Enabled) { it.Checked = !it.Checked; } int specIdx = specMenu.IndexOf(it); spectra.GetSpectrum(specIdx).visible = !spectra.GetSpectrum(specIdx).visible; specGraph.Invalidate(); DrawSpectra(); SetGraphYScale(); }
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 void ClearHelpers(ToolStripItemCollection dropdown, ToolStripItem tss, string prefix) { int i = dropdown.IndexOf(tss) + 1; while (true) { if (i >= dropdown.Count) { break; } if (!dropdown[i].Name.StartsWith(prefix)) { break; } dropdown.RemoveAt(i); } }
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); }
public static bool RemoveCommand(String commandId, ToolStripItemCollection items) { ToolStripItem cmd = GetCommandItem(commandId, ref items); if (cmd != null) { // Prevent sequential visible separators int iItem = items.IndexOf(cmd); if (iItem != -1) { ToolStripItem nextCmd = null, prevCmd = null; if (iItem > 0) { prevCmd = items[iItem - 1]; } if (iItem < (items.Count - 1)) { nextCmd = items[iItem + 1]; } if ((nextCmd is ToolStripSeparator) && ((prevCmd == null) || (prevCmd is ToolStripSeparator))) { items.Remove(nextCmd); } else if ((prevCmd is ToolStripSeparator) && (nextCmd == null)) { items.Remove(prevCmd); } items.Remove(cmd); } return(true); } return(false); }
private void AddHelper(ToolStripItemCollection dropdown, ToolStripItem tss, string prefix, int helper, string value) { ToolStripMenuItem tsiHelper = new ToolStripMenuItem(value, null, tsHelper_Click) { Name = prefix + helper, Tag = helper, }; int i = dropdown.IndexOf(tss); while (true) { i++; if (i >= dropdown.Count) { break; } if (!dropdown[i].Name.StartsWith(prefix)) { break; } } dropdown.Insert(i, tsiHelper); }
public override bool Loaded() { Host2 = Host; ToolStripMenuItem but = new ToolStripMenuItem("Survey (Grid)"); but.Click += but_Click; ToolStripItemCollection col = Host.FPMenuMap.Items; int index = col.Count; foreach (ToolStripItem item in col) { if (item.Text.Equals("Auto WP")) { index = col.IndexOf(item); ((ToolStripMenuItem)item).DropDownItems.Add(but); break; } } return(true); }
/* private static void CheckCompatibilityRefl(string strFile) * { * ResolveEventHandler eh = delegate(object sender, ResolveEventArgs e) * { * string strName = e.Name; * if(strName.Equals("KeePass", StrUtil.CaseIgnoreCmp) || * strName.StartsWith("KeePass,", StrUtil.CaseIgnoreCmp)) * return Assembly.ReflectionOnlyLoadFrom(WinUtil.GetExecutable()); * * return Assembly.ReflectionOnlyLoad(strName); * }; * * AppDomain d = AppDomain.CurrentDomain; * d.ReflectionOnlyAssemblyResolve += eh; * try * { * Assembly asm = Assembly.ReflectionOnlyLoadFrom(strFile); * asm.GetTypes(); * } * finally { d.ReflectionOnlyAssemblyResolve -= eh; } * } */ internal void AddMenuItems(PluginMenuType t, ToolStripItemCollection c, ToolStripItem tsiPrev) { if (c == null) { Debug.Assert(false); return; } List <ToolStripItem> l = new List <ToolStripItem>(); foreach (PluginInfo pi in m_vPlugins) { if (pi == null) { Debug.Assert(false); continue; } Plugin p = pi.Interface; if (p == null) { Debug.Assert(false); continue; } ToolStripMenuItem tsmi = p.GetMenuItem(t); if (tsmi != null) { // string strTip = tsmi.ToolTipText; // if((strTip == null) || (strTip == tsmi.Text)) // strTip = string.Empty; // if(strTip.Length != 0) strTip += MessageService.NewParagraph; // strTip += KPRes.Plugin + ": " + pi.Name; // tsmi.ToolTipText = strTip; l.Add(tsmi); } } if (l.Count == 0) { return; } int iPrev = ((tsiPrev != null) ? c.IndexOf(tsiPrev) : -1); if (iPrev < 0) { Debug.Assert(false); iPrev = c.Count - 1; } int iIns = iPrev + 1; l.Sort(PluginManager.CompareToolStripItems); if ((iPrev >= 0) && (iPrev < c.Count) && !(c[iPrev] is ToolStripSeparator)) { l.Insert(0, new ToolStripSeparator()); } if ((iIns < c.Count) && !(c[iIns] is ToolStripSeparator)) { l.Add(new ToolStripSeparator()); } if (iIns == c.Count) { c.AddRange(l.ToArray()); } else { for (int i = 0; i < l.Count; ++i) { c.Insert(iIns + i, l[i]); } } }
public static bool HideCommand(String commandId, ToolStripItemCollection items) { ToolStripItem cmd = GetCommandItem(commandId, items); if (cmd != null) { cmd.Visible = false; cmd.Enabled = false; // Prevent sequential visible separators ToolStripItem nextVisCmd = null; ToolStripItem prevVisCmd = null; int iItem = items.IndexOf(cmd); // Handle nested menus // ie. cmd may not be an immediate child of items if ((iItem == -1) && (cmd.OwnerItem is ToolStripMenuItem)) { items = (cmd.OwnerItem as ToolStripMenuItem).DropDownItems; iItem = items.IndexOf(cmd); } if (iItem != -1) { int iNext = iItem, iPrev = iItem; while (iPrev-- > 0) { if (items[iPrev].Visible) { prevVisCmd = items[iPrev]; break; } } while (++iNext < items.Count) { if (items[iNext].Visible) { nextVisCmd = items[iNext]; break; } } if ((nextVisCmd is ToolStripSeparator) && ((prevVisCmd == null) || (prevVisCmd is ToolStripSeparator))) { nextVisCmd.Visible = false; nextVisCmd.Enabled = false; } else if ((prevVisCmd is ToolStripSeparator) && (nextVisCmd == null)) { prevVisCmd.Visible = false; prevVisCmd.Enabled = false; } } return(true); } return(false); }
public int IndexOf(IBarItem item) { return(collection.IndexOf(item as ToolStripItem)); }
public void CreateCopy(ToolStripItemCollection tsicTarget, ToolStripItem tsiPosRef, bool bAfter, ToolStripMenuItem tsmiBase) { if (tsicTarget == null) { Debug.Assert(false); return; } if (tsmiBase == null) { Debug.Assert(false); return; } ToolStripMenuItem tsmi = new ToolStripMenuItem(); string strName = tsmiBase.Name, strNameNew = null; if (!string.IsNullOrEmpty(strName)) { if (strName.StartsWith("m_menu", StrUtil.CaseIgnoreCmp)) { strNameNew = "m_ctx" + strName.Substring(6); } } if (!string.IsNullOrEmpty(strNameNew)) { ToolStripItem[] v = tsicTarget.Find(strNameNew, true); if ((v == null) || (v.Length == 0)) { tsmi.Name = strNameNew; } else { Debug.Assert(false); } } else { Debug.Assert(false); } CreateLink(tsmi, tsmiBase, (tsmiBase.DropDownItems.Count == 0)); int i, n = tsicTarget.Count; if (tsiPosRef == null) { i = (bAfter ? n : 0); } else { i = tsicTarget.IndexOf(tsiPosRef); if (i < 0) { Debug.Assert(false); i = n; } else if (bAfter) { ++i; } } tsicTarget.Insert(i, tsmi); foreach (ToolStripItem tsiSub in tsmiBase.DropDownItems) { ToolStripMenuItem tsmiSub = (tsiSub as ToolStripMenuItem); if (tsmiSub != null) { CreateCopy(tsmi.DropDownItems, null, true, tsmiSub); } else if (tsiSub is ToolStripSeparator) { tsmi.DropDownItems.Add(new ToolStripSeparator()); } else { Debug.Assert(false); } } }