From dcca642652154312f3525ba1cb826597ac0a7fb2 Mon Sep 17 00:00:00 2001 From: Aaron Bockover Date: Tue, 2 Apr 2019 16:39:18 -0400 Subject: Sync with vs-editor-core@ca2b3268 --- .../ViewElementFactories/ClassifiedTextElement.cs | 14 +++++ .../ViewElementFactories/ClassifiedTextRun.cs | 61 ++++++++++++++++++ .../ViewElementFactories/ClassifiedTextRunStyle.cs | 38 ++++++++++++ .../Text/Def/TextUI/EditorOptions/ViewOptions.cs | 48 +++++++++++++++ .../Def/TextUIWpf/EditorOptions/WpfViewOptions.cs | 72 ++++++++++++++++++++++ .../Text/Impl/EditorOperations/EditorOperations.cs | 16 ++--- 6 files changed, 242 insertions(+), 7 deletions(-) create mode 100644 src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextRunStyle.cs (limited to 'src/Editor/Text') diff --git a/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextElement.cs b/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextElement.cs index f003e81..a75a46a 100644 --- a/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextElement.cs +++ b/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextElement.cs @@ -37,5 +37,19 @@ /// A sequence of classified runs of text. /// public IEnumerable Runs { get; } + + /// + /// Creates a new element with a hyperlink. + /// + /// The text rendered by this run. + /// The tooltip for the hyperlink. + /// The action to execute on navigation. + /// containing the hyperlink. + public static ClassifiedTextElement CreateHyperlink(string text, string tooltip, Action navigationAction) + { + Requires.NotNull(text, nameof(text)); + Requires.NotNull(navigationAction, nameof(navigationAction)); + return new ClassifiedTextElement(new ClassifiedTextRun("url", text, navigationAction, tooltip)); + } } } diff --git a/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextRun.cs b/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextRun.cs index 11f10db..caaeab2 100644 --- a/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextRun.cs +++ b/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextRun.cs @@ -26,10 +26,56 @@ /// are supported cross platform. /// public ClassifiedTextRun(string classificationTypeName, string text) + : this(classificationTypeName, text, ClassifiedTextRunStyle.Plain) + { + } + + /// + /// Creates a new run of classified text. + /// + /// + /// A name indicating a that maps to a format that will be applied to the text. + /// + /// The text rendered by this run. + /// The style that will be applied to the text. + /// + /// Classification types can be platform specific. Only classifications defined in PredefinedClassificationTypeNames + /// are supported cross platform. + /// + public ClassifiedTextRun(string classificationTypeName, string text, ClassifiedTextRunStyle style) { this.ClassificationTypeName = classificationTypeName ?? throw new ArgumentNullException(nameof(classificationTypeName)); this.Text = text ?? throw new ArgumentNullException(nameof(text)); + this.Style = style; + } + + /// + /// Creates a new run of classified text. + /// + /// + /// A name indicating a that maps to a format that will be applied to the text. + /// + /// The text rendered by this run. + /// The style that will be applied to the text. + /// + /// Classification types can be platform specific. Only classifications defined in PredefinedClassificationTypeNames + /// are supported cross platform. + /// + public ClassifiedTextRun( + string classificationTypeName, + string text, + Action navigationAction, + string tooltip = null, + ClassifiedTextRunStyle style = ClassifiedTextRunStyle.Plain) + { + this.ClassificationTypeName = classificationTypeName + ?? throw new ArgumentNullException(nameof(classificationTypeName)); + this.Text = text ?? throw new ArgumentNullException(nameof(text)); + this.Style = style; + + this.NavigationAction = navigationAction ?? throw new ArgumentNullException(nameof(navigationAction)); + this.Tooltip = tooltip; } /// @@ -41,5 +87,20 @@ /// The text that will be formatted by 's corresponding formatting. /// public string Text { get; } + + /// + /// The style that will be applied to the text. + /// + public ClassifiedTextRunStyle Style { get; } + + /// + /// The text that will be displayed on the hyperlink tooltip. + /// + public string Tooltip { get; } = null; + + /// + /// The navigation action for the hyperlink. + /// + public Action NavigationAction { get; } = null; } } diff --git a/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextRunStyle.cs b/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextRunStyle.cs new file mode 100644 index 0000000..80b0168 --- /dev/null +++ b/src/Editor/Text/Def/TextUI/Adornments/ToolTipService/ViewElementFactories/ClassifiedTextRunStyle.cs @@ -0,0 +1,38 @@ +namespace Microsoft.VisualStudio.Text.Adornments +{ + using System; + +#pragma warning disable CA1714 // Flags enums should have plural names + /// + /// The text style for a . + /// + [Flags] + public enum ClassifiedTextRunStyle +#pragma warning restore CA1714 // Flags enums should have plural names + { + /// + /// Plain text. + /// + Plain = 0b_0000, + + /// + /// Bolded text. + /// + Bold = 0b_0001, + + /// + /// Italic text. + /// + Italic = 0b_0010, + + /// + /// Underlined text. + /// + Underline = 0b_0100, + + /// + /// Use the font specified by the classification. + /// + UseClassificationFont = 0b_1000, + } +} diff --git a/src/Editor/Text/Def/TextUI/EditorOptions/ViewOptions.cs b/src/Editor/Text/Def/TextUI/EditorOptions/ViewOptions.cs index b121e18..38457c4 100644 --- a/src/Editor/Text/Def/TextUI/EditorOptions/ViewOptions.cs +++ b/src/Editor/Text/Def/TextUI/EditorOptions/ViewOptions.cs @@ -470,6 +470,18 @@ namespace Microsoft.VisualStudio.Text.Editor public static readonly EditorOptionKey ZoomLevelId = new EditorOptionKey(ZoomLevelName); public const string ZoomLevelName = "TextView/ZoomLevel"; + /// + /// Determines the minimum view zoom level. + /// + public static readonly EditorOptionKey MinZoomLevelId = new EditorOptionKey(MinZoomLevelName); + public const string MinZoomLevelName = "TextView/MinZoomLevel"; + + /// + /// Determines the maximum view zoom level. + /// + public static readonly EditorOptionKey MaxZoomLevelId = new EditorOptionKey(MaxZoomLevelName); + public const string MaxZoomLevelName = "TextView/MaxZoomLevel"; + /// /// Determines whether to enable mouse click + modifier keypress for go to definition. /// @@ -1273,6 +1285,42 @@ namespace Microsoft.VisualStudio.Text.Editor public override EditorOptionKey Key { get { return DefaultTextViewOptions.ZoomLevelId; } } } + /// + /// Defines the minimum zoomlevel. + /// + [Export(typeof(EditorOptionDefinition))] + [Name(DefaultTextViewOptions.MinZoomLevelName)] + public sealed class MinZoomLevel : EditorOptionDefinition + { + /// + /// Gets the default value. + /// + public override double Default => ZoomConstants.MinZoom; + + /// + /// Gets the key for the text view zoom level. + /// + public override EditorOptionKey Key => DefaultTextViewOptions.MinZoomLevelId; + } + + /// + /// Defines the maximum zoomlevel. + /// + [Export(typeof(EditorOptionDefinition))] + [Name(DefaultTextViewOptions.MaxZoomLevelName)] + public sealed class MaxZoomLevel : EditorOptionDefinition + { + /// + /// Gets the default value. + /// + public override double Default => ZoomConstants.MaxZoom; + + /// + /// Gets the key for the text view zoom level. + /// + public override EditorOptionKey Key => DefaultTextViewOptions.MaxZoomLevelId; + } + /// /// Determines whether to enable mouse click + modifier keypress for go to definition. /// diff --git a/src/Editor/Text/Def/TextUIWpf/EditorOptions/WpfViewOptions.cs b/src/Editor/Text/Def/TextUIWpf/EditorOptions/WpfViewOptions.cs index d5ca1c2..8dd2049 100644 --- a/src/Editor/Text/Def/TextUIWpf/EditorOptions/WpfViewOptions.cs +++ b/src/Editor/Text/Def/TextUIWpf/EditorOptions/WpfViewOptions.cs @@ -81,6 +81,78 @@ namespace Microsoft.VisualStudio.Text.Editor.OptionsExtensionMethods return options.GetOptionValue(DefaultTextViewOptions.ZoomLevelId); } + + /// + /// Specifies the minimum allowed zoomlevel + /// + /// The . + public static double MinZoom(this IEditorOptions options) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + return options.GetOptionValue(DefaultTextViewOptions.MinZoomLevelId); + } + + /// + /// Specifies the maximum allowed zoomlevel + /// + /// The . + public static double MaxZoom(this IEditorOptions options) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + return options.GetOptionValue(DefaultTextViewOptions.MaxZoomLevelId); + } + + /// + /// Set the persisted zoomlevel. + /// + /// The . + /// The new zoom level. This value will be + /// clamped to fit between + /// and + public static void SetZoomLevel(this IEditorOptions options, double zoomLevel) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + options.SetOptionValue( + DefaultTextViewOptions.ZoomLevelId, + Math.Min(options.MaxZoom(), Math.Max(options.MinZoom(), zoomLevel))); + } + + /// + /// Set the minimum zoomlevel. + /// + /// The . + /// The new minimum zoom level. + public static void SetMinZoomLevel(this IEditorOptions options, double minZoomLevel) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + options.SetOptionValue( + DefaultTextViewOptions.MinZoomLevelId, + minZoomLevel); + } + + /// + /// Set the maximum zoomlevel. + /// + /// The . + /// The new maximum zoom level. + public static void SetMaxZoomLevel(this IEditorOptions options, double maxZoomLevel) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + options.SetOptionValue( + DefaultTextViewOptions.MaxZoomLevelId, + maxZoomLevel); + } + #endregion } } diff --git a/src/Editor/Text/Impl/EditorOperations/EditorOperations.cs b/src/Editor/Text/Impl/EditorOperations/EditorOperations.cs index ec55c3b..7c01a8e 100644 --- a/src/Editor/Text/Impl/EditorOperations/EditorOperations.cs +++ b/src/Editor/Text/Impl/EditorOperations/EditorOperations.cs @@ -3228,28 +3228,30 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation _undoHistory.CurrentTransaction.AddUndo(beforeTextBufferChangeUndoPrimitive); } - public bool CanZoomIn => CanZoomTo && _textView.ZoomLevel < ZoomConstants.MaxZoom; + public bool CanZoomIn => CanZoomTo && _textView.ZoomLevel < _textView.Options.GlobalOptions.MaxZoom(); public void ZoomIn() { if (CanZoomIn) { - double zoomLevel = Math.Min(_textView.ZoomLevel * ZoomConstants.ScalingFactor, ZoomConstants.MaxZoom); - if (zoomLevel < ZoomConstants.MaxZoom || Math.Abs(zoomLevel - ZoomConstants.MaxZoom) < 0.00001) + var maxZoom = _textView.Options.GlobalOptions.MaxZoom(); + double zoomLevel = Math.Min(_textView.ZoomLevel * ZoomConstants.ScalingFactor, maxZoom); + if (zoomLevel < maxZoom || Math.Abs(zoomLevel - maxZoom) < 0.00001) { _textView.Options.GlobalOptions.SetOptionValue(DefaultTextViewOptions.ZoomLevelId, zoomLevel); } } } - public bool CanZoomOut => CanZoomTo && _textView.ZoomLevel > ZoomConstants.MinZoom; + public bool CanZoomOut => CanZoomTo && _textView.ZoomLevel > _textView.Options.GlobalOptions.MinZoom(); public void ZoomOut() { if (CanZoomOut) { - double zoomLevel = Math.Max(_textView.ZoomLevel / ZoomConstants.ScalingFactor, ZoomConstants.MinZoom); - if (zoomLevel > ZoomConstants.MinZoom || Math.Abs(zoomLevel - ZoomConstants.MinZoom) < 0.00001) + var minZoom = _textView.Options.GlobalOptions.MinZoom(); + double zoomLevel = Math.Max(_textView.ZoomLevel / ZoomConstants.ScalingFactor, minZoom); + if (zoomLevel > minZoom || Math.Abs(zoomLevel - minZoom) < 0.00001) { _textView.Options.GlobalOptions.SetOptionValue(DefaultTextViewOptions.ZoomLevelId, zoomLevel); } @@ -3262,7 +3264,7 @@ namespace Microsoft.VisualStudio.Text.Operations.Implementation { if (CanZoomTo) { - _textView.Options.GlobalOptions.SetOptionValue(DefaultTextViewOptions.ZoomLevelId, zoomLevel); + _textView.Options.GlobalOptions.SetZoomLevel(zoomLevel); } } -- cgit v1.2.3