namespace Microsoft.VisualStudio.Text.Formatting { using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Utilities; using System.ComponentModel.Composition; [Export(typeof(ILineTransformSourceProvider))] [ContentType("text")] [TextViewRole(PredefinedTextViewRoles.Interactive)] public partial class LineTransformSource : ILineTransformSourceProvider, ILineTransformSource { IWpfTextView view; public ILineTransformSource Create(IWpfTextView textView) { this.view = textView; return this; } public LineTransform GetLineTransform(ITextViewLine line, double yPosition, Microsoft.VisualStudio.Text.Editor.ViewRelativePosition placement) { return GetLineTransform(line); } } } namespace Microsoft.VisualStudio.Text.Formatting { public partial class LineTransformSource { public LineTransform GetLineTransform(ITextViewLine line) { return line.DefaultLineTransform; } } }
Exercises
- Make all lines double-spaced.
namespace Microsoft.VisualStudio.Text.Formatting { public partial class LineTransformSource { public LineTransform GetLineTransform(ITextViewLine line) { var currentTransform = line.LineTransform; // line.Height would not work here! var transform = new LineTransform(currentTransform.TopSpace, line.TextHeight, currentTransform.VerticalScale, currentTransform.Right); return transform; } } }
Another version:
namespace Microsoft.VisualStudio.Text.Formatting { public partial class LineTransformSource { public LineTransform GetLineTransform(ITextViewLine line) { var currentTransform = line.LineTransform; if (line.Change == TextViewLineChange.NewOrReformatted) return new LineTransform(currentTransform.TopSpace, line.TextHeight, currentTransform.VerticalScale, currentTransform.Right); else return line.DefaultLineTransform; } } }
- Sadece brace olan satirlari kucult.
namespace Microsoft.VisualStudio.Text.Formatting { public partial class LineTransformSource { public LineTransform GetLineTransform(ITextViewLine line) { var s = line.Extent.GetText().Trim(); if (line.Change == TextViewLineChange.NewOrReformatted && (s == "{" || s == "}" || s == "};")) { return new LineTransform(0.5); } return line.DefaultLineTransform; } } }
- Collapse empty lines.
namespace Microsoft.VisualStudio.Text.Formatting { public partial class LineTransformSource { public LineTransform GetLineTransform(ITextViewLine line) { if (string.IsNullOrWhiteSpace(line.Extent.GetText())) return new LineTransform(0.001); else return line.DefaultLineTransform; } } }
- Comment’li olan satirlari hide et.
namespace Microsoft.VisualStudio.Text.Formatting { public partial class LineTransformSource { public LineTransform GetLineTransform(ITextViewLine line) { if (System.Text.RegularExpressions.Regex.IsMatch(line.Extent.GetText(), @"\s*//")) return new LineTransform(0.001); else return line.DefaultLineTransform; } } }
- Selection olan satirlari 1.61 (golden ratio) scale et.
- Caret’in oldugu line’i 1.61 (golden ratio) scale et.
- Satirlarin en sagina line number ekle, ama her number ayni hizada olsun.
- Ilk satirdan once copyright goster.
- Son satirdan sonra file istatistiklerini goster.
Leave a comment