Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/EditorFeatures/Core.Wpf/CodeAnalysisColors.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:me="clr-namespace:Microsoft.CodeAnalysis.Editor"
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
xmlns:imagecatalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
xmlns:rename="clr-namespace:Microsoft.CodeAnalysis.Editor.Implementation.InlineRename"
xmlns:utilities="clr-namespace:Microsoft.CodeAnalysis.Editor.Shared.Utilities"
x:ClassModifier="internal"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
MinWidth="300"
Expand All @@ -26,15 +24,15 @@
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Colors.xaml"/>
<ResourceDictionary Source="DashboardColors.xaml"/>
</ResourceDictionary.MergedDictionaries>

<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

<SolidColorBrush x:Key="ForegroundText" Color="{DynamicResource {x:Static utilities:CodeAnalysisColors.SystemCaptionTextColorKey}}"/>
<SolidColorBrush x:Key="ForegroundText" Color="{DynamicResource {x:Static rename:DashboardColors.SystemCaptionTextColorKey}}"/>

<Style TargetType="CheckBox">
<Setter Property="Foreground" Value="{DynamicResource {x:Static utilities:CodeAnalysisColors.CheckBoxTextBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static rename:DashboardColors.CheckBoxTextBrushKey}}"/>
</Style>

<Style TargetType="TextBlock">
Expand All @@ -58,7 +56,7 @@
</Grid.RowDefinitions>

<Border Grid.Row="0" BorderBrush="Transparent"
Background="{DynamicResource {x:Static utilities:CodeAnalysisColors.BackgroundBrushKey}}"
Background="{DynamicResource {x:Static rename:DashboardColors.BackgroundBrushKey}}"
BorderThickness="0"
Padding="7">
<StackPanel>
Expand Down Expand Up @@ -246,12 +244,12 @@

<Button Name="ApplyButton" Click="Apply_Click" IsDefault="True" MinWidth="75" MinHeight="23" Padding="10,1,10,1" Margin="0,8,0,0" HorizontalAlignment="Right"
ToolTip="{Binding ElementName=dashboard, Path=ApplyToolTip}"
Style="{DynamicResource {x:Static utilities:CodeAnalysisColors.ButtonStyleKey}}"
Style="{DynamicResource {x:Static rename:DashboardColors.ButtonStyleKey}}"
Content="{Binding ElementName=dashboard, Path=ApplyRename}"
AutomationProperties.Name="{Binding ElementName=dashboard, Path=ApplyRename}"/>
</StackPanel>
</Border>

<Rectangle Name="DashboardAccentBar" Grid.Row="1" Height="4" Fill="{DynamicResource {x:Static utilities:CodeAnalysisColors.AccentBarColorKey}}" />
<Rectangle Name="DashboardAccentBar" Grid.Row="1" Height="4" Fill="{DynamicResource {x:Static rename:DashboardColors.AccentBarColorKey}}" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Linq;
using System.Runtime.CompilerServices;
Expand All @@ -19,6 +17,8 @@ internal class DashboardAdornmentManager : IDisposable
private readonly IWpfTextView _textView;
private readonly InlineRenameService _renameService;
private readonly IEditorFormatMapService _editorFormatMapService;
private readonly IDashboardColorUpdater? _dashboardColorUpdater;

private readonly IAdornmentLayer _adornmentLayer;

private static readonly ConditionalWeakTable<InlineRenameSession, DashboardViewModel> s_createdViewModels =
Expand All @@ -27,10 +27,12 @@ internal class DashboardAdornmentManager : IDisposable
public DashboardAdornmentManager(
InlineRenameService renameService,
IEditorFormatMapService editorFormatMapService,
IDashboardColorUpdater? dashboardColorUpdater,
IWpfTextView textView)
{
_renameService = renameService;
_editorFormatMapService = editorFormatMapService;
_dashboardColorUpdater = dashboardColorUpdater;
_textView = textView;

_adornmentLayer = textView.GetAdornmentLayer(DashboardAdornmentProvider.AdornmentLayerName);
Expand Down Expand Up @@ -60,6 +62,8 @@ private void UpdateAdornments()
if (_renameService.ActiveSession != null &&
ViewIncludesBufferFromWorkspace(_textView, _renameService.ActiveSession.Workspace))
{
_dashboardColorUpdater?.UpdateColors();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with theme updates after opening?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, since the thing we're passing around here is the keys, not the colors/brushes themselves. Turns out that's what makes the other approaches difficult -- it's not just the values that are dynamic, but the keys themselves.

var newAdornment = new Dashboard(
s_createdViewModels.GetValue(_renameService.ActiveSession, session => new DashboardViewModel(session)),
_editorFormatMapService,
Expand All @@ -75,7 +79,7 @@ private static bool ViewIncludesBufferFromWorkspace(IWpfTextView textView, Works
.Any();
}

private static Workspace GetWorkspace(SourceTextContainer textContainer)
private static Workspace? GetWorkspace(SourceTextContainer textContainer)
{
Workspace.TryGetWorkspace(textContainer, out var workspace);
return workspace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable disable

using System;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
Expand All @@ -25,6 +23,8 @@ internal class DashboardAdornmentProvider : IWpfTextViewConnectionListener
{
private readonly InlineRenameService _renameService;
private readonly IEditorFormatMapService _editorFormatMapService;
private readonly IDashboardColorUpdater? _dashboardColorUpdater;

public const string AdornmentLayerName = "RoslynRenameDashboard";

[Export]
Expand All @@ -36,22 +36,24 @@ internal class DashboardAdornmentProvider : IWpfTextViewConnectionListener
[Order(After = PredefinedAdornmentLayers.TextMarker)]
[Order(After = PredefinedAdornmentLayers.CurrentLineHighlighter)]
[Order(After = PredefinedAdornmentLayers.Squiggle)]
internal readonly AdornmentLayerDefinition AdornmentLayer;
internal readonly AdornmentLayerDefinition? AdornmentLayer;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public DashboardAdornmentProvider(
InlineRenameService renameService,
IEditorFormatMapService editorFormatMapService)
IEditorFormatMapService editorFormatMapService,
[Import(AllowDefault = true)] IDashboardColorUpdater? dashboardColorUpdater)
{
_renameService = renameService;
_editorFormatMapService = editorFormatMapService;
_dashboardColorUpdater = dashboardColorUpdater;
}

public void SubjectBuffersConnected(IWpfTextView textView, ConnectionReason reason, Collection<ITextBuffer> subjectBuffers)
{
// Create it for the view if we don't already have one
textView.GetOrCreateAutoClosingProperty(v => new DashboardAdornmentManager(_renameService, _editorFormatMapService, v));
textView.GetOrCreateAutoClosingProperty(v => new DashboardAdornmentManager(_renameService, _editorFormatMapService, _dashboardColorUpdater, v));
}

public void SubjectBuffersDisconnected(IWpfTextView textView, ConnectionReason reason, Collection<ITextBuffer> subjectBuffers)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
{
internal static class DashboardColors
{
// In the Dashboard XAML, we bind to these keys to provide the correct color resources.
// The default values of these fields match the names of the keys in DashboardColors.xaml,
// but in Visual Studio we will change these keys (since they are settable) to the keys for
// the actual Visual Studio resource keys.
//
// Each entry here should have a corresponding entry in DashboardColors.xaml to specify the
// default color.

public static object SystemCaptionTextColorKey { get; set; } = "SystemCaptionTextColor";
public static object SystemCaptionTextBrushKey { get; set; } = "SystemCaptionTextBrush";
public static object CheckBoxTextBrushKey { get; set; } = "CheckBoxTextBrush";
public static object BackgroundBrushKey { get; set; } = "BackgroundBrush";
public static object AccentBarColorKey { get; set; } = "AccentBarBrush";
public static object ButtonStyleKey { get; set; } = "ButtonStyle";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<!-- These resources provide the default colors for the dashboard if we're not hosted
in a specific host that will override them, like Visual Studio. Each resource here
corresponds to an entry in DashboardColors.cs, where it can be overwritten by a host. -->

<Color x:Key="SystemCaptionTextColor">Black</Color>
<SolidColorBrush x:Key="SystemCaptionTextBrush" Color="Black"/>
<SolidColorBrush x:Key="CheckBoxTextBrush" Color="Black"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
{
internal interface IDashboardColorUpdater
{
/// <summary>
/// Implemented by a host to set the properties on <see cref="DashboardColors"/>.
/// </summary>
public void UpdateColors();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
<PackageReference Include="Microsoft.VisualStudio.Imaging" Version="$(MicrosoftVisualStudioImagingVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" Version="$(MicrosoftVisualStudioImagingInterop140DesignTimeVersion)" />
<PackageReference Include="Microsoft.VisualStudio.InteractiveWindow" Version="$(MicrosoftVisualStudioInteractiveWindowVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Interop" Version="$(MicrosoftVisualStudioInteropVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Language.NavigateTo.Interfaces" Version="$(MicrosoftVisualStudioLanguageNavigateToInterfacesVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Language.StandardClassification" Version="$(MicrosoftVisualStudioLanguageStandardClassificationVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Language.Intellisense" Version="$(MicrosoftVisualStudioLanguageIntellisenseVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="$(MicrosoftVisualStudioShell150Version)" />
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="$(MicrosoftVisualStudioTextUIWpfVersion)" />
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="$(MicrosoftVisualStudioThreadingVersion)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Implementation.InlineRename;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.PlatformUI;
using Microsoft.VisualStudio.Shell;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.InlineRename
{
[Export(typeof(IDashboardColorUpdater))]
internal class DashboardColorUpdater : IDashboardColorUpdater
{
[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public DashboardColorUpdater()
{
}

public void UpdateColors()
{
DashboardColors.SystemCaptionTextColorKey = EnvironmentColors.SystemWindowTextColorKey;
DashboardColors.SystemCaptionTextBrushKey = EnvironmentColors.SystemWindowTextBrushKey;
DashboardColors.CheckBoxTextBrushKey = EnvironmentColors.SystemWindowTextBrushKey;
DashboardColors.BackgroundBrushKey = VsBrushes.CommandBarGradientBeginKey;
DashboardColors.AccentBarColorKey = EnvironmentColors.FileTabInactiveDocumentBorderEdgeBrushKey;
DashboardColors.ButtonStyleKey = VsResourceKeys.ButtonStyleKey;
}
}
}