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(); } }
// add a document to the MRU list public void AddDocument(string fileName) { // look for the file in the current list RecentDocumentItem doc = RecentDocuments.FirstOrDefault(x => x.FileName == fileName); if (doc != null) { // update date doc.Date = DateTime.Now; } else if (!string.IsNullOrEmpty(fileName)) { // not a member, add doc = new RecentDocumentItem { Text = Path.GetFileName(fileName), SubText = Path.GetDirectoryName(fileName), Date = DateTime.Now }; RecentDocuments.Add(doc); } // trim list while (RecentDocuments.Count > MAX_ITEMS) { // first - check not pinned docs var notPinned = RecentDocuments.Where(x => !x.Pinned).OrderBy(x => x.Date); if (notPinned.Count() > 0) { RecentDocuments.Remove(notPinned.Last()); } else { // remove last pinned doc RecentDocuments.Remove(RecentDocuments.OrderBy(x => x.Date).Last()); } } }
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); } } }