public void AddRecentFile(string filename) { if (string.IsNullOrEmpty(filename) || filename.ToLower() == "untitled") { return; } if (RecentDocuments.Contains(filename)) { RecentDocuments.Remove(filename); } RecentDocuments.Insert(0, filename); OnPropertyChanged(nameof(RecentDocuments)); if (RecentDocuments.Count > RecentDocumentsLength) { // the hard way to force collection to properly refresh so bindings work properly var recents = RecentDocuments.Take(RecentDocumentsLength); RecentDocuments.Clear(); foreach (var recent in recents) { RecentDocuments.Add(recent); } } }
// public void ReferenceRecentDocument(string path) { int i = RecentDocuments.IndexOf(path); if (i >= 0) { RecentDocuments.RemoveAt(i); } RecentDocuments.Insert(0, path); while (RecentDocuments.Count > RecentDocumentsMax) // BindingList doesn't support RemoveRange() { RecentDocuments.RemoveAt(RecentDocuments.Count - 1); } }
public void AddRecentFile(string filename) { if (string.IsNullOrEmpty(filename) || filename.ToLower() == "untitled") { return; } if (RecentDocuments.Contains(filename)) { RecentDocuments.Remove(filename); } RecentDocuments.Insert(0, filename); OnPropertyChanged(nameof(RecentDocuments)); if (RecentDocuments.Count > 12) { RecentDocuments = RecentDocuments.Take(12).ToList(); } }
public void AddRecentFile(string filename) { if (string.IsNullOrEmpty(filename) || filename.ToLower() == "untitled") { return; } if (RecentDocuments.Contains(filename)) { RecentDocuments.Remove(filename); } RecentDocuments.Insert(0, filename); OnPropertyChanged(nameof(RecentDocuments)); if (RecentDocuments.Count > RecentDocumentsLength) { RecentDocuments.Clear(); foreach (var recent in RecentDocuments.Take(RecentDocumentsLength)) { RecentDocuments.Add(recent); } } }