public OverrideEqualsGetHashCodeMethodsDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor endAnchor, ITextAnchor insertionPosition, IClass selectedClass, IMethod selectedMethod, string baseCall) : base(context, editor, insertionPosition) { if (selectedClass == null) throw new ArgumentNullException("selectedClass"); InitializeComponent(); this.selectedClass = selectedClass; this.startAnchor = startAnchor; this.insertionEndAnchor = endAnchor; this.selectedMethod = selectedMethod; this.baseCall = baseCall; addIEquatable.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddInterface}"), "IEquatable<" + selectedClass.Name + ">"); string otherMethod = selectedMethod.Name == "Equals" ? "GetHashCode" : "Equals"; addOtherMethod.Content = StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod}", new StringTagPair("otherMethod", otherMethod)); addIEquatable.IsEnabled = !selectedClass.BaseTypes.Any( type => { if (!type.IsGenericReturnType) return false; var genericType = type.CastToGenericReturnType(); var boundTo = genericType.TypeParameter.BoundTo; if (boundTo == null) return false; return boundTo.Name == selectedClass.Name; } ); }
internal static CreatePropertiesDialog CreateDialog(InsertionContext context) { ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor; if (textEditor == null) { return(null); } using (textEditor.Document.OpenUndoGroup()) { IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService; if (uiService == null) { return(null); } ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition); anchor.MovementType = AnchorMovementType.BeforeInsertion; CreatePropertiesDialog dialog = new CreatePropertiesDialog(context, textEditor, anchor); dialog.Element = uiService.CreateInlineUIElement(anchor, dialog); // Add creation of this inline dialog as undoable operation TextDocument document = textEditor.Document as TextDocument; if (document != null) { document.UndoStack.Push(dialog.UndoableCreationOperation); } return(dialog); } }
public InlineUIElementGenerator(TextView textView, UIElement element, ITextAnchor anchor) { this.textView = textView; this.element = element; this.anchor = anchor; this.anchor.Deleted += delegate { Remove(); }; }
void CreateAnchor() { if (anchor != null) { // Detach from Deleted event: don't delete the bookmark // if the anchor at the old position is deleted after the anchor was moved anchor.Deleted -= AnchorDeleted; } if (document != null) { int lineNumber = Math.Max(1, Math.Min(location.Line, document.LineCount)); int lineLength = document.GetLineByNumber(lineNumber).Length; int offset = document.GetOffset( lineNumber, Math.Max(1, Math.Min(location.Column, lineLength + 1)) ); anchor = document.CreateAnchor(offset); // after insertion: keep bookmarks after the initial whitespace (see DefaultFormattingStrategy.SmartReplaceLine) anchor.MovementType = AnchorMovementType.AfterInsertion; anchor.Deleted += AnchorDeleted; } else { anchor = null; } }
void AnchorDeleted(object sender, EventArgs e) { // the anchor just became invalid, so don't try to use it again location = TextLocation.Empty; anchor = null; RemoveMark(); }
public InsertCtorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor) : base(context, editor, anchor) { InitializeComponent(); Visibility = System.Windows.Visibility.Collapsed; }
public OverrideEqualsGetHashCodeMethodsDialog(InsertionContext context, ITextEditor editor, ITextAnchor endAnchor, ITextAnchor insertionPosition, ITypeDefinition selectedClass, IMethod selectedMethod, AstNode baseCallNode) : base(context, editor, insertionPosition) { if (selectedClass == null) throw new ArgumentNullException("selectedClass"); InitializeComponent(); this.selectedClass = selectedClass; this.insertionEndAnchor = endAnchor; this.selectedMethod = selectedMethod; this.baseCallNode = baseCallNode; addIEquatable.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddInterface}"), "IEquatable<" + selectedClass.Name + ">"); string otherMethod = selectedMethod.Name == "Equals" ? "GetHashCode" : "Equals"; addOtherMethod.Content = StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod}", new StringTagPair("otherMethod", otherMethod)); addIEquatable.IsEnabled = !selectedClass.GetAllBaseTypes().Any( type => { if (!type.IsParameterized || (type.TypeParameterCount != 1)) return false; if (type.FullName != "System.IEquatable") return false; return type.TypeArguments.First().FullName == selectedClass.FullName; } ); }
InsertCtorDialog CreateDialog(InsertionContext context) { ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor; if (textEditor == null) { return(null); } IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService; if (uiService == null) { return(null); } ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition); anchor.MovementType = AnchorMovementType.BeforeInsertion; InsertCtorDialog dialog = new InsertCtorDialog(context, textEditor, anchor); dialog.Element = uiService.CreateInlineUIElement(anchor, dialog); return(dialog); }
void AnchorDeleted(object sender, EventArgs e) { // the anchor just became invalid, so don't try to use it again location = Location.Empty; anchor = null; RemoveMark(); }
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor anchor, IList<IField> fields, string baseCall) : base(context, editor, anchor) { InitializeComponent(); this.baseCall = baseCall; this.fields = fields.Select(f => new PropertyOrFieldWrapper(f) { IsSelected = true }).ToList(); this.listBox.ItemsSource = this.fields; }
/// <inheritdoc /> public IInlineUIElement CreateInlineUIElement(ITextAnchor position, UIElement element) { if (position == null) throw new ArgumentNullException("position"); if (element == null) throw new ArgumentNullException("element"); InlineUIElementGenerator inline = new InlineUIElementGenerator(textView, element, position); this.textView.ElementGenerators.Add(inline); return inline; }
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor anchor, IList<IField> fields, string baseCall) : base(context, editor, anchor) { InitializeComponent(); this.baseCall = baseCall; this.listBox.ItemsSource = fields.Where(f => f.ReturnType != null).Select(f => new PropertyOrFieldWrapper(f)).ToList(); listBox.SelectAll(); }
public InsertCtorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor, IClass current, IList<PropertyOrFieldWrapper> possibleParameters) : base(context, editor, anchor) { InitializeComponent(); this.varList.ItemsSource = parameterList = possibleParameters; if (!parameterList.Any()) Visibility = System.Windows.Visibility.Collapsed; }
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor anchor, IList<PropertyOrFieldWrapper> fields, string baseCall) : base(context, editor, anchor) { InitializeComponent(); this.baseCall = baseCall; this.listBox.ItemsSource = fields; listBox.SelectAll(); }
InsertCtorDialog CreateDialog(InsertionContext context) { ITextEditor textEditor = context.TextArea.GetService(typeof(ITextEditor)) as ITextEditor; if (textEditor == null) { return(null); } IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService; if (uiService == null) { return(null); } ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName); if (parseInfo == null) { return(null); } CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator; // cannot use insertion position at this point, because it might not be // valid, because we are still generating the elements. // DOM is not updated ICSharpCode.AvalonEdit.Document.TextLocation loc = context.Document.GetLocation(context.StartPosition); IClass current = parseInfo.CompilationUnit.GetInnermostClass(loc.Line, loc.Column); if (current == null) { return(null); } List <PropertyOrFieldWrapper> parameters = CreateCtorParams(current).ToList(); if (!parameters.Any()) { return(null); } ITextAnchor anchor = textEditor.Document.CreateAnchor(context.InsertionPosition); anchor.MovementType = AnchorMovementType.BeforeInsertion; InsertCtorDialog dialog = new InsertCtorDialog(context, textEditor, anchor, current, parameters); dialog.Element = uiService.CreateInlineUIElement(anchor, dialog); return(dialog); }
void baseAnchor_Deleted(object sender, EventArgs e) { isDeleted = true; baseAnchor = null; currentDocument = null; if (Deleted != null) { Deleted(this, e); } }
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor, IList<PropertyOrFieldWrapper> fields, AstNode baseCallNode) : base(context, editor, anchor) { InitializeComponent(); this.baseCallNode = baseCallNode; parameterList = fields; this.listBox.ItemsSource = fields; SelectAllChecked(); }
public InsertCtorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor, IClass current, IList <PropertyOrFieldWrapper> possibleParameters) : base(context, editor, anchor) { InitializeComponent(); this.varList.ItemsSource = parameterList = possibleParameters; if (!parameterList.Any()) { Visibility = System.Windows.Visibility.Collapsed; } }
internal void Detach() { if (isDeleted) return; Debug.Assert(currentDocument != null); TextLocation loc = baseAnchor.Location; line = loc.Line; column = loc.Column; baseAnchor = null; currentDocument = null; }
internal void AttachTo(IDocument document) { if (isDeleted) return; Debug.Assert(currentDocument == null && document != null); this.currentDocument = document; line = Math.Min(line, document.LineCount); column = Math.Min(column, document.GetLineByNumber(line).Length + 1); baseAnchor = document.CreateAnchor(document.GetOffset(line, column)); baseAnchor.MovementType = movementType; baseAnchor.SurviveDeletion = surviveDeletion; baseAnchor.Deleted += baseAnchor_Deleted; }
protected AbstractInlineRefactorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor) { if (context == null) throw new ArgumentNullException("context"); this.anchor = insertionEndAnchor = anchor; this.editor = editor; this.context = context; this.classFinderContext = new ClassFinder(ParserService.ParseCurrentViewContent(), editor.Document.Text, anchor.Offset); this.Background = SystemColors.ControlBrush; }
protected AbstractInlineRefactorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor) { if (context == null) throw new ArgumentNullException("context"); this.anchor = insertionEndAnchor = anchor; this.editor = editor; this.insertionContext = context; this.Background = SystemColors.ControlBrush; undoableCreationOperation = new UndoableInlineDialogCreation(this); }
protected AbstractInlineRefactorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor) { if (context == null) { throw new ArgumentNullException("context"); } this.anchor = insertionEndAnchor = anchor; this.editor = editor; this.insertionContext = context; this.Background = SystemColors.ControlBrush; undoableCreationOperation = new UndoableInlineDialogCreation(this); }
internal void AttachTo(IDocument document) { if (isDeleted) { return; } Debug.Assert(currentDocument == null && document != null); this.currentDocument = document; line = Math.Min(line, document.TotalNumberOfLines); column = Math.Min(column, document.GetLine(line).Length + 1); baseAnchor = document.CreateAnchor(document.PositionToOffset(line, column)); baseAnchor.MovementType = movementType; baseAnchor.SurviveDeletion = surviveDeletion; baseAnchor.Deleted += baseAnchor_Deleted; }
protected AbstractInlineRefactorDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor) { if (context == null) { throw new ArgumentNullException("context"); } this.anchor = insertionEndAnchor = anchor; this.editor = editor; this.context = context; this.classFinderContext = new ClassFinder(ParserService.ParseCurrentViewContent(), editor.Document.Text, anchor.Offset); this.Background = SystemColors.ControlBrush; }
/// <inheritdoc /> public IInlineUIElement CreateInlineUIElement(ITextAnchor position, UIElement element) { if (position == null) { throw new ArgumentNullException("position"); } if (element == null) { throw new ArgumentNullException("element"); } InlineUIElementGenerator inline = new InlineUIElementGenerator(textView, element, position); this.textView.ElementGenerators.Add(inline); return(inline); }
public CreatePropertiesDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor, IClass current, IList<FieldWrapper> availableFields) : base(context, editor, anchor) { InitializeComponent(); this.listBox.ItemsSource = fields = availableFields; if (!fields.Any()) Visibility = System.Windows.Visibility.Collapsed; implementInterface.IsChecked = !current.IsStatic && HasOnPropertyChanged(current); if (current.IsStatic) implementInterface.Visibility = System.Windows.Visibility.Collapsed; listBox.UnselectAll(); }
internal void Detach() { if (isDeleted) { return; } Debug.Assert(currentDocument != null); Location loc = baseAnchor.Location; line = loc.Line; column = loc.Column; baseAnchor = null; currentDocument = null; }
void CreateAnchor() { if (document != null) { int lineNumber = Math.Max(1, Math.Min(location.Line, document.TotalNumberOfLines)); int lineLength = document.GetLine(lineNumber).Length; int offset = document.PositionToOffset( lineNumber, Math.Max(1, Math.Min(location.Column, lineLength + 1)) ); anchor = document.CreateAnchor(offset); // after insertion: keep bookmarks after the initial whitespace (see DefaultFormattingStrategy.SmartReplaceLine) anchor.MovementType = AnchorMovementType.AfterInsertion; anchor.Deleted += AnchorDeleted; } else { anchor = null; } }
void ConvertToAutomaticProperty(ITextEditor editor, IProperty property, IField fieldDef, Ast.PropertyDeclaration astProp) { CodeGenerator codeGen = property.DeclaringType.ProjectContent.Language.CodeGenerator; int fieldStartOffset = editor.Document.PositionToOffset(fieldDef.Region.BeginLine, fieldDef.Region.BeginColumn); int fieldEndOffset = editor.Document.PositionToOffset(fieldDef.Region.EndLine, fieldDef.Region.EndColumn); int startOffset = editor.Document.PositionToOffset(property.Region.BeginLine, property.Region.BeginColumn); int endOffset = editor.Document.PositionToOffset(property.BodyRegion.EndLine, property.BodyRegion.EndColumn); ITextAnchor startAnchor = editor.Document.CreateAnchor(startOffset); ITextAnchor endAnchor = editor.Document.CreateAnchor(endOffset); if (astProp.HasGetRegion) { astProp.GetRegion.Block = null; } if (!astProp.HasSetRegion) { astProp.SetRegion = new Ast.PropertySetRegion(null, null); astProp.SetRegion.Modifier = CodeGenerator.ConvertModifier(fieldDef.Modifiers, new ClassFinder(fieldDef)) & (Ast.Modifiers.Private | Ast.Modifiers.Internal | Ast.Modifiers.Protected | Ast.Modifiers.Public); } Ast.FieldDeclaration f = ParseMember <Ast.FieldDeclaration>(Path.GetExtension(editor.FileName), GetMemberText(fieldDef, editor)); astProp.Initializer = f.Fields.First().Initializer; if (astProp.HasSetRegion) { astProp.SetRegion.Block = null; } using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.ConvertToAutomaticProperty}")) { var refs = RefactoringService.FindReferences(fieldDef, monitor); using (editor.Document.OpenUndoGroup()) { FindReferencesAndRenameHelper.RenameReferences(refs, property.Name); editor.Document.Remove(fieldStartOffset, fieldEndOffset - fieldStartOffset); editor.Document.Replace(startAnchor.Offset, endAnchor.Offset - startAnchor.Offset, codeGen.GenerateCode(astProp, "")); } } }
private void CreateAnchor() { if (document != null) { int lineNumber = Math.Max(1, Math.Min(location.Line, document.TotalNumberOfLines)); int lineLength = 0; int offset = document.PositionToOffset( lineNumber, Math.Max(1, Math.Min(location.Column, lineLength + 1)) ); anchor = document.CreateAnchor(offset); // after insertion: keep bookmarks after the initial whitespace (see DefaultFormattingStrategy.SmartReplaceLine) anchor.MovementType = AnchorMovementType.AfterInsertion; anchor.Deleted += AnchorDeleted; } else { anchor = null; } }
public CreatePropertiesDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor, IClass current, IList <FieldWrapper> availableFields) : base(context, editor, anchor) { InitializeComponent(); this.listBox.ItemsSource = fields = availableFields; if (!fields.Any()) { Visibility = System.Windows.Visibility.Collapsed; } implementInterface.IsChecked = !current.IsStatic && HasOnPropertyChanged(current); if (current.IsStatic) { implementInterface.Visibility = System.Windows.Visibility.Collapsed; } listBox.UnselectAll(); }
public OverrideEqualsGetHashCodeMethodsDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor endAnchor, ITextAnchor insertionPosition, IClass selectedClass, IMethod selectedMethod, string baseCall) : base(context, editor, insertionPosition) { if (selectedClass == null) { throw new ArgumentNullException("selectedClass"); } InitializeComponent(); this.selectedClass = selectedClass; this.startAnchor = startAnchor; this.insertionEndAnchor = endAnchor; this.selectedMethod = selectedMethod; this.baseCall = baseCall; addIEquatable.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddInterface}"), "IEquatable<" + selectedClass.Name + ">"); string otherMethod = selectedMethod.Name == "Equals" ? "GetHashCode" : "Equals"; addOtherMethod.Content = StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod}", new StringTagPair("otherMethod", otherMethod)); addIEquatable.IsEnabled = !selectedClass.BaseTypes.Any( type => { if (!type.IsGenericReturnType) { return(false); } var genericType = type.CastToGenericReturnType(); var boundTo = genericType.TypeParameter.BoundTo; if (boundTo == null) { return(false); } return(boundTo.Name == selectedClass.Name); } ); }
public OverrideEqualsGetHashCodeMethodsDialog(InsertionContext context, ITextEditor editor, ITextAnchor endAnchor, ITextAnchor insertionPosition, ITypeDefinition selectedClass, IMethod selectedMethod, AstNode baseCallNode) : base(context, editor, insertionPosition) { if (selectedClass == null) { throw new ArgumentNullException("selectedClass"); } InitializeComponent(); this.selectedClass = selectedClass; this.insertionEndAnchor = endAnchor; this.selectedMethod = selectedMethod; this.baseCallNode = baseCallNode; addIEquatable.Content = string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddInterface}"), "IEquatable<" + selectedClass.Name + ">"); string otherMethod = selectedMethod.Name == "Equals" ? "GetHashCode" : "Equals"; addOtherMethod.Content = StringParser.Parse("${res:AddIns.SharpRefactoring.OverrideEqualsGetHashCodeMethods.AddOtherMethod}", new StringTagPair("otherMethod", otherMethod)); addIEquatable.IsEnabled = !selectedClass.GetAllBaseTypes().Any( type => { if (!type.IsParameterized || (type.TypeParameterCount != 1)) { return(false); } if (type.FullName != "System.IEquatable") { return(false); } return(type.TypeArguments.First().FullName == selectedClass.FullName); } ); }
public void Insert(CompletionContext context, ICompletionItem item) { if (item == null) { throw new ArgumentNullException("item"); } if (!(item is OverrideCompletionItem)) { throw new ArgumentException("item is not an OverrideCompletionItem"); } OverrideCompletionItem completionItem = item as OverrideCompletionItem; ITextEditor textEditor = context.Editor; IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService; if (uiService == null) { return; } ParseInformation parseInfo = ParserService.GetParseInformation(textEditor.FileName); if (parseInfo == null) { return; } CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator; IClass current = parseInfo.CompilationUnit.GetInnermostClass(textEditor.Caret.Line, textEditor.Caret.Column); ClassFinder finder = new ClassFinder(current, textEditor.Caret.Line, textEditor.Caret.Column); if (current == null) { return; } using (textEditor.Document.OpenUndoGroup()) { ITextAnchor startAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset); startAnchor.MovementType = AnchorMovementType.BeforeInsertion; ITextAnchor endAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset); endAnchor.MovementType = AnchorMovementType.AfterInsertion; MethodDeclaration member = (MethodDeclaration)generator.GetOverridingMethod(completionItem.Member, finder); string indent = DocumentUtilitites.GetWhitespaceBefore(textEditor.Document, textEditor.Caret.Offset); string codeForBaseCall = generator.GenerateCode(member.Body.Children.OfType <AbstractNode>().First(), ""); string code = generator.GenerateCode(member, indent); int marker = code.IndexOf(codeForBaseCall); textEditor.Document.Insert(startAnchor.Offset, code.Substring(0, marker).TrimStart()); ITextAnchor insertionPos = textEditor.Document.CreateAnchor(endAnchor.Offset); insertionPos.MovementType = AnchorMovementType.BeforeInsertion; InsertionContext insertionContext = new InsertionContext(textEditor.GetService(typeof(TextArea)) as TextArea, startAnchor.Offset); AbstractInlineRefactorDialog dialog = new OverrideEqualsGetHashCodeMethodsDialog(insertionContext, textEditor, startAnchor, endAnchor, insertionPos, current, completionItem.Member as IMethod, codeForBaseCall.Trim()); dialog.Element = uiService.CreateInlineUIElement(insertionPos, dialog); textEditor.Document.InsertNormalized(endAnchor.Offset, Environment.NewLine + code.Substring(marker + codeForBaseCall.Length)); insertionContext.RegisterActiveElement(new InlineRefactorSnippetElement(cxt => null, ""), dialog); insertionContext.RaiseInsertionCompleted(EventArgs.Empty); } }
public CreatePropertiesDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor) : base(context, editor, anchor) { InitializeComponent(); }
void baseAnchor_Deleted(object sender, EventArgs e) { isDeleted = true; baseAnchor = null; currentDocument = null; if (Deleted != null) Deleted(this, e); }
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor anchor, IList <PropertyOrFieldWrapper> fields, string baseCall) : base(context, editor, anchor) { InitializeComponent(); this.baseCall = baseCall; this.listBox.ItemsSource = fields; listBox.SelectAll(); }
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor startAnchor, ITextAnchor anchor, IList <IField> fields, string baseCall) : base(context, editor, anchor) { InitializeComponent(); this.baseCall = baseCall; this.fields = fields.Select(f => new PropertyOrFieldWrapper(f) { IsSelected = true }).ToList(); this.listBox.ItemsSource = this.fields; }
public OverrideToStringMethodDialog(InsertionContext context, ITextEditor editor, ITextAnchor anchor, IList <PropertyOrFieldWrapper> fields, AstNode baseCallNode) : base(context, editor, anchor) { InitializeComponent(); this.baseCallNode = baseCallNode; parameterList = fields; this.listBox.ItemsSource = fields; SelectAllChecked(); }
public override void Complete(CompletionContext context) { if (declarationBegin > context.StartOffset) { base.Complete(context); return; } TypeSystemAstBuilder b = new TypeSystemAstBuilder(contextAtCaret); b.ShowTypeParameterConstraints = false; b.GenerateBody = true; var entityDeclaration = b.ConvertEntity(this.Entity); entityDeclaration.Modifiers &= ~(Modifiers.Virt | Modifiers.Abstract); entityDeclaration.Modifiers |= Modifiers.Override; var body = entityDeclaration.GetChildByRole(Roles.Body); Statement baseCallStatement = body.Children.OfType <Statement>().FirstOrDefault(); if (!this.Entity.IsAbstract) { // modify body to call the base method if (this.Entity.SymbolKind == SymbolKind.Method) { var baseCall = new BaseReferenceExpression().Invoke(this.Entity.Name, new Expression[] { }); if (((IMethod)this.Entity).ReturnType.IsKnownType(KnownTypeCode.Void)) { baseCallStatement = new ExpressionStatement(baseCall); } else { baseCallStatement = new ReturnStatement(baseCall); } // Clear body of inserted method entityDeclaration.GetChildByRole(Roles.Body).Statements.Clear(); } } var document = context.Editor.Document; StringWriter w = new StringWriter(); var formattingOptions = AlFormattingPolicies.Instance.GetProjectOptions(contextAtCaret.Compilation.GetProject()); var segmentDict = SegmentTrackingOutputFormatter.WriteNode( w, entityDeclaration, formattingOptions.OptionsContainer.GetEffectiveOptions(), context.Editor.Options); using (document.OpenUndoGroup()) { InsertionContext insertionContext = new InsertionContext(context.Editor.GetService(typeof(TextArea)) as TextArea, declarationBegin); insertionContext.InsertionPosition = context.Editor.Caret.Offset; string newText = w.ToString().TrimEnd(); document.Replace(declarationBegin, context.EndOffset - declarationBegin, newText); var throwStatement = entityDeclaration.Descendants.FirstOrDefault(n => n is ThrowStatement); if (throwStatement != null) { var segment = segmentDict[throwStatement]; context.Editor.Select(declarationBegin + segment.Offset, segment.Length); } AlFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions.OptionsContainer); var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None); var typeResolveContext = refactoringContext.GetTypeResolveContext(); if (typeResolveContext == null) { return; } var resolvedCurrent = typeResolveContext.CurrentTypeDefinition; IEditorUIService uiService = context.Editor.GetService(typeof(IEditorUIService)) as IEditorUIService; ITextAnchor endAnchor = context.Editor.Document.CreateAnchor(context.Editor.Caret.Offset); endAnchor.MovementType = AnchorMovementType.AfterInsertion; ITextAnchor startAnchor = context.Editor.Document.CreateAnchor(context.Editor.Caret.Offset); startAnchor.MovementType = AnchorMovementType.BeforeInsertion; ITextAnchor insertionPos = context.Editor.Document.CreateAnchor(endAnchor.Offset); insertionPos.MovementType = AnchorMovementType.BeforeInsertion; var current = typeResolveContext.CurrentTypeDefinition; AbstractInlineRefactorDialog dialog = new OverrideEqualsGetHashCodeMethodsDialog(insertionContext, context.Editor, endAnchor, insertionPos, current, Entity as IMethod, baseCallStatement); dialog.Element = uiService.CreateInlineUIElement(insertionPos, dialog); insertionContext.RegisterActiveElement(new InlineRefactorSnippetElement(cxt => null, ""), dialog); insertionContext.RaiseInsertionCompleted(EventArgs.Empty); } }