protected override void DrawLine(ViewDrawArgs e, IndentInfo indent) { if (!IsAllowDrawIndent(indent)) { return; } CustomDrawLineEventArgs args; CellIndentInfo cellIndentInfo = indent as CellIndentInfo; if (cellIndentInfo == null) { args = new CustomDrawLineEventArgs(e.Cache, indent.Appearance, indent.Bounds, null); } else { args = new CustomDrawLineEventArgs(e.Cache, indent.Appearance, indent.Bounds, cellIndentInfo.Cell); } View.RaiseCustomDrawGridLine(args); if (args.Handled) { return; } base.DrawLine(e, indent); }
/// <summary>Increments the indentation by the specified depth and returns a disposable handle.</summary> /// <remarks>The indentation is decremented by disposing the handle.</remarks> /// <exception cref="ArgumentOutOfRangeException">Thrown when one or more arguments are outside the required range.</exception> /// <param name="depth">The depth.</param> /// <returns>The indentation handle.</returns> public IDisposable Indent(int depth) { if (depth < 0) { throw new ArgumentOutOfRangeException("depth", "Negative indent is not allowed"); } this.indent = new IndentInfo(this, this.IndentDepth + depth); return(this.indent); }
private static Document ApplyFix(Diagnostic diagnostic, SyntaxNode syntaxRoot, Document document) { Document result = document; if (syntaxRoot.FindNode(diagnostic.Location.SourceSpan) is UsingDirectiveSyntax directive && diagnostic.Properties.TryGetValue(LevelProperty, out string levelText) && int.TryParse(levelText, out int level)) { IndentInfo indent = new IndentInfo(directive, level); result = ApplyFix(indent, syntaxRoot, result); } return(result); }
void GetLineIndentInfo(int line_number, out IndentInfo info) { info.line_start_char_index = GetLineStartCharIndexFromLineNumber(line_number); int ln; info.line = GetLineFromCharIndex(info.line_start_char_index, out ln); Debug.Assert(line_number == ln); info.indent_char_count = GetLineIndentCharCount(info.line, 0, info.line.Length); info.indent_column_index = GetColumnIndexFromTabbedText(info.line, 0, info.indent_char_count, TAB_SIZE); if (info.indent_char_count > 0) { m_UseTabsToIndent = info.line[0] == '\t'; } }
private static Document ApplyFix(IndentInfo indent, SyntaxNode syntaxRoot, Document document) { string newIndentText; Project project = document.Project; OptionSet options = project.Solution.Workspace.Options; int indentSize = options.GetOption(FormattingOptions.IndentationSize, project.Language); int newIndentTextLogicalLength = indentSize * indent.Level; if (options.GetOption(FormattingOptions.UseTabs, project.Language)) { int tabSize = Math.Max(options.GetOption(FormattingOptions.TabSize, project.Language), 1); int numTabs = newIndentTextLogicalLength / tabSize; int numSpaces = newIndentTextLogicalLength % tabSize; newIndentText = new string('\t', numTabs) + new string(' ', numSpaces); } else { newIndentText = new string(' ', newIndentTextLogicalLength); } SyntaxNode newSyntaxRoot; if (indent.IndentTrivia == null) { // Insert leading indent trivia. SyntaxToken keyword = indent.Using.UsingKeyword; var newLeadingTrivia = keyword.LeadingTrivia.Concat(new[] { SyntaxFactory.Whitespace(newIndentText) }); SyntaxToken newKeyword = keyword.WithLeadingTrivia(newLeadingTrivia); newSyntaxRoot = syntaxRoot.ReplaceToken(keyword, newKeyword); } else if (indent.Level == 0) { // Remove the invalid leading indent trivia. newSyntaxRoot = syntaxRoot.ReplaceTrivia(indent.IndentTrivia.Value, default(SyntaxTrivia)); } else { // Replace the existing indent trivia with the correct indentation. SyntaxTrivia newIndentTrivia = SyntaxFactory.Whitespace(newIndentText); newSyntaxRoot = syntaxRoot.ReplaceTrivia(indent.IndentTrivia.Value, newIndentTrivia); } Document result = document.WithSyntaxRoot(newSyntaxRoot); return(result); }
void GetAutoIndentForLine(int line_number, out IndentInfo info) { info = new IndentInfo(); for (int i = line_number - 1, e = Math.Max(0, line_number - 1 - AUTO_INDENT_MAX_PREV_LINES_TO_ANALYZE); i > e; --i) { IndentInfo indent_info; GetLineIndentInfo(i, out indent_info); if (indent_info.IsSpaceOnlyLine()) { if (i == line_number - 1) { info = indent_info; } } else { info = indent_info; break; } } }
public NemerleProjectSourcesButchEditHelper(ProjectInfo projectInfo, string description, IndentInfo identInfo) { _projectInfo = projectInfo; _description = description; _identInfo = identInfo; }
void GetLineIndentInfo(int line_number, out IndentInfo info) { info.line_start_char_index = GetLineStartCharIndexFromLineNumber(line_number); int ln; info.line = GetLineFromCharIndex(info.line_start_char_index, out ln); Debug.Assert(line_number == ln); info.indent_char_count = GetLineIndentCharCount(info.line, 0, info.line.Length); info.indent_column_index = GetColumnIndexFromTabbedText(info.line, 0, info.indent_char_count, TAB_SIZE); if (info.indent_char_count > 0) m_UseTabsToIndent = info.line[0] == '\t'; }
void GetAutoIndentForLine(int line_number, out IndentInfo info) { info = new IndentInfo(); for (int i = line_number - 1, e = Math.Max(0, line_number - 1 - AUTO_INDENT_MAX_PREV_LINES_TO_ANALYZE); i > e; --i) { IndentInfo indent_info; GetLineIndentInfo(i, out indent_info); if (indent_info.IsSpaceOnlyLine()) { if (i == line_number - 1) info = indent_info; } else { info = indent_info; break; } } }
/// <summary>Constructor.</summary> /// <param name="owner">The owner.</param> /// <param name="depth">The depth.</param> public IndentInfo(RichTextWriter owner, int depth) { this.owner = owner; this.depth = depth; this.previous = owner.indent; }