diff --git a/RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodModel.cs b/RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodModel.cs index ebffc9d048..f4a7d49fda 100644 --- a/RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodModel.cs +++ b/RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodModel.cs @@ -8,6 +8,7 @@ using Rubberduck.VBEditor; using Rubberduck.Parsing.VBA; using Rubberduck.SmartIndenter; +using Rubberduck.UI; using Rubberduck.VBEditor.SafeComWrappers.Abstract; namespace Rubberduck.Refactorings.ExtractMethod @@ -122,7 +123,7 @@ private void Setup() if (string.IsNullOrWhiteSpace(NewMethodName)) { - NewMethodName = "NewMethod"; + NewMethodName = RubberduckUI.ExtractMethod_DefaultNewMethodName; } SelectedCode = string.Join(Environment.NewLine, SelectedContexts.Select(c => c.GetText())); @@ -176,10 +177,10 @@ public string PreviewCode switch (parameter.ParameterType) { case ExtractParameterNewType.PublicModuleField: - fields.Add(String.Format($"{Tokens.Public} {parameter.Name} {Tokens.As} {parameter.TypeName}")); + fields.Add(string.Format($"{Tokens.Public} {parameter.Name} {Tokens.As} {parameter.TypeName}")); break; case ExtractParameterNewType.PrivateModuleField: - fields.Add(String.Format($"{Tokens.Private} {parameter.Name} {Tokens.As} {parameter.TypeName}")); + fields.Add(string.Format($"{Tokens.Private} {parameter.Name} {Tokens.As} {parameter.TypeName}")); break; case ExtractParameterNewType.ByRefParameter: parameters.Add(string.Format($"{parameter.Name} {Tokens.As} {parameter.TypeName}")); @@ -198,7 +199,9 @@ public string PreviewCode } } - var isFunction = ReturnParameter != null; + var isFunction = ReturnParameter != null && + !(ReturnParameter.TypeName == string.Empty && + ReturnParameter.Name == RubberduckUI.ExtractMethod_NoneSelected); /* string.Empty are used to create blank lines @@ -211,7 +214,14 @@ public string PreviewCode strings.AddRange(fields); strings.Add(string.Empty); } - strings.Add($@"{Tokens.Private} {(isFunction ? Tokens.Function : Tokens.Sub)} {NewMethodName ?? "NewMethod"}({string.Join(", " , parameters)}) {(isFunction ? string.Concat(Tokens.As, " ", ReturnParameter.TypeName ?? Tokens.Variant) : string.Empty)}"); + strings.Add( + $@"{Tokens.Private} {(isFunction ? Tokens.Function : Tokens.Sub)} { + NewMethodName ?? RubberduckUI.ExtractMethod_DefaultNewMethodName + }({string.Join(", ", parameters)}) { + (isFunction + ? string.Concat(Tokens.As, " ", ReturnParameter.TypeName ?? Tokens.Variant) + : string.Empty) + }"); strings.AddRange(variables); if (variables.Any()) { diff --git a/RetailCoder.VBE/Rubberduck.csproj b/RetailCoder.VBE/Rubberduck.csproj index b7e1724a58..6820378006 100644 --- a/RetailCoder.VBE/Rubberduck.csproj +++ b/RetailCoder.VBE/Rubberduck.csproj @@ -448,12 +448,6 @@ ExtractInterfaceView.xaml - - Form - - - ExtractMethodDialog - Original.cs - ExtractMethodView.xaml @@ -835,7 +829,6 @@ ExtractMethodDialog.cs - Form @@ -1020,9 +1013,6 @@ ExtractInterfaceDialog.cs - - ExtractMethodDialog - Original.cs - RegexAssistantDialog.cs diff --git a/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodDialog.Designer.cs b/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodDialog.Designer.cs index 4f20eadc18..a0989f48cf 100644 --- a/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodDialog.Designer.cs +++ b/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodDialog.Designer.cs @@ -52,7 +52,6 @@ private void InitializeComponent() this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(600, 481); this.Controls.Add(this.elementHost1); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; diff --git a/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodView.xaml b/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodView.xaml index 5891bfdd6d..a62606ebdb 100644 --- a/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodView.xaml +++ b/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodView.xaml @@ -123,8 +123,8 @@ CanUserAddRows="False" HeadersVisibility="None" GridLinesVisibility="All" - VerticalScrollBarVisibility="Visible" - HorizontalScrollBarVisibility="Hidden" + VerticalScrollBarVisibility="Auto" + HorizontalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource PrettifyRow}" ColumnHeaderHeight="22" BorderThickness="0"> diff --git a/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodViewModel.cs b/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodViewModel.cs index 79b8c82b63..295cfaa30a 100644 --- a/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodViewModel.cs +++ b/RetailCoder.VBE/UI/Refactorings/ExtractMethod/ExtractMethodViewModel.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; -using System.Windows.Data; using System.Windows.Forms; using NLog; using Rubberduck.Parsing.Grammar; @@ -71,11 +70,12 @@ public string NewMethodName } } - public IEnumerable ReturnParameters => + public IEnumerable ReturnParameters => new[] - { - new ExtractedParameter(string.Empty,ExtractParameterNewType.PrivateLocalVariable,"(None)") - }.Union(Parameters); + { + new ExtractedParameter(string.Empty, ExtractParameterNewType.PrivateLocalVariable, + RubberduckUI.ExtractMethod_NoneSelected) + }.Union(Parameters); public ExtractedParameter ReturnParameter { @@ -88,7 +88,7 @@ public ExtractedParameter ReturnParameter } public string SourceMethodName => Model.SourceMethodName; - public string PreviewCaption => $@"Code Preview extracted from {SourceMethodName}"; + public string PreviewCaption => string.Format(RubberduckUI.ExtractMethod_CodePreviewCaption, SourceMethodName); public string PreviewCode => Model.PreviewCode; public IEnumerable Inputs; public IEnumerable Outputs; diff --git a/RetailCoder.VBE/UI/RubberduckUI.Designer.cs b/RetailCoder.VBE/UI/RubberduckUI.Designer.cs index 5784e2999d..f89deed1f9 100644 --- a/RetailCoder.VBE/UI/RubberduckUI.Designer.cs +++ b/RetailCoder.VBE/UI/RubberduckUI.Designer.cs @@ -1762,6 +1762,24 @@ public class RubberduckUI { } } + /// + /// Looks up a localized string similar to Code Preview extracted from {0}. + /// + public static string ExtractMethod_CodePreviewCaption { + get { + return ResourceManager.GetString("ExtractMethod_CodePreviewCaption", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to NewMethod. + /// + public static string ExtractMethod_DefaultNewMethodName { + get { + return ResourceManager.GetString("ExtractMethod_DefaultNewMethodName", resourceCulture); + } + } + /// /// Looks up a localized string similar to Please specify method name, return type and/or parameters (if applicable), and other options.. /// @@ -1780,6 +1798,15 @@ public class RubberduckUI { } } + /// + /// Looks up a localized string similar to (None). + /// + public static string ExtractMethod_NoneSelected { + get { + return ResourceManager.GetString("ExtractMethod_NoneSelected", resourceCulture); + } + } + /// /// Looks up a localized string similar to (none). /// @@ -3807,6 +3834,15 @@ public class RubberduckUI { } } + /// + /// Looks up a localized string similar to Code Metrics. + /// + public static string RubberduckMenu_CodeMetrics { + get { + return ResourceManager.GetString("RubberduckMenu_CodeMetrics", resourceCulture); + } + } + /// /// Looks up a localized string similar to Na&vigate. /// diff --git a/RetailCoder.VBE/UI/RubberduckUI.resx b/RetailCoder.VBE/UI/RubberduckUI.resx index 72c607d664..28d5027a2e 100644 --- a/RetailCoder.VBE/UI/RubberduckUI.resx +++ b/RetailCoder.VBE/UI/RubberduckUI.resx @@ -2167,4 +2167,13 @@ Would you like to import them to Rubberduck? Select a return type, if any: + + Code Preview extracted from {0} + + + NewMethod + + + (None) + \ No newline at end of file