提交 6082fa80 编写于 作者: J Jakub Majocha 提交者: Kevin Ransom (msft)

Style QuickInfo links in XAML (#2883)

* quickinfo styles in xaml

* refactor

* reduce diff
上级 4fcfb8b6
namespace Microsoft.VisualStudio.FSharp.Editor
open System.ComponentModel.Composition
open System
open System.Windows
open System.Windows.Controls
open System.Windows.Data
open System.Windows.Media
open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.Classification
......@@ -35,44 +34,19 @@ module private SessionHandling =
member __.AugmentQuickInfoSession(session,_,_) = currentSession <- Some session
member __.Dispose() = () }
module private SourceLink =
let solid = 70uy, DashStyles.Solid
let dot = 255uy, DashStyle([1.0; 5.0], 0.0)
let dash = 90uy, DashStyle([5.0; 5.0], 0.0)
let none = 0uy, DashStyles.Solid
let opacityCoverter =
{ new IValueConverter with
member this.Convert(value, _, parameter, _) =
match value with
| :? Color as c -> Color.FromArgb(unbox parameter, c.R, c.G, c.B) :> _
| _ -> Binding.DoNothing
member this.ConvertBack(_,_,_,_) = Binding.DoNothing }
let getUnderlineStyle() =
if not Settings.QuickInfo.DisplayLinks then none
else
match Settings.QuickInfo.UnderlineStyle with
| QuickInfoUnderlineStyle.Solid -> solid
| QuickInfoUnderlineStyle.Dot -> dot
| QuickInfoUnderlineStyle.Dash -> dash
type internal SourceLink(run) as this =
inherit Documents.Hyperlink(run)
let opacity, dashStyle = SourceLink.getUnderlineStyle()
let underlineBrush = Media.SolidColorBrush()
do BindingOperations.SetBinding(underlineBrush, SolidColorBrush.ColorProperty, Binding("Foreground.Color", Source = this, Converter = SourceLink.opacityCoverter, ConverterParameter = opacity)) |> ignore
let normalUnderline = TextDecorationCollection [TextDecoration(Location = TextDecorationLocation.Underline, PenOffset = 1.0)]
let slightUnderline = TextDecorationCollection [TextDecoration(Location = TextDecorationLocation.Underline, PenOffset = 1.0, Pen = Pen(Brush = underlineBrush, DashStyle = dashStyle))]
do this.TextDecorations <- slightUnderline
override this.OnMouseEnter(e) =
base.OnMouseEnter(e)
this.TextDecorations <- normalUnderline
override this.OnMouseLeave(e) =
base.OnMouseLeave(e)
this.TextDecorations <- slightUnderline
module private HyperlinkStyles =
// TODO: move this one time initialization to a more suitable spot
do Application.ResourceAssembly <- typeof<Microsoft.VisualStudio.FSharp.UIResources.Strings>.Assembly
let private styles = ResourceDictionary(Source = Uri("HyperlinkStyles.xaml", UriKind.Relative))
let getCurrent() : Style =
let key =
if Settings.QuickInfo.DisplayLinks then
match Settings.QuickInfo.UnderlineStyle with
| QuickInfoUnderlineStyle.Solid -> "solid_underline"
| QuickInfoUnderlineStyle.Dot -> "dot_underline"
| QuickInfoUnderlineStyle.Dash -> "dash_underline"
else "no_underline"
downcast styles.[key]
[<Export>]
type internal QuickInfoViewProvider
......@@ -105,7 +79,7 @@ type internal QuickInfoViewProvider
let inl =
match taggedText with
| :? Layout.NavigableTaggedText as nav when navigation.IsTargetValid nav.Range ->
let h = SourceLink (run, ToolTip = nav.Range.FileName)
let h = Documents.Hyperlink(run, ToolTip = nav.Range.FileName)
h.Click.Add <| navigateAndDismiss nav.Range
h :> Documents.Inline
| _ -> run :> _
......@@ -118,6 +92,7 @@ type internal QuickInfoViewProvider
DependencyObjectExtensions.SetDefaultTextProperties(tb, formatMap.Value)
tb.Inlines.AddRange inlines
if tb.Inlines.Count = 0 then tb.Visibility <- Visibility.Collapsed
tb.Resources.[typeof<Documents.Hyperlink>] <- HyperlinkStyles.getCurrent()
tb :> FrameworkElement
{ new IDeferredQuickInfoContent with member x.Create() = createTextLinks() }
......
......@@ -76,6 +76,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="HyperlinkStyles.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="IntelliSenseOptionControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
......
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<SolidColorBrush x:Key="inherited_brush" Color="{Binding Foreground.Color, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Hyperlink}}" />
<SolidColorBrush x:Key="inherited_semi_brush" Opacity="0.28" Color="{Binding Foreground.Color, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Hyperlink}}" />
<DashStyle x:Key="dash_dashstyle" Dashes="5 5"/>
<DashStyle x:Key="dot_dashstyle" Dashes="1 5"/>
<Pen x:Key="dot_pen" DashStyle="{StaticResource dot_dashstyle}" Brush="{StaticResource inherited_brush}"/>
<Pen x:Key="solid_pen" Brush="{StaticResource inherited_semi_brush}"/>
<Pen x:Key="mouseover_pen" Brush="{StaticResource inherited_brush}"/>
<Pen x:Key="dash_pen" DashStyle="{StaticResource dash_dashstyle}" Brush="{StaticResource inherited_semi_brush}"/>
<TextDecorationCollection x:Key="solid_deco">
<TextDecoration PenOffset="1" Pen="{StaticResource solid_pen}"/>
</TextDecorationCollection>
<TextDecorationCollection x:Key="dash_deco">
<TextDecoration PenOffset="1" Pen="{StaticResource dash_pen}"/>
</TextDecorationCollection>
<TextDecorationCollection x:Key="dot_deco">
<TextDecoration PenOffset="1" Pen="{StaticResource dot_pen}"/>
</TextDecorationCollection>
<TextDecorationCollection x:Key="full_deco">
<TextDecoration PenOffset="1" Pen="{StaticResource mouseover_pen}" />
</TextDecorationCollection>
<Style x:Key="base_sourcelink" TargetType="Hyperlink" >
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="TextDecorations" Value="{StaticResource full_deco}"/>
</Trigger>
</Style.Triggers>
</Style>
<Style x:Key="solid_underline" TargetType="Hyperlink" BasedOn="{StaticResource base_sourcelink}">
<Setter Property="TextDecorations" Value="{StaticResource solid_deco}"/>
</Style>
<Style x:Key="dash_underline" TargetType="Hyperlink" BasedOn="{StaticResource base_sourcelink}">
<Setter Property="TextDecorations" Value="{StaticResource dash_deco}"/>
</Style>
<Style x:Key="dot_underline" TargetType="Hyperlink" BasedOn="{StaticResource base_sourcelink}">
<Setter Property="TextDecorations" Value="{StaticResource dot_deco}"/>
</Style>
<Style x:Key="no_underline" TargetType="Hyperlink" BasedOn="{StaticResource base_sourcelink}">
<Setter Property="TextDecorations" Value="{x:Null}"/>
</Style>
</ResourceDictionary>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册