public override void CorrectIndenting (PolicyContainer policyParent, IEnumerable<string> mimeTypeChain, TextEditorData data, int line) { LineSegment lineSegment = data.Document.GetLine (line); if (lineSegment == null) return; var policy = policyParent.Get<CFormattingPolicy> (mimeTypeChain); var tracker = new DocumentStateTracker<CIndentEngine> (new CIndentEngine (policy), data); tracker.UpdateEngine (lineSegment.Offset); for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.EditableLength; i++) { tracker.Engine.Push (data.Document.GetCharAt (i)); } string curIndent = lineSegment.GetIndentation (data.Document); int nlwsp = curIndent.Length; if (!tracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.Length && data.Document.GetCharAt (lineSegment.Offset + nlwsp) == '*')) { // Possibly replace the indent string newIndent = tracker.Engine.ThisLineIndent; if (newIndent != curIndent) data.Replace (lineSegment.Offset, nlwsp, newIndent); } tracker.Dispose (); }
public override void CorrectIndenting(PolicyContainer policyParent, IEnumerable <string> mimeTypeChain, TextEditorData data, int line) { LineSegment lineSegment = data.Document.GetLine(line); if (lineSegment == null) { return; } var policy = policyParent.Get <CSharpFormattingPolicy> (mimeTypeChain); var tracker = new DocumentStateTracker <CSharpIndentEngine> (new CSharpIndentEngine(policy), data); tracker.UpdateEngine(lineSegment.Offset); for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.EditableLength; i++) { tracker.Engine.Push(data.Document.GetCharAt(i)); } string curIndent = lineSegment.GetIndentation(data.Document); int nlwsp = curIndent.Length; if (!tracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.Length && data.Document.GetCharAt(lineSegment.Offset + nlwsp) == '*')) { // Possibly replace the indent string newIndent = tracker.Engine.ThisLineIndent; if (newIndent != curIndent) { data.Replace(lineSegment.Offset, nlwsp, newIndent); } } tracker.Dispose(); }
public override void CorrectIndenting(object textEditorData, int line) { TextEditorData data = (TextEditorData)textEditorData; LineSegment lineSegment = data.Document.GetLine(line); if (lineSegment == null) { return; } IEnumerable <string> types = MonoDevelop.Ide.DesktopService.GetMimeTypeInheritanceChain(CSharpFormatter.MimeType); var policy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <CSharpFormattingPolicy> (types); DocumentStateTracker <CSharpIndentEngine> tracker = new DocumentStateTracker <CSharpIndentEngine> (new CSharpIndentEngine(policy), data); tracker.UpdateEngine(lineSegment.Offset); for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.EditableLength; i++) { tracker.Engine.Push(data.Document.GetCharAt(i)); } string curIndent = lineSegment.GetIndentation(data.Document); int nlwsp = curIndent.Length; // int cursor = data.Caret.Offset; // int pos = lineSegment.Offset; // int offset = cursor > pos + nlwsp ? cursor - (pos + nlwsp) : 0; if (!tracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.Length && data.Document.GetCharAt(lineSegment.Offset + nlwsp) == '*')) { // Possibly replace the indent string newIndent = tracker.Engine.ThisLineIndent; // int newIndentLength = newIndent.Length; if (newIndent != curIndent) { data.Replace(lineSegment.Offset, nlwsp, newIndent); } } /* * string endIndent = tracker.Engine.ThisLineIndent; * string indent = endIndent.Length < beginIndent.Length ? endIndent : beginIndent; * if (indent != curIndent) * data.Replace (lineSegment.Offset, curIndent.Length, indent); */ tracker.Dispose(); }
public override void Dispose () { Editor.CaretPositionChanged -= HandleCaretPositionChanged; if (tracker != null) { tracker.Dispose (); tracker = null; } DocumentContext.DocumentParsed -= UpdateParsedDocument; if (IdeApp.Workspace != null) { IdeApp.Workspace.FileAddedToProject -= HandleProjectChanged; IdeApp.Workspace.FileRemovedFromProject -= HandleProjectChanged; } base.Dispose (); }
public override void CorrectIndenting (object textEditorData, int line) { TextEditorData data = (TextEditorData)textEditorData; LineSegment lineSegment = data.Document.GetLine (line); if (lineSegment == null) return; IEnumerable<string> types = MonoDevelop.Ide.DesktopService.GetMimeTypeInheritanceChain (CSharpFormatter.MimeType); var policy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<CSharpFormattingPolicy> (types); DocumentStateTracker<CSharpIndentEngine> tracker = new DocumentStateTracker<CSharpIndentEngine> (new CSharpIndentEngine (policy), data); tracker.UpdateEngine (lineSegment.Offset); for (int i = lineSegment.Offset; i < lineSegment.Offset + lineSegment.EditableLength; i++) { tracker.Engine.Push (data.Document.GetCharAt (i)); } string curIndent = lineSegment.GetIndentation (data.Document); int nlwsp = curIndent.Length; // int cursor = data.Caret.Offset; // int pos = lineSegment.Offset; // int offset = cursor > pos + nlwsp ? cursor - (pos + nlwsp) : 0; if (!tracker.Engine.LineBeganInsideMultiLineComment || (nlwsp < lineSegment.Length && data.Document.GetCharAt (lineSegment.Offset + nlwsp) == '*')) { // Possibly replace the indent string newIndent = tracker.Engine.ThisLineIndent; // int newIndentLength = newIndent.Length; if (newIndent != curIndent) data.Replace (lineSegment.Offset, nlwsp, newIndent); } /* string endIndent = tracker.Engine.ThisLineIndent; string indent = endIndent.Length < beginIndent.Length ? endIndent : beginIndent; if (indent != curIndent) data.Replace (lineSegment.Offset, curIndent.Length, indent); */ tracker.Dispose (); }