Skip to content

Commit

Permalink
Text styling using DynamiResource (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomasz Gołębiowski <[email protected]>
  • Loading branch information
tomaszgolebiowski and Tomasz Gołębiowski authored Sep 10, 2024
1 parent 1341ea0 commit 84e71cf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/Cody.UI/Cody.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.0-previews-4-31709-430" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Web.WebView2">
<Version>1.0.2592.51</Version>
</PackageReference>
Expand Down
12 changes: 1 addition & 11 deletions src/Cody.UI/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System;
using System.Threading.Tasks;
using System.Windows;
using Cody.Core.Agent;
using Cody.Core.Logging;
using Cody.UI.MVVM;
using System.Windows.Input;
using Cody.Core.Infrastructure;
using System.Windows.Media;

namespace Cody.UI.ViewModels
{
Expand All @@ -17,12 +15,11 @@ public class MainViewModel : NotifyPropertyChangedBase, IWebChatHost

private readonly ILog _logger;

public MainViewModel(IWebViewsManager webViewsManager, NotificationHandlers notificationHandlers, Brush textColor, ILog logger)
public MainViewModel(IWebViewsManager webViewsManager, NotificationHandlers notificationHandlers, ILog logger)
{
_webViewsManager = webViewsManager;
NotificationHandlers = notificationHandlers;
_logger = logger;
_textColor = textColor;

NotificationHandlers.OnSetHtmlEvent += OnSetHtmlHandler;
NotificationHandlers.OnPostMessageEvent += OnPostMessageHandler;
Expand Down Expand Up @@ -60,13 +57,6 @@ private void OnSetHtmlHandler(object sender, SetHtmlEvent e)
Html = e.Html;
}

private Brush _textColor;

public Brush TextColor
{
get { return _textColor; }
}

private string _html;

public string Html
Expand Down
8 changes: 5 additions & 3 deletions src/Cody.UI/Views/MainView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
xmlns:local="clr-namespace:Cody.UI.Views"
xmlns:controls="clr-namespace:Cody.UI.Controls"
xmlns:converters="clr-namespace:Cody.UI.Converters"
xmlns:vsshell="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
Background="{DynamicResource {x:Static vsshell:VsBrushes.WindowKey}}"
Foreground="{DynamicResource {x:Static vsshell:VsBrushes.WindowTextKey}}"
FontSize="{DynamicResource {x:Static vsshell:VsFonts.CaptionFontSizeKey}}"
mc:Ignorable="d"
d:DesignHeight="750"
d:DesignWidth="400"
Expand All @@ -14,10 +18,8 @@
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="{Binding TextColor}"
TextAlignment="Center"
Text="Loading Cody Chat ..."
FontSize="16"
Text="Loading Cody chat..."
/>
<controls:WebView2Dev
Html="{Binding Html}"
Expand Down
9 changes: 1 addition & 8 deletions src/Cody.VisualStudio/CodyToolWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
using Cody.UI.Views;
using Cody.VisualStudio.Inf;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.PlatformUI;
using System.Windows.Media;
using System.Drawing;

#pragma warning disable VSTHRD010

Expand Down Expand Up @@ -42,12 +39,8 @@ public CodyToolWindow() : base(null)
var logger = package.Logger;
var notificationsHandlers = package.NotificationHandlers;
var webViewsManager = package.WebViewsManager;

// TODO: move to ThemeService and inject it to MainViewModel
var textColor = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
var wpfTextColor = new SolidColorBrush(System.Windows.Media.Color.FromRgb(textColor.R, textColor.G, textColor.B));

var viewModel = new MainViewModel(webViewsManager, notificationsHandlers, wpfTextColor, logger);
var viewModel = new MainViewModel(webViewsManager, notificationsHandlers, logger);
var view = new MainView
{
DataContext = viewModel
Expand Down

0 comments on commit 84e71cf

Please sign in to comment.