miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 4 changed files with 233 additions and 0 deletions.
Added +75 -0
Added +54 -0
Added +64 -0
Added +40 -0
Added +75 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/FindNextStringCommand.cs b/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/FindNextStringCommand.cs
new file mode 100644
index 0000000..b972cff
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/FindNextStringCommand.cs
@@ -0,0 +1,75 @@
+#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.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.PlugIns.SearchTools.Commands
+{
+    /// <summary>The find next string command.</summary>
+    public class FindNextStringCommand : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="FindNextStringCommand"/> class.</summary>
+        public FindNextStringCommand() : base("Find Next String")
+        {
+            SmallImage = ImageResource.find;
+            ShortcutKeys = Keys.F3;
+        }
+
+        /// <summary>Two execution methods - through the "Find Text" window or by hitting F3.
+        /// If simply hitting F3, we are executing the current search from current cursor position for this window.
+        /// Different windows can also have different search text.</summary>
+        public override void Execute()
+        {
+            IFindReplaceProvider editorFindProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;
+
+            if (editorFindProvider != null)
+            {
+                FindTextRequest findTextRequest = null;
+                int key = editorFindProvider.GetHashCode();
+
+                // is there a request in the table for this window?
+                if (SearchToolsCommon.FindReplaceTextRequests.ContainsKey(key))
+                {
+                    findTextRequest = SearchToolsCommon.FindReplaceTextRequests[key];
+                }
+                else
+                {
+                    if (SearchToolsCommon.FindReplaceTextRequests.Count > 0)
+                    {
+                        // if there is an entry in the list of searches create an instance
+                        findTextRequest = new FindTextRequest(editorFindProvider);
+                        findTextRequest.Position = editorFindProvider.CursorOffset;
+                    }
+                    else
+                    {
+                        // none in table, default to curently selected text if its the editor
+                        IEditor editor = ActiveFormAsEditor;
+                        if (editor != null && editor.SelectedText.Length > 0)
+                        {
+                            findTextRequest = new FindTextRequest(editorFindProvider, editor.SelectedText);
+                            findTextRequest.Position = editorFindProvider.CursorOffset;
+                        }
+                    }
+                }
+
+                if (findTextRequest != null)
+                {
+                    // wrap around to start if at last pos
+                    if (findTextRequest.Position != 0)
+                    {
+                        findTextRequest.Position = editorFindProvider.CursorOffset;
+                    }
+
+                    findTextRequest = editorFindProvider.TextFindService.FindNext(findTextRequest);
+                    SearchToolsCommon.FindReplaceTextRequests[key] = findTextRequest;
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
Added +54 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ReplaceStringCommand.cs b/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ReplaceStringCommand.cs
new file mode 100644
index 0000000..a7c38de
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ReplaceStringCommand.cs
@@ -0,0 +1,54 @@
+#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 MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.PlugIns.SearchTools.Commands
+{
+    /// <summary>The replace string command.</summary>
+    public class ReplaceStringCommand : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="ReplaceStringCommand"/> class.</summary>
+        public ReplaceStringCommand()
+            : base("Replace String")
+        {
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            IFindReplaceProvider editorFindProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;
+
+            if (editorFindProvider != null)
+            {
+                FindTextRequest req = null;
+                int key = editorFindProvider.GetHashCode();
+
+                // is there a request in the table for this window?
+                if (SearchToolsCommon.FindReplaceTextRequests.ContainsKey(key))
+                {
+                    req = SearchToolsCommon.FindReplaceTextRequests[key];
+                }
+
+                if (req != null)
+                {
+                    // wrap around to start if at last pos
+                    if (req.Position != 0)
+                    {
+                        req.Position = editorFindProvider.CursorOffset;
+                    }
+
+                    if (editorFindProvider.ReplaceString(req.ReplaceValue, req.Position - req.SearchValue.Length, req.SearchValue.Length))
+                    {
+                        CommandManager.GetCommandInstance<FindNextStringCommand>().Execute();
+                    }
+                }
+            }
+        }
+    }
+}
\ No newline at end of file
Added +64 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ShowFindTextFormCommand.cs b/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ShowFindTextFormCommand.cs
new file mode 100644
index 0000000..f27c357
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ShowFindTextFormCommand.cs
@@ -0,0 +1,64 @@
+#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.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.PlugIns.SearchTools.Commands
+{
+    /// <summary>The show find text form command.</summary>
+    public class ShowFindTextFormCommand : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="ShowFindTextFormCommand"/> class.</summary>
+        public ShowFindTextFormCommand()
+            : base("&Find Text...")
+        {
+            SmallImage = ImageResource.find;
+            ShortcutKeys = Keys.Control | Keys.F;
+        }
+
+
+        /// <summary>Gets a value indicating whether Enabled.</summary>
+        public override bool Enabled
+        {
+            get { return HostWindow.ActiveChildForm is IFindReplaceProvider; }
+        }
+
+        /// <summary>Gets FindReplaceWindow.</summary>
+        public IFindReplaceWindow FindReplaceWindow { get; private set; }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            if (!Enabled)
+            {
+                return;
+            }
+
+            // if the window is an editor, grab the highlighted text
+            IFindReplaceProvider findReplaceProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;
+
+            if (FindReplaceWindow == null || FindReplaceWindow.IsDisposed)
+            {
+                FindReplaceWindow = new FindReplaceForm(Services);
+            }
+
+            if (findReplaceProvider is IEditor)
+            {
+                FindReplaceWindow.FindString = ((IEditor)findReplaceProvider).SelectedText;
+            }
+
+            FindReplaceWindow.TopMost = true;
+
+            if (!FindReplaceWindow.Visible)
+            {
+                FindReplaceWindow.Show(HostWindow.Instance);
+            }
+        }
+    }
+}
\ No newline at end of file
Added +40 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ShowGoToLineFormCommand.cs b/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ShowGoToLineFormCommand.cs
new file mode 100644
index 0000000..88158bd
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/PlugIns/SearchTools/Commands/ShowGoToLineFormCommand.cs
@@ -0,0 +1,40 @@
+#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.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.PlugIns.SearchTools.Commands
+{
+    /// <summary>The show go to line form command.</summary>
+    public class ShowGoToLineFormCommand : CommandBase
+    {
+        /// <summary>Initializes a new instance of the <see cref="ShowGoToLineFormCommand"/> class.</summary>
+        public ShowGoToLineFormCommand()
+            : base("Go To Line...")
+        {
+            ShortcutKeys = Keys.Control | Keys.G;
+        }
+
+        /// <summary>Gets a value indicating whether Enabled.</summary>
+        public override bool Enabled
+        {
+            get { return HostWindow.ActiveChildForm is INavigatableDocument; }
+        }
+
+        /// <summary>Execute the command.</summary>
+        public override void Execute()
+        {
+            if (Enabled)
+            {
+                GoToLineForm frm = Services.Resolve<GoToLineForm>();
+                frm.ShowDialog(HostWindow as Form);
+            }
+        }
+    }
+}
\ No newline at end of file