improved menu performance and folder browser fix
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
using System.Windows;
|
|
||||||
|
|
||||||
using static mpvnet.Global;
|
using static mpvnet.Global;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace mpvnet
|
namespace mpvnet
|
||||||
{
|
{
|
||||||
@@ -88,7 +88,7 @@ namespace mpvnet
|
|||||||
public static void Open_DVD_Or_BD_Folder()
|
public static void Open_DVD_Or_BD_Folder()
|
||||||
{
|
{
|
||||||
App.InvokeOnMainThread(new Action(() => {
|
App.InvokeOnMainThread(new Action(() => {
|
||||||
using (var dialog = new BetterFolderBrowser())
|
using (var dialog = new FolderBrowser())
|
||||||
if (dialog.ShowDialog() == DialogResult.OK)
|
if (dialog.ShowDialog() == DialogResult.OK)
|
||||||
Core.LoadDiskFolder(dialog.SelectedPath);
|
Core.LoadDiskFolder(dialog.SelectedPath);
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1,94 +1,48 @@
|
|||||||
|
|
||||||
// https://github.com/Willy-Kimura/BetterFolderBrowser
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace mpvnet
|
namespace mpvnet
|
||||||
{
|
{
|
||||||
public partial class BetterFolderBrowser : CommonDialog
|
public partial class FolderBrowser : CommonDialog
|
||||||
{
|
{
|
||||||
IContainer components = null;
|
|
||||||
BetterFolderBrowserDialog _dialog = new BetterFolderBrowserDialog();
|
BetterFolderBrowserDialog _dialog = new BetterFolderBrowserDialog();
|
||||||
|
|
||||||
public BetterFolderBrowser()
|
public string SelectedPath {
|
||||||
{
|
get => _dialog.FileName;
|
||||||
InitializeComponent();
|
set => _dialog.FileName = value;
|
||||||
SetDefaults();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
components.Dispose();
|
|
||||||
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitializeComponent() => components = new Container();
|
|
||||||
|
|
||||||
public string Title
|
|
||||||
{
|
|
||||||
get { return _dialog.Title; }
|
|
||||||
set { _dialog.Title = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string RootFolder
|
|
||||||
{
|
|
||||||
get { return _dialog.InitialDirectory; }
|
|
||||||
set { _dialog.InitialDirectory = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Multiselect
|
|
||||||
{
|
|
||||||
get { return _dialog.AllowMultiselect; }
|
|
||||||
set { _dialog.AllowMultiselect = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string SelectedPath => _dialog.FileName;
|
|
||||||
|
|
||||||
public string[] SelectedPaths => _dialog.FileNames;
|
|
||||||
|
|
||||||
public string SelectedFolder => _dialog.FileName;
|
|
||||||
|
|
||||||
public string[] SelectedFolders => _dialog.FileNames;
|
|
||||||
|
|
||||||
void SetDefaults()
|
|
||||||
{
|
|
||||||
_dialog.AllowMultiselect = false;
|
|
||||||
_dialog.Title = "Please select a folder...";
|
|
||||||
_dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public new DialogResult ShowDialog()
|
public new DialogResult ShowDialog()
|
||||||
{
|
{
|
||||||
DialogResult result;
|
return _dialog.ShowDialog(GetOwnerHandle()) ? DialogResult.OK : DialogResult.Cancel;
|
||||||
|
|
||||||
if (_dialog.ShowDialog(IntPtr.Zero))
|
|
||||||
result = DialogResult.OK;
|
|
||||||
else
|
|
||||||
result = DialogResult.Cancel;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public new DialogResult ShowDialog(IWin32Window owner)
|
public static IntPtr GetOwnerHandle()
|
||||||
{
|
{
|
||||||
DialogResult result;
|
IntPtr foregroundWindow = GetForegroundWindow();
|
||||||
|
GetWindowThreadProcessId(foregroundWindow, out var procID);
|
||||||
|
|
||||||
if (_dialog.ShowDialog(owner.Handle))
|
using (var proc = Process.GetCurrentProcess())
|
||||||
result = DialogResult.OK;
|
if (proc.Id == procID)
|
||||||
else
|
return foregroundWindow;
|
||||||
result = DialogResult.Cancel;
|
|
||||||
|
|
||||||
return result;
|
return IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern IntPtr GetForegroundWindow();
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||||
|
|
||||||
protected override bool RunDialog(IntPtr hwndOwner) => _dialog.ShowDialog(hwndOwner);
|
protected override bool RunDialog(IntPtr hwndOwner) => _dialog.ShowDialog(hwndOwner);
|
||||||
|
|
||||||
public override void Reset() => SetDefaults();
|
public override void Reset() { }
|
||||||
|
|
||||||
class BetterFolderBrowserDialog
|
class BetterFolderBrowserDialog
|
||||||
{
|
{
|
||||||
@@ -105,27 +59,14 @@ namespace mpvnet
|
|||||||
ofd.Multiselect = false;
|
ofd.Multiselect = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AllowMultiselect {
|
public string FileName {
|
||||||
get { return ofd.Multiselect; }
|
get => ofd.FileName;
|
||||||
set { ofd.Multiselect = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string[] FileNames => ofd.FileNames;
|
|
||||||
|
|
||||||
public string InitialDirectory {
|
|
||||||
get { return ofd.InitialDirectory; }
|
|
||||||
set {
|
set {
|
||||||
ofd.InitialDirectory = (value == null || value.Length == 0) ? Environment.CurrentDirectory : value;
|
if (Directory.Exists(value))
|
||||||
|
ofd.InitialDirectory = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Title {
|
|
||||||
get { return ofd.Title; }
|
|
||||||
set { ofd.Title = (value == null) ? "Select a folder" : value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public string FileName => ofd.FileName;
|
|
||||||
|
|
||||||
public bool ShowDialog() => ShowDialog(IntPtr.Zero);
|
public bool ShowDialog() => ShowDialog(IntPtr.Zero);
|
||||||
|
|
||||||
public bool ShowDialog(IntPtr hWndOwner)
|
public bool ShowDialog(IntPtr hWndOwner)
|
||||||
@@ -201,7 +142,7 @@ namespace mpvnet
|
|||||||
string[] names = typeName.Split('.');
|
string[] names = typeName.Split('.');
|
||||||
|
|
||||||
if (names.Length > 0)
|
if (names.Length > 0)
|
||||||
type = m_asmb.GetType((m_ns + Convert.ToString(".")) + names[0]);
|
type = m_asmb.GetType(m_ns + Convert.ToString(".") + names[0]);
|
||||||
|
|
||||||
for (int i = 1; i < names.Length; i++)
|
for (int i = 1; i < names.Length; i++)
|
||||||
type = type.GetNestedType(names[i], BindingFlags.NonPublic);
|
type = type.GetNestedType(names[i], BindingFlags.NonPublic);
|
||||||
@@ -9,12 +9,13 @@ using System.Runtime.InteropServices;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using System.Windows.Forms.Integration;
|
using System.Windows.Forms.Integration;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
|
||||||
|
using MsgBoxEx;
|
||||||
using WpfControls = System.Windows.Controls;
|
using WpfControls = System.Windows.Controls;
|
||||||
|
|
||||||
using static mpvnet.Native;
|
using static mpvnet.Native;
|
||||||
using static mpvnet.Global;
|
using static mpvnet.Global;
|
||||||
using MsgBoxEx;
|
|
||||||
|
|
||||||
namespace mpvnet
|
namespace mpvnet
|
||||||
{
|
{
|
||||||
@@ -639,6 +640,8 @@ namespace mpvnet
|
|||||||
try {
|
try {
|
||||||
App.RunTask(() => {
|
App.RunTask(() => {
|
||||||
MenuAutoResetEvent.WaitOne();
|
MenuAutoResetEvent.WaitOne();
|
||||||
|
System.Windows.Application.Current.Dispatcher.Invoke(
|
||||||
|
DispatcherPriority.Background, new Action(delegate { }));
|
||||||
Core.Command(item.Command);
|
Core.Command(item.Command);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.ComponentModel;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Drawing.Text;
|
using System.Drawing.Text;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Interop;
|
using System.Windows.Interop;
|
||||||
@@ -101,8 +102,8 @@ namespace MsgBoxEx
|
|||||||
|
|
||||||
public static IntPtr GetOwnerHandle()
|
public static IntPtr GetOwnerHandle()
|
||||||
{
|
{
|
||||||
IntPtr foregroundWindow = Native.GetForegroundWindow();
|
IntPtr foregroundWindow = GetForegroundWindow();
|
||||||
Native.GetWindowThreadProcessId(foregroundWindow, out var procID);
|
GetWindowThreadProcessId(foregroundWindow, out var procID);
|
||||||
|
|
||||||
using (var proc = Process.GetCurrentProcess())
|
using (var proc = Process.GetCurrentProcess())
|
||||||
if (proc.Id == procID)
|
if (proc.Id == procID)
|
||||||
@@ -111,6 +112,12 @@ namespace MsgBoxEx
|
|||||||
return IntPtr.Zero;
|
return IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern IntPtr GetForegroundWindow();
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
||||||
|
|
||||||
public static Color ColorFromString(string colorString)
|
public static Color ColorFromString(string colorString)
|
||||||
{
|
{
|
||||||
Color wpfColor = Colors.Black;
|
Color wpfColor = Colors.Black;
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
|
|
||||||
using System;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace MsgBoxEx
|
|
||||||
{
|
|
||||||
class Native
|
|
||||||
{
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
public static extern IntPtr GetForegroundWindow();
|
|
||||||
|
|
||||||
[DllImport("user32.dll")]
|
|
||||||
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -62,13 +62,12 @@ namespace DynamicGUI
|
|||||||
switch (StringSetting.Type)
|
switch (StringSetting.Type)
|
||||||
{
|
{
|
||||||
case "folder":
|
case "folder":
|
||||||
using (var d = new WinForms.FolderBrowserDialog())
|
using (FolderBrowser fb = new FolderBrowser())
|
||||||
{
|
{
|
||||||
d.Description = "Choose a folder.";
|
fb.SelectedPath = ValueTextBox.Text;
|
||||||
d.SelectedPath = ValueTextBox.Text;
|
|
||||||
|
|
||||||
if (d.ShowDialog() == WinForms.DialogResult.OK)
|
if (fb.ShowDialog() == WinForms.DialogResult.OK)
|
||||||
ValueTextBox.Text = d.SelectedPath;
|
ValueTextBox.Text = fb.SelectedPath;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "color":
|
case "color":
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Misc\App.cs" />
|
<Compile Include="Misc\App.cs" />
|
||||||
<Compile Include="Misc\BetterFolderBrowser.cs">
|
<Compile Include="Misc\FolderBrowser.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Misc\Common.cs" />
|
<Compile Include="Misc\Common.cs" />
|
||||||
@@ -112,7 +112,6 @@
|
|||||||
<Compile Include="WPF\MsgBox\MsgBoxExtendedFunctionality.cs" />
|
<Compile Include="WPF\MsgBox\MsgBoxExtendedFunctionality.cs" />
|
||||||
<Compile Include="WPF\MsgBox\MsgBoxUrl.cs" />
|
<Compile Include="WPF\MsgBox\MsgBoxUrl.cs" />
|
||||||
<Compile Include="WPF\MsgBox\MsgEnumerators.cs" />
|
<Compile Include="WPF\MsgBox\MsgEnumerators.cs" />
|
||||||
<Compile Include="WPF\MsgBox\Native.cs" />
|
|
||||||
<Compile Include="WPF\RelayCommand.cs" />
|
<Compile Include="WPF\RelayCommand.cs" />
|
||||||
<Compile Include="Misc\CSharpScriptHost.cs" />
|
<Compile Include="Misc\CSharpScriptHost.cs" />
|
||||||
<Compile Include="Misc\Extension.cs" />
|
<Compile Include="Misc\Extension.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user