Example #1
0
        /// <summary>Update the recent files menu</summary>
        public void UpdateMenu()
        {
            if (m_menu == null || m_on_click == null)
            {
                return;
            }
            m_menu.DropDownItems.Clear();
            foreach (string f in m_files)
            {
                var item = new ToolStripMenuItem(f)
                {
                    MergeAction = m_menu.MergeAction
                };
                item.Click += (s, a) =>
                {
                    var menu = (ToolStripMenuItem)s;
                    Add(menu.Text, false);
                    m_on_click(menu.Text);
                };
                item.MouseDown += (s, a) =>
                {
                    var menu = (ToolStripMenuItem)s;
                    if (a.Button != MouseButtons.Right)
                    {
                        return;
                    }
                    var dd = (ToolStripDropDown)menu.GetCurrentParent();
                    dd.AutoClose = false;
                    ShowMenuItemContextMenu(item, a.X, a.Y, () => { dd.AutoClose = true; dd.Close(); });
                };
                m_menu.DropDownItems.Add(item);
            }

            m_menu.DropDownItems.Add(new ToolStripSeparator {
                MergeAction = m_menu.MergeAction
            });

            // Add a menu item for clearing the recent files list
            var clear_all = new ToolStripMenuItem(ResetListText)
            {
                MergeAction = m_menu.MergeAction
            };

            clear_all.Click += (s, a) =>
            {
                var menu = (ToolStripMenuItem)s;
                ((ToolStripDropDown)menu.GetCurrentParent()).Close();
                Clear();
                RecentListChanged?.Invoke(this, EventArgs.Empty);
            };
            m_menu.DropDownItems.Add(clear_all);
        }
Example #2
0
        /// <summary>Add a file to the recent files list</summary>
        public void Add(string file, bool update_menu)
        {
            if (string.IsNullOrEmpty(file))
            {
                throw new Exception("Invalid recent file");
            }

            Remove(file, false);
            m_files.Insert(0, file);
            if (m_files.Count > MaxCount)
            {
                m_files.RemoveAt(m_files.Count - 1);
            }
            if (update_menu)
            {
                UpdateMenu();
            }
            RecentListChanged?.Invoke(this, EventArgs.Empty);
        }
Example #3
0
 /// <summary>
 /// Safely invoke FileLogChanged
 /// </summary>
 public static void ChangeRecentList()
 {
     RecentListChanged.SafeInvoke(null, EventArgs.Empty);
 }