public void AddFile(string filePath) { if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException("fileName"); } RecentFile recentFile = recentFiles.FirstOrDefault(c => c.FilePath == filePath); if (recentFile != null) { int oldIndex = recentFiles.IndexOf(recentFile); int newIndex = recentFile.IsPinned ? 0 : PinCount; if (oldIndex != newIndex) { recentFiles.Move(oldIndex, newIndex); } } else { if (PinCount < maxFilesNumber) { if (recentFiles.Count >= maxFilesNumber) { RemoveAt(recentFiles.Count - 1); } Insert(PinCount, new RecentFile(filePath)); } } }
void IXmlSerializable.ReadXml(XmlReader reader) { if (reader == null) { throw new ArgumentException("reader"); } reader.ReadToDescendant("RecentFile"); while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "RecentFile") { RecentFile recentFile = new RecentFile(); ((IXmlSerializable)recentFile).ReadXml(reader); Add(recentFile); } if (!reader.IsEmptyElement) { reader.ReadEndElement(); } }
private void RecentFilePropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "IsPinned") { RecentFile recentFile = (RecentFile)sender; int oldIndex = recentFiles.IndexOf(recentFile); if (recentFile.IsPinned) { recentFiles.Move(oldIndex, 0); } else { int newIndex = PinCount; if (oldIndex != newIndex) { recentFiles.Move(oldIndex, newIndex); } } } }
private void Insert(int index, RecentFile file) { file.PropertyChanged += RecentFilePropertyChanged; recentFiles.Insert(index, file); }
private void Add(RecentFile recentFile) { recentFile.PropertyChanged += RecentFilePropertyChanged; recentFiles.Add(recentFile); }
void IXmlSerializable.ReadXml(XmlReader reader) { if (reader==null){throw new ArgumentException("reader");} reader.ReadToDescendant("RecentFile"); while (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "RecentFile") { RecentFile recentFile = new RecentFile(); ((IXmlSerializable)recentFile).ReadXml(reader); Add(recentFile); } if (!reader.IsEmptyElement) { reader.ReadEndElement(); } }