Esempio n. 1
0
        /// <summary>
        ///     Adds a new menu item to the menu.
        /// </summary>
        /// <param name="menuItem">The menu item to add.</param>
        public void Add(RecentMenuItem menuItem)
        {
            if (!menuItem.FileInfo.Exists)
            {
                return;
            }

            Remove(menuItem, false);

            if (_items.Count == _maxDisplayItems)
            {
                _items.RemoveAt(_items.Count - 1);
            }

            _items.Insert(0, menuItem);

            menuItem.Click += (s, e) =>
            {
                if (ItemClicked != null)
                {
                    ItemClicked(s, e);
                }
            };

            PopulateItems();
        }
Esempio n. 2
0
        /// <summary>
        ///     Removes a menu item from the menu
        /// </summary>
        /// <param name="menuItem">The menu item to remove.</param>
        /// <param name="removeExistingFiles">Indicates whether menu items with the same file path should be removed as well.</param>
        /// <param name="repopulateDisplayItems">Indicates whether the menu should be repopulated afterwards.</param>
        public void Remove(RecentMenuItem menuItem, bool removeExistingFiles, bool repopulateDisplayItems = true)
        {
            _items.Remove(menuItem);

            if (removeExistingFiles)
            {
                _items.RemoveAll(x => x.FileInfo.FullName.Equals(menuItem.FileInfo.FullName, StringComparison.OrdinalIgnoreCase));
            }

            if (repopulateDisplayItems)
            {
                PopulateItems();
            }
        }