/// <summary> /// Called when this switch body element is inserted to the editor. /// </summary> public override void Insert(InsertionContext context) { this.context = context; this.context.Deactivated += new EventHandler <SnippetEventArgs>(InteractiveModeCompleted); this.anchor = SetUpAnchorAtInsertion(context); this.classFinderContext = new ClassFinder(ParserService.ParseCurrentViewContent(), Editor.Document.Text, Editor.Caret.Offset); }
public virtual void GenerateCode(TextArea textArea, IList items) { List <AbstractNode> nodes = new List <AbstractNode>(); GenerateCode(nodes, items); codeGen.InsertCodeInClass(selectedClass, new TextEditorDocument(textArea.Document), textArea.Caret.Line, nodes.ToArray()); ParserService.ParseCurrentViewContent(); }
void CreateChangedEvent(object sender, EventArgs e) { MenuCommand item = (MenuCommand)sender; IProperty member = (IProperty)item.Tag; TextEditorControl textEditor = FindReferencesAndRenameHelper.JumpBehindDefinition(member); member.DeclaringType.ProjectContent.Language.CodeGenerator.CreateChangedEvent(member, new TextEditorDocument(textEditor.Document)); ParserService.ParseCurrentViewContent(); }
void ExpandAutomaticProperty(object sender, EventArgs e) { MenuCommand item = (MenuCommand)sender; IProperty member = (IProperty)item.Tag; ITextEditor textEditor = FindReferencesAndRenameHelper.JumpToDefinition(member); if (textEditor != null) { CodeGenerator codeGen = member.DeclaringType.ProjectContent.Language.CodeGenerator; IField field = new DefaultField(member.ReturnType, codeGen.GetFieldName(member.Name), member.Modifiers & ModifierEnum.Static, DomRegion.Empty, member.DeclaringType); ClassFinder finder = new ClassFinder(member); Ast.PropertyDeclaration p = codeGen.CreateProperty(field, member.CanGet, member.CanSet); p.Modifier = CodeGenerator.ConvertModifier(member.Modifiers, finder); PropertyDeclaration oldProp = ParseMember <PropertyDeclaration>(Path.GetExtension(textEditor.FileName), GetMemberText(member, textEditor)); if (member.CanGet) { p.GetRegion.Modifier = CodeGenerator.ConvertModifier(member.GetterModifiers, finder); } if (member.CanSet) { p.SetRegion.Modifier = CodeGenerator.ConvertModifier(member.SetterModifiers, finder); } int startOffset = textEditor.Document.PositionToOffset(member.Region.BeginLine, member.Region.BeginColumn); int endOffset = textEditor.Document.PositionToOffset(member.Region.EndLine, member.Region.EndColumn); if (!member.BodyRegion.IsEmpty) { endOffset = textEditor.Document.PositionToOffset(member.BodyRegion.EndLine, member.BodyRegion.EndColumn); } FieldDeclaration f = CodeGenerator.ConvertMember(field, finder); f.Fields[0].Initializer = oldProp.Initializer; using (textEditor.Document.OpenUndoGroup()) { textEditor.Document.Remove(startOffset, endOffset - startOffset); if (codeGen.Options.EmptyLinesBetweenMembers) { var line = textEditor.Document.GetLine(member.Region.BeginLine); textEditor.Document.Remove(line.Offset, line.TotalLength); } codeGen.InsertCodeInClass(member.DeclaringType, new RefactoringDocumentAdapter(textEditor.Document), member.Region.BeginLine - 1, f, p); } ParserService.ParseCurrentViewContent(); } }
void CreateOnEventMethod(object sender, EventArgs e) { MenuCommand item = (MenuCommand)sender; IEvent member = (IEvent)item.Tag; TextEditorControl textEditor = FindReferencesAndRenameHelper.JumpBehindDefinition(member); CodeGenerator codeGen = member.DeclaringType.ProjectContent.Language.CodeGenerator; codeGen.InsertCodeAfter(member, new TextEditorDocument(textEditor.Document), codeGen.CreateOnEventMethod(member)); ParserService.ParseCurrentViewContent(); }
public virtual void Execute() { var d = FindReferencesAndRenameHelper.GetDocument(TargetClass); if (d == null) { return; } CodeGenerator.ImplementAbstractClass(new RefactoringDocumentAdapter(d), TargetClass, ClassToImplement); ParserService.ParseCurrentViewContent(); }
public override void Execute() { var codeGen = TargetClass.ProjectContent.Language.CodeGenerator; var d = FindReferencesAndRenameHelper.GetDocument(TargetClass); if (d == null) { return; } codeGen.ImplementInterface(this.ClassToImplement, new RefactoringDocumentAdapter(d), this.IsExplicitImpl, this.TargetClass); ParserService.ParseCurrentViewContent(); }
void CreateProperty(object sender, EventArgs e, bool includeSetter) { MenuCommand item = (MenuCommand)sender; IField member = (IField)item.Tag; ITextEditor textEditor = FindReferencesAndRenameHelper.JumpBehindDefinition(member); if (textEditor != null) { CodeGenerator codeGen = member.DeclaringType.ProjectContent.Language.CodeGenerator; codeGen.InsertCodeAfter(member, new RefactoringDocumentAdapter(textEditor.Document), codeGen.CreateProperty(member, true, includeSetter)); ParserService.ParseCurrentViewContent(); } }
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; }
// void GoToBase(object sender, EventArgs e) // { // MenuCommand item = (MenuCommand)sender; // IClass c = (IClass)item.Tag; // IClass baseClass = c.BaseClass; // if (baseClass != null) { // string fileName = baseClass.CompilationUnit.FileName; // if (fileName != null) { // FileService.JumpToFilePosition(fileName, baseClass.Region.BeginLine, baseClass.Region.BeginColumn); // } // } // } public static IClass GetClass(object menuOwner) { IClass c; ClassNode classNode = menuOwner as ClassNode; if (classNode != null) { c = classNode.Class; } else { ClassBookmark bookmark = (ClassBookmark)menuOwner; c = bookmark.Class; } ParserService.ParseCurrentViewContent(); c = c.ProjectContent.GetClass(c.FullyQualifiedName, c.TypeParameters.Count, c.ProjectContent.Language, GetClassOptions.LookForInnerClass); return(GetCurrentPart(c)); }
public ToolStripItem[] BuildSubmenu(Codon codon, object owner) { MenuCommand cmd; IClass c; ClassNode classNode = owner as ClassNode; if (classNode != null) { c = classNode.Class; } else { ClassBookmark bookmark = (ClassBookmark)owner; c = bookmark.Class; } ParserService.ParseCurrentViewContent(); c = c.ProjectContent.GetClass(c.FullyQualifiedName, c.TypeParameters.Count, c.ProjectContent.Language, GetClassOptions.LookForInnerClass); c = GetCurrentPart(c); if (c == null) { return(new ToolStripMenuItem[0]); } List <ToolStripItem> list = new List <ToolStripItem>(); // "Go to base" for classes is not that useful as it is faster to click the base class in the editor. // Also, we have "Find base classes" which shows all base classes. // if (c.BaseTypes.Count > 0) { // list.Add(new MenuSeparator()); // cmd = new MenuCommand("${res:SharpDevelop.Refactoring.GoToBaseCommand}", GoToBase); // cmd.Tag = c; // list.Add(cmd); // } cmd = FindReferencesAndRenameHelper.MakeFindReferencesMenuCommand(FindReferences); cmd.Tag = c; list.Add(cmd); list.AddIfNotNull(MakeFindBaseClassesItem(c)); list.AddIfNotNull(MakeFindDerivedClassesItem(c)); return(list.ToArray()); }
public EditorActionsProvider(ITextEditor editor, IList <IContextActionsProvider> providers) { if (editor == null) { throw new ArgumentNullException("editor"); } if (providers == null) { throw new ArgumentNullException("providers"); } this.editor = editor; this.providers = providers; // DO NOT USE Wait on the main thread! // causes deadlocks! // parseTask.Wait(); // Reparse so that we have up-to-date DOM. ParserService.ParseCurrentViewContent(); this.EditorContext = new EditorContext(editor); }
void AddImplementInterfaceCommandItems(List <ToolStripItem> subItems, IClass c, bool explicitImpl) { CodeGenerator codeGen = c.ProjectContent.Language.CodeGenerator; IAmbience ambience = AmbienceService.CurrentAmbience; ambience.ConversionFlags = ConversionFlags.None; foreach (IReturnType rt in c.BaseTypes) { IClass interf = rt.GetUnderlyingClass(); if (interf != null && interf.ClassType == ClassType.Interface) { IReturnType rtCopy = rt; // copy for access by anonymous method EventHandler eh = delegate { TextEditorDocument d = new TextEditorDocument(GetDocument(c)); if (d != null) { codeGen.ImplementInterface(rtCopy, d, explicitImpl, c); } ParserService.ParseCurrentViewContent(); }; subItems.Add(new MenuCommand(ambience.Convert(interf), eh)); } } }
public ToolStripItem[] BuildSubmenu(Codon codon, object owner) { MenuCommand cmd; IClass c; ClassNode classNode = owner as ClassNode; if (classNode != null) { c = classNode.Class; } else { ClassBookmark bookmark = (ClassBookmark)owner; c = bookmark.Class; } ParserService.ParseCurrentViewContent(); c = c.ProjectContent.GetClass(c.FullyQualifiedName, c.TypeParameters.Count); if (c == null) { return(new ToolStripMenuItem[0]); } LanguageProperties language = c.ProjectContent.Language; List <ToolStripItem> list = new List <ToolStripItem>(); if (!FindReferencesAndRenameHelper.IsReadOnly(c)) { if (c.DeclaringType == null && !c.BodyRegion.IsEmpty && !c.Name.Equals(Path.GetFileNameWithoutExtension(c.CompilationUnit.FileName), StringComparison.InvariantCultureIgnoreCase)) { // File name does not match class name string correctFileName = Path.Combine(Path.GetDirectoryName(c.CompilationUnit.FileName), c.Name + Path.GetExtension(c.CompilationUnit.FileName)); if (FileUtility.IsValidFileName(correctFileName) && Path.IsPathRooted(correctFileName) && !File.Exists(correctFileName)) { if (c.CompilationUnit.Classes.Count == 1) { // Rename file to ## cmd = new MenuCommand(StringParser.Parse("${res:SharpDevelop.Refactoring.RenameFileTo}", new string[, ] { { "FileName", Path.GetFileName(correctFileName) } }), delegate { FileService.RenameFile(c.CompilationUnit.FileName, correctFileName, false); if (c.ProjectContent.Project != null) { ((IProject)c.ProjectContent.Project).Save(); } }); list.Add(cmd); } else if (language.RefactoringProvider.SupportsCreateNewFileLikeExisting && language.RefactoringProvider.SupportsGetFullCodeRangeForType) { // Move class to file ## cmd = new MenuCommand(StringParser.Parse("${res:SharpDevelop.Refactoring.MoveClassToFile}", new string[, ] { { "FileName", Path.GetFileName(correctFileName) } }), delegate { MoveClassToFile(c, correctFileName); }); list.Add(cmd); } } } cmd = new MenuCommand("${res:SharpDevelop.Refactoring.RenameCommand}", Rename); cmd.Tag = c; list.Add(cmd); } if (c.BaseTypes.Count > 0) { cmd = new MenuCommand("${res:SharpDevelop.Refactoring.GoToBaseCommand}", GoToBase); cmd.Tag = c; list.Add(cmd); if (c.ClassType != ClassType.Interface && !FindReferencesAndRenameHelper.IsReadOnly(c)) { AddImplementInterfaceCommands(c, list); } } if (!c.IsSealed && !c.IsStatic) { cmd = new MenuCommand("${res:SharpDevelop.Refactoring.FindDerivedClassesCommand}", FindDerivedClasses); cmd.Tag = c; list.Add(cmd); } cmd = new MenuCommand("${res:SharpDevelop.Refactoring.FindReferencesCommand}", FindReferences); cmd.Tag = c; list.Add(cmd); return(list.ToArray()); }