Esempio n. 1
0
            public DllRow(ToolStripItemCollection menuItems, TabControl funPanelTabs, string dllPath)
            {
                Dock        = DockStyle.Top;
                BackColor   = ColorSettings.Get("DllRow");
                Height      = 30;
                ColumnCount = 2;

                pathLabel = new Label
                {
                    Text     = dllPath,
                    AutoSize = true,
                    Padding  = new Padding(7)
                };

                removeDllBtn = new Button
                {
                    Text     = "Удалить",
                    AutoSize = true
                };
                removeDllBtn.Click += (object sender, EventArgs e) =>
                {
                    menuItems.Cast <ToolStripItem>()
                    .SingleOrDefault(x => x.Text == pathLabel.Text)
                    .With(menuItems.Remove);
                    var tabs = funPanelTabs.Controls;
                    tabs.Cast <TabPage>().SingleOrDefault(x => x.Text == pathLabel.Text).With(tabs.Remove);
                    Parent = null;
                };
                Controls.Add(removeDllBtn);
                Controls.Add(pathLabel);
            }
Esempio n. 2
0
 static List <ToolStripItem> NonDefaultMenus(ToolStripItemCollection items)
 {
     return(items.Cast <ToolStripItem>()
            .Where(x => x.Text != "Exit" &&
                   x.Text != "Options" &&
                   x.Text != "Open logs" &&
                   x.Text != "Raise issue")
            .ToList());
 }
    /// <summary>
    /// Gets a IEnumerable from a ToolStripItemCollection.
    /// </summary>
    static public IEnumerable <ToolStripItem> ToEnumerable(this ToolStripItemCollection collection, Func <ToolStripItem, bool> predicate = null)
    {
        var result = collection.Cast <ToolStripItem>();

        if (predicate is not null)
        {
            result = result.Where(predicate);
        }
        return(result);
    }
Esempio n. 4
0
        private void rmEvents(ToolStripItemCollection tsmic)
        {
            foreach (ToolStripItem t in tsmic.Cast <ToolStripItem>())
            {
                Object o = typeof(ToolStripItem).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic).GetValue(t);

                using (EventHandlerList list = (EventHandlerList)(t.GetType().GetProperty("Events", BindingFlags.NonPublic | BindingFlags.Instance)).GetValue(t))
                    list.RemoveHandler(o, list[o]);
            }
        }
Esempio n. 5
0
        private static void translateMenu(ToolStripItemCollection items, Action action)
        {
#if DEBUG
            var toRemove = items.Cast <ToolStripItem>().Where(tsi => object.Equals(tsi.Tag, "dup/av")).ToArray();
            foreach (var item in toRemove)
            {
                items.Remove(item);
            }
#endif
            action();
#if DEBUG
            var used = items.Cast <ToolStripItem>().Where(tsi => tsi.Text.Contains('&')).Select(tsi => tsi.Text[tsi.Text.IndexOf('&') + 1]).GroupBy(c => char.ToLowerInvariant(c)).Select(gr => new { Ch = gr.Key, Count = gr.Count() }).ToArray();
            if (used.Any(i => i.Count > 1) || items.Cast <ToolStripItem>().Any(tsi => object.Equals(tsi.Tag, "no_hotkey")))
            {
                items.Add(new ToolStripMenuItem($"duplicates: {used.Where(i => i.Count > 1).Select(i => i.Ch).Order().JoinString().Apply(s => s.Length == 0 ? "(none)" : s)}; available: {"abcdefghijklmnopqrstuvwxyz".Except(used.Select(i => i.Ch)).Order().JoinString()}")
                {
                    Tag = "dup/av"
                });
            }
#endif
        }
        private ToolStripMenuItem GetParentMenuItem(string nameBefore, ToolStripItemCollection collection)
        {
            var tsiParent = collection.Cast <ToolStripMenuItem>().FirstOrDefault(tsiItem =>
                                                                                 string.Compare(tsiItem.Text, nameBefore, StringComparison.OrdinalIgnoreCase) == 0);

            if (tsiParent != null)
            {
                return(tsiParent);
            }
            tsiParent = new ToolStripMenuItem {
                Text = nameBefore
            };
            collection.Add(tsiParent);

            return(tsiParent);
        }
Esempio n. 7
0
        public static void RemoveToolsMenu(this IPluginHost host, string name)
        {
            ToolStripItemCollection menu = host.MainWindow.ToolsMenu.DropDownItems;

            ToolStripItem item = menu.Cast <ToolStripItem>().FirstOrDefault(i => i.Name == name);

            if (item != null)
            {
                var items = (item as ToolStripMenuItem).DropDownItems;

                foreach (ToolStripMenuItem i in items)
                {
                    host.CustomConfig.SetBool(i.Name, i.Checked);
                }

                menu.Remove(item);
            }
        }
Esempio n. 8
0
        private ToolStripItem FindItemByName(ToolStripItemCollection items, string name)
        {
            foreach (var item in items.Cast <ToolStripItem>())
            {
                if (item.Name == name)
                {
                    return(item);
                }

                if (item is ToolStripDropDownItem toolStripDropDownItem)
                {
                    var childResult = FindItemByName(toolStripDropDownItem.DropDownItems, name);
                    if (childResult != null)
                    {
                        return(childResult);
                    }
                }
            }

            return(null);
        }
Esempio n. 9
0
 static List <ToolStripItem> NonDefaultMenus(ToolStripItemCollection items)
 {
     return(items.Cast <ToolStripItem>()
            .Where(x => x.Text != "Options")
            .ToList());
 }
Esempio n. 10
0
 private IEnumerable <ToolStripItem> ActualItems(ToolStripItemCollection items)
 {
     return(items.Cast <ToolStripItem>().Where(item => !(item is ToolStripSeparator)));
 }