diff --git a/docs/Changelog.md b/docs/Changelog.md index 45f854d..4f831d4 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -2,9 +2,13 @@ 5.4.9.1 (2021-0?-??) ==================== +- Everything search removed to keep the core player lightweight, + it might come back as user script or extension. +- Fancy new command palette implementation, it's now integrated into the main window. +- Playlist is now shown with the new command palette and not using the OSD. - New media info command: `Ctrl+m script-message mpv.net show-media-info #menu: View > Show Media Info` - Context menu font render quality fix. -- Context menu and `cycle-audio` command support external audio and subtitle tracks. +- Context menu and `cycle-audio` command supports external audio and subtitle tracks. - Fix window size not being saved. - libmpv shinchiro 2021-06-06 diff --git a/src/DynamicGUI/OptionSettingControl.xaml.cs b/src/DynamicGUI/OptionSettingControl.xaml.cs index b5a408c..3cdbaa4 100644 --- a/src/DynamicGUI/OptionSettingControl.xaml.cs +++ b/src/DynamicGUI/OptionSettingControl.xaml.cs @@ -29,9 +29,7 @@ namespace DynamicGUI Link.SetURL(optionSetting.URL); } - public Theme Theme { - get => Theme.Current; - } + public Theme Theme => Theme.Current; string _SearchableText; diff --git a/src/DynamicGUI/StringSettingControl.xaml.cs b/src/DynamicGUI/StringSettingControl.xaml.cs index b933e8b..82bdbae 100644 --- a/src/DynamicGUI/StringSettingControl.xaml.cs +++ b/src/DynamicGUI/StringSettingControl.xaml.cs @@ -35,9 +35,7 @@ namespace DynamicGUI LinkTextBlock.Visibility = Visibility.Collapsed; } - public Theme Theme { - get => Theme.Current; - } + public Theme Theme => Theme.Current; string _SearchableText; diff --git a/src/Misc/App.cs b/src/Misc/App.cs index 096c98e..e291917 100644 --- a/src/Misc/App.cs +++ b/src/Misc/App.cs @@ -12,8 +12,6 @@ namespace mpvnet { public static class App { - public static event Action ShowCommandPalette; - public static List TempFiles { get; } = new List(); public static string ConfPath { get => Core.ConfigFolder + "mpvnet.conf"; } diff --git a/src/Misc/Commands.cs b/src/Misc/Commands.cs index f17b94b..9604ba1 100644 --- a/src/Misc/Commands.cs +++ b/src/Misc/Commands.cs @@ -44,7 +44,6 @@ namespace mpvnet case "show-input-editor": ShowDialog(typeof(InputWindow)); break; case "show-keys": ShowTextWithEditor("input-key-list", Core.get_property_string("input-key-list").Replace(",", BR)); break; case "show-media-info": ShowMediaInfo(args); break; - case "show-media-search": ShowDialog(typeof(EverythingWindow)); break; case "show-playlist": ShowPlaylist(); break; case "show-profiles": ShowTextWithEditor("profile-list", mpvHelp.GetProfiles()); break; case "show-properties": ShowProperties(); break; diff --git a/src/Misc/CorePlayer.cs b/src/Misc/CorePlayer.cs index f248419..0afbfd9 100644 --- a/src/Misc/CorePlayer.cs +++ b/src/Misc/CorePlayer.cs @@ -388,7 +388,7 @@ namespace mpvnet if (LogMessage != null || LogMessageAsync != null) { string msg = $"[{ConvertFromUtf8(data.prefix)}] {ConvertFromUtf8(data.text)}"; - InvokeAsync(LogMessageAsync, data.log_level, msg); + InvokeAsync(LogMessageAsync, data.log_level, msg); LogMessage?.Invoke(data.log_level, msg); } } diff --git a/src/Misc/Misc.cs b/src/Misc/Misc.cs index 60cd03d..79f87fa 100644 --- a/src/Misc/Misc.cs +++ b/src/Misc/Misc.cs @@ -242,7 +242,14 @@ namespace mpvnet public static IEnumerable GetItems() { - return CommandItem.Items.Select(i => new CommandPaletteItem() { Text = i.Display, SecondaryText = i.Input }); + var aaa = CommandItem.Items.ToArray(); + return CommandItem.Items + .Where(i => i.Command != "") + .Select(i => new CommandPaletteItem() { + Text = i.Display, + SecondaryText = i.Input, + Action = () => Core.command(i.Command) + }); } } } diff --git a/src/Resources/input.conf.txt b/src/Resources/input.conf.txt index eb372e0..18a6b70 100644 --- a/src/Resources/input.conf.txt +++ b/src/Resources/input.conf.txt @@ -34,7 +34,6 @@ Alt+s script-message mpv.net load-sub #menu: Open > Load external subtitle files... _ ignore #menu: Open > - _ script-message mpv.net open-files append #menu: Open > Add files to playlist... - F3 script-message mpv.net show-media-search #menu: Open > Show media search... _ ignore #menu: Open > - _ ignore #menu: Open > Recent diff --git a/src/WPF/AboutWindow.xaml.cs b/src/WPF/AboutWindow.xaml.cs index 149f12d..359200e 100644 --- a/src/WPF/AboutWindow.xaml.cs +++ b/src/WPF/AboutWindow.xaml.cs @@ -16,8 +16,6 @@ namespace mpvnet protected override void OnPreviewKeyDown(KeyEventArgs e) => Close(); protected override void OnMouseDown(MouseButtonEventArgs e) => Close(); - public Theme Theme { - get => Theme.Current; - } + public Theme Theme => Theme.Current; } } diff --git a/src/WPF/CommandPaletteControl.xaml b/src/WPF/CommandPaletteControl.xaml index 3326325..433aa84 100644 --- a/src/WPF/CommandPaletteControl.xaml +++ b/src/WPF/CommandPaletteControl.xaml @@ -13,7 +13,8 @@ > - + + diff --git a/src/WPF/CommandPaletteControl.xaml.cs b/src/WPF/CommandPaletteControl.xaml.cs index 67cb36a..dd614dd 100644 --- a/src/WPF/CommandPaletteControl.xaml.cs +++ b/src/WPF/CommandPaletteControl.xaml.cs @@ -14,6 +14,7 @@ namespace mpvnet { public ICollectionView CollectionView { get; set; } public ICommand EscapeCommand { get; } + public ICommand ExecuteCommand { get; } public CollectionViewSource CollectionViewSource { get; } public ObservableCollection Items { get; } = new ObservableCollection(); @@ -27,7 +28,8 @@ namespace mpvnet MainListView.ItemsSource = CollectionView; EscapeCommand = new RelayCommand(OnEscapeCommand); - SearchControl.SearchTextBox.PreviewKeyDown += SearchControl_PreviewKeyDown; + ExecuteCommand = new RelayCommand(OnExecuteCommand); + SearchControl.SearchTextBox.PreviewKeyDown += SearchTextBox_PreviewKeyDown; SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged; SearchControl.SearchTextBox.BorderBrush = Theme.Background; SearchControl.HideClearButton = true; @@ -39,7 +41,7 @@ namespace mpvnet SelectFirst(); } - void SearchControl_PreviewKeyDown(object sender, KeyEventArgs e) + void SearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e) { switch (e.Key) { @@ -66,16 +68,18 @@ namespace mpvnet MainListView.ScrollIntoView(MainListView.SelectedItem); } break; - case Key.Enter: - Execute(); - break; } } - void OnEscapeCommand(object param) - { - MainForm.Instance.HideCommandPalette(); - } + void MainListView_SizeChanged(object sender, SizeChangedEventArgs e) => AdjustHeight(); + + void MainListView_MouseUp(object sender, MouseButtonEventArgs e) => Execute(); + + void OnEscapeCommand(object param) => MainForm.Instance.HideCommandPalette(); + + void OnExecuteCommand(object param) => Execute(); + + void OnLoaded(object sender, RoutedEventArgs e) => Keyboard.Focus(SearchControl.SearchTextBox); public Theme Theme => Theme.Current; @@ -94,7 +98,10 @@ namespace mpvnet public void SelectFirst() { if (MainListView.Items.Count > 0) + { MainListView.SelectedIndex = 0; + MainListView.ScrollIntoView(MainListView.SelectedItem); + } } void Execute() @@ -104,14 +111,10 @@ namespace mpvnet CommandPaletteItem item = MainListView.SelectedItem as CommandPaletteItem; MainForm.Instance.HideCommandPalette(); item.Action.Invoke(); + MainForm.Instance.Voodoo(); } } - void OnLoaded(object sender, RoutedEventArgs e) - { - Keyboard.Focus(SearchControl.SearchTextBox); - } - public void SetItems(IEnumerable items) { Items.Clear(); @@ -120,21 +123,11 @@ namespace mpvnet Items.Add(i); } - void MainListView_SizeChanged(object sender, SizeChangedEventArgs e) - { - AdjustHeight(); - } - public void AdjustHeight() { double actualHeight = SearchControl.ActualHeight + MainListView.ActualHeight; int dpi = Native.GetDPI(MainForm.Instance.Handle); MainForm.Instance.CommandPaletteHost.Height = (int)(actualHeight / 96.0 * dpi); } - - void MainListView_MouseUp(object sender, MouseButtonEventArgs e) - { - Execute(); - } } } diff --git a/src/WPF/ConfWindow.xaml.cs b/src/WPF/ConfWindow.xaml.cs index 3302ee8..31a1af0 100644 --- a/src/WPF/ConfWindow.xaml.cs +++ b/src/WPF/ConfWindow.xaml.cs @@ -35,9 +35,7 @@ namespace mpvnet FilterListBox.SelectedItem = SearchControl.Text.TrimEnd(':'); } - public Theme Theme { - get => Theme.Current; - } + public Theme Theme => Theme.Current; void LoadSettings() { @@ -75,10 +73,10 @@ namespace mpvnet { base.OnClosed(e); App.Settings.ConfigEditorSearch = SearchControl.Text; - + if (InitialContent == GetCompareString()) return; - + File.WriteAllText(Core.ConfPath, GetContent("mpv")); File.WriteAllText(App.ConfPath, GetContent("mpvnet")); @@ -89,7 +87,7 @@ namespace mpvnet if (item.File == "mpv") { Core.ProcessProperty(item.Name, item.Value); - + try { Core.set_property_string(item.Name, item.Value, true); diff --git a/src/WPF/EverythingWindow.xaml b/src/WPF/EverythingWindow.xaml deleted file mode 100644 index 6816e5a..0000000 --- a/src/WPF/EverythingWindow.xaml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/WPF/EverythingWindow.xaml.cs b/src/WPF/EverythingWindow.xaml.cs deleted file mode 100644 index 5ea1ef5..0000000 --- a/src/WPF/EverythingWindow.xaml.cs +++ /dev/null @@ -1,169 +0,0 @@ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices; -using System.Text; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Input; -using System.Windows.Interop; - -using static mpvnet.Global; - -namespace mpvnet -{ - public partial class EverythingWindow : Window - { - public EverythingWindow() - { - InitializeComponent(); - DataContext = this; - } - - public Theme Theme { - get => Theme.Current; - } - - const int EVERYTHING_REQUEST_FILE_NAME = 0x00000001; - const int EVERYTHING_REQUEST_PATH = 0x00000002; - - [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(); - - 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; - } - - 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; - } - - void FilterTextBox_PreviewKeyDown(object sender, KeyEventArgs e) - { - switch (e.Key) - { - case Key.Up: - { - int index = ListView.SelectedIndex; - - if (--index < 0) - index = 0; - - ListView.SelectedIndex = index; - ListView.ScrollIntoView(ListView.SelectedItem); - } - break; - case Key.Down: - { - int index = ListView.SelectedIndex; - - 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; - } - } - - void ListView_PreviewKeyDown(object sender, KeyEventArgs e) - { - if (e.Key == Key.Escape) - Close(); - - if (e.Key == Key.Enter) - Execute(); - } - - void Execute() - { - if (ListView.SelectedItem != null) - Core.LoadFiles(new[] { ListView.SelectedItem as string }, true, Keyboard.Modifiers == ModifierKeys.Control); - - Keyboard.Focus(FilterTextBox); - } - - void ListView_MouseUp(object sender, MouseButtonEventArgs e) => Execute(); - - void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e) - { - string searchtext = FilterTextBox.Text; - App.RunTask(() => Search(searchtext)); - } - - object LockObject = new object(); - - void Search(string searchText) - { - lock (LockObject) - { - try - { - List items = new List(); - StringBuilder sb = new StringBuilder(500); - Everything_SetSearch(searchText); - Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME | EVERYTHING_REQUEST_PATH); - Everything_Query(true); - uint count = Everything_GetNumResults(); - - for (uint i = 0; i < count; i++) - { - Everything_GetResultFullPathName(i, sb, (uint)sb.Capacity); - string ext = sb.ToString().Ext(); - - if (CorePlayer.AudioTypes.Contains(ext) || CorePlayer.VideoTypes.Contains(ext) || CorePlayer.ImageTypes.Contains(ext)) - items.Add(sb.ToString()); - - if (items.Count > 100) - break; - } - - Application.Current.Dispatcher.Invoke(() => { - ListView.ItemsSource = items; - SelectFirst(); - }); - } - catch (Exception) - { - Msg.ShowError("Search query failed.", - "The search feature depends on [Everything](https://www.voidtools.com) being installed."); - } - } - } - } -} diff --git a/src/WPF/InputWindow.xaml.cs b/src/WPF/InputWindow.xaml.cs index ea80588..0d8c2e3 100644 --- a/src/WPF/InputWindow.xaml.cs +++ b/src/WPF/InputWindow.xaml.cs @@ -26,14 +26,11 @@ namespace mpvnet DataGrid.SelectionMode = DataGridSelectionMode.Single; CollectionViewSource collectionViewSource = new CollectionViewSource() { Source = CommandItem.Items }; CollectionView = collectionViewSource.View; - var yourCostumFilter = new Predicate(item => Filter((CommandItem)item)); - CollectionView.Filter = yourCostumFilter; + CollectionView.Filter = new Predicate(item => Filter((CommandItem)item)); DataGrid.ItemsSource = CollectionView; } - public Theme Theme { - get => Theme.Current; - } + public Theme Theme => Theme.Current; void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e) { diff --git a/src/WPF/LearnWindow.xaml.cs b/src/WPF/LearnWindow.xaml.cs index fdef6f1..e7a0696 100644 --- a/src/WPF/LearnWindow.xaml.cs +++ b/src/WPF/LearnWindow.xaml.cs @@ -30,9 +30,7 @@ namespace mpvnet DataContext = this; } - public Theme Theme { - get => Theme.Current; - } + public Theme Theme => Theme.Current; [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern short GetKeyState(int keyCode); diff --git a/src/WPF/SetupWindow.xaml.cs b/src/WPF/SetupWindow.xaml.cs index 883a8a9..8aac09b 100644 --- a/src/WPF/SetupWindow.xaml.cs +++ b/src/WPF/SetupWindow.xaml.cs @@ -19,9 +19,7 @@ namespace mpvnet DataContext = this; } - public Theme Theme { - get => Theme.Current; - } + public Theme Theme => Theme.Current; static BitmapSource _ShieldIcon; @@ -45,7 +43,7 @@ namespace mpvnet using (Process proc = new Process()) { proc.StartInfo.FileName = WinForms.Application.ExecutablePath; - proc.StartInfo.Arguments = "--reg-file-assoc " + String.Join(" ", extensions); + proc.StartInfo.Arguments = "--reg-file-assoc " + string.Join(" ", extensions); proc.StartInfo.Verb = "runas"; proc.StartInfo.UseShellExecute = true; proc.Start(); diff --git a/src/WinForms/MainForm.cs b/src/WinForms/MainForm.cs index 2864223..22d4fa6 100644 --- a/src/WinForms/MainForm.cs +++ b/src/WinForms/MainForm.cs @@ -29,7 +29,7 @@ namespace mpvnet int TaskbarButtonCreatedMessage; int ShownTickCount; - Taskbar Taskbar; + Taskbar Taskbar; bool WasMaximized; public MainForm() @@ -52,7 +52,7 @@ namespace mpvnet Core.observe_property("window-maximized", PropChangeWindowMaximized); Core.observe_property("window-minimized", PropChangeWindowMinimized); - + Core.observe_property_bool("pause", PropChangePause); Core.observe_property_bool("fullscreen", PropChangeFullscreen); Core.observe_property_bool("ontop", PropChangeOnTop); @@ -65,7 +65,7 @@ namespace mpvnet Core.observe_property_string("title", PropChangeTitle); Core.observe_property_int("edition", PropChangeEdition); - + if (Core.GPUAPI != "vulkan") Core.ProcessCommandLine(false); @@ -73,7 +73,7 @@ namespace mpvnet Application.ThreadException += (sender, e) => App.ShowException(e.Exception); TaskbarButtonCreatedMessage = RegisterWindowMessage("TaskbarButtonCreated"); - + ContextMenu = new ContextMenuStripEx(components); ContextMenu.Opened += ContextMenu_Opened; ContextMenu.Opening += ContextMenu_Opening; @@ -99,7 +99,7 @@ namespace mpvnet FormBorderStyle = FormBorderStyle.None; Point pos = App.Settings.WindowPosition; - + if ((pos.X != 0 || pos.Y != 0) && App.RememberWindowPosition) { Left = pos.X - Width / 2; @@ -168,6 +168,8 @@ namespace mpvnet bool IsFullscreen => WindowState == FormWindowState.Maximized && FormBorderStyle == FormBorderStyle.None; + bool IsCommandPaletteVissible() => CommandPaletteHost != null && CommandPaletteHost.Visible; + bool IsMouseInOSC() { Point pos = PointToClient(MousePosition); @@ -179,8 +181,6 @@ namespace mpvnet return pos.Y > ClientSize.Height * 0.85 || pos.Y < top; } - bool IsCommandPaletteVissible() => CommandPaletteHost != null && CommandPaletteHost.Visible; - void ContextMenu_Opening(object sender, CancelEventArgs e) { lock (Core.MediaTracks) @@ -273,7 +273,7 @@ namespace mpvnet foreach (string path in App.Settings.RecentFiles) MenuItem.Add(recent.DropDownItems, path, () => Core.LoadFiles(new[] { path }, true, Control.ModifierKeys.HasFlag(Keys.Control))); - + recent.DropDownItems.Add(new ToolStripSeparator()); MenuItem mi = new MenuItem("Clear List"); mi.Action = () => App.Settings.RecentFiles.Clear(); @@ -316,7 +316,7 @@ namespace mpvnet if (mi.DropDownItems.Count > 0) { MenuItem val = FindMenuItem(text, mi.DropDownItems); - + if (val != null) return val; } @@ -338,7 +338,7 @@ namespace mpvnet return; } } - + Screen screen = Screen.FromControl(this); int autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * Core.Autofit); @@ -348,7 +348,7 @@ namespace mpvnet Core.VideoSize = new Size((int)(autoFitHeight * (16 / 9f)), autoFitHeight); Size videoSize = Core.VideoSize; - + int height = videoSize.Height; int width = videoSize.Width; @@ -626,6 +626,12 @@ namespace mpvnet void SetTitle() => BeginInvoke(new Action(() => Text = Core.expand(Title))); + public void Voodoo() + { + Message m = new Message() { Msg = 0x0202 }; // WM_LBUTTONUP + SendMessage(Handle, m.Msg, m.WParam, m.LParam); + } + void SaveWindowProperties() { if (WindowState == FormWindowState.Normal) @@ -677,8 +683,6 @@ namespace mpvnet protected override void WndProc(ref Message m) { - //Debug.WriteLine(m); - switch (m.Msg) { case 0x100: // WM_KEYDOWN @@ -916,8 +920,7 @@ namespace mpvnet protected override void OnActivated(EventArgs e) { base.OnActivated(e); - Message m = new Message() { Msg = 0x0202 }; // WM_LBUTTONUP - SendMessage(Handle, m.Msg, m.WParam, m.LParam); + Voodoo(); } protected override void OnShown(EventArgs e) @@ -1044,6 +1047,12 @@ namespace mpvnet base.OnKeyDown(e); } + protected override void OnLayout(LayoutEventArgs args) + { + base.OnLayout(args); + AdjustCommandPaletteLeftAndWidth(); + } + public void ShowCommandPalette() { if (CommandPaletteHost == null) @@ -1082,11 +1091,5 @@ namespace mpvnet CommandPaletteHost.Left = (ClientSize.Width - CommandPaletteHost.Size.Width) / 2; } - - protected override void OnLayout(LayoutEventArgs args) - { - base.OnLayout(args); - AdjustCommandPaletteLeftAndWidth(); - } } } diff --git a/src/mpv.net.csproj b/src/mpv.net.csproj index 9c5279e..a18bab3 100644 --- a/src/mpv.net.csproj +++ b/src/mpv.net.csproj @@ -104,10 +104,6 @@ MSBuild:Compile Designer - - MSBuild:Compile - Designer - Designer MSBuild:Compile @@ -163,9 +159,6 @@ SetupWindow.xaml - - EverythingWindow.xaml - ConfWindow.xaml