Example #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.");
            }

            RecentFile __recentFile = m_RecentFiles.FirstOrDefault(r => r.Path == _fileName);

            if (null != __recentFile)
            {
                int __oldIndex = m_RecentFiles.IndexOf(__recentFile);
                int __newIndex = __recentFile.IsPinned ? 0 : PinCount;
                if (__oldIndex != __newIndex)
                {
                    m_RecentFiles.Move(__oldIndex, __newIndex);
                }
            }
            else
            {
                if (PinCount < m_MaxFilesNumber)
                {
                    if (m_RecentFiles.Count >= m_MaxFilesNumber)
                    {
                        RemoveAt(m_RecentFiles.Count - 1);
                    }

                    Insert(PinCount, new RecentFile(_fileName));
                }
            }
        }
Example #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 (null == _recentFile)
            {
                throw new ArgumentNullException(nameof(_recentFile));
            }

            if (m_RecentFiles.Remove(_recentFile))
            {
                _recentFile.PropertyChanged -= RecentFilePropertyChanged;
            }

            else
            {
                throw new ArgumentException("The passed recentFile was not found in the recent files list.");
            }
        }
Example #3
0
        void IXmlSerializable.ReadXml(XmlReader _reader)
        {
            if (null == _reader)
            {
                throw new ArgumentNullException(nameof(_reader));
            }

            _reader.ReadToDescendant(RECENT_FILE);
            while (_reader.MoveToContent() == XmlNodeType.Element && _reader.LocalName == RECENT_FILE)
            {
                var __recentFile = new RecentFile();
                ((IXmlSerializable)__recentFile).ReadXml(_reader);
                Add(__recentFile);
            }

            if (!_reader.IsEmptyElement)
            {
                _reader.ReadEndElement();
            }
        }
Example #4
0
 void Add(RecentFile _recentFile)
 {
     _recentFile.PropertyChanged += RecentFilePropertyChanged;
     m_RecentFiles.Add(_recentFile);
 }
Example #5
0
 void Insert(int _index, RecentFile _recentFile)
 {
     _recentFile.PropertyChanged += RecentFilePropertyChanged;
     m_RecentFiles.Insert(_index, _recentFile);
 }