Skip to content

Commit 6669655

Browse files
committed
Merge pull request #955 from SlavaRa/feature/CodeRefactor_rename_field_toLowercase_toUppercase
[CodeRefactor] Support for hot keys are converting to uppercase, lowercase in rename form
2 parents f0ba0d4 + 96fcbf5 commit 6669655

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

External/Plugins/CodeRefactor/CodeRefactor.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@
7474
-->
7575
<ItemGroup>
7676
<Reference Include="System" />
77+
<Reference Include="System.Data" />
7778
<Reference Include="System.Drawing" />
7879
<Reference Include="System.Windows.Forms" />
80+
<Reference Include="System.Xml" />
7981
</ItemGroup>
8082
<ItemGroup>
8183
<Compile Include="Commands\ExtractLocalVariableCommand.cs" />

External/Plugins/CodeRefactor/Commands/Rename.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using ASCompletion.Completion;
66
using ASCompletion.Context;
77
using ASCompletion.Model;
8+
using CodeRefactor.Controls;
89
using CodeRefactor.Provider;
910
using PluginCore;
1011
using PluginCore.Controls;
@@ -370,8 +371,7 @@ private String GetNewName(String originalName)
370371
{
371372
String label = TextHelper.GetString("Label.NewName");
372373
String title = String.Format(TextHelper.GetString("Title.RenameDialog"), originalName);
373-
String suggestion = originalName;
374-
LineEntryDialog askName = new LineEntryDialog(title, label, suggestion);
374+
LineEntryDialog askName = new LineEntryDialog(title, label, originalName);
375375
DialogResult choice = askName.ShowDialog();
376376
if (choice == DialogResult.OK && askName.Line.Trim().Length > 0 && askName.Line.Trim() != originalName)
377377
{

External/Plugins/ProjectManager/Helpers/LineEntryDialog.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
using System.Collections;
44
using System.ComponentModel;
55
using System.Windows.Forms;
6+
using PluginCore;
67
using PluginCore.Localization;
78

89
namespace ProjectManager.Helpers
910
{
1011
/// <summary>
1112
/// A simple form where a user can enter a text string.
1213
/// </summary>
13-
public class LineEntryDialog : System.Windows.Forms.Form
14+
public class LineEntryDialog : Form
1415
{
16+
readonly Keys shortcutToLowercase;
17+
readonly Keys shortcutToUppercase;
1518
string line;
1619

1720
#region Form Designer Components
1821

19-
private System.Windows.Forms.TextBox lineBox;
22+
protected System.Windows.Forms.TextBox lineBox;
2023
private System.Windows.Forms.Button btnOK;
2124
private System.Windows.Forms.Button btnCancel;
2225
/// <summary>
@@ -37,12 +40,14 @@ public string Line
3740

3841
public LineEntryDialog(string captionText, string labelText, string defaultLine)
3942
{
43+
shortcutToLowercase = PluginBase.MainForm.GetShortcutItemKeys("EditMenu.ToLowercase");
44+
shortcutToUppercase = PluginBase.MainForm.GetShortcutItemKeys("EditMenu.ToUppercase");
4045
InitializeComponent();
4146
InititalizeLocalization();
42-
this.Font = PluginCore.PluginBase.Settings.DefaultFont;
43-
47+
this.Font = PluginBase.Settings.DefaultFont;
4448
this.Text = " " + captionText;
4549
titleLabel.Text = labelText;
50+
lineBox.KeyDown += OnLineBoxOnKeyDown;
4651
lineBox.Text = (defaultLine != null) ? defaultLine : string.Empty;
4752
lineBox.SelectAll();
4853
lineBox.Focus();
@@ -167,6 +172,20 @@ private void btnCancel_Click(object sender, System.EventArgs e)
167172
this.Close();
168173
}
169174

175+
void OnLineBoxOnKeyDown(object sender, KeyEventArgs args)
176+
{
177+
string selectedText = lineBox.SelectedText;
178+
if (string.IsNullOrEmpty(selectedText)) return;
179+
Keys keys = args.KeyData;
180+
if (keys == shortcutToLowercase) selectedText = selectedText.ToLower();
181+
else if (keys == shortcutToUppercase) selectedText = selectedText.ToUpper();
182+
else return;
183+
int selectionStart = lineBox.SelectionStart;
184+
int selectionLength = lineBox.SelectionLength;
185+
lineBox.Paste(selectedText);
186+
SelectRange(selectionStart, selectionLength);
187+
}
188+
170189
public void SelectRange(int start, int length)
171190
{
172191
lineBox.Select(start, length);

0 commit comments

Comments
 (0)