コード例 #1
0
        /// <summary>
        /// Stores the given file to the recent file list, and automatically
        /// saves the list down to the settings file
        /// </summary>
        /// <param name="file">The file to store on this list</param>
        public void StoreFile(string file)
        {
            Settings settings = Settings.GetSettings();

            string fullPath = Path.GetFullPath(file);

            // Don't do anything if the file is already at the top of the file list
            if (fullPath == _fileList[0])
            {
                return;
            }

            // Search if the file is not already in the list, and push it to the top
            int index = 0;

            for (int i = 1; i < _fileList.Length; i++)
            {
                if (fullPath == _fileList[i] || i == _fileList.Length - 1)
                {
                    index = (i == _fileList.Length - 1 ? i : i - 1);
                    break;
                }
            }

            // Push all current values down
            for (int i = index; i >= 0; i--)
            {
                if (i + 1 >= _fileList.Length)
                {
                    continue;
                }

                _fileList[i + 1] = _fileList[i];

                settings.SetValue("Recent Files\\File" + (i + 1), _fileList[i + 1]);
            }

            _fileList[0] = fullPath;

            settings.SetValue("Recent Files\\File" + 0, fullPath);
        }
コード例 #2
0
        /// <summary>
        /// Removes an index from this RecentFileList
        /// </summary>
        /// <param name="index">The index of the item to remove</param>
        public void RemoveFromList(int index)
        {
            Settings settings = Settings.GetSettings();

            if (index == _fileList.Length - 1)
            {
                _fileList[index] = "";
                settings.SetValue("Recent Files\\File" + index, "");
                return;
            }

            // Push all current values down
            for (int i = index; i < _fileList.Length - 1; i++)
            {
                _fileList[i] = _fileList[i + 1];

                settings.SetValue("Recent Files\\File" + i, _fileList[i]);
            }

            _fileList[_fileList.Length - 1] = "";
            settings.SetValue("Recent Files\\File" + (_fileList.Length - 1), "");
        }