miniSql

创建
zgc123@gmail.com authored at 11/19/2023 1:40:15 AM
6136600
Tree
0 Parent(s)
Summary: 1 changed files with 75 additions and 0 deletions.
Added +75 -0
Added +75 -0
diff --git a/minisqlquery-master/src/MiniSqlQuery/Commands/DuplicateLineCommand.cs b/minisqlquery-master/src/MiniSqlQuery/Commands/DuplicateLineCommand.cs
new file mode 100644
index 0000000..a71f955
--- /dev/null
+++ b/minisqlquery-master/src/MiniSqlQuery/Commands/DuplicateLineCommand.cs
@@ -0,0 +1,75 @@
+#region License
+// Copyright 2005-2009 Paul Kohler (http://pksoftware.net/MiniSqlQuery/). All rights reserved.
+// This source code is made available under the terms of the Microsoft Public License (Ms-PL)
+// http://minisqlquery.codeplex.com/license
+#endregion
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Windows.Forms;
+using MiniSqlQuery.Core;
+using MiniSqlQuery.Core.Commands;
+
+namespace MiniSqlQuery.Commands
+{
+	/// <summary>
+	/// Whatever line the cursor is on this command will duplicate that line (its a resharper this that I use alot!)
+	/// </summary>
+	public class DuplicateLineCommand
+		: CommandBase
+	{
+		public DuplicateLineCommand()
+			: base("Duplicate Line")
+		{
+			ShortcutKeys = Keys.Control | Keys.D;
+			//todo SmallImage = ImageResource.?;
+		}
+
+		/// <summary>
+		/// Gets a value indicating whether this <see cref="ICommand"/> is enabled.
+		/// The window needs to implement the <see cref="IFindReplaceProvider"/> and 
+		/// support replacing text (<see cref="IFindReplaceProvider.CanReplaceText"/>).
+		/// </summary>
+		/// <value>
+		/// 	<c>true</c> if enabled; otherwise, <c>false</c>.
+		/// </value>
+		public override bool Enabled
+		{
+			get
+			{
+				IFindReplaceProvider findReplaceProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;
+				if (findReplaceProvider == null || !findReplaceProvider.CanReplaceText)
+				{
+					return false;
+				}
+				return true;
+			}
+		}
+
+		/// <summary>
+		/// Finds the current line position and duplicates that line.
+		/// </summary>
+		public override void Execute()
+		{
+			IFindReplaceProvider findReplaceProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;
+
+			if (findReplaceProvider == null || !findReplaceProvider.CanReplaceText)
+			{
+				return;
+			}
+
+			// todo!
+
+			int offset = findReplaceProvider.CursorOffset;
+			int originalLineStartOffset = 0;
+			int lineLength = 0;
+
+			string line = "?";
+			// find current text "line", back to start or \n and find next \n or eof
+
+			line = line + Environment.NewLine + line;
+
+			findReplaceProvider.ReplaceString(line, 0, 0);
+		}
+	}
+}
\ No newline at end of file