Пример #1
0
        /// <summary>
        ///     Load Recent list from Registry.
        ///     Called from Initialize.
        /// </summary>
        private void LoadRecent()
        {
            try
            {
                RecentFilesCollection.Clear();

                RegistryKey?key = Registry.CurrentUser.OpenSubKey(_registryPath);

                if (key is not null)
                {
                    for (int i = 0; i < _maxNumberOfFiles; i++)
                    {
                        string sKey = RegEntryName + i.ToString(CultureInfo.InvariantCulture);

                        var s = key.GetValue(sKey, "") as string;

                        if (s is null || s.Length == 0)
                        {
                            break;
                        }

                        RecentFilesCollection.Add(new RecentFile(s, GetDisplayName(s)));
                    }
                }
            }
            catch
            {
                //Logger.Error("Loading Recent from Registry failed: " + ex.Message);
            }
        }
Пример #2
0
        // Check that the list contains a set of entries
        // in the order given and nothing else.
        private void CheckListContains(params int[] item)
        {
            RecentFilesCollection files = recentFiles.Entries;

            Assert.AreEqual(item.Length, files.Count, "Count");

            for (int index = 0; index < files.Count; index++)
            {
                Assert.AreEqual(item[index].ToString(), files[index].Path, "Item");
            }
        }
Пример #3
0
        // Check that the list is set right: 1, 2, ...
        private void CheckMockValues(int count)
        {
            RecentFilesCollection files = recentFiles.Entries;

            Assert.AreEqual(count, files.Count, "Count");

            for (int index = 0; index < count; index++)
            {
                Assert.AreEqual((index + 1).ToString(), files[index].Path, "Item");
            }
        }
Пример #4
0
        /// <summary>
        ///     Remove file name from Recent list.
        ///     Call this function when File - Open operation failed.
        /// </summary>
        /// <param name="fullFileName">File Name</param>
        public void Remove(string fullFileName)
        {
            int i = 0;

            IEnumerator <RecentFile> myEnumerator = RecentFilesCollection.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                if (String.Equals(myEnumerator.Current.FullFileName, fullFileName, StringComparison.InvariantCultureIgnoreCase))
                {
                    RecentFilesCollection.RemoveAt(i);
                    return;
                }

                i++;
            }
        }
Пример #5
0
        /// <summary>
        ///     Add file name to Recent list.
        ///     Call this function when file is opened successfully.
        ///     If file already exists in the list, it is moved to the first place.
        /// </summary>
        /// <param name="fullFileName">File Name</param>
        public void Add(string fullFileName)
        {
            if (String.IsNullOrWhiteSpace(fullFileName))
            {
                return;
            }

            Remove(fullFileName);

            // if array has maximum length, remove last element
            if (RecentFilesCollection.Count == _maxNumberOfFiles)
            {
                RecentFilesCollection.RemoveAt(_maxNumberOfFiles - 1);
            }

            // add new file name to the start of array
            RecentFilesCollection.Insert(0, new RecentFile(fullFileName, GetDisplayName(fullFileName)));
        }
Пример #6
0
        public void ClearList()
        {
            RecentFilesCollection.Clear();

            try
            {
                RegistryKey key = Registry.CurrentUser.CreateSubKey(_registryPath);

                if (key is not null)
                {
                    int n = RecentFilesCollection.Count;

                    int i;
                    for (i = 0; i < _maxNumberOfFiles; i++)
                    {
                        key.DeleteValue(RegEntryName + i.ToString(CultureInfo.InvariantCulture), false);
                    }
                }
            }
            catch
            {
                //Logger.Error("Saving Recent to Registry failed: " + ex.Message);
            }
        }