static void CheckStartPoint (TextDocument doc, InsertionPoint point, bool isEndPoint) { DocumentLine line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length + 1 == point.Location.Column) { int lineNr = point.Location.Line; while (lineNr > 1 && doc.GetLineIndent (lineNr - 1).Length == doc.GetLine (lineNr - 1).Length) { lineNr--; } line = doc.GetLine (lineNr); point.Location = new DocumentLocation (lineNr, doc.GetLineIndent (line).Length + 1); } if (doc.GetLineIndent (line).Length + 1 < point.Location.Column) point.LineBefore = NewLineInsertion.Eol; if (point.Location.Column < line.Length + 1) point.LineAfter = isEndPoint ? NewLineInsertion.Eol : NewLineInsertion.BlankLine; }
public override void Run(RefactoringOptions options) { var declaringType = options.ResolveResult.CallingType; MonoDevelop.Ide.Gui.Document doc = options.Document; var fileName = doc.FileName; MonoDevelop.Ide.Gui.Document openDocument = IdeApp.Workbench.OpenDocument(fileName, (OpenDocumentOptions) 39); if (openDocument == null) { MessageService.ShowError(string.Format("Can't open file {0}.", fileName)); } else { insertionPoint = GetInsertionPoint(openDocument, declaringType); base.Run(options); } }
public InsertionCursorEventArgs (bool success, InsertionPoint insertionPoint) { Success = success; InsertionPoint = insertionPoint; }
static void CheckEndPoint (TextDocument doc, InsertionPoint point, bool isStartPoint) { DocumentLine line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length + 1 < point.Location.Column) point.LineBefore = NewLineInsertion.BlankLine; if (point.Location.Column < line.Length + 1) point.LineAfter = NewLineInsertion.Eol; }
public override void Run (RefactoringOptions options) { IResolver resolver = options.GetResolver (); INRefactoryASTProvider provider = options.GetASTProvider (); TextEditorData data = options.GetTextEditorData (); IType type = options.ResolveResult.CallingType; if (invoke.TargetObject is IdentifierExpression) { fileName = options.Document.FileName; newMethodName = ((IdentifierExpression)invoke.TargetObject).Identifier; indent = options.GetIndent (options.ResolveResult.CallingMember); if (options.ResolveResult.CallingMember.IsStatic) modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Static; } else { newMethodName = ((MemberReferenceExpression)invoke.TargetObject).MemberName; string callingObject = provider.OutputNode (options.Dom, ((MemberReferenceExpression)invoke.TargetObject).TargetObject); ResolveResult resolveResult = resolver.Resolve (new ExpressionResult (callingObject), resolvePosition); type = options.Dom.GetType (resolveResult.ResolvedType); fileName = type.CompilationUnit.FileName; if (resolveResult.StaticResolve) modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Static; if (fileName == options.Document.FileName) { indent = options.GetIndent (options.ResolveResult.CallingMember); // insertNewMethod.Offset = options.Document.TextEditor.GetPositionFromLineColumn (options.ResolveResult.CallingMember.BodyRegion.End.Line, options.ResolveResult.CallingMember.BodyRegion.End.Column); } else { var openDocument = IdeApp.Workbench.OpenDocument (fileName); data = openDocument.Editor; if (data == null) return; modifiers |= ICSharpCode.NRefactory.Ast.Modifiers.Public; bool isInInterface = type.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface; if (isInInterface) modifiers = ICSharpCode.NRefactory.Ast.Modifiers.None; if (data == null) throw new InvalidOperationException ("Can't open file:" + modifiers); try { indent = data.Document.GetLine (type.Location.Line - 1).GetIndentation (data.Document) ?? ""; } catch (Exception) { indent = ""; } indent += "\t"; // insertNewMethod.Offset = otherFile.Document.LocationToOffset (type.BodyRegion.End.Line - 1, 0); } } InsertionCursorEditMode mode = new InsertionCursorEditMode (data.Parent, HelperMethods.GetInsertionPoints (data.Document, type)); if (fileName == options.Document.FileName) { for (int i = 0; i < mode.InsertionPoints.Count; i++) { var point = mode.InsertionPoints[i]; if (point.Location < data.Caret.Location) { mode.CurIndex = i; } else { break; } } } ModeHelpWindow helpWindow = new ModeHelpWindow (); helpWindow.TransientFor = IdeApp.Workbench.RootWindow; helpWindow.TitleText = GettextCatalog.GetString ("<b>Create Method -- Targeting</b>"); helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Key</b>"), GettextCatalog.GetString ("<b>Behavior</b>"))); helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Up</b>"), GettextCatalog.GetString ("Move to <b>previous</b> target point."))); helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Down</b>"), GettextCatalog.GetString ("Move to <b>next</b> target point."))); helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Enter</b>"), GettextCatalog.GetString ("<b>Declare new method</b> at target point."))); helpWindow.Items.Add (new KeyValuePair<string, string> (GettextCatalog.GetString ("<b>Esc</b>"), GettextCatalog.GetString ("<b>Cancel</b> this refactoring."))); mode.HelpWindow = helpWindow; mode.StartMode (); mode.Exited += delegate(object s, InsertionCursorEventArgs args) { if (args.Success) { insertionPoint = args.InsertionPoint; insertionOffset = data.Document.LocationToOffset (args.InsertionPoint.Location); base.Run (options); if (string.IsNullOrEmpty (fileName)) return; MonoDevelop.Ide.Gui.Document document = IdeApp.Workbench.OpenDocument (fileName); TextEditorData docData = document.Editor; if (docData != null) { docData.ClearSelection (); docData.Caret.Offset = selectionEnd; docData.SetSelection (selectionStart, selectionEnd); } } }; }
public void SetInsertionPoint (InsertionPoint point) { this.insertionPoint = point; }
public InsertionCursorEventArgs(bool success, InsertionPoint insertionPoint) { Success = success; InsertionPoint = insertionPoint; }
static void CheckStartPoint (Document doc, InsertionPoint point) { LineSegment line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length < point.Location.Column) point.ShouldInsertNewLineBefore = true; if (point.Location.Column < line.EditableLength) point.ShouldInsertNewLineAfter = true; }
static void CheckEndPoint (Document doc, InsertionPoint point, bool isStartPoint) { LineSegment line = doc.GetLine (point.Location.Line); if (line == null) return; if (doc.GetLineIndent (line).Length < point.Location.Column) point.LineBefore = NewLineInsertion.BlankLine; if (point.Location.Column < line.EditableLength) point.LineAfter = NewLineInsertion.Eol; }