public void Handle(DocumentDeleted message) { RecentDocuments .Where(x => x.Id == message.DocumentId) .ToList() .Apply(x => RecentDocuments.Remove(x)); //TODO: update collections //Collections // .Where(x => x.Name == message.Document.CollectionType) // .Apply(x => x.Count--); }
// 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()); } } }