Skip to content

Commit 75bf642

Browse files
Creating a Common.UI.Controls lib (#45542)
## Summary of the Pull Request @jiripolasek FYI This PR creates a new `Common.UI.Controls` library that contains shared WinUI controls. We have been copying code manually between CmdPal and Settings, and now with the new KBM we will run into the same issue. This lib has shared controls projects can add to their proj so we have a single source of truth. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] Closes: #45388 <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed --------- Co-authored-by: Jiří Polášek <[email protected]>
1 parent 795c64c commit 75bf642

File tree

63 files changed

+302
-792
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+302
-792
lines changed

.github/actions/spell-check/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,7 @@ psz
14971497
ptb
14981498
ptc
14991499
PTCHAR
1500+
ptcontrols
15001501
ptd
15011502
PTOKEN
15021503
PToy

PowerToys.slnx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<Platform Solution="*|ARM64" Project="ARM64" />
1414
<Platform Solution="*|x64" Project="x64" />
1515
</Project>
16+
<Project Path="src/common/Common.UI.Controls/Common.UI.Controls.csproj">
17+
<Platform Solution="*|ARM64" Project="ARM64" />
18+
<Platform Solution="*|x64" Project="x64" />
19+
</Project>
1620
<Project Path="src/common/COMUtils/COMUtils.vcxproj" Id="7319089e-46d6-4400-bc65-e39bdf1416ee" />
1721
<Project Path="src/common/Display/Display.vcxproj" Id="caba8dfb-823b-4bf2-93ac-3f31984150d9" />
1822
<Project Path="src/common/FilePreviewCommon/FilePreviewCommon.csproj">
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$(RepoRoot)src\Common.Dotnet.CsWinRT.props" />
3+
<Import Project="$(RepoRoot)src\Common.SelfContained.props" />
4+
5+
<PropertyGroup>
6+
<OutputType>Library</OutputType>
7+
<TargetFramework>net9.0-windows10.0.26100.0</TargetFramework>
8+
<RootNamespace>Microsoft.PowerToys.Common.UI.Controls</RootNamespace>
9+
<AssemblyName>PowerToys.Common.UI.Controls</AssemblyName>
10+
<UseWinUI>true</UseWinUI>
11+
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
12+
<GenerateLibraryLayout>true</GenerateLibraryLayout>
13+
<ProjectPriFileName>PowerToys.Common.UI.Controls.pri</ProjectPriFileName>
14+
<Nullable>enable</Nullable>
15+
<Platforms>x64;ARM64</Platforms>
16+
</PropertyGroup>
17+
18+
<ItemGroup>
19+
<PackageReference Include="Microsoft.WindowsAppSDK" />
20+
<PackageReference Include="CommunityToolkit.WinUI.Controls.Primitives" />
21+
<PackageReference Include="CommunityToolkit.WinUI.Extensions" />
22+
<PackageReference Include="CommunityToolkit.WinUI.Converters" />
23+
<PackageReference Include="CommunityToolkit.Labs.WinUI.Controls.MarkdownTextBlock" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<ProjectReference Include="..\ManagedCommon\ManagedCommon.csproj" />
28+
</ItemGroup>
29+
30+
</Project>

src/settings-ui/Settings.UI/SettingsXAML/Controls/CheckBoxWithDescriptionControl.cs renamed to src/common/Common.UI.Controls/Controls/CheckBoxWithDescriptionControl/CheckBoxWithDescriptionControl.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation
1+
// Copyright (c) Microsoft Corporation
22
// The Microsoft Corporation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

@@ -8,7 +8,7 @@
88
using Microsoft.UI.Xaml.Automation;
99
using Microsoft.UI.Xaml.Controls;
1010

11-
namespace Microsoft.PowerToys.Settings.UI.Controls
11+
namespace Microsoft.PowerToys.Common.UI.Controls
1212
{
1313
public partial class CheckBoxWithDescriptionControl : CheckBox
1414
{
@@ -39,7 +39,7 @@ private void CheckBoxSubTextControl_Loaded(object sender, RoutedEventArgs e)
3939
// Add text box only if the description is not empty. Required for additional plugin options.
4040
if (!string.IsNullOrWhiteSpace(Description))
4141
{
42-
panel.Children.Add(new IsEnabledTextBlock() { Style = (Style)App.Current.Resources["SecondaryIsEnabledTextBlockStyle"], Text = Description });
42+
panel.Children.Add(new IsEnabledTextBlock() { Style = (Style)Application.Current.Resources["SecondaryIsEnabledTextBlockStyle"], Text = Description });
4343
}
4444

4545
this.Content = panel;

src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml renamed to src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<ResourceDictionary
1+
<ResourceDictionary
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls">
4+
xmlns:controls="using:Microsoft.PowerToys.Common.UI.Controls">
55

66
<Style BasedOn="{StaticResource DefaultIsEnabledTextBlockStyle}" TargetType="controls:IsEnabledTextBlock" />
77

@@ -36,11 +36,13 @@
3636
</Setter.Value>
3737
</Setter>
3838
</Style>
39+
3940
<Style
4041
x:Key="SecondaryIsEnabledTextBlockStyle"
4142
BasedOn="{StaticResource DefaultIsEnabledTextBlockStyle}"
4243
TargetType="controls:IsEnabledTextBlock">
4344
<Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}" />
44-
<Setter Property="FontSize" Value="{StaticResource SecondaryTextFontSize}" />
45+
<Setter Property="FontSize" Value="12" />
4546
</Style>
47+
4648
</ResourceDictionary>

src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml.cs renamed to src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation
1+
// Copyright (c) Microsoft Corporation
22
// The Microsoft Corporation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

@@ -7,15 +7,15 @@
77
using Microsoft.UI.Xaml;
88
using Microsoft.UI.Xaml.Controls;
99

10-
namespace Microsoft.PowerToys.Settings.UI.Controls
10+
namespace Microsoft.PowerToys.Common.UI.Controls
1111
{
1212
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
1313
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
1414
public partial class IsEnabledTextBlock : Control
1515
{
1616
public IsEnabledTextBlock()
1717
{
18-
this.DefaultStyleKey = typeof(KeyVisual);
18+
this.DefaultStyleKey = typeof(IsEnabledTextBlock);
1919
}
2020

2121
protected override void OnApplyTemplate()

src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml renamed to src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<ResourceDictionary
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:local="using:Microsoft.PowerToys.Settings.UI.Controls"
5+
xmlns:local="using:Microsoft.PowerToys.Common.UI.Controls"
66
xmlns:ui="using:CommunityToolkit.WinUI">
77

88
<Style BasedOn="{StaticResource DefaultKeyCharPresenterStyle}" TargetType="local:KeyCharPresenter" />

src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml.cs renamed to src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,10 @@
22
// The Microsoft Corporation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
8-
using System.Runtime.InteropServices.WindowsRuntime;
95
using Microsoft.UI.Xaml;
106
using Microsoft.UI.Xaml.Controls;
11-
using Microsoft.UI.Xaml.Data;
12-
using Microsoft.UI.Xaml.Documents;
13-
using Microsoft.UI.Xaml.Input;
14-
using Microsoft.UI.Xaml.Media;
157

16-
namespace Microsoft.PowerToys.Settings.UI.Controls;
8+
namespace Microsoft.PowerToys.Common.UI.Controls;
179

1810
public sealed partial class KeyCharPresenter : Control
1911
{

src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml renamed to src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<ResourceDictionary
1+
<ResourceDictionary
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
xmlns:local="using:Microsoft.PowerToys.Settings.UI.Controls">
4+
xmlns:local="using:Microsoft.PowerToys.Common.UI.Controls">
55

66
<Style BasedOn="{StaticResource DefaultKeyVisualStyle}" TargetType="local:KeyVisual" />
77

@@ -210,4 +210,4 @@
210210
</Setter.Value>
211211
</Setter>
212212
</Style>
213-
</ResourceDictionary>
213+
</ResourceDictionary>

src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml.cs renamed to src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Copyright (c) Microsoft Corporation
1+
// Copyright (c) Microsoft Corporation
22
// The Microsoft Corporation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

55
using Microsoft.UI.Xaml;
66
using Microsoft.UI.Xaml.Controls;
77
using Windows.System;
88

9-
namespace Microsoft.PowerToys.Settings.UI.Controls
9+
namespace Microsoft.PowerToys.Common.UI.Controls
1010
{
1111
[TemplatePart(Name = KeyPresenter, Type = typeof(KeyCharPresenter))]
1212
[TemplateVisualState(Name = NormalState, GroupName = "CommonStates")]
@@ -20,7 +20,7 @@ public sealed partial class KeyVisual : Control
2020
private const string DisabledState = "Disabled";
2121
private const string InvalidState = "Invalid";
2222
private const string WarningState = "Warning";
23-
private KeyCharPresenter _keyPresenter;
23+
private KeyCharPresenter _keyPresenter = null!;
2424

2525
public object Content
2626
{

0 commit comments

Comments
 (0)