fixed crash issue.

fixed sorting string display issue.
fixed status update issue

Signed-off-by: Shawn Yuan (from Dev Box) <shuaiyuan@microsoft.com>
This commit is contained in:
Shawn Yuan (from Dev Box)
2025-12-04 13:26:11 +08:00
parent a40be6f9be
commit 3381e82fc1
15 changed files with 189 additions and 31 deletions

View File

@@ -32,6 +32,7 @@ public sealed partial class AppsListPage : Page
_context = context;
ViewModel = context.AllAppsViewModel;
DataContext = ViewModel;
ViewModel.RefreshSettings();
}
}

View File

@@ -57,4 +57,12 @@ public sealed partial class ShellPage : Page
var context = new FlyoutNavigationContext(_launcherViewModel, _allAppsViewModel, _coordinator);
ContentFrame.Navigate(typeof(LaunchPage), context, new SlideNavigationTransitionInfo { Effect = SlideNavigationTransitionEffect.FromLeft });
}
internal void RefreshIfAppsList()
{
if (ContentFrame.Content is AppsListPage appsListPage)
{
appsListPage.ViewModel?.RefreshSettings();
}
}
}

View File

@@ -239,6 +239,7 @@ public sealed partial class MainWindow : WindowEx, IDisposable
Activate();
_isVisible = true;
EnsureGlobalMouseHook();
ShellHost.RefreshIfAppsList();
}
private void OnActivated(object sender, WindowActivatedEventArgs args)

View File

@@ -15,6 +15,8 @@ public interface IQuickAccessCoordinator
void OpenSettings();
void OpenSettingsForModule(ModuleType moduleType);
void OpenGeneralSettingsForUpdates();
Task<bool> ShowDocumentationAsync();

View File

@@ -43,6 +43,43 @@ internal sealed class QuickAccessCoordinator : IQuickAccessCoordinator, IDisposa
_window.RequestHide();
}
public void OpenSettingsForModule(ModuleType moduleType)
{
var settingsWindow = moduleType switch
{
ModuleType.AdvancedPaste => SettingsDeepLink.SettingsWindow.AdvancedPaste,
ModuleType.AlwaysOnTop => SettingsDeepLink.SettingsWindow.AlwaysOnTop,
ModuleType.Awake => SettingsDeepLink.SettingsWindow.Awake,
ModuleType.ColorPicker => SettingsDeepLink.SettingsWindow.ColorPicker,
ModuleType.CmdPal => SettingsDeepLink.SettingsWindow.CmdPal,
ModuleType.CropAndLock => SettingsDeepLink.SettingsWindow.CropAndLock,
ModuleType.EnvironmentVariables => SettingsDeepLink.SettingsWindow.EnvironmentVariables,
ModuleType.FancyZones => SettingsDeepLink.SettingsWindow.FancyZones,
ModuleType.FileLocksmith => SettingsDeepLink.SettingsWindow.FileLocksmith,
ModuleType.Hosts => SettingsDeepLink.SettingsWindow.Hosts,
ModuleType.ImageResizer => SettingsDeepLink.SettingsWindow.ImageResizer,
ModuleType.KeyboardManager => SettingsDeepLink.SettingsWindow.KBM,
ModuleType.LightSwitch => SettingsDeepLink.SettingsWindow.LightSwitch,
ModuleType.MouseWithoutBorders => SettingsDeepLink.SettingsWindow.MouseWithoutBorders,
ModuleType.NewPlus => SettingsDeepLink.SettingsWindow.NewPlus,
ModuleType.Peek => SettingsDeepLink.SettingsWindow.Peek,
ModuleType.PowerRename => SettingsDeepLink.SettingsWindow.PowerRename,
ModuleType.PowerLauncher => SettingsDeepLink.SettingsWindow.PowerLauncher,
ModuleType.PowerAccent => SettingsDeepLink.SettingsWindow.PowerAccent,
ModuleType.RegistryPreview => SettingsDeepLink.SettingsWindow.RegistryPreview,
ModuleType.MeasureTool => SettingsDeepLink.SettingsWindow.MeasureTool,
ModuleType.ShortcutGuide => SettingsDeepLink.SettingsWindow.ShortcutGuide,
ModuleType.PowerOCR => SettingsDeepLink.SettingsWindow.PowerOCR,
ModuleType.Workspaces => SettingsDeepLink.SettingsWindow.Workspaces,
ModuleType.ZoomIt => SettingsDeepLink.SettingsWindow.ZoomIt,
ModuleType.FindMyMouse or ModuleType.MouseHighlighter or ModuleType.MouseJump or ModuleType.MousePointerCrosshairs or ModuleType.CursorWrap => SettingsDeepLink.SettingsWindow.MouseUtils,
_ => SettingsDeepLink.SettingsWindow.Dashboard,
};
SettingsDeepLink.OpenSettings(settingsWindow, true);
_window.RequestHide();
}
public void OpenGeneralSettingsForUpdates()
{
SettingsDeepLink.OpenSettings(SettingsDeepLink.SettingsWindow.Overview, true);

View File

@@ -13,6 +13,7 @@ using Microsoft.PowerToys.QuickAccess.Services;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.Library.ViewModels.Commands;
using Microsoft.UI.Dispatching;
using Microsoft.Windows.ApplicationModel.Resources;
@@ -71,6 +72,14 @@ public sealed class AllAppsViewModel : Observable
});
}
public void RefreshSettings()
{
if (_settingsRepository.ReloadSettings())
{
OnSettingsChanged(_settingsRepository.SettingsConfig);
}
}
private void RefreshFlyoutMenuItems()
{
var desiredItems = new List<FlyoutMenuItem>();
@@ -109,6 +118,7 @@ public sealed class AllAppsViewModel : Observable
Tag = moduleType,
Icon = ModuleHelper.GetModuleTypeFluentIconName(moduleType),
EnabledChangedCallback = EnabledChangedOnUI,
ClickCommand = new RelayCommand(() => _coordinator.OpenSettingsForModule(moduleType)),
});
}
}

View File

@@ -6,33 +6,30 @@ using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Controls;
namespace Microsoft.PowerToys.QuickAccess.ViewModels;
public sealed class FlyoutMenuItem : INotifyPropertyChanged
public sealed class FlyoutMenuItem : ModuleListItem
{
private bool _visible;
private bool _isEnabled;
public string Label { get; set; } = string.Empty;
public string Icon { get; set; } = string.Empty;
public string ToolTip { get; set; } = string.Empty;
public ModuleType Tag { get; set; }
public bool IsLocked { get; set; }
public bool IsEnabled
public new ModuleType Tag
{
get => _isEnabled;
get => (ModuleType)(base.Tag ?? ModuleType.PowerLauncher);
set => base.Tag = value;
}
public override bool IsEnabled
{
get => base.IsEnabled;
set
{
if (_isEnabled != value)
if (base.IsEnabled != value)
{
_isEnabled = value;
OnPropertyChanged();
base.IsEnabled = value;
EnabledChangedCallback?.Invoke(this);
}
}
@@ -52,11 +49,4 @@ public sealed class FlyoutMenuItem : INotifyPropertyChanged
}
}
}
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}

View File

@@ -30,7 +30,6 @@
Title="{x:Bind Title, Mode=OneWay}"
MinWidth="400"
Padding="0"
VerticalAlignment="Top"
DividerVisibility="Collapsed">
<controls:Card.TitleContent>
<Button
@@ -71,7 +70,7 @@
<tkcontrols:SettingsCard
MinHeight="0"
Padding="12,4,12,4"
tk:FrameworkElementExtensions.AncestorType="ItemsRepeater"
tk:FrameworkElementExtensions.AncestorType="controls:ModuleList"
Background="Transparent"
BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
BorderThickness="0,1,0,0"

View File

@@ -9,9 +9,13 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
{
public sealed partial class ModuleList : UserControl
{
private object? _sortButton;
public ModuleList()
{
this.InitializeComponent();
_sortButton = ModulesCard.TitleContent;
UpdateHeaderVisibility();
}
public bool IsItemClickable
@@ -44,7 +48,29 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
set => SetValue(TitleProperty, value);
}
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(ModuleList), new PropertyMetadata(default(string)));
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(ModuleList), new PropertyMetadata(default(string), OnTitleChanged));
private static void OnTitleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((ModuleList)d).UpdateHeaderVisibility();
}
private void UpdateHeaderVisibility()
{
if (ModulesCard == null)
{
return;
}
if (string.IsNullOrEmpty(Title))
{
ModulesCard.TitleContent = null;
}
else
{
ModulesCard.TitleContent = _sortButton;
}
}
private void SortAlphabetical_Click(object sender, RoutedEventArgs e)
{
@@ -58,8 +84,10 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
private void OnSettingsCardClick(object sender, RoutedEventArgs e)
{
// TO DO:
// ViewModel.DashboardListItemClick(sender);
if (sender is FrameworkElement element && element.DataContext is ModuleListItem item)
{
item.ClickCommand?.Execute(item.Tag);
}
}
}
}

View File

@@ -21,11 +21,11 @@
BorderThickness="{x:Bind BorderThickness, Mode=OneWay}"
CornerRadius="{x:Bind CornerRadius, Mode=OneWay}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" MinHeight="44" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid x:Name="TitleGrid">
<Grid x:Name="TitleGrid" MinHeight="44">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />

View File

@@ -11,9 +11,9 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
{
public static readonly DependencyProperty TitleContentProperty = DependencyProperty.Register(nameof(TitleContent), typeof(object), typeof(Card), new PropertyMetadata(defaultValue: null, OnVisualPropertyChanged));
public object TitleContent
public object? TitleContent
{
get => (object)GetValue(TitleContentProperty);
get => (object?)GetValue(TitleContentProperty);
set => SetValue(TitleContentProperty, value);
}

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Dashboard_SortBy_ToolTip.Text" xml:space="preserve">
<value>Sort utilities</value>
</data>
<data name="Dashboard_SortAlphabetical.Text" xml:space="preserve">
<value>Alphabetically</value>
</data>
<data name="Dashboard_SortByStatus.Text" xml:space="preserve">
<value>By status</value>
</data>
<data name="Dashboard_SortBy.[using:Microsoft.UI.Xaml.Automation]AutomationProperties.Name" xml:space="preserve">
<value>Sort utilities</value>
</data>
</root>

View File

@@ -89,6 +89,10 @@ namespace Microsoft.PowerToys.Settings.UI
{
ModuleHelper.SetIsModuleEnabled(generalSettingsConfig, moduleType, isEnabled);
var outgoing = new OutGoingGeneralSettings(generalSettingsConfig);
// Save settings to file
new SettingsUtils().SaveSettings(generalSettingsConfig.ToJsonString());
this.DispatcherQueue.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.Normal, () =>
{
ShellPage.SendDefaultIPCMessage(outgoing.ToString());

View File

@@ -228,6 +228,7 @@
x:Uid="UtilitiesHeader"
Grid.RowSpan="2"
Grid.Column="1"
VerticalAlignment="Top"
ItemsSource="{x:Bind ViewModel.AllModules, Mode=OneWay}"
SortOption="{x:Bind ViewModel.DashboardSortOrder, Mode=TwoWay, Converter={StaticResource EnumToModuleListSortOptionConverter}}" />
</Grid>

View File

@@ -82,6 +82,10 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
{
generalSettingsConfig.DashboardSortOrder = value;
OutGoingGeneralSettings outgoing = new OutGoingGeneralSettings(generalSettingsConfig);
// Save settings to file
new SettingsUtils().SaveSettings(generalSettingsConfig.ToJsonString());
SendConfigMSG(outgoing.ToString());
SortModuleList();
}