Example #1
0
        public void PinnedTest()
        {
            var recentFile = new RecentFile("Doc1");

            AssertHelper.IsRaisePropertyChangedEvent(recentFile, x => x.IsPinned, () => recentFile.IsPinned = true);
            Assert.IsTrue(recentFile.IsPinned);
        }
Example #2
0
        public void WriteXmlTest_Precondition()
        {
            var recentFile = new RecentFile("Doc1");

            IXmlSerializable serializable = recentFile;
            serializable.WriteXml(null);
        }
Example #3
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)
        {
            Preconditions.NotNullOrWhiteSpace(fileName, "The argument fileName must not be null or empty.");

            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));
                }
            }
        }
Example #4
0
        public void GetSchemaTest()
        {
            var recentFile = new RecentFile("Doc1");

            IXmlSerializable serializable = recentFile;
            Assert.IsNull(serializable.GetSchema());
        }
Example #5
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();
            }
        }
Example #6
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);
             }
         }
     }
 }
Example #7
0
 private void Insert(int index, RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Insert(index, recentFile);
 }
Example #8
0
 private void Add(RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Add(recentFile);
 }
Example #9
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(); }
        }
Example #10
0
 public void ConstructorTest()
 {
     var recentFile = new RecentFile("Doc1");
     Assert.AreEqual("Doc1", recentFile.Path);
     Assert.IsFalse(recentFile.IsPinned);
 }
Example #11
0
 private void Add(RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Add(recentFile);
 }
Example #12
0
 private void Insert(int index, RecentFile recentFile)
 {
     recentFile.PropertyChanged += RecentFilePropertyChanged;
     recentFiles.Insert(index, recentFile);
 }