Compare commits

...

5 Commits

Author SHA1 Message Date
Niels Laute
12baf82f0f Merge branch 'main' into copilot/fix-shortcut-conflict-window 2026-01-08 12:01:22 +01:00
Davide Giacometti
0add0d5d48 remove useless comments and please spellcheck 2025-10-16 21:23:58 +02:00
Davide Giacometti
77c7688bdd minor changes and further improvements 2025-10-16 21:01:50 +02:00
copilot-swe-agent[bot]
58e3e362f8 Implement singleton pattern for ShortcutConflictWindow
- Added static fields and methods in App.xaml.cs to manage ShortcutConflictWindow singleton
- Updated ShortcutConflictWindow to clear singleton reference on close
- Modified all three locations that create ShortcutConflictWindow to check for existing instance
- If window already exists, activate it instead of creating a new one

Co-authored-by: davidegiacometti <25966642+davidegiacometti@users.noreply.github.com>
2025-10-16 18:37:36 +00:00
copilot-swe-agent[bot]
bdecd75099 Initial plan 2025-10-16 18:26:37 +00:00
5 changed files with 71 additions and 21 deletions

View File

@@ -8,7 +8,6 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using ManagedCommon;
using Microsoft.PowerToys.Settings.UI.Helpers;
@@ -16,11 +15,11 @@ using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
using Microsoft.PowerToys.Settings.UI.SerializationContext;
using Microsoft.PowerToys.Settings.UI.Services;
using Microsoft.PowerToys.Settings.UI.SettingsXAML.Controls.Dashboard;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.PowerToys.Telemetry;
using Microsoft.UI.Xaml;
using PowerToys.Interop;
using Windows.UI.Popups;
using WinRT.Interop;
using WinUIEx;
@@ -339,6 +338,8 @@ namespace Microsoft.PowerToys.Settings.UI
private static MainWindow settingsWindow;
private static OobeWindow oobeWindow;
private static FlyoutWindow flyoutWindow;
private static ShortcutConflictWindow shortcutConflictWindow;
public static void ClearSettingsWindow()
{
@@ -365,6 +366,26 @@ namespace Microsoft.PowerToys.Settings.UI
oobeWindow = null;
}
public static void ClearFlyoutWindow()
{
flyoutWindow = null;
}
public static ShortcutConflictWindow GetShortcutConflictWindow()
{
return shortcutConflictWindow;
}
public static void SetShortcutConflictWindow(ShortcutConflictWindow window)
{
shortcutConflictWindow = window;
}
public static void ClearShortcutConflictWindow()
{
shortcutConflictWindow = null;
}
public static Type GetPage(string settingWindow)
{
switch (settingWindow)

View File

@@ -2,10 +2,7 @@
// 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 System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Microsoft.PowerToys.Settings.UI.Library.HotkeyConflicts;
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
using Microsoft.PowerToys.Settings.UI.SettingsXAML.Controls.Dashboard;
@@ -154,11 +151,16 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
ConflictCount = this.ConflictCount,
});
// Create and show the new window instead of dialog
var conflictWindow = new ShortcutConflictWindow();
// Show the window
conflictWindow.Activate();
if (App.GetShortcutConflictWindow() == null)
{
var conflictWindow = new ShortcutConflictWindow();
App.SetShortcutConflictWindow(conflictWindow);
conflictWindow.Activate();
}
else
{
App.GetShortcutConflictWindow().Activate();
}
}
}
}

View File

@@ -2,16 +2,13 @@
// 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 CommunityToolkit.WinUI.Controls;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
using Microsoft.PowerToys.Settings.UI.Library.HotkeyConflicts;
using Microsoft.PowerToys.Settings.UI.Services;
using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.PowerToys.Settings.UI.Views;
using Microsoft.UI;
using Microsoft.UI.Windowing;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
@@ -26,7 +23,11 @@ namespace Microsoft.PowerToys.Settings.UI.SettingsXAML.Controls.Dashboard
public ShortcutConflictWindow()
{
App.ThemeService.ThemeChanged += OnThemeChanged;
App.ThemeService.ApplyTheme();
var settingsUtils = SettingsUtils.Default;
ViewModel = new ShortcutConflictViewModel(
settingsUtils,
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
@@ -50,6 +51,11 @@ namespace Microsoft.PowerToys.Settings.UI.SettingsXAML.Controls.Dashboard
ViewModel.OnPageLoaded();
}
private void OnThemeChanged(object sender, ElementTheme theme)
{
WindowHelper.SetTheme(this, theme);
}
private void CenterOnScreen()
{
var displayArea = DisplayArea.GetFromWindowId(this.AppWindow.Id, DisplayAreaFallback.Nearest);
@@ -126,7 +132,16 @@ namespace Microsoft.PowerToys.Settings.UI.SettingsXAML.Controls.Dashboard
private void WindowEx_Closed(object sender, WindowEventArgs args)
{
App.ClearShortcutConflictWindow();
ViewModel?.Dispose();
var mainWindow = App.GetSettingsWindow();
if (mainWindow != null)
{
mainWindow.CloseHiddenWindow();
}
App.ThemeService.ThemeChanged -= OnThemeChanged;
}
private void Window_Activated_SetIcon(object sender, WindowActivatedEventArgs args)

View File

@@ -9,7 +9,6 @@ using System.Linq;
using CommunityToolkit.WinUI;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.HotkeyConflicts;
using Microsoft.PowerToys.Settings.UI.Library.Telemetry.Events;
using Microsoft.PowerToys.Settings.UI.Services;
using Microsoft.PowerToys.Settings.UI.SettingsXAML.Controls.Dashboard;
@@ -300,9 +299,16 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
// Close the current shortcut dialog
shortcutDialog.Hide();
// Create and show the ShortcutConflictWindow
var conflictWindow = new ShortcutConflictWindow();
conflictWindow.Activate();
if (App.GetShortcutConflictWindow() == null)
{
var conflictWindow = new ShortcutConflictWindow();
App.SetShortcutConflictWindow(conflictWindow);
conflictWindow.Activate();
}
else
{
App.GetShortcutConflictWindow().Activate();
}
}
private void UpdateKeyVisualStyles()

View File

@@ -7,7 +7,6 @@ using global::PowerToys.GPOWrapper;
using Microsoft.PowerToys.Settings.UI.Helpers;
using Microsoft.PowerToys.Settings.UI.Library;
using Microsoft.PowerToys.Settings.UI.Library.HotkeyConflicts;
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
using Microsoft.PowerToys.Settings.UI.OOBE.Enums;
using Microsoft.PowerToys.Settings.UI.OOBE.ViewModel;
using Microsoft.PowerToys.Settings.UI.Services;
@@ -280,9 +279,16 @@ namespace Microsoft.PowerToys.Settings.UI.OOBE.Views
return;
}
// Create and show the shortcut conflict window
var conflictWindow = new ShortcutConflictWindow();
conflictWindow.Activate();
if (App.GetShortcutConflictWindow() == null)
{
var conflictWindow = new ShortcutConflictWindow();
App.SetShortcutConflictWindow(conflictWindow);
conflictWindow.Activate();
}
else
{
App.GetShortcutConflictWindow().Activate();
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)