private void Update()
 {
     for (int k = DropDownItems.Count - 1; k >= _favouritesStartIndex; k--)
     {
         DropDownItems.RemoveAt(k);
     }
     foreach (MostRecentItem item in _favourites)
     {
         DropDownItems.Add(CreateFavouriteItem(item));
     }
 }
示例#2
0
 private void removeChild(MenuItem associatedMenuItem)
 {
     for (int i = DropDownItems.Count - 1; i >= 0; i--)
     {
         CustomToolStripMenuItem customMenuItem = DropDownItems[i] as CustomToolStripMenuItem;
         if ((customMenuItem != null) && (customMenuItem.AssociatedMenuItem == associatedMenuItem))
         {
             DropDownItems.RemoveAt(i);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Adds a file to this RecentFileMenu
        /// </summary>
        public void AddFile(string fileName)
        {
            // check if the file is already in the collection
            int alreadyIn = GetIndex(fileName);

            if (alreadyIn > 0) // remove it
            {
                Settings.Default.RecentFiles.RemoveAt(alreadyIn);
                if (DropDownItems.Count > alreadyIn)
                {
                    DropDownItems.RemoveAt(alreadyIn);
                }
            }
            else if (alreadyIn == 0) // it´s the latest file so return
            {
                return;
            }

            if (!this.Enabled)
            {
                this.Enabled = true;
            }

            // insert the file on top of the list
            Settings.Default.RecentFiles.Insert(0, fileName);
            DropDownItems.Insert(0, new RecentFileMenuItem(fileName));

            // remove the last one, if max size is reached
            if (Settings.Default.RecentFiles.Count > Maximum)
            {
                Settings.Default.RecentFiles.RemoveAt(Maximum);
            }
            if (Settings.Default.RecentFiles.Count > Settings.Default.RecentFilesMax &&
                DropDownItems.Count > Settings.Default.RecentFilesMax)
            {
                DropDownItems.RemoveAt(Settings.Default.RecentFilesMax);
            }

            // save the changes
            Settings.Default.Save();
        }
        public void addEntry(string entry)
        {
            if (alreadyHasEntry(entry))
            {
                moveEntryForward(entry);
            }
            else
            {
                if (DropDownItems.Count == 10)
                {
                    DropDownItems.RemoveAt(0);
                }

                ToolStripMenuItem menuEntry = new ToolStripMenuItem(entry);
                menuEntry.Click += (object sender, EventArgs e) =>
                {
                    OnEntryClicked((ToolStripMenuItem)sender, EventArgs.Empty);
                };

                DropDownItems.Add(menuEntry);
            }
        }
        private void HostsArchiveList_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
        {
            switch (e.ListChangedType)
            {
            case System.ComponentModel.ListChangedType.Reset:
                Reset();
                break;

            case System.ComponentModel.ListChangedType.ItemAdded:
            {
                DropDownItems.Insert(e.NewIndex, new HostsArchiveToolStripMenuItem(_model[e.NewIndex]));
            }
            break;

            case System.ComponentModel.ListChangedType.ItemDeleted:
                DropDownItems.RemoveAt(e.NewIndex);
                break;

            case System.ComponentModel.ListChangedType.ItemMoved:
            {
                var item = DropDownItems[e.OldIndex];
                DropDownItems.RemoveAt(e.OldIndex);
                DropDownItems.Insert(e.NewIndex, item);
            }
            break;

            case System.ComponentModel.ListChangedType.ItemChanged:
            {
                if (DropDownItems[e.NewIndex] is HostsArchiveToolStripMenuItem item)
                {
                    item.Model = _model[e.NewIndex];
                }
            }
            break;

            default:
                break;
            }
        }