Skip to content

Commit 074fe49

Browse files
Don't reference VS Shell binaries in EditorFeatures.Wpf
EditorFeatures.Wpf is supposed to be independent of the VS Shell, the idea is this layer can be hosted in other applications using the VS editor but not VS itself. This re-adds indirection for fetching the dashboard colors, but now only does it when the dashboard is opened. While I was here I ended up renaming CodeAnalysisColors to DashboardColors which is a bit clearer what it is.
1 parent fd9a5f8 commit 074fe49

File tree

9 files changed

+93
-32
lines changed

9 files changed

+93
-32
lines changed

src/EditorFeatures/Core.Wpf/CodeAnalysisColors.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/EditorFeatures/Core.Wpf/InlineRename/Dashboard/Dashboard.xaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7-
xmlns:me="clr-namespace:Microsoft.CodeAnalysis.Editor"
87
xmlns:imaging="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.Imaging"
98
xmlns:imagecatalog="clr-namespace:Microsoft.VisualStudio.Imaging;assembly=Microsoft.VisualStudio.ImageCatalog"
109
xmlns:rename="clr-namespace:Microsoft.CodeAnalysis.Editor.Implementation.InlineRename"
11-
xmlns:utilities="clr-namespace:Microsoft.CodeAnalysis.Editor.Shared.Utilities"
1210
x:ClassModifier="internal"
1311
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
1412
MinWidth="300"
@@ -26,15 +24,15 @@
2624
<UserControl.Resources>
2725
<ResourceDictionary>
2826
<ResourceDictionary.MergedDictionaries>
29-
<ResourceDictionary Source="Colors.xaml"/>
27+
<ResourceDictionary Source="DashboardColors.xaml"/>
3028
</ResourceDictionary.MergedDictionaries>
3129

3230
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
3331

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

3634
<Style TargetType="CheckBox">
37-
<Setter Property="Foreground" Value="{DynamicResource {x:Static utilities:CodeAnalysisColors.CheckBoxTextBrushKey}}"/>
35+
<Setter Property="Foreground" Value="{DynamicResource {x:Static rename:DashboardColors.CheckBoxTextBrushKey}}"/>
3836
</Style>
3937

4038
<Style TargetType="TextBlock">
@@ -58,7 +56,7 @@
5856
</Grid.RowDefinitions>
5957

6058
<Border Grid.Row="0" BorderBrush="Transparent"
61-
Background="{DynamicResource {x:Static utilities:CodeAnalysisColors.BackgroundBrushKey}}"
59+
Background="{DynamicResource {x:Static rename:DashboardColors.BackgroundBrushKey}}"
6260
BorderThickness="0"
6361
Padding="7">
6462
<StackPanel>
@@ -246,12 +244,12 @@
246244

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

255-
<Rectangle Name="DashboardAccentBar" Grid.Row="1" Height="4" Fill="{DynamicResource {x:Static utilities:CodeAnalysisColors.AccentBarColorKey}}" />
253+
<Rectangle Name="DashboardAccentBar" Grid.Row="1" Height="4" Fill="{DynamicResource {x:Static rename:DashboardColors.AccentBarColorKey}}" />
256254
</Grid>
257255
</UserControl>

src/EditorFeatures/Core.Wpf/InlineRename/Dashboard/DashboardAdornmentManager.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ internal class DashboardAdornmentManager : IDisposable
1717
private readonly IWpfTextView _textView;
1818
private readonly InlineRenameService _renameService;
1919
private readonly IEditorFormatMapService _editorFormatMapService;
20+
private readonly IDashboardColorUpdater? _dashboardColorUpdater;
21+
2022
private readonly IAdornmentLayer _adornmentLayer;
2123

2224
private static readonly ConditionalWeakTable<InlineRenameSession, DashboardViewModel> s_createdViewModels =
@@ -25,10 +27,12 @@ internal class DashboardAdornmentManager : IDisposable
2527
public DashboardAdornmentManager(
2628
InlineRenameService renameService,
2729
IEditorFormatMapService editorFormatMapService,
30+
IDashboardColorUpdater? dashboardColorUpdater,
2831
IWpfTextView textView)
2932
{
3033
_renameService = renameService;
3134
_editorFormatMapService = editorFormatMapService;
35+
_dashboardColorUpdater = dashboardColorUpdater;
3236
_textView = textView;
3337

3438
_adornmentLayer = textView.GetAdornmentLayer(DashboardAdornmentProvider.AdornmentLayerName);
@@ -58,6 +62,8 @@ private void UpdateAdornments()
5862
if (_renameService.ActiveSession != null &&
5963
ViewIncludesBufferFromWorkspace(_textView, _renameService.ActiveSession.Workspace))
6064
{
65+
_dashboardColorUpdater?.UpdateColors();
66+
6167
var newAdornment = new Dashboard(
6268
s_createdViewModels.GetValue(_renameService.ActiveSession, session => new DashboardViewModel(session)),
6369
_editorFormatMapService,

src/EditorFeatures/Core.Wpf/InlineRename/Dashboard/DashboardAdornmentProvider.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ internal class DashboardAdornmentProvider : IWpfTextViewConnectionListener
2323
{
2424
private readonly InlineRenameService _renameService;
2525
private readonly IEditorFormatMapService _editorFormatMapService;
26+
private readonly IDashboardColorUpdater? _dashboardColorUpdater;
27+
2628
public const string AdornmentLayerName = "RoslynRenameDashboard";
2729

2830
[Export]
@@ -40,16 +42,18 @@ internal class DashboardAdornmentProvider : IWpfTextViewConnectionListener
4042
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
4143
public DashboardAdornmentProvider(
4244
InlineRenameService renameService,
43-
IEditorFormatMapService editorFormatMapService)
45+
IEditorFormatMapService editorFormatMapService,
46+
[Import(AllowDefault = true)] IDashboardColorUpdater? dashboardColorUpdater)
4447
{
4548
_renameService = renameService;
4649
_editorFormatMapService = editorFormatMapService;
50+
_dashboardColorUpdater = dashboardColorUpdater;
4751
}
4852

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

5559
public void SubjectBuffersDisconnected(IWpfTextView textView, ConnectionReason reason, Collection<ITextBuffer> subjectBuffers)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
6+
{
7+
internal static class DashboardColors
8+
{
9+
// In the Dashboard XAML, we bind to these keys to provide the correct color resources.
10+
// The default values of these fields match the names of the keys in DashboardColors.xaml,
11+
// but in Visual Studio we will change these keys (since they are settable) to the keys for
12+
// the actual Visual Studio resource keys.
13+
//
14+
// Each entry here should have a corresponding entry in DashboardColors.xaml to specify the
15+
// default color.
16+
17+
public static object SystemCaptionTextColorKey { get; set; } = "SystemCaptionTextColor";
18+
public static object SystemCaptionTextBrushKey { get; set; } = "SystemCaptionTextBrush";
19+
public static object CheckBoxTextBrushKey { get; set; } = "CheckBoxTextBrush";
20+
public static object BackgroundBrushKey { get; set; } = "BackgroundBrush";
21+
public static object AccentBarColorKey { get; set; } = "AccentBarBrush";
22+
public static object ButtonStyleKey { get; set; } = "ButtonStyle";
23+
}
24+
}

src/EditorFeatures/Core.Wpf/InlineRename/Dashboard/Colors.xaml renamed to src/EditorFeatures/Core.Wpf/InlineRename/Dashboard/DashboardColors.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
44

5+
<!-- These resources provide the default colors for the dashboard if we're not hosted
6+
in a specific host that will override them, like Visual Studio. Each resource here
7+
corresponds to an entry in DashboardColors.cs, where it can be overwritten by a host. -->
8+
59
<Color x:Key="SystemCaptionTextColor">Black</Color>
610
<SolidColorBrush x:Key="SystemCaptionTextBrush" Color="Black"/>
711
<SolidColorBrush x:Key="CheckBoxTextBrush" Color="Black"/>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace Microsoft.CodeAnalysis.Editor.Implementation.InlineRename
6+
{
7+
internal interface IDashboardColorUpdater
8+
{
9+
/// <summary>
10+
/// Implemented by a host to set the properties on <see cref="DashboardColors"/>.
11+
/// </summary>
12+
public void UpdateColors();
13+
}
14+
}

src/EditorFeatures/Core.Wpf/Microsoft.CodeAnalysis.EditorFeatures.Wpf.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
<PackageReference Include="Microsoft.VisualStudio.Imaging" Version="$(MicrosoftVisualStudioImagingVersion)" />
3434
<PackageReference Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" Version="$(MicrosoftVisualStudioImagingInterop140DesignTimeVersion)" />
3535
<PackageReference Include="Microsoft.VisualStudio.InteractiveWindow" Version="$(MicrosoftVisualStudioInteractiveWindowVersion)" />
36-
<PackageReference Include="Microsoft.VisualStudio.Interop" Version="$(MicrosoftVisualStudioInteropVersion)" />
3736
<PackageReference Include="Microsoft.VisualStudio.Language.NavigateTo.Interfaces" Version="$(MicrosoftVisualStudioLanguageNavigateToInterfacesVersion)" />
3837
<PackageReference Include="Microsoft.VisualStudio.Language.StandardClassification" Version="$(MicrosoftVisualStudioLanguageStandardClassificationVersion)" />
3938
<PackageReference Include="Microsoft.VisualStudio.Language.Intellisense" Version="$(MicrosoftVisualStudioLanguageIntellisenseVersion)" />
40-
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="$(MicrosoftVisualStudioShell150Version)" />
4139
<PackageReference Include="Microsoft.VisualStudio.Text.UI.Wpf" Version="$(MicrosoftVisualStudioTextUIWpfVersion)" />
4240
<PackageReference Include="Microsoft.VisualStudio.Threading" Version="$(MicrosoftVisualStudioThreadingVersion)" />
4341
</ItemGroup>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.ComponentModel.Composition;
7+
using Microsoft.CodeAnalysis.Editor.Implementation.InlineRename;
8+
using Microsoft.CodeAnalysis.Host.Mef;
9+
using Microsoft.VisualStudio.PlatformUI;
10+
using Microsoft.VisualStudio.Shell;
11+
12+
namespace Microsoft.VisualStudio.LanguageServices.Implementation.InlineRename
13+
{
14+
[Export(typeof(IDashboardColorUpdater))]
15+
internal class DashboardColorUpdater : IDashboardColorUpdater
16+
{
17+
[ImportingConstructor]
18+
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
19+
public DashboardColorUpdater()
20+
{
21+
}
22+
23+
public void UpdateColors()
24+
{
25+
DashboardColors.SystemCaptionTextColorKey = EnvironmentColors.SystemWindowTextColorKey;
26+
DashboardColors.SystemCaptionTextBrushKey = EnvironmentColors.SystemWindowTextBrushKey;
27+
DashboardColors.CheckBoxTextBrushKey = EnvironmentColors.SystemWindowTextBrushKey;
28+
DashboardColors.BackgroundBrushKey = VsBrushes.CommandBarGradientBeginKey;
29+
DashboardColors.AccentBarColorKey = EnvironmentColors.FileTabInactiveDocumentBorderEdgeBrushKey;
30+
DashboardColors.ButtonStyleKey = VsResourceKeys.ButtonStyleKey;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)