Skip to content

Commit

Permalink
Merge pull request #5327 from BZngr/4805_EncapsulateFieldTypeMember
Browse files Browse the repository at this point in the history
Rewrite of EncapsulateField refactoring, introduces "wrap with private type" functionality
  • Loading branch information
retailcoder authored Jan 17, 2020
2 parents 9b3bd2d + 93156c5 commit 5d7369a
Show file tree
Hide file tree
Showing 49 changed files with 7,201 additions and 1,193 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text.RegularExpressions;
using Rubberduck.CodeAnalysis.Settings;
using Rubberduck.Common;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Inspections.Extensions;
using Rubberduck.Inspections.Results;
Expand Down Expand Up @@ -49,69 +50,6 @@ namespace Rubberduck.Inspections.Concrete
public sealed class HungarianNotationInspection : InspectionBase
{
#region statics
private static readonly List<string> HungarianPrefixes = new List<string>
{
"chk",
"cbo",
"cmd",
"btn",
"fra",
"img",
"lbl",
"lst",
"mnu",
"opt",
"pic",
"shp",
"txt",
"tmr",
"chk",
"dlg",
"drv",
"frm",
"grd",
"obj",
"rpt",
"fld",
"idx",
"tbl",
"tbd",
"bas",
"cls",
"g",
"m",
"bln",
"byt",
"col",
"dtm",
"dbl",
"cur",
"int",
"lng",
"sng",
"str",
"udt",
"vnt",
"var",
"pgr",
"dao",
"b",
"by",
"c",
"chr",
"i",
"l",
"s",
"o",
"n",
"dt",
"dat",
"a",
"arr"
};

private static readonly Regex HungarianIdentifierRegex = new Regex($"^({string.Join("|", HungarianPrefixes)})[A-Z0-9].*$");

private static readonly List<DeclarationType> TargetDeclarationTypes = new List<DeclarationType>
{
DeclarationType.Parameter,
Expand Down Expand Up @@ -154,7 +92,7 @@ protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
&& TargetDeclarationTypes.Contains(declaration.DeclarationType)
&& !IgnoredProcedureTypes.Contains(declaration.DeclarationType)
&& !IgnoredProcedureTypes.Contains(declaration.ParentDeclaration.DeclarationType)
&& HungarianIdentifierRegex.IsMatch(declaration.IdentifierName))
&& declaration.IdentifierName.TryMatchHungarianNotationCriteria(out _))
.Select(issue => new DeclarationInspectionResult(this,
string.Format(Resources.Inspections.InspectionResults.IdentifierNameInspection,
RubberduckUI.ResourceManager.GetString($"DeclarationType_{issue.DeclarationType}", CultureInfo.CurrentUICulture),
Expand Down
26 changes: 26 additions & 0 deletions Rubberduck.Core/UI/Converters/BoolToVisibleVisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace Rubberduck.UI.Converters
{
public class BoolToVisibleVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var typedValue = (bool)value;
return typedValue ? Visibility.Visible : Visibility.Collapsed;
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
var typedValue = (Visibility)value;
return typedValue != Visibility.Collapsed;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,8 @@ namespace Rubberduck.UI.Refactorings.EncapsulateField
{
public sealed class EncapsulateFieldDialog : RefactoringDialogBase<EncapsulateFieldModel, EncapsulateFieldView, EncapsulateFieldViewModel>
{
private bool _isExpanded;
private new int MinHeight => _isExpanded ? 560 : 305;

public EncapsulateFieldDialog(DialogData dialogData, EncapsulateFieldModel model, EncapsulateFieldView view, EncapsulateFieldViewModel viewModel) : base(dialogData, model, view, viewModel)
{
ViewModel.ExpansionStateChanged += Vm_ExpansionStateChanged;
}

private void Vm_ExpansionStateChanged(object sender, bool isExpanded)
{
_isExpanded = isExpanded;
Height = MinHeight;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ namespace Rubberduck.UI.Refactorings.EncapsulateField
internal class EncapsulateFieldPresenter : RefactoringPresenterBase<EncapsulateFieldModel>, IEncapsulateFieldPresenter
{
private static readonly DialogData DialogData =
DialogData.Create(RubberduckUI.EncapsulateField_Caption, 305, 667);
DialogData.Create(RubberduckUI.EncapsulateField_Caption, 800, 900);

public EncapsulateFieldPresenter(EncapsulateFieldModel model,
IRefactoringDialogFactory dialogFactory) : base(DialogData, model, dialogFactory) { }

public override EncapsulateFieldModel Show()
{
return Model.TargetDeclaration == null ? null : base.Show();
}
}
}
Loading

0 comments on commit 5d7369a

Please sign in to comment.