#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
{
///
/// Whatever line the cursor is on this command will duplicate that line (its a resharper this that I use alot!)
///
public class DuplicateLineCommand
: CommandBase
{
public DuplicateLineCommand()
: base("Duplicate Line")
{
ShortcutKeys = Keys.Control | Keys.D;
//todo SmallImage = ImageResource.?;
}
///
/// Gets a value indicating whether this is enabled.
/// The window needs to implement the and
/// support replacing text ().
///
///
/// true if enabled; otherwise, false.
///
public override bool Enabled
{
get
{
IFindReplaceProvider findReplaceProvider = HostWindow.ActiveChildForm as IFindReplaceProvider;
if (findReplaceProvider == null || !findReplaceProvider.CanReplaceText)
{
return false;
}
return true;
}
}
///
/// Finds the current line position and duplicates that line.
///
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);
}
}
}