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.Native;
using static mpvnet.Global; using static mpvnet.Global;
using System.Threading;
namespace mpvnet namespace mpvnet
{ {
public partial class MainForm : Form public partial class MainForm : Form
{ {
public AutoResetEvent MenuAutoResetEvent { get; } = new AutoResetEvent(false);
public ElementHost CommandPaletteHost { get; set; } public ElementHost CommandPaletteHost { get; set; }
public static MainForm Instance { get; set; } public static MainForm Instance { get; set; }
public static IntPtr Hwnd { get; set; } public static IntPtr Hwnd { get; set; }
@@ -608,8 +610,6 @@ namespace mpvnet
public void BuildMenu() public void BuildMenu()
{ {
ContextMenu = new WpfControls.ContextMenu();
string content = File.ReadAllText(Core.InputConfPath); string content = File.ReadAllText(Core.InputConfPath);
var items = CommandItem.GetItems(content); var items = CommandItem.GetItems(content);
@@ -636,7 +636,10 @@ namespace mpvnet
{ {
menuItem.Click += (sender, args) => { menuItem.Click += (sender, args) => {
try { try {
App.RunTask(() => {
MenuAutoResetEvent.WaitOne();
Core.Command(item.Command); Core.Command(item.Command);
});
} }
catch (Exception ex) { catch (Exception ex) {
Msg.ShowException(ex); Msg.ShowException(ex);
@@ -997,6 +1000,8 @@ namespace mpvnet
WPF.Init(); WPF.Init();
App.UpdateWpfColors(); App.UpdateWpfColors();
ContextMenu = new WpfControls.ContextMenu();
ContextMenu.Closed += ContextMenu_Closed;
BuildMenu(); BuildMenu();
System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
@@ -1008,6 +1013,11 @@ namespace mpvnet
WasShown = true; WasShown = true;
} }
void ContextMenu_Closed(object sender, System.Windows.RoutedEventArgs e)
{
MenuAutoResetEvent.Set();
}
protected override void OnResize(EventArgs e) protected override void OnResize(EventArgs e)
{ {
base.OnResize(e); base.OnResize(e);

View File

@@ -99,9 +99,6 @@ namespace mpvnet
var items = new Dictionary<string, CommandItem>(); var items = new Dictionary<string, CommandItem>();
foreach (CommandItem i in CommandItem.Items) 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;
} }