void CreateDropDownItems()
        {
            // let's assume that if a menuBuilder exists,
            // as in the Search Results panel or the Class
            // Browser toolbar, it will handle this step.
            if (menuBuilder != null)
            {
                return;
            }

            // also, let's prevent a null exception
            // in the event that there are no subitems
            if (subItems == null || subItems.Count == 0)
            {
                return;
            }

            DropDownItems.Clear();
            foreach (object item in subItems)
            {
                if (item is ToolStripItem)
                {
                    DropDownItems.Add((ToolStripItem)item);
                    if (item is IStatusUpdate)
                    {
                        ((IStatusUpdate)item).UpdateStatus();
                        ((IStatusUpdate)item).UpdateText();
                    }
                }
                else
                {
                    IMenuItemBuilder submenuBuilder = (IMenuItemBuilder)item;
                    DropDownItems.AddRange(submenuBuilder.BuildItems(codon, caller).Cast <ToolStripItem>().ToArray());
                }
            }
        }
Beispiel #2
0
        void OnDropDownOpening(object sender, EventArgs e)
        {
            DropDownItems.Clear();

            if (list == null)
            {
                return;
            }

            var currentTags = list.Tags;
            var tags        = DataStore.Database.GetTags(false);

            foreach (var tag in tags)
            {
                var item = new ToolStripMenuItem(tag.Key)
                {
                    Tag = tag.Key, CheckOnClick = true, Checked = currentTags.Contains(tag.Key)
                };
                item.CheckedChanged += ItemCheckedChanged;
                DropDownItems.Insert(DropDownItems.Count, item);
            }

            DropDownItems.Insert(DropDownItems.Count, customTag);
        }
        private void OnDropDownOpening(object sender, EventArgs e)
        {
            var revisions = _revisionFunc?.Invoke();

            if (revisions == null || revisions.Count == 0)
            {
                if (sender == null)
                {
                    // create the initial dummy menu on a dummy revision
                    revisions = new List <GitRevision> {
                        new GitRevision(GitUIPluginInterfaces.ObjectId.WorkTreeId)
                    };
                }
                else
                {
                    HideDropDown();
                    return;
                }
            }

            DropDownItems.Clear();

            List <string> branchNames = new List <string>();
            List <string> tagNames    = new List <string>();

            foreach (var revision in revisions)
            {
                var refLists = new GitRefListsForRevision(revision);
                branchNames.AddRange(refLists.GetAllBranchNames());
                tagNames.AddRange(refLists.GetAllTagNames());
            }

            _itemNumber = 0;

            // Add items for branches
            if (branchNames.Any())
            {
                var caption = new ToolStripMenuItem {
                    Text = Strings.Branches
                };
                MenuUtil.SetAsCaptionMenuItem(caption, Owner);
                DropDownItems.Add(caption);

                foreach (var name in branchNames)
                {
                    AddItem(name, textToCopy: name, Images.Branch, hotkey: null);
                }

                DropDownItems.Add(new ToolStripSeparator());
            }

            // Add items for tags
            if (tagNames.Any())
            {
                var caption = new ToolStripMenuItem {
                    Text = Strings.Tags
                };
                MenuUtil.SetAsCaptionMenuItem(caption, Owner);
                DropDownItems.Add(caption);

                foreach (var name in tagNames)
                {
                    AddItem(name, textToCopy: name, Images.Tag, hotkey: null);
                }

                DropDownItems.Add(new ToolStripSeparator());
            }

            // Add other items
            int count = revisions.Count();

            AddItem(Strings.GetCommitHash(count), r => r.Guid, Images.CommitId, 'C', Keys.Control | Keys.C);
            AddItem(Strings.GetMessage(count), r => r.Body ?? r.Subject, Images.Message, 'M');
            AddItem(Strings.GetAuthor(count), r => $"{r.Author} <{r.AuthorEmail}>", Images.Author, 'A');

            if (count == 1 && revisions.First().AuthorDate == revisions.First().CommitDate)
            {
                AddItem(Strings.Date, r => r.AuthorDate.ToString(), Images.Date, 'D');
            }
            else
            {
                AddItem(Strings.GetAuthorDate(count), r => r.AuthorDate.ToString(), Images.Date, 'T');
                AddItem(Strings.GetCommitDate(count), r => r.CommitDate.ToString(), Images.Date, 'D');
            }
        }
 protected override void OnDropDownShow(EventArgs e)
 {
     DropDownItems.Clear();
     DropDownItems.AddRange(m_itemList);
     base.OnDropDownShow(e);
 }
 public void ClearItems()
 {
     DropDownItems.Clear();
 }
 private void Reset()
 {
     DropDownItems.Clear();
     DropDownItems.AddRange(_model.Select(a => new HostsArchiveToolStripMenuItem(a)).ToArray());
 }
Beispiel #7
0
        public void BuildFilterList()
        {
            Program.AssertOnEventThread();

            if (inFilterListUpdate)
            {
                // queue up an update after the current one has finished,
                // in case the update has missed the relevant change
                retryFilterListUpdate = true;
                return;
            }

            inFilterListUpdate = true;

            try
            {
                DropDownItems.Clear();
                DeregisterEvents();
                RegisterEvents();

                foreach (IXenConnection c in ConnectionsManager.XenConnectionsCopy)
                {
                    Pool p = Helpers.GetPool(c);

                    if (p == null)// Stand alone host
                    {
                        foreach (Host h in c.Cache.Hosts)
                        {
                            var item = GenerateFilterItem(h, h.uuid);
                            item.Checked = HostCheckStates.ContainsKey(h.uuid);
                            DropDownItems.Add(item);
                            break;
                        }
                    }
                    else
                    {
                        DropDownItems.Add(GeneratePoolFilterItem(p));
                    }
                }

                if (DropDownItems.Count > 0)
                {
                    toolStripMenuItemAll = new ToolStripMenuItem
                    {
                        Text    = Messages.FILTER_SHOW_ALL,
                        Enabled = FilterIsOn
                    };

                    DropDownItems.AddRange(new ToolStripItem[]
                    {
                        new ToolStripSeparator(),
                        toolStripMenuItemAll
                    });
                }

                Enabled = DropDownItems.Count > 0;
            }
            finally
            {
                inFilterListUpdate = false;
                if (retryFilterListUpdate)
                {
                    // there was a request to update while we were building,
                    // rebuild in case we missed something
                    retryFilterListUpdate = false;
                    BuildFilterList();
                }
            }
        }
Beispiel #8
0
 private void ClearChildItems()
 {
     DropDownItems.Clear();
     Enabled = false;
 }
        public CopyContextMenuItem()
        {
            Image = Images.CopyToClipboard;
            Text  = "Copy to clipboard";

            // Add a dummy copy item, so that the shortcut key works.
            // This item will never be seen by the user, as the submenu is rebuilt on opening.
            AddItem("Dummy item", r => r.Guid, image: null, Keys.Control | Keys.C, showShortcutKeys: false);

            DropDownOpening += OnDropDownOpening;

            void OnDropDownOpening(object sender, EventArgs e)
            {
                var revision = _revisionFunc?.Invoke();

                if (revision == null)
                {
                    HideDropDown();
                    return;
                }

                DropDownItems.Clear();

                var refLists    = new GitRefListsForRevision(revision);
                var branchNames = refLists.GetAllBranchNames();
                var tagNames    = refLists.GetAllTagNames();

                // Add items for branches
                if (branchNames.Any())
                {
                    var caption = new ToolStripMenuItem {
                        Text = Strings.Branches
                    };
                    MenuUtil.SetAsCaptionMenuItem(caption, Owner);
                    DropDownItems.Add(caption);

                    foreach (var name in branchNames)
                    {
                        AddItem(name, _ => name, Images.Branch);
                    }

                    DropDownItems.Add(new ToolStripSeparator());
                }

                // Add items for tags
                if (tagNames.Any())
                {
                    var caption = new ToolStripMenuItem {
                        Text = Strings.Tags
                    };
                    MenuUtil.SetAsCaptionMenuItem(caption, Owner);
                    DropDownItems.Add(caption);

                    foreach (var name in tagNames)
                    {
                        AddItem(name, _ => name, Images.Tag);
                    }

                    DropDownItems.Add(new ToolStripSeparator());
                }

                // Add other items
                AddItem($"{Strings.CommitHash}     ({revision.ObjectId.ToShortString()}...)", r => r.Guid, Images.CommitId, Keys.Control | Keys.C);
                AddItem($"{Strings.Message}     ({revision.Subject.ShortenTo(30)})", r => r.Body ?? r.Subject, Images.Message);
                AddItem($"{Strings.Author}     ({revision.Author})", r => r.Author, Images.Author);

                if (revision.AuthorDate == revision.CommitDate)
                {
                    AddItem($"{Strings.Date}     ({revision.CommitDate})", r => r.CommitDate.ToString(), Images.Date);
                }
                else
                {
                    AddItem($"{Strings.AuthorDate}     ({revision.AuthorDate})", r => r.AuthorDate.ToString(), Images.Date);
                    AddItem($"{Strings.CommitDate}     ({revision.CommitDate})", r => r.CommitDate.ToString(), Images.Date);
                }
            }

            void AddItem(string displayText, Func <GitRevision, string> clipboardText, Image image, Keys shortcutKeys = Keys.None, bool showShortcutKeys = true)
            {
                var item = new ToolStripMenuItem
                {
                    Text             = displayText,
                    ShortcutKeys     = shortcutKeys,
                    ShowShortcutKeys = showShortcutKeys,
                    Image            = image
                };

                item.Click += delegate
                {
                    var revision = _revisionFunc?.Invoke();
                    if (revision != null)
                    {
                        Clipboard.SetText(clipboardText(revision));
                    }
                };

                DropDownItems.Add(item);
            }
        }
        public CopyContextMenuItem()
        {
            Image = Images.CopyToClipboard;
            Text  = "Copy to clipboard";

            // Action template
            Action <Func <GitRevision, string> > extractText = (Func <GitRevision, string> extractRevisionText) =>
            {
                var gitRevisions = _revisionFunc?.Invoke();
                var sb           = new StringBuilder();
                foreach (var revision in gitRevisions)
                {
                    sb.AppendLine(extractRevisionText(revision));
                }

                Clipboard.SetText(sb.ToString());
            };

            // Add a dummy copy item, so that the shortcut key works.
            // This item will never be seen by the user, as the submenu is rebuilt on opening.
            AddItem("Dummy item", () => extractText(r => r.Guid), image: null, Keys.Control | Keys.C, showShortcutKeys: false);

            DropDownOpening += OnDropDownOpening;

            void OnDropDownOpening(object sender, EventArgs e)
            {
                var revisions = _revisionFunc?.Invoke();

                if (revisions == null || revisions.Count == 0)
                {
                    HideDropDown();
                    return;
                }

                DropDownItems.Clear();

                List <string> branchNames = new List <string>();
                List <string> tagNames    = new List <string>();

                foreach (var revision in revisions)
                {
                    var refLists = new GitRefListsForRevision(revision);
                    branchNames.AddRange(refLists.GetAllBranchNames());
                    tagNames.AddRange(refLists.GetAllTagNames());
                }

                // Add items for branches
                if (branchNames.Any())
                {
                    var caption = new ToolStripMenuItem {
                        Text = Strings.Branches
                    };
                    MenuUtil.SetAsCaptionMenuItem(caption, Owner);
                    DropDownItems.Add(caption);

                    foreach (var name in branchNames)
                    {
                        AddItem(name, () => Clipboard.SetText(name), Images.Branch);
                    }

                    DropDownItems.Add(new ToolStripSeparator());
                }

                // Add items for tags
                if (tagNames.Any())
                {
                    var caption = new ToolStripMenuItem {
                        Text = Strings.Tags
                    };
                    MenuUtil.SetAsCaptionMenuItem(caption, Owner);
                    DropDownItems.Add(caption);

                    foreach (var name in tagNames)
                    {
                        AddItem(name, () => Clipboard.SetText(name), Images.Tag);
                    }

                    DropDownItems.Add(new ToolStripSeparator());
                }

                var count = revisions.Count();

                AddItem(Strings.GetCommitHash(count), () => extractText(r => r.Guid), Images.CommitId, Keys.Control | Keys.C);
                AddItem(Strings.GetMessage(count), () => extractText(r => r.Body ?? r.Subject), Images.Message);
                AddItem(Strings.GetAuthor(count), () => extractText(r => r.Author), Images.Author);
                AddItem(Strings.GetAuthorDate(count), () => extractText(r => r.AuthorDate.ToString()), Images.Date);
                AddItem(Strings.GetCommitDate(count), () => extractText(r => r.CommitDate.ToString()), Images.Date);
            }

            void AddItem(string displayText, Action clickAction, Image image, Keys shortcutKeys = Keys.None, bool showShortcutKeys = true)
            {
                var item = new ToolStripMenuItem
                {
                    Text             = displayText,
                    ShortcutKeys     = shortcutKeys,
                    ShowShortcutKeys = showShortcutKeys,
                    Image            = image
                };

                item.Click += delegate
                {
                    clickAction();
                };

                DropDownItems.Add(item);
            }
        }