/* Copyright (C) 2014-2019 de4dot@gmail.com This file is part of dnSpy dnSpy is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. dnSpy is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with dnSpy. If not, see . */ using System; using Microsoft.VisualStudio.Text; using Microsoft.VisualStudio.Text.Classification; using Microsoft.VisualStudio.Text.Editor; using Microsoft.VisualStudio.Text.Formatting; namespace dnSpy.Contracts.Text.Editor { /// /// Custom line number margin. The must have the /// role and /// you must call . /// Option is used /// to show or hide it after creation. /// public static class CustomLineNumberMargin { static readonly object Key = new object(); /// /// Gets the custom line number margin /// /// Text view /// static ICustomLineNumberMargin GetMargin(ITextView textView) { if (textView is null) throw new ArgumentNullException(nameof(textView)); if (!textView.Properties.TryGetProperty(Key, out ICustomLineNumberMargin margin)) throw new InvalidOperationException("No custom line number margin was found"); return margin; } /// /// Sets the owner and must only be called once /// /// Text view /// Owner public static void SetOwner(ITextView textView, ICustomLineNumberMarginOwner owner) { if (textView is null) throw new ArgumentNullException(nameof(textView)); if (owner is null) throw new ArgumentNullException(nameof(owner)); GetMargin(textView).SetOwner(owner); } internal static void SetMargin(ITextView textView, ICustomLineNumberMargin margin) { if (textView is null) throw new ArgumentNullException(nameof(textView)); if (margin is null) throw new ArgumentNullException(nameof(margin)); textView.Properties.AddProperty(Key, margin); } } /// /// Custom line number margin /// interface ICustomLineNumberMargin { /// /// Sets the owner and must only be called once /// /// Owner void SetOwner(ICustomLineNumberMarginOwner owner); } /// /// Custom line number margin owner /// public interface ICustomLineNumberMarginOwner { /// /// Gets maximum number of digits in a line number or null to use the default value /// /// int? GetMaxLineNumberDigits(); /// /// Gets the line number or null to not print any line number. You should normally return null if /// 's is false. /// /// View line /// Snapshot line /// State, initially null /// int? GetLineNumber(ITextViewLine viewLine, ITextSnapshotLine snapshotLine, ref object? state); /// /// Gets for the line number text /// /// View line /// Snapshot line /// Line number returned by /// State, initialized by /// TextFormattingRunProperties GetLineNumberTextFormattingRunProperties(ITextViewLine viewLine, ITextSnapshotLine snapshotLine, int lineNumber, object? state); /// /// Gets the default text formatting properties /// /// TextFormattingRunProperties? GetDefaultTextFormattingRunProperties(); /// /// Gets called when text formatting properties have changed /// /// Classification format map void OnTextPropertiesChanged(IClassificationFormatMap classificationFormatMap); /// /// Called when the margin is visible /// void OnVisible(); /// /// Called when the margin is hidden and when the margin gets disposed /// void OnInvisible(); } }