Full support for select.lua
select.lua is a new simple command palette script embedded into mpv/libmpv. In the context menu select.lua features can be found under 'View > On Screen Menu'. https://github.com/mpv-player/mpv/blob/master/player/lua/select.lua
This commit is contained in:
@@ -55,19 +55,19 @@ public class GuiCommand
|
||||
["show-media-info"] = ShowMediaInfo,
|
||||
["show-menu"] = args => ShowMenu?.Invoke(),
|
||||
["show-profiles"] = args => Msg.ShowInfo(Player.GetProfiles()),
|
||||
["show-properties"] = args => ShowProperties(),
|
||||
["show-properties"] = args => Player.Command("script-binding select/show-properties"),
|
||||
["show-protocols"] = args => ShowProtocols(),
|
||||
["window-scale"] = args => WindowScaleNet?.Invoke(float.Parse(args[0], CultureInfo.InvariantCulture)),
|
||||
|
||||
|
||||
// deprecated
|
||||
["show-recent"] = args => ShowRemoved(), // deprecated
|
||||
["show-playlist"] = args => ShowPlaylist(), // deprecated
|
||||
["quick-bookmark"] = args => QuickBookmark(), // deprecated
|
||||
["show-history"] = args => ShowHistory(), // deprecated
|
||||
["show-command-palette"] = args => ShowCommandPalette(), // deprecated
|
||||
["show-audio-tracks"] = args => ShowTracks(), // deprecated
|
||||
["show-subtitle-tracks"] = args => ShowTracks(), // deprecated
|
||||
["show-playlist"] = args => Player.Command("script-binding select/select-playlist"), // deprecated
|
||||
["show-command-palette"] = args => Player.Command("script-binding select/select-binding"), // deprecated
|
||||
["show-audio-tracks"] = args => Player.Command("script-binding select/select-aid"), // deprecated
|
||||
["show-subtitle-tracks"] = args => Player.Command("script-binding select/select-sid"), // deprecated
|
||||
};
|
||||
|
||||
void ShowDialog(Type winType)
|
||||
@@ -161,9 +161,6 @@ public class GuiCommand
|
||||
ShowTextWithEditor("Input Commands", header + sb.ToString());
|
||||
}
|
||||
|
||||
void ShowProperties() =>
|
||||
ShowTextWithEditor("Properties", Core.GetPropertyString("property-list").Replace(",", BR));
|
||||
|
||||
void ShowKeys() =>
|
||||
ShowTextWithEditor("Keys", Core.GetPropertyString("input-key-list").Replace(",", BR));
|
||||
|
||||
@@ -384,28 +381,6 @@ public class GuiCommand
|
||||
Msg.ShowInfo(_("mpv.net was successfully removed from the Path environment variable."));
|
||||
}
|
||||
|
||||
// deprecated
|
||||
void ShowTracks() =>
|
||||
Msg.ShowInfo(_("This feature was removed, but there are user scripts:") + BR2 +
|
||||
"https://github.com/stax76/mpv-scripts#command_palette" + BR +
|
||||
"https://github.com/stax76/mpv-scripts#search_menu" + BR +
|
||||
"https://github.com/tomasklaen/uosc");
|
||||
|
||||
// deprecated
|
||||
void ShowPlaylist() =>
|
||||
Msg.ShowInfo(_("This feature was removed, but there are user scripts:") + BR2 +
|
||||
"https://github.com/stax76/mpv-scripts#command_palette" + BR +
|
||||
"https://github.com/stax76/mpv-scripts#search_menu" + BR +
|
||||
"https://github.com/tomasklaen/uosc" + BR +
|
||||
"https://github.com/jonniek/mpv-playlistmanager");
|
||||
|
||||
// deprecated
|
||||
void ShowCommandPalette() =>
|
||||
Msg.ShowInfo(_("This feature was removed, but there are user scripts:") + BR2 +
|
||||
"https://github.com/stax76/mpv-scripts#command_palette" + BR +
|
||||
"https://github.com/stax76/mpv-scripts#search_menu" + BR +
|
||||
"https://github.com/tomasklaen/uosc");
|
||||
|
||||
// deprecated
|
||||
void QuickBookmark() =>
|
||||
Msg.ShowInfo(_("This feature was removed, but there are user scripts:") + BR2 +
|
||||
@@ -419,13 +394,3 @@ public class GuiCommand
|
||||
// deprecated
|
||||
void ShowRemoved() => Msg.ShowInfo(_("This feature was removed."));
|
||||
}
|
||||
|
||||
|
||||
//public void ShowCommandPalette()
|
||||
//{
|
||||
// MainForm.Instance?.BeginInvoke(() => {
|
||||
// CommandPalette.Instance.SetItems(CommandPalette.GetItems());
|
||||
// MainForm.Instance.ShowCommandPalette();
|
||||
// CommandPalette.Instance.SelectFirst();
|
||||
// });
|
||||
//}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
|
||||
using MpvNet.Windows.WPF.Controls;
|
||||
|
||||
namespace MpvNet.Windows.UI;
|
||||
|
||||
public class CommandPalette
|
||||
{
|
||||
public static CommandPaletteControl Instance { get; } = new CommandPaletteControl();
|
||||
|
||||
public static IEnumerable<CommandPaletteItem> GetItems()
|
||||
{
|
||||
return InputHelp.GetBindingsFromContent(App.InputConf.GetContent())
|
||||
.Where(i => i.Command != "")
|
||||
.Select(i => new CommandPaletteItem()
|
||||
{
|
||||
Text = i.Comment,
|
||||
SecondaryText = i.Input,
|
||||
Action = () => Core.Command(i.Command),
|
||||
Binding = i
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
|
||||
namespace MpvNet.Windows.UI;
|
||||
|
||||
public class CommandPaletteItem
|
||||
{
|
||||
public CommandPaletteItem() { }
|
||||
|
||||
public CommandPaletteItem(string text, Action action)
|
||||
{
|
||||
Text = text;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public CommandPaletteItem(string text, string secondaryText, Action action)
|
||||
{
|
||||
Text = text;
|
||||
Action = action;
|
||||
SecondaryText = secondaryText;
|
||||
}
|
||||
|
||||
public string Text { get; set; } = "";
|
||||
public string SecondaryText { get; set; } = "";
|
||||
public Action? Action { get; set; }
|
||||
public Binding? Binding { get; set; }
|
||||
}
|
||||
@@ -1,127 +0,0 @@
|
||||
<UserControl
|
||||
x:Class="MpvNet.Windows.WPF.Controls.CommandPaletteControl"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:controls="clr-namespace:MpvNet.Windows.WPF.Controls"
|
||||
mc:Ignorable="d"
|
||||
|
||||
FontSize="13"
|
||||
Loaded="OnLoaded"
|
||||
Background="#111111"
|
||||
>
|
||||
|
||||
<UserControl.InputBindings>
|
||||
<KeyBinding Gesture="Esc" Command="{Binding EscapeCommand}"/>
|
||||
<KeyBinding Gesture="Enter" Command="{Binding ExecuteCommand}"/>
|
||||
</UserControl.InputBindings>
|
||||
|
||||
<Border Name="MainBorder"
|
||||
BorderThickness="1,0,1,1"
|
||||
CornerRadius="0,0,5,5"
|
||||
Padding="0,0,0,5"
|
||||
BorderBrush="{Binding Theme.MenuHighlight}"
|
||||
Background="{Binding Theme.Background}"
|
||||
SnapsToDevicePixels="True"
|
||||
>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Border BorderBrush="{Binding Theme.Heading}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="3"
|
||||
Margin="7"
|
||||
>
|
||||
|
||||
<controls:SearchControl
|
||||
HintText="Search"
|
||||
x:Name="SearchControl"
|
||||
Grid.ColumnSpan="2"
|
||||
Padding="1,1,1,0"
|
||||
/>
|
||||
</Border>
|
||||
|
||||
<ListView
|
||||
Name="MainListView"
|
||||
Grid.Row="1"
|
||||
Foreground="{Binding Theme.Foreground}"
|
||||
Background="{Binding Theme.Background}"
|
||||
BorderThickness="0"
|
||||
MaxHeight="202"
|
||||
SizeChanged="MainListView_SizeChanged"
|
||||
MouseUp="MainListView_MouseUp"
|
||||
>
|
||||
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListBoxItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
|
||||
<Setter Property="Height" Value="25"></Setter>
|
||||
<Setter Property="BorderThickness" Value="0"></Setter>
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="{x:Type ListBoxItem}">
|
||||
<Border x:Name="BD"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Background="{TemplateBinding Background}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="true">
|
||||
|
||||
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="IsMouseOver" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="BD" Value="{DynamicResource HighlightBrush}" />
|
||||
</MultiTrigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="Selector.IsSelectionActive" Value="False" />
|
||||
<Condition Property="IsSelected" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Background" TargetName="BD" Value="{DynamicResource BorderBrush}" />
|
||||
</MultiTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
|
||||
<Style.Resources>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="CornerRadius" Value="3"/>
|
||||
</Style>
|
||||
</Style.Resources>
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition />
|
||||
<ColumnDefinition />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<TextBlock Text="{Binding Text}"></TextBlock>
|
||||
|
||||
<TextBlock
|
||||
Grid.Column="1"
|
||||
Text="{Binding SecondaryText}"
|
||||
HorizontalAlignment="Right"
|
||||
/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</Grid>
|
||||
</Border>
|
||||
</UserControl>
|
||||
@@ -1,150 +0,0 @@
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
using MpvNet.Windows.UI;
|
||||
using MpvNet.Windows.WinForms;
|
||||
|
||||
namespace MpvNet.Windows.WPF.Controls;
|
||||
|
||||
public partial class CommandPaletteControl : UserControl
|
||||
{
|
||||
public ICollectionView CollectionView { get; set; }
|
||||
public CollectionViewSource CollectionViewSource { get; }
|
||||
public ObservableCollection<CommandPaletteItem> Items { get; } = new ObservableCollection<CommandPaletteItem>();
|
||||
|
||||
public CommandPaletteControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
CollectionViewSource = new CollectionViewSource() { Source = Items };
|
||||
CollectionView = CollectionViewSource.View;
|
||||
CollectionView.Filter = new Predicate<object>(item => Filter((CommandPaletteItem)item));
|
||||
MainListView.ItemsSource = CollectionView;
|
||||
|
||||
SearchControl.SearchTextBox.PreviewKeyDown += SearchTextBox_PreviewKeyDown;
|
||||
SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged;
|
||||
SearchControl.HideClearButton = true;
|
||||
|
||||
if (Environment.OSVersion.Version < new Version(10, 0))
|
||||
MainBorder.CornerRadius = new CornerRadius(0);
|
||||
}
|
||||
|
||||
void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
CollectionView.Refresh();
|
||||
SelectFirst();
|
||||
}
|
||||
|
||||
void SearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Up:
|
||||
{
|
||||
int index = MainListView.SelectedIndex;
|
||||
index -= 1;
|
||||
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
|
||||
MainListView.SelectedIndex = index;
|
||||
MainListView.ScrollIntoView(MainListView.SelectedItem);
|
||||
}
|
||||
break;
|
||||
case Key.Down:
|
||||
{
|
||||
int index = MainListView.SelectedIndex;
|
||||
|
||||
if (++index > MainListView.Items.Count - 1)
|
||||
index = MainListView.Items.Count - 1;
|
||||
|
||||
MainListView.SelectedIndex = index;
|
||||
MainListView.ScrollIntoView(MainListView.SelectedItem);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainListView_SizeChanged(object sender, SizeChangedEventArgs e) => AdjustHeight();
|
||||
|
||||
void MainListView_MouseUp(object sender, MouseButtonEventArgs e) => ExecuteInternal();
|
||||
|
||||
[RelayCommand]
|
||||
void Escape(object param) => MainForm.Instance?.HideCommandPalette();
|
||||
|
||||
[RelayCommand]
|
||||
void Execute() => ExecuteInternal();
|
||||
|
||||
void OnLoaded(object sender, RoutedEventArgs e) => Keyboard.Focus(SearchControl.SearchTextBox);
|
||||
|
||||
public Theme Theme => Theme.Current!;
|
||||
|
||||
bool Filter(CommandPaletteItem item)
|
||||
{
|
||||
string filter = SearchControl.SearchTextBox.Text.ToLower();
|
||||
|
||||
if (item.Binding != null)
|
||||
{
|
||||
//if (item.CommandItem.Alias.ContainsEx(filter))
|
||||
// return true;
|
||||
|
||||
if (filter.Length == 1)
|
||||
return item.Binding.Input.ToLower()
|
||||
.Replace("ctrl+", "")
|
||||
.Replace("shift+", "")
|
||||
.Replace("alt+", "") == filter.ToLower();
|
||||
|
||||
if (item.Binding.Command.ToLower().Contains(filter))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (filter == "" || item.Text.ToLower().Contains(filter) ||
|
||||
item.SecondaryText.ToLower().Contains(filter))
|
||||
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void SelectFirst()
|
||||
{
|
||||
if (MainListView.Items.Count > 0)
|
||||
{
|
||||
MainListView.SelectedIndex = 0;
|
||||
MainListView.ScrollIntoView(MainListView.SelectedItem);
|
||||
}
|
||||
}
|
||||
|
||||
void ExecuteInternal()
|
||||
{
|
||||
if (MainListView.SelectedItem != null)
|
||||
{
|
||||
CommandPaletteItem? item = MainListView.SelectedItem as CommandPaletteItem;
|
||||
MainForm.Instance?.HideCommandPalette();
|
||||
item?.Action?.Invoke();
|
||||
//MainForm.Instance.Voodoo(); //TODO: Voodoo
|
||||
}
|
||||
}
|
||||
|
||||
public void SetItems(IEnumerable<CommandPaletteItem> items)
|
||||
{
|
||||
Items.Clear();
|
||||
|
||||
foreach (var i in items)
|
||||
Items.Add(i);
|
||||
}
|
||||
|
||||
public void AdjustHeight()
|
||||
{
|
||||
double actualHeight = SearchControl.ActualHeight + MainListView.ActualHeight + 5 + 16;
|
||||
int dpi = MainForm.GetDpi(MainForm.Instance!.Handle);
|
||||
MainForm.Instance.CommandPaletteHost.Height = (int)(actualHeight / 96.0 * dpi);
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ public partial class MainForm : Form
|
||||
{
|
||||
public SnapManager SnapManager = new SnapManager();
|
||||
public IntPtr MpvWindowHandle { get; set; }
|
||||
public ElementHost? CommandPaletteHost { get; set; }
|
||||
public bool WasShown { get; set; }
|
||||
public static MainForm? Instance { get; set; }
|
||||
WpfControls.ContextMenu ContextMenu { get; } = new WpfControls.ContextMenu();
|
||||
@@ -280,8 +279,6 @@ public partial class MainForm : Form
|
||||
pos.Y > ClientSize.Height * 0.78;
|
||||
}
|
||||
|
||||
bool IsCommandPaletteVissible() => CommandPaletteHost != null && CommandPaletteHost.Visible;
|
||||
|
||||
void UpdateMenu()
|
||||
{
|
||||
Player.UpdateExternalTracks();
|
||||
@@ -1254,8 +1251,7 @@ public partial class MainForm : Form
|
||||
else if ((Environment.TickCount - _lastCursorChanged > 1500 ||
|
||||
Environment.TickCount - _lastCursorChanged > 5000) &&
|
||||
ClientRectangle.Contains(PointToClient(MousePosition)) &&
|
||||
ActiveForm == this && !ContextMenu.IsVisible && !IsMouseInOsc() &&
|
||||
!IsCommandPaletteVissible())
|
||||
ActiveForm == this && !ContextMenu.IsVisible && !IsMouseInOsc())
|
||||
|
||||
HideCursor();
|
||||
}
|
||||
@@ -1515,103 +1511,4 @@ public partial class MainForm : Form
|
||||
|
||||
[DllImport("DwmApi")]
|
||||
static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);
|
||||
|
||||
//protected override void OnLayout(LayoutEventArgs args)
|
||||
//{
|
||||
// base.OnLayout(args);
|
||||
// AdjustCommandPaletteLeftAndWidth();
|
||||
//}
|
||||
|
||||
//class ElementHostEx : ElementHost
|
||||
//{
|
||||
// protected override void OnHandleCreated(EventArgs e)
|
||||
// {
|
||||
// base.OnHandleCreated(e);
|
||||
// const int LWA_ColorKey = 1;
|
||||
|
||||
// if (Environment.OSVersion.Version > new Version(10, 0))
|
||||
// SetLayeredWindowAttributes(Handle, 0x111111, 255, LWA_ColorKey);
|
||||
// }
|
||||
|
||||
// protected override CreateParams CreateParams
|
||||
// {
|
||||
// get
|
||||
// {
|
||||
// CreateParams cp = base.CreateParams;
|
||||
|
||||
// if (Environment.OSVersion.Version > new Version(10, 0))
|
||||
// cp.ExStyle |= 0x00080000; // WS_EX_LAYERED
|
||||
|
||||
// cp.ExStyle |= 0x00000008; // WS_EX_TOPMOST
|
||||
|
||||
// cp.Style |= 0x04000000; //WS_CLIPSIBLINGS
|
||||
// cp.Style |= 0x02000000; //WS_CLIPCHILDREN
|
||||
|
||||
// return cp;
|
||||
// }
|
||||
// }
|
||||
|
||||
// protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// return base.ProcessCmdKey(ref msg, keyData);
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
|
||||
// [DllImport("user32.dll")]
|
||||
// public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, int dwFlags);
|
||||
//}
|
||||
|
||||
//public void ShowCommandPalette()
|
||||
//{
|
||||
// if (CommandPaletteHost == null)
|
||||
// {
|
||||
// CommandPaletteHost = new ElementHostEx();
|
||||
// CommandPaletteHost.Dock = DockStyle.Fill;
|
||||
// CommandPaletteHost.BackColor = Color.FromArgb(0x111111);
|
||||
|
||||
// AdjustCommandPaletteLeftAndWidth();
|
||||
// CommandPaletteHost.Child = CommandPalette.Instance;
|
||||
// CommandPalette.Instance.AdjustHeight();
|
||||
// Controls.Add(CommandPaletteHost);
|
||||
// CommandPaletteHost.BringToFront();
|
||||
// }
|
||||
//}
|
||||
|
||||
public void HideCommandPalette()
|
||||
{
|
||||
if (CommandPaletteHost != null)
|
||||
{
|
||||
CommandPaletteHost.Visible = false;
|
||||
|
||||
CommandPalette.Instance.Items.Clear();
|
||||
CommandPalette.Instance.SearchControl.SearchTextBox.Text = "";
|
||||
CommandPalette.Instance.UpdateLayout();
|
||||
|
||||
ActiveControl = null;
|
||||
Controls.Remove(CommandPaletteHost);
|
||||
|
||||
CommandPaletteHost.Child = null;
|
||||
CommandPaletteHost.Dispose();
|
||||
CommandPaletteHost = null;
|
||||
}
|
||||
}
|
||||
|
||||
//void AdjustCommandPaletteLeftAndWidth()
|
||||
//{
|
||||
// if (CommandPaletteHost == null)
|
||||
// return;
|
||||
|
||||
// CommandPaletteHost.Width = FontHeight * 26;
|
||||
|
||||
// if (CommandPaletteHost.Width > ClientSize.Width)
|
||||
// CommandPaletteHost.Width = ClientSize.Width;
|
||||
|
||||
// CommandPaletteHost.Left = (ClientSize.Width - CommandPaletteHost.Size.Width) / 2;
|
||||
//}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user