From c08ddd5057d5c5b3cd47f99cb36d9601f367dc81 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Tue, 24 Aug 2021 15:20:54 +0200 Subject: [PATCH] menu performance --- src/Misc/MainForm.cs | 16 +++++++++++++--- src/WPF/InputWindow.xaml.cs | 5 +---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Misc/MainForm.cs b/src/Misc/MainForm.cs index ddb330c..53ec93b 100644 --- a/src/Misc/MainForm.cs +++ b/src/Misc/MainForm.cs @@ -13,11 +13,13 @@ using WpfControls = System.Windows.Controls; using static mpvnet.Native; using static mpvnet.Global; +using System.Threading; namespace mpvnet { public partial class MainForm : Form { + public AutoResetEvent MenuAutoResetEvent { get; } = new AutoResetEvent(false); public ElementHost CommandPaletteHost { get; set; } public static MainForm Instance { get; set; } public static IntPtr Hwnd { get; set; } @@ -608,8 +610,6 @@ namespace mpvnet public void BuildMenu() { - ContextMenu = new WpfControls.ContextMenu(); - string content = File.ReadAllText(Core.InputConfPath); var items = CommandItem.GetItems(content); @@ -636,7 +636,10 @@ namespace mpvnet { menuItem.Click += (sender, args) => { try { - Core.Command(item.Command); + App.RunTask(() => { + MenuAutoResetEvent.WaitOne(); + Core.Command(item.Command); + }); } catch (Exception ex) { Msg.ShowException(ex); @@ -997,6 +1000,8 @@ namespace mpvnet WPF.Init(); App.UpdateWpfColors(); + ContextMenu = new WpfControls.ContextMenu(); + ContextMenu.Closed += ContextMenu_Closed; BuildMenu(); System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); @@ -1008,6 +1013,11 @@ namespace mpvnet WasShown = true; } + void ContextMenu_Closed(object sender, System.Windows.RoutedEventArgs e) + { + MenuAutoResetEvent.Set(); + } + protected override void OnResize(EventArgs e) { base.OnResize(e); diff --git a/src/WPF/InputWindow.xaml.cs b/src/WPF/InputWindow.xaml.cs index 0d8c2e3..5a226df 100644 --- a/src/WPF/InputWindow.xaml.cs +++ b/src/WPF/InputWindow.xaml.cs @@ -99,10 +99,7 @@ namespace mpvnet var items = new Dictionary(); foreach (CommandItem i in CommandItem.Items) - if (items.ContainsKey(i.Input) && i.Input != "") - Msg.ShowInfo($"Duplicate found:{BR2 + i.Input}: {i.Path + BR2}{items[i.Input].Input}: {items[i.Input].Path + BR2}Please note that you can chain multiple commands in the same line by using a semicolon as separator.", "Duplicate Found"); - else - items[i.Input] = i; + items[i.Input] = i; } void Window_Loaded(object sender, RoutedEventArgs e) => Keyboard.Focus(SearchControl.SearchTextBox);