示例#1
0
        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));
                }
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        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);
                    }
                }
            }
        }
示例#4
0
 private void Insert(int index, RecentFile file)
 {
     file.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Insert(index, file);
 }
示例#5
0
 private void Add(RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Add(recentFile);
 }
示例#6
0
        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(); }
        }
示例#7
0
 private void Add(RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Add(recentFile);
 }
示例#8
0
 private void Insert(int index, RecentFile file)
 {
     file.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Insert(index, file);
 }