Represents a recent file.
Inheritance: Model, IXmlSerializable
Esempio n. 1
0
        /// <summary>
        /// Adds a file to the recent file list. If the file already exists in the list then it only changes the position in the list.
        /// </summary>
        /// <param name="fileName">The path of the recent file.</param>
        /// <exception cref="ArgumentException">The argument fileName must not be null or empty.</exception>
        public void AddFile(string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException("The argument fileName must not be null or empty.", nameof(fileName));
            }

            RecentFile recentFile = recentFiles.FirstOrDefault(r => r.Path == fileName);

            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(fileName));
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Removes the specified recent file.
 /// </summary>
 /// <param name="recentFile">The recent file to remove.</param>
 /// <exception cref="ArgumentNullException">The argument recentFile must not be null.</exception>
 /// <exception cref="ArgumentException">The argument recentFile was not found in the recent files list.</exception>
 public void Remove(RecentFile recentFile)
 {
     if (recentFile == null)
     {
         throw new ArgumentNullException("recentFile");
     }
     if (!recentFiles.Remove(recentFile))
     {
         throw new ArgumentException("The passed recentFile was not found in the recent files list.");
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Removes the specified recent file.
 /// </summary>
 /// <param name="recentFile">The recent file to remove.</param>
 /// <exception cref="ArgumentNullException">The argument recentFile must not be null.</exception>
 /// <exception cref="ArgumentException">The argument recentFile was not found in the recent files list.</exception>
 public void Remove(RecentFile recentFile)
 {
     if (recentFile == null)
     {
         throw new ArgumentNullException(nameof(recentFile));
     }
     if (recentFiles.Remove(recentFile))
     {
         recentFile.PropertyChanged -= RecentFilePropertyChanged;
     }
     else
     {
         throw new ArgumentException("The passed recentFile was not found in the recent files list.", nameof(recentFile));
     }
 }
Esempio n. 4
0
        public void ArgumentsTest()
        {
            AssertHelper.ExpectedException<ArgumentException>(() => new RecentFile(null));

            RecentFile recentFile = new RecentFile("Doc1");
            Assert.AreEqual("Doc1", recentFile.Path);

            AssertHelper.PropertyChangedEvent(recentFile, x => x.IsPinned, () => recentFile.IsPinned = true);
            Assert.IsTrue(recentFile.IsPinned);

            IXmlSerializable serializable = recentFile;
            Assert.IsNull(serializable.GetSchema());
            AssertHelper.ExpectedException<ArgumentNullException>(() => serializable.ReadXml(null));
            AssertHelper.ExpectedException<ArgumentNullException>(() => serializable.WriteXml(null));
        }
Esempio n. 5
0
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(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();
            }
        }
Esempio n. 6
0
 private void RecentFilePropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.PropertyName == nameof(RecentFile.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);
             }
         }
     }
 }
Esempio n. 7
0
 private void Insert(int index, RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Insert(index, recentFile);
 }
Esempio n. 8
0
 private void Add(RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Add(recentFile);
 }
Esempio n. 9
0
 /// <summary>
 /// Removes the specified recent file.
 /// </summary>
 /// <param name="recentFile">The recent file to remove.</param>
 /// <exception cref="ArgumentNullException">The argument recentFile must not be null.</exception>
 /// <exception cref="ArgumentException">The argument recentFile was not found in the recent files list.</exception>
 public void Remove(RecentFile recentFile)
 {
     if (recentFile == null) { throw new ArgumentNullException("recentFile"); }
     if (recentFiles.Remove(recentFile))
     {
         recentFile.PropertyChanged -= RecentFilePropertyChanged;
     }
     else
     {
         throw new ArgumentException("The passed recentFile was not found in the recent files list.");
     }
 }
Esempio n. 10
0
        void IXmlSerializable.ReadXml(XmlReader reader)
        {
            if (reader == null) { throw new ArgumentNullException("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(); }
        }
Esempio n. 11
0
 private void Add(RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Add(recentFile);
 }
Esempio n. 12
0
 private void Insert(int index, RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Insert(index, recentFile);
 }
 /// <summary>
 /// Removes the specified recent file.
 /// </summary>
 /// <param name="recentFile">The recent file to remove.</param>
 /// <exception cref="ArgumentNullException">The argument recentFile must not be null.</exception>
 /// <exception cref="ArgumentException">The argument recentFile was not found in the recent files list.</exception>
 public void Remove(RecentFile recentFile)
 {
     if (recentFile == null) { throw new ArgumentNullException("recentFile"); }
     if (!recentFiles.Remove(recentFile))
     {
         throw new ArgumentException("The passed recentFile was not found in the recent files list.");
     }
 }