-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #414 from reduckted/feature/fonts-and-colors
Fonts and Colors
- Loading branch information
Showing
62 changed files
with
3,669 additions
and
115 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
demo/VSSDK.TestExtension/Commands/FontsAndColorsWindowCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Community.VisualStudio.Toolkit; | ||
using Microsoft.VisualStudio.Shell; | ||
using Task = System.Threading.Tasks.Task; | ||
|
||
namespace TestExtension | ||
{ | ||
[Command(PackageIds.FontsAndColorsWindow)] | ||
internal sealed class FontsAndColorsWindowCommand : BaseCommand<FontsAndColorsWindowCommand> | ||
{ | ||
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) => | ||
await FontsAndColorsWindow.ShowAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
demo/VSSDK.TestExtension/ToolWindows/FontsAndColors/DemoFontAndColorCategory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Runtime.InteropServices; | ||
using Community.VisualStudio.Toolkit; | ||
using Microsoft.VisualStudio.Shell.Interop; | ||
using Microsoft.VisualStudio.TextManager.Interop; | ||
|
||
namespace TestExtension | ||
{ | ||
[Guid("bfbcd352-3b43-4034-b951-7ca841a16c81")] | ||
public class DemoFontAndColorCategory : BaseFontAndColorCategory<DemoFontAndColorCategory> | ||
{ | ||
public DemoFontAndColorCategory() : base(new FontDefinition("Consolas", 12)) { } | ||
|
||
public override string Name => "Fonts and Colors Demo"; | ||
|
||
public ColorDefinition TopLeft { get; } = new( | ||
"Top Left", | ||
defaultBackground: VisualStudioColor.Indexed(COLORINDEX.CI_RED), | ||
defaultForeground: VisualStudioColor.Indexed(COLORINDEX.CI_WHITE), | ||
options: ColorDefinition.DefaultOptions | ColorOptions.AllowBoldChange | ||
); | ||
|
||
public ColorDefinition TopRight { get; } = new( | ||
"Top Right", | ||
defaultBackground: VisualStudioColor.Automatic(), | ||
defaultForeground: VisualStudioColor.Automatic(), | ||
automaticBackground: VisualStudioColor.VsColor(__VSSYSCOLOREX.VSCOLOR_ENVIRONMENT_BACKGROUND), | ||
automaticForeground: VisualStudioColor.VsColor(__VSSYSCOLOREX.VSCOLOR_PANEL_TEXT), | ||
options: ColorDefinition.DefaultOptions | ColorOptions.AllowBoldChange | ||
); | ||
|
||
public ColorDefinition BottomLeft { get; } = new( | ||
"Bottom Left", | ||
defaultBackground: VisualStudioColor.SysColor(13), | ||
defaultForeground: VisualStudioColor.SysColor(14), | ||
options: ColorOptions.AllowBackgroundChange | ColorOptions.AllowForegroundChange | ||
); | ||
|
||
public ColorDefinition BottomRight { get; } = new( | ||
"Bottom Right", | ||
defaultBackground: VisualStudioColor.Indexed(COLORINDEX.CI_DARKGREEN), | ||
defaultForeground: VisualStudioColor.Indexed(COLORINDEX.CI_WHITE) | ||
); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
demo/VSSDK.TestExtension/ToolWindows/FontsAndColors/DemoFontAndColorProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using Community.VisualStudio.Toolkit; | ||
|
||
namespace TestExtension | ||
{ | ||
[Guid("d2bc5f5f-6c24-4f6c-b6ef-aea775be5fa4")] | ||
public class DemoFontAndColorProvider : BaseFontAndColorProvider { } | ||
} |
43 changes: 43 additions & 0 deletions
43
demo/VSSDK.TestExtension/ToolWindows/FontsAndColors/FontsAndColorsWindow.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using Community.VisualStudio.Toolkit; | ||
using Microsoft.VisualStudio.Imaging; | ||
|
||
namespace TestExtension | ||
{ | ||
public class FontsAndColorsWindow : BaseToolWindow<FontsAndColorsWindow> | ||
{ | ||
public override string GetTitle(int toolWindowId) => "Fonts and Colors Window"; | ||
|
||
public override Type PaneType => typeof(Pane); | ||
|
||
public override async Task<FrameworkElement> CreateAsync(int toolWindowId, CancellationToken cancellationToken) | ||
{ | ||
return new FontsAndColorsWindowControl | ||
{ | ||
DataContext = new FontsAndColorsWindowViewModel( | ||
await VS.FontsAndColors.GetConfiguredFontAndColorsAsync<DemoFontAndColorCategory>(), | ||
Package.JoinableTaskFactory | ||
) | ||
}; | ||
} | ||
|
||
[Guid("b7141d35-7b95-4ad0-a37d-58220c1aa5e3")] | ||
internal class Pane : ToolkitToolWindowPane | ||
{ | ||
public Pane() | ||
{ | ||
BitmapImageMoniker = KnownMonikers.ColorDialog; | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
((Content as FontsAndColorsWindowControl).DataContext as IDisposable)?.Dispose(); | ||
base.Dispose(disposing); | ||
} | ||
} | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
demo/VSSDK.TestExtension/ToolWindows/FontsAndColors/FontsAndColorsWindowControl.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<UserControl | ||
x:Class="TestExtension.FontsAndColorsWindowControl" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
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:local="clr-namespace:TestExtension" | ||
xmlns:toolkit="clr-namespace:Community.VisualStudio.Toolkit;assembly=Community.VisualStudio.Toolkit" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" | ||
d:DataContext="{d:DesignInstance Type=local:FontsAndColorsWindowViewModel, IsDesignTimeCreatable=False}" | ||
toolkit:Themes.UseVsTheme="True" | ||
> | ||
|
||
<Grid Margin="10"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto"/> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="100"/> | ||
</Grid.RowDefinitions> | ||
|
||
<Button Grid.Row="0" Command="{Binding EditFontsAndColorsCommand}"> | ||
Edit Fonts and Colors... | ||
</Button> | ||
|
||
<Grid | ||
Grid.Row="1" | ||
Margin="0,10" | ||
TextElement.FontFamily="{Binding Font.Family}" | ||
TextElement.FontSize="{Binding Font.Size}" | ||
> | ||
|
||
<Grid.Resources> | ||
<Style TargetType="TextBlock"> | ||
<Setter Property="HorizontalAlignment" Value="Center"/> | ||
<Setter Property="VerticalAlignment" Value="Center"/> | ||
</Style> | ||
</Grid.Resources> | ||
|
||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"/> | ||
<ColumnDefinition Width="10"/> | ||
<ColumnDefinition Width="*"/> | ||
</Grid.ColumnDefinitions> | ||
|
||
<Grid.RowDefinitions> | ||
<RowDefinition Height="*"/> | ||
<RowDefinition Height="10"/> | ||
<RowDefinition Height="*"/> | ||
</Grid.RowDefinitions> | ||
|
||
<Border | ||
Grid.Column="0" | ||
Grid.Row="0" | ||
Background="{Binding TopLeft.BackgroundBrush}" | ||
TextElement.Foreground="{Binding TopLeft.ForegroundBrush}" | ||
TextElement.FontWeight="{Binding TopLeft.FontWeight}" | ||
> | ||
<TextBlock> | ||
Top Left | ||
<LineBreak/> | ||
Default: Red / White | ||
</TextBlock> | ||
</Border> | ||
|
||
<Border | ||
Grid.Column="2" | ||
Grid.Row="0" | ||
Background="{Binding TopRight.BackgroundBrush}" | ||
TextElement.Foreground="{Binding TopRight.ForegroundBrush}" | ||
TextElement.FontWeight="{Binding TopRight.FontWeight}" | ||
> | ||
<TextBlock> | ||
Top Right | ||
<LineBreak/> | ||
Default: Auto / Auto | ||
</TextBlock> | ||
</Border> | ||
|
||
<Border | ||
Grid.Column="0" | ||
Grid.Row="2" | ||
Background="{Binding BottomLeft.BackgroundBrush}" | ||
TextElement.Foreground="{Binding BottomLeft.ForegroundBrush}" | ||
TextElement.FontWeight="{Binding BottomLeft.FontWeight}" | ||
> | ||
<TextBlock> | ||
Bottom Left | ||
<LineBreak/> | ||
Default: Yellow / Black | ||
</TextBlock> | ||
</Border> | ||
|
||
<Border | ||
Grid.Column="2" | ||
Grid.Row="2" | ||
Background="{Binding BottomRight.BackgroundBrush}" | ||
TextElement.Foreground="{Binding BottomRight.ForegroundBrush}" | ||
TextElement.FontWeight="{Binding BottomRight.FontWeight}" | ||
> | ||
<TextBlock> | ||
Bottom Right | ||
<LineBreak/> | ||
Default: Green / White | ||
</TextBlock> | ||
</Border> | ||
</Grid> | ||
|
||
<ListBox Grid.Row="2" ItemsSource="{Binding Events}"/> | ||
</Grid> | ||
</UserControl> |
24 changes: 24 additions & 0 deletions
24
demo/VSSDK.TestExtension/ToolWindows/FontsAndColors/FontsAndColorsWindowControl.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Windows.Controls; | ||
using System.Windows.Documents; | ||
using Community.VisualStudio.Toolkit; | ||
|
||
namespace TestExtension | ||
{ | ||
public partial class FontsAndColorsWindowControl : UserControl | ||
{ | ||
public FontsAndColorsWindowControl() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void ApplyColor(Border border, ConfiguredColor color) | ||
{ | ||
// Bind the border's properties to the configured | ||
// color properties. This could also be done in XAML. | ||
border.DataContext = color; | ||
border.SetBinding(BackgroundProperty, nameof(ConfiguredColor.BackgroundBrush)); | ||
border.SetBinding(TextElement.ForegroundProperty, nameof(ConfiguredColor.ForegroundBrush)); | ||
border.SetBinding(TextElement.FontWeightProperty, nameof(ConfiguredColor.FontWeight)); | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
demo/VSSDK.TestExtension/ToolWindows/FontsAndColors/FontsAndColorsWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Windows.Input; | ||
using Community.VisualStudio.Toolkit; | ||
using Microsoft.VisualStudio.PlatformUI; | ||
using Microsoft.VisualStudio.Shell; | ||
using Microsoft.VisualStudio.Threading; | ||
|
||
namespace TestExtension | ||
{ | ||
public class FontsAndColorsWindowViewModel : IDisposable | ||
{ | ||
private readonly ConfiguredFontAndColorSet<DemoFontAndColorCategory> _fontAndColors; | ||
private readonly ObservableCollection<string> _events; | ||
|
||
public FontsAndColorsWindowViewModel(ConfiguredFontAndColorSet<DemoFontAndColorCategory> fontAndColors, JoinableTaskFactory joinableTaskFactory) | ||
{ | ||
// Remember the font and color set so that | ||
// we can dispose of it when we are disposed. | ||
_fontAndColors = fontAndColors; | ||
|
||
EditFontsAndColorsCommand = new DelegateCommand( | ||
() => VS.Commands.ExecuteAsync( | ||
KnownCommands.Tools_Options, | ||
"{57F6B7D2-1436-11D1-883C-0000F87579D2}" | ||
).FireAndForget(), | ||
() => true, | ||
joinableTaskFactory | ||
); | ||
|
||
_events = new ObservableCollection<string>(); | ||
Events = new ReadOnlyObservableCollection<string>(_events); | ||
|
||
fontAndColors.FontChanged += OnFontChanged; | ||
fontAndColors.ColorChanged += OnColorChanged; | ||
|
||
TopLeft = fontAndColors.GetColor(fontAndColors.Category.TopLeft); | ||
TopRight = fontAndColors.GetColor(fontAndColors.Category.TopRight); | ||
BottomLeft = fontAndColors.GetColor(fontAndColors.Category.BottomLeft); | ||
BottomRight = fontAndColors.GetColor(fontAndColors.Category.BottomRight); | ||
} | ||
|
||
private void OnFontChanged(object sender, EventArgs e) | ||
{ | ||
_events.Insert(0, $"{DateTime.Now}: Font Changed"); | ||
} | ||
|
||
private void OnColorChanged(object sender, ConfiguredColorChangedEventArgs e) | ||
{ | ||
_events.Insert(0, $"{DateTime.Now}: Color Changed - {e.Definition.Name}"); | ||
} | ||
|
||
public ICommand EditFontsAndColorsCommand { get; } | ||
|
||
public ReadOnlyObservableCollection<string> Events { get; } | ||
|
||
public ConfiguredFont Font => _fontAndColors.Font; | ||
|
||
public ConfiguredColor TopLeft { get; } | ||
|
||
public ConfiguredColor TopRight { get; } | ||
|
||
public ConfiguredColor BottomLeft { get; } | ||
|
||
public ConfiguredColor BottomRight { get; } | ||
|
||
public void Dispose() | ||
{ | ||
_fontAndColors.FontChanged -= OnFontChanged; | ||
_fontAndColors.ColorChanged -= OnColorChanged; | ||
|
||
// Dispose of the font and color set so that it stops | ||
// listening for changes to the font and colors. | ||
_fontAndColors.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.