/// <summary> /// Inserts an event handler. /// </summary> public bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out string file, out int position) { position = GetExistingEventHandler(eventMethodName); if (position == -1) { // Ensure the text editor has the latest version // of the source code before we insert any new code. viewContent.MergeFormChanges(); // Insert the event handler at the end of the class with an extra // new line before it. IDocument doc = viewContent.DesignerCodeFileDocument; string eventHandler = CreateEventHandler(eventMethodName, body, NRefactoryToPythonConverter.GetIndentString(textEditorProperties)); int line = doc.LineSegmentCollection.Count; LineSegment lastLineSegment = doc.GetLineSegment(line - 1); int offset = lastLineSegment.Offset + lastLineSegment.Length; string newContent = "\r\n" + eventHandler; if (lastLineSegment.Length > 0) { // Add an extra new line between the last line and the event handler. newContent = "\r\n" + newContent; } doc.Insert(offset, newContent); // Set position so it points to the line // where the event handler was inserted. position = line + 1; } // Set the filename so it refers to the form being designed. file = viewContent.DesignerCodeFile.FileName; return(true); }
/// <summary> /// Inserts an event handler. /// </summary> public bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out string file, out int position) { position = GetExistingEventHandler(eventMethodName); if (position == -1) { // Ensure the text editor has the latest version // of the source code before we insert any new code. viewContent.MergeFormChanges(); // Insert the event handler at the end of the class with an extra // new line before it. IDocument doc = viewContent.DesignerCodeFileDocument; string eventHandler = CreateEventHandler(eventMethodName, body, NRefactoryToRubyConverter.GetIndentString(textEditorProperties)); LineSegment classEndLine = GetClassEndLine(doc); InsertEventHandlerBeforeLine(doc, eventHandler, classEndLine); // Set position so it points to the line // where the event handler was inserted. position = classEndLine.LineNumber + 1; } // Set the filename so it refers to the form being designed. file = viewContent.DesignerCodeFile.FileName; return(true); }
/// <summary> /// Inserts an event handler. /// </summary> public bool InsertComponentEvent(IComponent component, EventDescriptor edesc, string eventMethodName, string body, out string file, out int position) { position = GetExistingEventHandler(eventMethodName); if (position == -1) { // Ensure the text editor has the latest version // of the source code before we insert any new code. viewContent.MergeFormChanges(); // Insert the event handler at the end of the class. IDocument doc = ViewContent.DesignerCodeFileDocument; string eventHandler = CreateEventHandler(eventMethodName, body, TextEditorOptions.IndentationString); position = InsertEventHandler(doc, eventHandler); } // Set the filename so it refers to the form being designed. file = ViewContent.DesignerCodeFile.FileName; return(true); }