mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Some refactoring and removal of redundant code
This commit is contained in:
@@ -69,33 +69,9 @@
|
||||
</Button>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<ListView
|
||||
<controls:ModuleList
|
||||
Grid.Row="1"
|
||||
Margin="0,16,0,0"
|
||||
ItemsSource="{x:Bind ViewModel.FlyoutMenuItems}"
|
||||
SelectionMode="None">
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
<ListView.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Padding="0,0,0,16" Orientation="Vertical" />
|
||||
</ItemsPanelTemplate>
|
||||
</ListView.ItemsPanel>
|
||||
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="viewModels:FlyoutMenuItem">
|
||||
<controls:ModuleSettingsCard
|
||||
HorizontalAlignment="Stretch"
|
||||
Icon="{x:Bind Icon, Mode=OneWay}"
|
||||
IsLocked="{x:Bind IsLocked, Mode=OneWay}"
|
||||
IsOn="{x:Bind IsEnabled, Mode=TwoWay}"
|
||||
Label="{x:Bind Label, Mode=OneWay}" />
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
IsItemClickable="False"
|
||||
ItemsSource="{x:Bind ViewModel.FlyoutMenuItems, Mode=OneWay}" />
|
||||
</Grid>
|
||||
</Page>
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Controls.Converters
|
||||
{
|
||||
public partial class BoolNegationConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is bool b)
|
||||
{
|
||||
return !b;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is bool b)
|
||||
{
|
||||
return !b;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Controls.Converters
|
||||
{
|
||||
public partial class BoolToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
bool bVal = false;
|
||||
if (value is bool b)
|
||||
{
|
||||
bVal = b;
|
||||
}
|
||||
else if (value is bool?)
|
||||
{
|
||||
bVal = (bool?)value ?? false;
|
||||
}
|
||||
|
||||
if (parameter is string s && s == "True")
|
||||
{
|
||||
// Invert
|
||||
bVal = !bVal;
|
||||
}
|
||||
|
||||
return bVal ? Visibility.Visible : Visibility.Collapsed;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
@@ -16,10 +16,11 @@ namespace Microsoft.PowerToys.Settings.UI.Controls.Converters
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the enum value as string
|
||||
var enumString = value.ToString();
|
||||
var parameterString = parameter.ToString();
|
||||
|
||||
return string.Equals(enumString, parameterString, StringComparison.OrdinalIgnoreCase);
|
||||
return enumString!.Equals(parameterString, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Controls.Converters
|
||||
{
|
||||
public partial class StringToBitmapImageConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is string path && !string.IsNullOrEmpty(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
return new BitmapImage(new Uri(path));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback or null
|
||||
}
|
||||
}
|
||||
|
||||
return Microsoft.UI.Xaml.DependencyProperty.UnsetValue;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Microsoft.UI.Xaml.Data;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Controls.Converters
|
||||
{
|
||||
public partial class StringToUriConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is string path && !string.IsNullOrEmpty(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
return new Uri(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fallback or null
|
||||
}
|
||||
}
|
||||
|
||||
return null!;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,23 @@
|
||||
xmlns:converters="using:Microsoft.PowerToys.Settings.UI.Controls.Converters"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:tk="using:CommunityToolkit.WinUI"
|
||||
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:ModuleListSortOptionToBooleanConverter x:Key="ModuleListSortOptionToBooleanConverter" />
|
||||
<x:Double x:Key="SettingsCardWrapThreshold">0</x:Double>
|
||||
<tkconverters:BoolToVisibilityConverter
|
||||
x:Key="BoolToVisibilityConverter"
|
||||
FalseValue="Collapsed"
|
||||
TrueValue="Visible" />
|
||||
<tkconverters:BoolToVisibilityConverter
|
||||
x:Key="ReverseBoolToVisibilityConverter"
|
||||
FalseValue="Visible"
|
||||
TrueValue="Collapsed" />
|
||||
<tkconverters:BoolNegationConverter x:Key="BoolNegationConverter" />
|
||||
</UserControl.Resources>
|
||||
|
||||
<controls:Card
|
||||
@@ -55,14 +68,54 @@
|
||||
</ItemsRepeater.Layout>
|
||||
<ItemsRepeater.ItemTemplate>
|
||||
<DataTemplate x:DataType="controls:ModuleListItem">
|
||||
<controls:ModuleSettingsCard
|
||||
Click="ModuleSettingsCard_Click"
|
||||
Icon="{x:Bind Icon}"
|
||||
IsLocked="{x:Bind IsLocked}"
|
||||
IsNew="{x:Bind IsNew}"
|
||||
<tkcontrols:SettingsCard
|
||||
MinHeight="0"
|
||||
Padding="12,4,12,4"
|
||||
tk:FrameworkElementExtensions.AncestorType="ItemsRepeater"
|
||||
Background="Transparent"
|
||||
BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
|
||||
BorderThickness="0,1,0,0"
|
||||
Click="OnSettingsCardClick"
|
||||
CornerRadius="0"
|
||||
IsClickEnabled="{Binding (tk:FrameworkElementExtensions.Ancestor).IsItemClickable, RelativeSource={RelativeSource Self}}">
|
||||
<tkcontrols:SettingsCard.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{x:Bind Label, Mode=OneWay}" />
|
||||
<!-- InfoBadge -->
|
||||
<InfoBadge
|
||||
x:Name="NewInfoBadge"
|
||||
Margin="4,0,0,0"
|
||||
Style="{StaticResource AttentionDotInfoBadgeStyle}"
|
||||
Visibility="{x:Bind IsNew, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
<FontIcon
|
||||
Width="20"
|
||||
Margin="4,0,0,0"
|
||||
FontSize="16"
|
||||
Glyph=""
|
||||
Visibility="{x:Bind IsLocked, Converter={StaticResource ReverseBoolToVisibilityConverter}, ConverterParameter=True}">
|
||||
<ToolTipService.ToolTip>
|
||||
<TextBlock Text="This setting is managed by your organization" TextWrapping="WrapWholeWords" />
|
||||
</ToolTipService.ToolTip>
|
||||
</FontIcon>
|
||||
</StackPanel>
|
||||
</tkcontrols:SettingsCard.Header>
|
||||
|
||||
<tkcontrols:SettingsCard.HeaderIcon>
|
||||
<ImageIcon>
|
||||
<ImageIcon.Source>
|
||||
<BitmapImage UriSource="{x:Bind Icon, Mode=OneWay}" />
|
||||
</ImageIcon.Source>
|
||||
</ImageIcon>
|
||||
</tkcontrols:SettingsCard.HeaderIcon>
|
||||
|
||||
<ToggleSwitch
|
||||
HorizontalAlignment="Right"
|
||||
AutomationProperties.Name="{x:Bind Label, Mode=OneWay}"
|
||||
IsEnabled="{x:Bind IsLocked, Converter={StaticResource BoolNegationConverter}, ConverterParameter=True, Mode=OneWay}"
|
||||
IsOn="{x:Bind IsEnabled, Mode=TwoWay}"
|
||||
Label="{x:Bind Label}"
|
||||
Tag="{x:Bind Tag}" />
|
||||
OffContent=""
|
||||
OnContent="" />
|
||||
</tkcontrols:SettingsCard>
|
||||
</DataTemplate>
|
||||
</ItemsRepeater.ItemTemplate>
|
||||
</ItemsRepeater>
|
||||
|
||||
@@ -14,6 +14,14 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
public bool IsItemClickable
|
||||
{
|
||||
get => (bool)GetValue(IsItemClickableProperty);
|
||||
set => SetValue(IsItemClickableProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsItemClickableProperty = DependencyProperty.Register(nameof(IsItemClickable), typeof(bool), typeof(ModuleList), new PropertyMetadata(true));
|
||||
|
||||
public object ItemsSource
|
||||
{
|
||||
get => (object)GetValue(ItemsSourceProperty);
|
||||
@@ -48,12 +56,10 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
SortOption = ModuleListSortOption.ByStatus;
|
||||
}
|
||||
|
||||
private void ModuleSettingsCard_Click(object sender, RoutedEventArgs e)
|
||||
private void OnSettingsCardClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is ModuleSettingsCard card && card.DataContext is ModuleListItem item)
|
||||
{
|
||||
item.ClickCommand?.Execute(item.Tag);
|
||||
}
|
||||
// TO DO:
|
||||
// ViewModel.DashboardListItemClick(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
<UserControl
|
||||
x:Class="Microsoft.PowerToys.Settings.UI.Controls.ModuleSettingsCard"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:converters="using:Microsoft.PowerToys.Settings.UI.Controls.Converters"
|
||||
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls">
|
||||
|
||||
<UserControl.Resources>
|
||||
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
|
||||
<converters:StringToBitmapImageConverter x:Key="StringToBitmapImageConverter" />
|
||||
<converters:StringToUriConverter x:Key="StringToUriConverter" />
|
||||
<x:Double x:Key="SettingsCardWrapThreshold">0</x:Double>
|
||||
</UserControl.Resources>
|
||||
|
||||
<tkcontrols:SettingsCard
|
||||
MinHeight="0"
|
||||
Padding="12,4,12,4"
|
||||
Background="Transparent"
|
||||
BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
|
||||
BorderThickness="0,1,0,0"
|
||||
Click="OnSettingsCardClick"
|
||||
CornerRadius="0"
|
||||
IsClickEnabled="True">
|
||||
<tkcontrols:SettingsCard.Header>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="{x:Bind Label, Mode=OneWay}" />
|
||||
<!-- InfoBadge -->
|
||||
<InfoBadge
|
||||
x:Name="NewInfoBadge"
|
||||
Margin="4,0,0,0"
|
||||
Style="{StaticResource AttentionDotInfoBadgeStyle}"
|
||||
Visibility="{x:Bind IsNew, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}" />
|
||||
<FontIcon
|
||||
Width="20"
|
||||
Margin="4,0,0,0"
|
||||
FontSize="16"
|
||||
Glyph=""
|
||||
Visibility="{x:Bind IsLocked, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
|
||||
<ToolTipService.ToolTip>
|
||||
<TextBlock Text="This setting is managed by your organization" TextWrapping="WrapWholeWords" />
|
||||
</ToolTipService.ToolTip>
|
||||
</FontIcon>
|
||||
</StackPanel>
|
||||
</tkcontrols:SettingsCard.Header>
|
||||
|
||||
<tkcontrols:SettingsCard.HeaderIcon>
|
||||
<BitmapIcon ShowAsMonochrome="False" UriSource="{x:Bind Icon, Mode=OneWay, Converter={StaticResource StringToUriConverter}}" />
|
||||
</tkcontrols:SettingsCard.HeaderIcon>
|
||||
|
||||
<ToggleSwitch
|
||||
HorizontalAlignment="Right"
|
||||
AutomationProperties.Name="{x:Bind Label, Mode=OneWay}"
|
||||
IsEnabled="{x:Bind IsLocked, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}"
|
||||
IsOn="{x:Bind IsOn, Mode=TwoWay}"
|
||||
OffContent=""
|
||||
OnContent="" />
|
||||
</tkcontrols:SettingsCard>
|
||||
</UserControl>
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Controls
|
||||
{
|
||||
public sealed partial class ModuleSettingsCard : UserControl
|
||||
{
|
||||
public ModuleSettingsCard()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
}
|
||||
|
||||
public string Label
|
||||
{
|
||||
get => (string)GetValue(LabelProperty);
|
||||
set => SetValue(LabelProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty LabelProperty = DependencyProperty.Register(nameof(Label), typeof(string), typeof(ModuleSettingsCard), new PropertyMetadata(string.Empty));
|
||||
|
||||
public string Icon
|
||||
{
|
||||
get => (string)GetValue(IconProperty);
|
||||
set => SetValue(IconProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon), typeof(string), typeof(ModuleSettingsCard), new PropertyMetadata(null));
|
||||
|
||||
public bool IsNew
|
||||
{
|
||||
get => (bool)GetValue(IsNewProperty);
|
||||
set => SetValue(IsNewProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsNewProperty = DependencyProperty.Register(nameof(IsNew), typeof(bool), typeof(ModuleSettingsCard), new PropertyMetadata(false));
|
||||
|
||||
public bool IsLocked
|
||||
{
|
||||
get => (bool)GetValue(IsLockedProperty);
|
||||
set => SetValue(IsLockedProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsLockedProperty = DependencyProperty.Register(nameof(IsLocked), typeof(bool), typeof(ModuleSettingsCard), new PropertyMetadata(false));
|
||||
|
||||
public bool IsOn
|
||||
{
|
||||
get => (bool)GetValue(IsOnProperty);
|
||||
set => SetValue(IsOnProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsOnProperty = DependencyProperty.Register(nameof(IsOn), typeof(bool), typeof(ModuleSettingsCard), new PropertyMetadata(false));
|
||||
|
||||
public event RoutedEventHandler? Click;
|
||||
|
||||
private void OnSettingsCardClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Click?.Invoke(this, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -165,7 +165,6 @@
|
||||
Margin="8,0,12,12"
|
||||
ItemsSource="{x:Bind ViewModel.QuickAccessItems, Mode=OneWay}"
|
||||
Visibility="{x:Bind ViewModel.QuickAccessItems.Count, Mode=OneWay, Converter={StaticResource DoubleToVisibilityConverter}}" />
|
||||
|
||||
<TextBlock
|
||||
x:Uid="NoActionsToShow"
|
||||
Margin="12"
|
||||
|
||||
Reference in New Issue
Block a user