diff options
Diffstat (limited to 'src')
7 files changed, 407 insertions, 7 deletions
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. /// </summary> public IEnumerable<ClassifiedTextRun> Runs { get; } + + /// <summary> + /// Creates a new element with a hyperlink. + /// </summary> + /// <param name="text">The text rendered by this run.</param> + /// <param name="tooltip">The tooltip for the hyperlink.</param> + /// <param name="navigationAction">The action to execute on navigation.</param> + /// <returns><see cref="ClassifiedTextElement"/> containing the hyperlink.</returns> + 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. /// </remarks> public ClassifiedTextRun(string classificationTypeName, string text) + : this(classificationTypeName, text, ClassifiedTextRunStyle.Plain) + { + } + + /// <summary> + /// Creates a new run of classified text. + /// </summary> + /// <param name="classificationTypeName"> + /// A name indicating a <see cref="IClassificationType"/> that maps to a format that will be applied to the text. + /// </param> + /// <param name="text">The text rendered by this run.</param> + /// <param name="style">The style that will be applied to the text.</param> + /// <remarks> + /// Classification types can be platform specific. Only classifications defined in PredefinedClassificationTypeNames + /// are supported cross platform. + /// </remarks> + 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; + } + + /// <summary> + /// Creates a new run of classified text. + /// </summary> + /// <param name="classificationTypeName"> + /// A name indicating a <see cref="IClassificationType"/> that maps to a format that will be applied to the text. + /// </param> + /// <param name="text">The text rendered by this run.</param> + /// <param name="style">The style that will be applied to the text.</param> + /// <remarks> + /// Classification types can be platform specific. Only classifications defined in PredefinedClassificationTypeNames + /// are supported cross platform. + /// </remarks> + 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; } /// <summary> @@ -41,5 +87,20 @@ /// The text that will be formatted by <see cref="ClassificationTypeName"/>'s corresponding formatting. /// </summary> public string Text { get; } + + /// <summary> + /// The style that will be applied to the text. + /// </summary> + public ClassifiedTextRunStyle Style { get; } + + /// <summary> + /// The text that will be displayed on the hyperlink tooltip. + /// </summary> + public string Tooltip { get; } = null; + + /// <summary> + /// The navigation action for the hyperlink. + /// </summary> + 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 + /// <summary> + /// The text style for a <see cref="ClassifiedTextRun"/>. + /// </summary> + [Flags] + public enum ClassifiedTextRunStyle +#pragma warning restore CA1714 // Flags enums should have plural names + { + /// <summary> + /// Plain text. + /// </summary> + Plain = 0b_0000, + + /// <summary> + /// Bolded text. + /// </summary> + Bold = 0b_0001, + + /// <summary> + /// Italic text. + /// </summary> + Italic = 0b_0010, + + /// <summary> + /// Underlined text. + /// </summary> + Underline = 0b_0100, + + /// <summary> + /// Use the font specified by the classification. + /// </summary> + 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 @@ -471,6 +471,18 @@ namespace Microsoft.VisualStudio.Text.Editor public const string ZoomLevelName = "TextView/ZoomLevel"; /// <summary> + /// Determines the minimum view zoom level. + /// </summary> + public static readonly EditorOptionKey<double> MinZoomLevelId = new EditorOptionKey<double>(MinZoomLevelName); + public const string MinZoomLevelName = "TextView/MinZoomLevel"; + + /// <summary> + /// Determines the maximum view zoom level. + /// </summary> + public static readonly EditorOptionKey<double> MaxZoomLevelId = new EditorOptionKey<double>(MaxZoomLevelName); + public const string MaxZoomLevelName = "TextView/MaxZoomLevel"; + + /// <summary> /// Determines whether to enable mouse click + modifier keypress for go to definition. /// </summary> public const string ClickGoToDefEnabledName = "TextView/ClickGoToDefEnabled"; @@ -1274,6 +1286,42 @@ namespace Microsoft.VisualStudio.Text.Editor } /// <summary> + /// Defines the minimum zoomlevel. + /// </summary> + [Export(typeof(EditorOptionDefinition))] + [Name(DefaultTextViewOptions.MinZoomLevelName)] + public sealed class MinZoomLevel : EditorOptionDefinition<double> + { + /// <summary> + /// Gets the default value. + /// </summary> + public override double Default => ZoomConstants.MinZoom; + + /// <summary> + /// Gets the key for the text view zoom level. + /// </summary> + public override EditorOptionKey<double> Key => DefaultTextViewOptions.MinZoomLevelId; + } + + /// <summary> + /// Defines the maximum zoomlevel. + /// </summary> + [Export(typeof(EditorOptionDefinition))] + [Name(DefaultTextViewOptions.MaxZoomLevelName)] + public sealed class MaxZoomLevel : EditorOptionDefinition<double> + { + /// <summary> + /// Gets the default value. + /// </summary> + public override double Default => ZoomConstants.MaxZoom; + + /// <summary> + /// Gets the key for the text view zoom level. + /// </summary> + public override EditorOptionKey<double> Key => DefaultTextViewOptions.MaxZoomLevelId; + } + + /// <summary> /// Determines whether to enable mouse click + modifier keypress for go to definition. /// </summary> [Export(typeof(EditorOptionDefinition))] 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<double>(DefaultTextViewOptions.ZoomLevelId); } + + /// <summary> + /// Specifies the minimum allowed zoomlevel + /// </summary> + /// <param name="options">The <see cref="IEditorOptions"/>.</param> + public static double MinZoom(this IEditorOptions options) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + return options.GetOptionValue(DefaultTextViewOptions.MinZoomLevelId); + } + + /// <summary> + /// Specifies the maximum allowed zoomlevel + /// </summary> + /// <param name="options">The <see cref="IEditorOptions"/>.</param> + public static double MaxZoom(this IEditorOptions options) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + return options.GetOptionValue(DefaultTextViewOptions.MaxZoomLevelId); + } + + /// <summary> + /// Set the persisted zoomlevel. + /// </summary> + /// <param name="options">The <see cref="IEditorOptions"/>.</param> + /// <param name="zoomLevel">The new zoom level. This value will be + /// clamped to fit between <see cref="MinZoom"/> + /// and <see cref="MaxZoom"/></param> + 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))); + } + + /// <summary> + /// Set the minimum zoomlevel. + /// </summary> + /// <param name="options">The <see cref="IEditorOptions"/>.</param> + /// <param name="minZoomLevel">The new minimum zoom level.</param> + public static void SetMinZoomLevel(this IEditorOptions options, double minZoomLevel) + { + if (options == null) + throw new ArgumentNullException(nameof(options)); + + options.SetOptionValue( + DefaultTextViewOptions.MinZoomLevelId, + minZoomLevel); + } + + /// <summary> + /// Set the maximum zoomlevel. + /// </summary> + /// <param name="options">The <see cref="IEditorOptions"/>.</param> + /// <param name="maxZoomLevel">The new maximum zoom level.</param> + 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); } } diff --git a/src/FPF/WindowsBase/System.ComponentModel/DependencyPropertyDescriptor.cs b/src/FPF/WindowsBase/System.ComponentModel/DependencyPropertyDescriptor.cs new file mode 100644 index 0000000..2a0f5cc --- /dev/null +++ b/src/FPF/WindowsBase/System.ComponentModel/DependencyPropertyDescriptor.cs @@ -0,0 +1,165 @@ +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Copyright (c) 2008 Novell, Inc. (http://www.novell.com) +// +// Authors: +// Chris Toshok (toshok@ximian.com) +// + +using System; +using System.Windows; + +namespace System.ComponentModel { + + public sealed class DependencyPropertyDescriptor : PropertyDescriptor { + internal DependencyPropertyDescriptor () : base (null) + { + } + + public override AttributeCollection Attributes + { + get { throw new NotImplementedException (); } + } + public override string Category + { + get { throw new NotImplementedException (); } + } + public override Type ComponentType + { + get { throw new NotImplementedException (); } + } + public override TypeConverter Converter + { + get { throw new NotImplementedException (); } + } + public DependencyProperty DependencyProperty + { + get { throw new NotImplementedException (); } + } + public override string Description + { + get { throw new NotImplementedException (); } + } + public override bool DesignTimeOnly + { + get { throw new NotImplementedException (); } + } + public override string DisplayName + { + get { throw new NotImplementedException (); } + } + public bool IsAttached + { + get { throw new NotImplementedException (); } + } + public override bool IsBrowsable + { + get { throw new NotImplementedException (); } + } + public override bool IsLocalizable + { + get { throw new NotImplementedException (); } + } + public override bool IsReadOnly + { + get { throw new NotImplementedException (); } + } + public PropertyMetadata Metadata + { + get { throw new NotImplementedException (); } + } + public override Type PropertyType + { + get { throw new NotImplementedException (); } + } + public override bool SupportsChangeEvents + { + get { throw new NotImplementedException (); } + } + + public override void AddValueChanged (object component, EventHandler handler) + { + throw new NotImplementedException (); + } + public override bool CanResetValue (object component) + { + throw new NotImplementedException (); + } + public override bool Equals (object obj) + { + throw new NotImplementedException (); + } + public override PropertyDescriptorCollection GetChildProperties (object instance, Attribute[] filter) + { + throw new NotImplementedException (); + } + public override object GetEditor (Type editorBaseType) + { + throw new NotImplementedException (); + } + public override int GetHashCode () + { + throw new NotImplementedException (); + } + public override object GetValue (object component) + { + throw new NotImplementedException (); + } + public override void RemoveValueChanged (object component, EventHandler handler) + { + throw new NotImplementedException (); + } + public override void ResetValue (object component) + { + throw new NotImplementedException (); + } + public override void SetValue (object component, object value) + { + throw new NotImplementedException (); + } + public override bool ShouldSerializeValue (object component) + { + throw new NotImplementedException (); + } + public override string ToString () + { + throw new NotImplementedException (); + } + + public static DependencyPropertyDescriptor FromName (string name, Type ownerType, Type targetType) + { + throw new NotImplementedException (); + } + public static DependencyPropertyDescriptor FromProperty (PropertyDescriptor property) + { + throw new NotImplementedException (); + } + public static DependencyPropertyDescriptor FromProperty (DependencyProperty dependencyProperty, Type targetType) + { + throw new NotImplementedException (); + } + + public CoerceValueCallback DesignerCoerceValueCallback { + get { throw new NotImplementedException (); } + set { throw new NotImplementedException (); } + } + } + +} |