Skip to content

Commit c8deeaa

Browse files
Merge pull request #56045 from jasonmalinowski/fix-editorfeatures.wpf-layering
Don't reference VS Shell binaries in EditorFeatures.Wpf
2 parents 9525fa5 + 074fe49 commit c8deeaa

File tree

9 files changed

+95
-38
lines changed

9 files changed

+95
-38
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: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable disable
6-
75
using System;
86
using System.Linq;
97
using System.Runtime.CompilerServices;
@@ -19,6 +17,8 @@ internal class DashboardAdornmentManager : IDisposable
1917
private readonly IWpfTextView _textView;
2018
private readonly InlineRenameService _renameService;
2119
private readonly IEditorFormatMapService _editorFormatMapService;
20+
private readonly IDashboardColorUpdater? _dashboardColorUpdater;
21+
2222
private readonly IAdornmentLayer _adornmentLayer;
2323

2424
private static readonly ConditionalWeakTable<InlineRenameSession, DashboardViewModel> s_createdViewModels =
@@ -27,10 +27,12 @@ internal class DashboardAdornmentManager : IDisposable
2727
public DashboardAdornmentManager(
2828
InlineRenameService renameService,
2929
IEditorFormatMapService editorFormatMapService,
30+
IDashboardColorUpdater? dashboardColorUpdater,
3031
IWpfTextView textView)
3132
{
3233
_renameService = renameService;
3334
_editorFormatMapService = editorFormatMapService;
35+
_dashboardColorUpdater = dashboardColorUpdater;
3436
_textView = textView;
3537

3638
_adornmentLayer = textView.GetAdornmentLayer(DashboardAdornmentProvider.AdornmentLayerName);
@@ -60,6 +62,8 @@ private void UpdateAdornments()
6062
if (_renameService.ActiveSession != null &&
6163
ViewIncludesBufferFromWorkspace(_textView, _renameService.ActiveSession.Workspace))
6264
{
65+
_dashboardColorUpdater?.UpdateColors();
66+
6367
var newAdornment = new Dashboard(
6468
s_createdViewModels.GetValue(_renameService.ActiveSession, session => new DashboardViewModel(session)),
6569
_editorFormatMapService,
@@ -75,7 +79,7 @@ private static bool ViewIncludesBufferFromWorkspace(IWpfTextView textView, Works
7579
.Any();
7680
}
7781

78-
private static Workspace GetWorkspace(SourceTextContainer textContainer)
82+
private static Workspace? GetWorkspace(SourceTextContainer textContainer)
7983
{
8084
Workspace.TryGetWorkspace(textContainer, out var workspace);
8185
return workspace;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#nullable disable
6-
75
using System;
86
using System.Collections.ObjectModel;
97
using System.ComponentModel.Composition;
@@ -25,6 +23,8 @@ internal class DashboardAdornmentProvider : IWpfTextViewConnectionListener
2523
{
2624
private readonly InlineRenameService _renameService;
2725
private readonly IEditorFormatMapService _editorFormatMapService;
26+
private readonly IDashboardColorUpdater? _dashboardColorUpdater;
27+
2828
public const string AdornmentLayerName = "RoslynRenameDashboard";
2929

3030
[Export]
@@ -36,22 +36,24 @@ internal class DashboardAdornmentProvider : IWpfTextViewConnectionListener
3636
[Order(After = PredefinedAdornmentLayers.TextMarker)]
3737
[Order(After = PredefinedAdornmentLayers.CurrentLineHighlighter)]
3838
[Order(After = PredefinedAdornmentLayers.Squiggle)]
39-
internal readonly AdornmentLayerDefinition AdornmentLayer;
39+
internal readonly AdornmentLayerDefinition? AdornmentLayer;
4040

4141
[ImportingConstructor]
4242
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
4343
public DashboardAdornmentProvider(
4444
InlineRenameService renameService,
45-
IEditorFormatMapService editorFormatMapService)
45+
IEditorFormatMapService editorFormatMapService,
46+
[Import(AllowDefault = true)] IDashboardColorUpdater? dashboardColorUpdater)
4647
{
4748
_renameService = renameService;
4849
_editorFormatMapService = editorFormatMapService;
50+
_dashboardColorUpdater = dashboardColorUpdater;
4951
}
5052

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

5759
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)