public void Add(string file, bool update_menu) { // Validate the filepath if (string.IsNullOrEmpty(file)) { throw new Exception("Invalid recent file path"); } // Move the item matching 'file' to the front of the list Filepaths.RemoveAll(x => string.Equals(x, file, StringComparison.CurrentCultureIgnoreCase)); Filepaths.Insert(0, file); // Cap the maximum number of recent files for (; Filepaths.Count > MaxCount;) { Filepaths.RemoveAt(Filepaths.Count - 1); } // Update the menu if (update_menu) { UpdateMenu(); } // Notify recent files changed RecentFilesListChanged?.Invoke(this, EventArgs.Empty); }
/// <summary>Reset the recent files list</summary> public void Clear() { Filepaths.Clear(); UpdateMenu(); // Notify recent files changed RecentFilesListChanged?.Invoke(this, EventArgs.Empty); }
/// <summary>Remove a filepath from the recent files list</summary> public void Remove(string file, bool update_menu) { Filepaths.RemoveAll(x => string.Equals(x, file, StringComparison.CurrentCultureIgnoreCase)); if (update_menu) { UpdateMenu(); } // Notify recent files changed RecentFilesListChanged?.Invoke(this, EventArgs.Empty); }