Browse Source

small improvements to ctor and propall snippet

pull/23/head
Siegfried Pammer 14 years ago
parent
commit
54623cb297
  1. 5
      src/AddIns/Misc/SharpRefactoring/Project/Src/CreateProperties.cs
  2. 22
      src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/CreatePropertiesDialog.xaml.cs
  3. 3
      src/AddIns/Misc/SharpRefactoring/Project/Src/InsertCtorSnippetRefactoring.cs

5
src/AddIns/Misc/SharpRefactoring/Project/Src/CreateProperties.cs

@ -56,7 +56,10 @@ namespace SharpRefactoring @@ -56,7 +56,10 @@ namespace SharpRefactoring
if (current == null)
return null;
List<FieldWrapper> parameters = FindFields(current).ToList();
List<FieldWrapper> parameters = FindFields(current).Where(f => !current.Properties.Any(p => p.Name == f.PropertyName)).ToList();
if (!parameters.Any())
return null;
ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);
anchor.MovementType = AnchorMovementType.BeforeInsertion;

22
src/AddIns/Misc/SharpRefactoring/Project/Src/Gui/CreatePropertiesDialog.xaml.cs

@ -31,11 +31,11 @@ namespace SharpRefactoring.Gui @@ -31,11 +31,11 @@ namespace SharpRefactoring.Gui
if (!fields.Any())
Visibility = System.Windows.Visibility.Collapsed;
implementInterface.IsChecked = HasOnPropertyChanged(current);
implementInterface.IsChecked = !current.IsStatic && HasOnPropertyChanged(current);
if (current.IsStatic)
implementInterface.Visibility = System.Windows.Visibility.Collapsed;
listBox.SelectedItems.Clear();
foreach (FieldWrapper field in fields.Where(f => !current.AllMembers.Any(m => m.Name == f.PropertyName)))
listBox.SelectedItems.Add(field);
listBox.UnselectAll();
}
protected override string GenerateCode(LanguageProperties language, IClass currentClass)
@ -47,7 +47,7 @@ namespace SharpRefactoring.Gui @@ -47,7 +47,7 @@ namespace SharpRefactoring.Gui
bool hasOnPropertyChanged = HasOnPropertyChanged(currentClass);
bool useEventArgs = false;
if (implementInterface) {
if (implementInterface && !currentClass.IsStatic) {
if (!hasOnPropertyChanged) {
var nodes = new List<AbstractNode>();
var rt = new GetClassReturnType(currentClass.ProjectContent, "System.ComponentModel.INotifyPropertyChanged", 0);
@ -75,8 +75,16 @@ namespace SharpRefactoring.Gui @@ -75,8 +75,16 @@ namespace SharpRefactoring.Gui
foreach (FieldWrapper field in listBox.SelectedItems) {
var prop = language.CodeGenerator.CreateProperty(field.Field, true, field.AddSetter);
if (field.AddSetter && implementInterface) {
prop.SetRegion.Block.AddChild(new ExpressionStatement(CreateInvocation(field.PropertyName, useEventArgs)));
if (!field.Field.IsStatic && !currentClass.IsStatic && field.AddSetter && implementInterface) {
var invocation = new ExpressionStatement(CreateInvocation(field.PropertyName, useEventArgs));
var assignment = prop.SetRegion.Block.Children[0];
prop.SetRegion.Block.Children.Clear();
prop.SetRegion.Block.AddChild(
new IfElseStatement(
new BinaryOperatorExpression(new IdentifierExpression(field.MemberName), BinaryOperatorType.InEquality, new IdentifierExpression("value")),
new BlockStatement { Children = { assignment, invocation } }
)
);
}
builder.AppendLine(language.CodeGenerator.GenerateCode(prop, indent));
}

3
src/AddIns/Misc/SharpRefactoring/Project/Src/InsertCtorSnippetRefactoring.cs

@ -58,6 +58,9 @@ namespace SharpRefactoring @@ -58,6 +58,9 @@ namespace SharpRefactoring
List<PropertyOrFieldWrapper> parameters = CreateCtorParams(current).ToList();
if (!parameters.Any())
return null;
ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition);
anchor.MovementType = AnchorMovementType.BeforeInsertion;

Loading…
Cancel
Save