From 51eb8b95a96c4b7c61f1d5aeaa28673295a27c76 Mon Sep 17 00:00:00 2001 From: Yusyuriv Date: Fri, 19 Apr 2024 19:37:35 +0600 Subject: [PATCH] Replace Window with ContentDialog when editing a hotkey in HotkeyControl2 --- Flow.Launcher/HotkeyControl2.xaml.cs | 30 ++--- Flow.Launcher/HotkeyControl2Dialog.xaml | 130 +++++++++------------ Flow.Launcher/HotkeyControl2Dialog.xaml.cs | 22 ++-- 3 files changed, 87 insertions(+), 95 deletions(-) diff --git a/Flow.Launcher/HotkeyControl2.xaml.cs b/Flow.Launcher/HotkeyControl2.xaml.cs index fb05f2418..46a39021b 100644 --- a/Flow.Launcher/HotkeyControl2.xaml.cs +++ b/Flow.Launcher/HotkeyControl2.xaml.cs @@ -1,6 +1,7 @@ #nullable enable using System.Collections.ObjectModel; +using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using Flow.Launcher.Core.Resource; @@ -11,13 +12,16 @@ namespace Flow.Launcher { public partial class HotkeyControl2 { - public string WindowTitle { get; set; } = string.Empty; + public string WindowTitle { + get { return (string)GetValue(WindowTitleProperty); } + set { SetValue(WindowTitleProperty, value); } + } public static readonly DependencyProperty WindowTitleProperty = DependencyProperty.Register( nameof(WindowTitle), typeof(string), typeof(HotkeyControl2), - new PropertyMetadata(default(string)) + new PropertyMetadata(string.Empty) ); /// @@ -107,29 +111,25 @@ namespace Flow.Launcher public void GetNewHotkey(object sender, RoutedEventArgs e) + { + OpenHotkeyDialog(); + } + + private async Task OpenHotkeyDialog() { if (!string.IsNullOrEmpty(Hotkey)) { HotKeyMapper.RemoveHotkey(Hotkey); } - var owner = Window.GetWindow(this); - var width = owner?.ActualWidth ?? 0; - var height = owner?.ActualHeight ?? 0; - var w = new HotkeyControl2Dialog - { - Title = WindowTitle, - Owner = owner, - Width = width, - Height = height - }; - w.ShowDialog(); - switch (w.ResultType) + var dialog = new HotkeyControl2Dialog(Hotkey, WindowTitle); + await dialog.ShowAsync(); + switch (dialog.ResultType) { case HotkeyControl2Dialog.EResultType.Cancel: return; case HotkeyControl2Dialog.EResultType.Save: - SetHotkey(w.ResultValue); + SetHotkey(dialog.ResultValue); break; case HotkeyControl2Dialog.EResultType.Reset: ResetToDefault(); diff --git a/Flow.Launcher/HotkeyControl2Dialog.xaml b/Flow.Launcher/HotkeyControl2Dialog.xaml index fa33049fe..dcec4c2d1 100644 --- a/Flow.Launcher/HotkeyControl2Dialog.xaml +++ b/Flow.Launcher/HotkeyControl2Dialog.xaml @@ -1,76 +1,62 @@ - - - - - - - - - - - - - - - + + + 0 + 0 + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - -