menu performance

This commit is contained in:
Frank Skare
2021-08-24 15:20:54 +02:00
parent 970dfc069d
commit c08ddd5057
2 changed files with 14 additions and 7 deletions

View File

@@ -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);

View File

@@ -99,10 +99,7 @@ namespace mpvnet
var items = new Dictionary<string, CommandItem>();
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);