diff --git a/README.md b/README.md index acf79b8..f573736 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,9 @@ mpv.net bugs and requests: - playing files from rar archives caused an exception - there was a bug that caused underscores beeing removed from input like MBTN_LEFT_DBL +- the search clear button in the input editor had a render issue in dark mode +- new search feature added to search and play media files, requires + [Everything](https://www.voidtools.com) to be installed. [Default Binding]() ### 3.5 (2019-05-09) diff --git a/mpv.net/Command.cs b/mpv.net/Command.cs index a1631d4..cff035d 100644 --- a/mpv.net/Command.cs +++ b/mpv.net/Command.cs @@ -91,6 +91,15 @@ namespace mpvnet })); } + public static void show_media_search(string[] args) + { + MainForm.Instance.Invoke(new Action(() => { + var w = new EverythingWindow(); + new WindowInteropHelper(w).Owner = MainForm.Instance.Handle; + w.ShowDialog(); + })); + } + public static void show_history(string[] args) { var fp = mp.MpvConfFolder + "history.txt"; diff --git a/mpv.net/Resources/inputConf.txt b/mpv.net/Resources/inputConf.txt index 166f59d..06816de 100644 --- a/mpv.net/Resources/inputConf.txt +++ b/mpv.net/Resources/inputConf.txt @@ -26,6 +26,7 @@ o script-message mpv.net open-files #menu: Open > Open Files... u script-message mpv.net open-url #menu: Open > Open URL... + Ctrl+S script-message mpv.net show-media-search #menu: Open > Show media search... _ ignore #menu: Open > - Alt+a script-message mpv.net load-audio #menu: Open > Load external audio files... Alt+s script-message mpv.net load-sub #menu: Open > Load external subtitle files... diff --git a/mpv.net/Windows/CommandPaletteWindow.xaml.cs b/mpv.net/Windows/CommandPaletteWindow.xaml.cs index 5f5c15c..2141aa0 100644 --- a/mpv.net/Windows/CommandPaletteWindow.xaml.cs +++ b/mpv.net/Windows/CommandPaletteWindow.xaml.cs @@ -1,6 +1,8 @@ using Microsoft.Win32; using System; using System.ComponentModel; +using System.Runtime.InteropServices; +using System.Text; using System.Windows; using System.Windows.Data; using System.Windows.Input; diff --git a/mpv.net/Windows/EverythingWindow.xaml b/mpv.net/Windows/EverythingWindow.xaml new file mode 100644 index 0000000..6cb0acd --- /dev/null +++ b/mpv.net/Windows/EverythingWindow.xaml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mpv.net/Windows/EverythingWindow.xaml.cs b/mpv.net/Windows/EverythingWindow.xaml.cs new file mode 100644 index 0000000..a0789de --- /dev/null +++ b/mpv.net/Windows/EverythingWindow.xaml.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Interop; +using System.Windows.Media; + +namespace mpvnet +{ + public partial class EverythingWindow : Window + { + public EverythingWindow() + { + InitializeComponent(); + + if (App.IsDarkMode) + { + ListView.Foreground = Brushes.White; + ListView.Background = Brushes.Black; + FilterTextBox.Foreground = Brushes.White; + FilterTextBox.Background = Brushes.Black; + } + } + + const int EVERYTHING_REQUEST_FILE_NAME = 0x00000001; + const int EVERYTHING_REQUEST_PATH = 0x00000002; + const int EVERYTHING_SORT_SIZE_DESCENDING = 6; + + [DllImport("Everything.dll", CharSet = CharSet.Unicode)] + public static extern int Everything_SetSearch(string lpSearchString); + + [DllImport("Everything.dll")] + public static extern void Everything_SetRequestFlags(UInt32 dwRequestFlags); + + [DllImport("Everything.dll")] + public static extern void Everything_SetSort(UInt32 dwSortType); + + [DllImport("Everything.dll", CharSet = CharSet.Unicode)] + public static extern bool Everything_Query(bool bWait); + + [DllImport("Everything.dll", CharSet = CharSet.Unicode)] + public static extern void Everything_GetResultFullPathName(UInt32 nIndex, StringBuilder lpString, UInt32 nMaxCount); + + [DllImport("Everything.dll")] + public static extern bool Everything_GetResultSize(UInt32 nIndex, out long lpFileSize); + + [DllImport("Everything.dll")] + public static extern UInt32 Everything_GetNumResults(); + + private void Window_Loaded(object sender, RoutedEventArgs e) + { + HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle); + source.AddHook(new HwndSourceHook(WndProc)); + Keyboard.Focus(FilterTextBox); + } + + void SelectFirst() + { + if (ListView.Items.Count > 0) + ListView.SelectedIndex = 0; + } + + private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) + { + if (msg == 0x200 /*WM_MOUSEMOVE*/ && Mouse.LeftButton != MouseButtonState.Pressed) + handled = true; + return IntPtr.Zero; + } + + private void FilterTextBox_PreviewKeyDown(object sender, KeyEventArgs e) + { + switch (e.Key) + { + case Key.Up: + { + int index = ListView.SelectedIndex; + index -= 1; + if (index < 0) index = 0; + ListView.SelectedIndex = index; + ListView.ScrollIntoView(ListView.SelectedItem); + } + break; + case Key.Down: + { + int index = ListView.SelectedIndex; + index += 1; + if (index > ListView.Items.Count - 1) index = ListView.Items.Count - 1; + ListView.SelectedIndex = index; + ListView.ScrollIntoView(ListView.SelectedItem); + } + break; + case Key.Escape: + Close(); + break; + case Key.Enter: + Execute(); + break; + } + } + + private void ListView_PreviewKeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Escape) Close(); + } + + void Execute() + { + if (ListView.SelectedItem != null) + mp.LoadFiles(ListView.SelectedItem as string); + } + + private void ListView_MouseUp(object sender, MouseButtonEventArgs e) + { + Execute(); + } + + private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e) + { + string searchtext = FilterTextBox.Text; + Task.Run(() => Search(searchtext)); + } + + object LockObject = new object(); + + void Search(string searchtext) + { + lock (LockObject) + { + try + { + List items = new List(); + UInt32 i; + const int bufsize = 500; + StringBuilder buf = new StringBuilder(bufsize); + Everything_SetSearch(searchtext); + Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH); + Everything_SetSort(EVERYTHING_SORT_SIZE_DESCENDING); + Everything_Query(true); + for (i = 0; i < Everything_GetNumResults(); i++) + { + Everything_GetResultFullPathName(i, buf, bufsize); + string ext = Path.GetExtension(buf.ToString()).TrimStart('.').ToLower(); + if (App.AudioTypes.Contains(ext) || App.VideoTypes.Contains(ext)) + items.Add(buf.ToString()); + if (items.Count > 20) break; + } + Application.Current.Dispatcher.Invoke(() => { + ListView.ItemsSource = items; + SelectFirst(); + }); + throw null; + } + catch (Exception) + { + Msg.ShowError("Search query failed.", + "The search feature depends on [Everything](https://www.voidtools.com) being installed."); + } + } + } + } +} \ No newline at end of file diff --git a/mpv.net/Windows/InputWindow.xaml.cs b/mpv.net/Windows/InputWindow.xaml.cs index 7819d65..37d0abf 100644 --- a/mpv.net/Windows/InputWindow.xaml.cs +++ b/mpv.net/Windows/InputWindow.xaml.cs @@ -30,10 +30,19 @@ namespace mpvnet if (App.IsDarkMode) { Foreground = Brushes.White; + Foreground2 = Brushes.Silver; Background = Brushes.Black; } } + public Brush Foreground2 { + get { return (Brush)GetValue(Foreground2Property); } + set { SetValue(Foreground2Property, value); } + } + + public static readonly DependencyProperty Foreground2Property = + DependencyProperty.Register("Foreground2", typeof(Brush), typeof(ConfWindow), new PropertyMetadata(Brushes.DarkSlateGray)); + private void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e) { CollectionView.Refresh(); diff --git a/mpv.net/mpv.net.csproj b/mpv.net/mpv.net.csproj index 9f2902c..dc8ea9b 100644 --- a/mpv.net/mpv.net.csproj +++ b/mpv.net/mpv.net.csproj @@ -146,6 +146,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -191,6 +195,9 @@ + + EverythingWindow.xaml + CommandPaletteWindow.xaml @@ -245,7 +252,6 @@ - diff --git a/mpv.net/screenshot.jpg b/mpv.net/screenshot.jpg deleted file mode 100644 index 4eb3255..0000000 Binary files a/mpv.net/screenshot.jpg and /dev/null differ