Skip to content

Commit 492d172

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 CodeAnalysiColors to DashboardColors which is a bit clearer what it is.
1 parent 521f08a commit 492d172

File tree

8 files changed

+82
-31
lines changed

8 files changed

+82
-31
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: 5 additions & 7 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"
@@ -27,10 +25,10 @@
2725
<ResourceDictionary>
2826
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
2927

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

3230
<Style TargetType="CheckBox">
33-
<Setter Property="Foreground" Value="{DynamicResource {x:Static utilities:CodeAnalysisColors.CheckBoxTextBrushKey}}"/>
31+
<Setter Property="Foreground" Value="{DynamicResource {x:Static rename:DashboardColors.CheckBoxTextBrushKey}}"/>
3432
</Style>
3533

3634
<Style TargetType="TextBlock">
@@ -54,7 +52,7 @@
5452
</Grid.RowDefinitions>
5553

5654
<Border Grid.Row="0" BorderBrush="Transparent"
57-
Background="{DynamicResource {x:Static utilities:CodeAnalysisColors.BackgroundBrushKey}}"
55+
Background="{DynamicResource {x:Static rename:DashboardColors.BackgroundBrushKey}}"
5856
BorderThickness="0"
5957
Padding="7">
6058
<StackPanel>
@@ -242,12 +240,12 @@
242240

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

251-
<Rectangle Name="DashboardAccentBar" Grid.Row="1" Height="4" Fill="{DynamicResource {x:Static utilities:CodeAnalysisColors.AccentBarColorKey}}" />
249+
<Rectangle Name="DashboardAccentBar" Grid.Row="1" Height="4" Fill="{DynamicResource {x:Static rename:DashboardColors.AccentBarColorKey}}" />
252250
</Grid>
253251
</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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
// Use VS color keys in order to support theming.
10+
public static object? SystemCaptionTextColorKey { get; set; }
11+
public static object? CheckBoxTextBrushKey { get; set; }
12+
public static object? SystemCaptionTextBrushKey { get; set; }
13+
public static object? BackgroundBrushKey { get; set; }
14+
public static object? ButtonStyleKey { get; set; }
15+
public static object? AccentBarColorKey { get; set; }
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
15+
}

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.CheckBoxTextBrushKey = EnvironmentColors.SystemWindowTextBrushKey;
27+
DashboardColors.SystemCaptionTextBrushKey = EnvironmentColors.SystemWindowTextBrushKey;
28+
DashboardColors.BackgroundBrushKey = VsBrushes.CommandBarGradientBeginKey;
29+
DashboardColors.ButtonStyleKey = VsResourceKeys.ButtonStyleKey;
30+
DashboardColors.AccentBarColorKey = EnvironmentColors.FileTabInactiveDocumentBorderEdgeBrushKey;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)