miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 1 changed files with 83 additions and 0 deletions.
Added +83 -0
Added +83 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery.Core/MostRecentFilesService.cs b/minisqlquery-master/src/MiniSqlQuery.Core/MostRecentFilesService.cs
new file mode 100644
index 0000000..dedcddb
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery.Core/MostRecentFilesService.cs
@@ -0,0 +1,83 @@
+#region License
+
+// Copyright 2005-2019 Paul Kohler (https://github.com/paulkohler/minisqlquery). All rights reserved.
+// This source code is made available under the terms of the GNU Lesser General Public License v3.0
+// https://github.com/paulkohler/minisqlquery/blob/master/LICENSE
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+
+namespace MiniSqlQuery.Core
+{
+    public class MostRecentFilesService : IMostRecentFilesService
+    {
+        private readonly List<string> _filenames;
+
+        public MostRecentFilesService()
+        {
+            _filenames = new List<string>();
+        }
+
+        public event EventHandler<MostRecentFilesChangedEventArgs> MostRecentFilesChanged;
+
+        public IList<string> Filenames
+        {
+            get { return _filenames; }
+        }
+
+        public void OnMostRecentFilesChanged(MostRecentFilesChangedEventArgs e)
+        {
+            var handler = MostRecentFilesChanged;
+            if (handler != null)
+            {
+                handler(this, e);
+            }
+        }
+
+        public void Register(string filename)
+        {
+            if (!_filenames.Contains(filename))
+            {
+                _filenames.Insert(0, filename);
+            }
+            else
+            {
+                // move to top of list
+                if (_filenames.Count > 1)
+                {
+                    _filenames.Remove(filename);
+                    _filenames.Insert(0, filename);
+                }
+            }
+
+            // enure the list is capped
+            while (_filenames.Count > MaxCommands)
+            {
+                _filenames.RemoveAt(_filenames.Count - 1);
+            }
+
+            NotifyListenersOfChange();
+        }
+
+        public void Remove(string filename)
+        {
+            if (_filenames.Contains(filename))
+            {
+                _filenames.Remove(filename);
+            }
+            NotifyListenersOfChange();
+        }
+
+        public int MaxCommands
+        {
+            get { return 10; }
+        }
+
+        protected void NotifyListenersOfChange()
+        {
+            OnMostRecentFilesChanged(new MostRecentFilesChangedEventArgs(_filenames));
+        }
+    }
+}
\ No newline at end of file