Exemplo n.º 1
0
        public void AddItem(string fileName)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                return;
            }

            MruMenuItem item = MenuItems.FirstOrDefault(m => m.FileName == fileName);

            if (item != null)
            {
                MenuItems.Remove(item);
            }
            else
            {
                item = new MruMenuItem()
                {
                    FileName = fileName,
                    Title    = Path.GetFileNameWithoutExtension(fileName)
                };
            }

            MenuItems.Insert(0, item);

            if (MenuItems.Count > MaxItems)
            {
                MenuItems.RemoveAt(MenuItems.Count - 1);
            }

            Save();
        }
Exemplo n.º 2
0
        protected virtual void OnMruItemSelected(MruMenuItem item)
        {
            var handler = MruItemSelected;

            if (handler != null)
            {
                handler.Invoke(this, item);
            }
        }
Exemplo n.º 3
0
        public void LoadParentMenu(ToolStripMenuItem parent)
        {
            int insertIdx = 0;

            var mruPlaceholder = parent.DropDownItems.OfType <MruPlaceholderToolStripMenuItem>().FirstOrDefault();

            if (mruPlaceholder != null)
            {
                insertIdx = parent.DropDownItems.IndexOf(mruPlaceholder);
                parent.DropDownItems.Remove(mruPlaceholder);
            }

            var existingMenuItems = parent.DropDownItems.OfType <MruToolStripMenuItem>().ToList();
            var firstmenuItem     = existingMenuItems.FirstOrDefault();

            if (firstmenuItem != null)
            {
                insertIdx = parent.DropDownItems.IndexOf(firstmenuItem);
            }
            else if (insertIdx == 0)
            {
                insertIdx = parent.DropDownItems.Count;
            }

            foreach (MruToolStripMenuItem existingMenuItem in existingMenuItems)
            {
                existingMenuItem.Click -= NewMenuItem_Click;
                parent.DropDownItems.Remove(existingMenuItem);
            }

            for (int i = 0; i < MenuItems.Count; i++)
            {
                MruMenuItem item        = MenuItems[i];
                var         newMenuItem = new MruToolStripMenuItem()
                {
                    Text    = $"{i + 1}. {item.Title}",
                    Tag     = item,
                    Enabled = item.IsEnabled
                };
                item.MenuItem      = newMenuItem;
                newMenuItem.Click += NewMenuItem_Click;
                parent.DropDownItems.Insert(insertIdx + i, newMenuItem);
            }
        }