Ejemplo n.º 1
0
        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);
                }
            }
        }
Ejemplo n.º 2
0
        // 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);
                }
            }
        }